@StackTrace(false) staticclass Ant extends Event { long id;
}
publicstaticvoid main(String... args) throws Exception { // Set up the test so half of the events have been consumed // when the dump occurs.
AtomicLong eventCount = new AtomicLong();
CountDownLatch halfLatch = new CountDownLatch(1);
CountDownLatch dumpLatch = new CountDownLatch(1);
Path directory = Path.of("chunks");
Files.createDirectory(directory); try (var rs = new RemoteRecordingStream(CONNECTION, directory)) {
rs.setMaxSize(100_000_000); // keep all data
rs.onEvent(event -> { try {
eventCount.incrementAndGet(); if (eventCount.get() == 10) {
halfLatch.countDown();
dumpLatch.await();
}
} catch (InterruptedException ie) {
ie.printStackTrace();
}
});
rs.startAsync(); long counter = 0; for (int i = 0; i < 10; i++) { try (Recording r = new Recording()) {
r.start();
Ant a = new Ant();
a.id = counter++;
a.commit();
Ant b = new Ant();
b.id = counter++;
b.commit();
} if (counter == 10) {
halfLatch.await();
}
}
Path file = Path.of("events.jfr"); // Wait for most (but not all) chunk files to be downloaded // before invoking dump()
awaitChunkFiles(directory); // To stress the implementation, release consumer thread // during the dump
dumpLatch.countDown();
rs.dump(file);
List<RecordedEvent> events = RecordingFile.readAllEvents(file); if (events.isEmpty()) { thrownew AssertionError("No events found");
} // Print events for debugging purposes
events.forEach(System.out::println); long expected = 0; for (var event : events) { long value = event.getLong("id"); if (value != expected) { thrownew Exception("Expected " + expected + ", got " + value);
}
expected++;
} if (expected != counter) { thrownew Exception("Not all events found");
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.