@Override public String combine(Set<String> settingValues) { for (String s : settingValues) { if ("true".equals(s)) { return"true";
}
} return"false";
}
privatestaticvoid testEnablement() throws Exception {
DogEvent b = new DogEvent();
assertFalse(b.shouldCommit(), "Expected false before recording is started");
try (Recording r = new Recording()) {
r.enable(CatEvent.class);
r.disable(DogEvent.class);
r.start();
CatEvent c = new CatEvent();
assertTrue(c.shouldCommit(), "Expected true for enabled event");
DogEvent d = new DogEvent();
assertFalse(d.shouldCommit(), "Expected false for disabled event");
}
CatEvent c = new CatEvent();
assertFalse(c.shouldCommit(), "Expected false after recording is stopped");
}
privatestaticvoid testThreshold() throws Exception { try (Recording r = new Recording()) {
r.enable(CatEvent.class).withThreshold(Duration.ofNanos(0));
r.enable(DogEvent.class).withThreshold(Duration.ofDays(1));
r.start();
CatEvent c = new CatEvent();
c.begin(); Thread.sleep(1);
c.end();
assertTrue(c.shouldCommit(), "Expected true if above threshold");
DogEvent d = new DogEvent();
d.begin(); Thread.sleep(1);
d.end();
assertFalse(d.shouldCommit(), "Expected false if below threshold");
}
}
privatestaticvoid testCustomSetting() throws Exception { try (Recording r = new Recording()) {
r.enable(BirdEvent.class).with("fly", "true");
r.start();
BirdEvent b1 = new BirdEvent();
b1.isFlying = false;
b1.begin();
b1.end();
assertFalse(b1.shouldCommit(), "Expected false if rejected by custom setting");
BirdEvent b2 = new BirdEvent();
b2.isFlying = true;
b2.begin();
b2.end();
assertTrue(b2.shouldCommit(), "Expected true if accepted by custom setting");
}
}
privatestaticvoid testWithoutEnd() throws Exception { try (Recording r = new Recording()) {
r.enable(CatEvent.class).withThreshold(Duration.ofDays(0));
r.enable(DogEvent.class).withThreshold(Duration.ofDays(1));
r.start();
CatEvent c = new CatEvent();
c.begin(); Thread.sleep(1);
assertTrue(c.shouldCommit(), "Expected true when above threshold and end() not invoked");
DogEvent d = new DogEvent();
d.begin(); Thread.sleep(1);
assertFalse(d.shouldCommit(), "Expected false when below threshold and end() not invoked");
}
}
privatestaticvoid testCommit() throws Exception { try (Recording r = new Recording()) {
r.enable(CatEvent.class);
r.start();
CatEvent c = new CatEvent();
c.begin(); Thread.sleep(1);
c.end(); if (c.shouldCommit()) {
c.commit();
}
r.stop();
Path file = Path.of("dump.jfr");
r.dump(file); boolean hasEvent = RecordingFile.readAllEvents(file).size() > 0;
assertTrue(hasEvent, "Expected event when using commit() after shouldCommit()");
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-11)
¤
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.