/* * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/ package jdk.jfr.jmx.streaming;
privatestaticvoid testUnstarted() throws Exception {
Path path = Path.of("recording.jfr"); var rs = new RemoteRecordingStream(CONNECTION);
rs.setMaxAge(Duration.ofHours(1)); try {
rs.dump(path); thrownew Exception("Should not be able to dump unstarted recording");
} catch (IOException ise) { // OK, expected
}
}
privatestaticvoid testClosed() throws Exception {
Path path = Path.of("recording.jfr"); var rs = new RemoteRecordingStream(CONNECTION);
rs.setMaxAge(Duration.ofHours(1));
rs.startAsync();
rs.close(); try {
rs.dump(path); thrownew Exception("Should not be able to dump closed recording");
} catch (IOException ise) { // OK, expected
}
}
privatestatic List<RecordedEvent> recordWithPolicy(String filename, Consumer<RemoteRecordingStream> policy) throws Exception {
CountDownLatch latch1 = new CountDownLatch(1);
CountDownLatch latch2 = new CountDownLatch(2);
CountDownLatch latch3 = new CountDownLatch(3); try (var rs = new RemoteRecordingStream(CONNECTION)) {
policy.accept(rs);
rs.onEvent(e -> {
latch1.countDown();
latch2.countDown();
latch3.countDown();
});
rs.startAsync();
DumpEvent e1 = new DumpEvent();
e1.commit();
latch1.await(); // Force chunk rotation try (Recording r = new Recording()) {
r.start();
DumpEvent e2 = new DumpEvent();
e2.commit();
}
latch2.await();
DumpEvent e3 = new DumpEvent();
e3.commit();
latch3.await();
Path p = Path.of(filename);
rs.dump(p); return RecordingFile.readAllEvents(p);
}
}
privatestaticvoid testSetMaxSize() throws Exception { var events = recordWithPolicy("max-size.jfr", rs -> { // keeps all events for the dump
rs.setMaxSize(100_000_000);
}); if (events.size() != 3) { thrownew Exception("Expected all 3 events to be in dump after setMaxSize");
}
}
privatestaticvoid testSetMaxAge() throws Exception { var events = recordWithPolicy("max-age.jfr", rs -> { // keeps all events for the dump
rs.setMaxAge(Duration.ofDays(1));
}); if (events.size() != 3) { thrownew Exception("Expected all 3 events to be in dump after setMaxAge");
}
}
privatestaticvoid testSetNoPolicy() throws Exception { var events = recordWithPolicy("no-policy.jfr", rs -> { // use default policy, remove after consumption
}); // Since latch3 have been triggered at least two events/chunks // before must have been consumed, possibly 3, but it's a race. if (events.size() > 1) { thrownew Exception("Expected at most one event to not be consumed");
}
}
privatestaticvoid testMultipleDumps() throws Exception {
CountDownLatch latch = new CountDownLatch(1); try (var rs = new RemoteRecordingStream(CONNECTION)) {
rs.setMaxAge(Duration.ofHours(1));
rs.onEvent(e -> {
latch.countDown();
});
rs.startAsync(); while (latch.getCount() > 0) {
DumpEvent e = new DumpEvent();
e.commit();
latch.await(10, TimeUnit.MILLISECONDS);
}
latch.await(); // Await first event
AtomicInteger counter = new AtomicInteger();
Callable<Boolean> f = () -> { try { int id = counter.incrementAndGet();
Path p = Path.of("multiple-" + id + ".jfr");
rs.dump(p); return !RecordingFile.readAllEvents(p).isEmpty();
} catch (IOException ioe) {
ioe.printStackTrace(); returnfalse;
}
}; var service = Executors.newFixedThreadPool(3); var f1 = service.submit(f); var f2 = service.submit(f); var f3 = service.submit(f); if (!f1.get() || !f2.get() || !f3.get()) { thrownew Exception("Failed to dump multiple recordings simultanously");
}
service.shutdown();
}
}
privatestaticvoid testOneDump() throws Exception {
CountDownLatch latch = new CountDownLatch(1); try (var rs = new RemoteRecordingStream(CONNECTION)) {
rs.setMaxSize(5_000_000);
rs.onEvent(e -> {
latch.countDown();
});
rs.startAsync(); while (latch.getCount() > 0) {
DumpEvent e = new DumpEvent();
e.commit();
latch.await(10, TimeUnit.MILLISECONDS);
}
Path p = Path.of("one-dump.jfr");
rs.dump(p); if (RecordingFile.readAllEvents(p).isEmpty()) { thrownew Exception("No events in dump");
}
}
}
privatestaticvoid testEventAfterDump() throws Exception {
CountDownLatch latch = new CountDownLatch(1); try (var rs = new RemoteRecordingStream(CONNECTION)) {
rs.setMaxAge(Duration.ofHours(1));
rs.onEvent(e -> {
latch.countDown();
});
rs.startAsync();
Path p = Path.of("after-dump.jfr");
rs.dump(p);
DumpEvent e = new DumpEvent();
e.commit();
latch.await();
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
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.