@@ -70,12 +70,17 @@ public static void main(String... args) throws Exception {
70
70
while (directorySize (dir ) < 50_000_000 ) {
71
71
emitEvents (500_000 );
72
72
}
73
+ System .out .println ("Before setMaxSize(1_000_000)" );
74
+ fileCount (dir );
73
75
e .setMaxSize (1_000_000 );
76
+ System .out .println ("After setMaxSize(1_000_000)" );
74
77
long count = fileCount (dir );
75
- if (count > 2 ) {
76
- // Two chunks can happen when header of new chunk is written and previous
77
- // chunk is not finalized.
78
- throw new Exception ("Expected only one or two chunks with setMaxSize(1_000_000). Found " + count );
78
+ if (count > 3 ) {
79
+ // Three files can happen when:
80
+ // File 1: Header of new chunk is written to disk
81
+ // File 2: Previous chunk is not yet finalized and added to list of DiskChunks
82
+ // File 3: Previous previous file is in the list of DiskChunks.
83
+ throw new Exception ("Expected at most three chunks with setMaxSize(1_000_000). Found " + count );
79
84
}
80
85
finished .set (true );
81
86
}
@@ -94,21 +99,24 @@ private static int fileCount(Path dir) throws IOException {
94
99
System .out .println ("Files:" );
95
100
AtomicInteger count = new AtomicInteger ();
96
101
Files .list (dir ).forEach (p -> {
97
- System .out .println (p );
102
+ System .out .println (p + " " + fileSize ( p ) );
98
103
count .incrementAndGet ();
99
104
});
100
105
return count .get ();
101
106
}
102
107
103
108
private static long directorySize (Path dir ) throws IOException {
104
- long p = Files .list (dir ).mapToLong (f -> {
105
- try {
106
- return Files .size (f );
107
- } catch (IOException e ) {
108
- return 0 ;
109
- }
110
- }).sum ();
109
+ long p = Files .list (dir ).mapToLong (f -> fileSize (f )).sum ();
111
110
System .out .println ("Directory size: " + p );
112
111
return p ;
113
112
}
113
+
114
+ private static long fileSize (Path p ) {
115
+ try {
116
+ return Files .size (p );
117
+ } catch (IOException e ) {
118
+ System .out .println ("Could not determine file size for " + p );
119
+ return 0 ;
120
+ }
121
+ }
114
122
}
0 commit comments