Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit bd35f97

Browse files
committed
8278628: jdk/jfr/jmx/streaming/TestMaxSize.java Expected only one or two chunks
Reviewed-by: mgronlun
1 parent e38df21 commit bd35f97

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

test/jdk/jdk/jfr/jmx/streaming/TestMaxSize.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,17 @@ public static void main(String... args) throws Exception {
7070
while (directorySize(dir) < 50_000_000) {
7171
emitEvents(500_000);
7272
}
73+
System.out.println("Before setMaxSize(1_000_000)");
74+
fileCount(dir);
7375
e.setMaxSize(1_000_000);
76+
System.out.println("After setMaxSize(1_000_000)");
7477
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);
7984
}
8085
finished.set(true);
8186
}
@@ -94,21 +99,24 @@ private static int fileCount(Path dir) throws IOException {
9499
System.out.println("Files:");
95100
AtomicInteger count = new AtomicInteger();
96101
Files.list(dir).forEach(p -> {
97-
System.out.println(p);
102+
System.out.println(p + " " + fileSize(p));
98103
count.incrementAndGet();
99104
});
100105
return count.get();
101106
}
102107

103108
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();
111110
System.out.println("Directory size: " + p);
112111
return p;
113112
}
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+
}
114122
}

0 commit comments

Comments
 (0)