/* * Copyright (c) 2020, 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;
/** * @test * @key jfr * @summary Tests that max size can be set for a RemoteRecordingStream * @requires vm.hasJFR * @library /test/lib /test/jdk * @run main/othervm jdk.jfr.jmx.streaming.TestMaxSize
*/ publicclass TestMaxSize {
staticclass Monkey extends Event {
}
publicstaticvoid main(String... args) throws Exception {
MBeanServerConnection conn = ManagementFactory.getPlatformMBeanServer();
Path dir = Files.createDirectories(Paths.get("max-size-" + System.currentTimeMillis()));
System.out.println(dir);
AtomicBoolean finished = new AtomicBoolean(); try (RemoteRecordingStream e = new RemoteRecordingStream(conn, dir)) {
e.startAsync();
e.onEvent(ev -> { if (finished.get()) { return;
} // Consume some events, but give back control // to stream so it can be closed. try { Thread.sleep(10);
} catch (InterruptedException e1) { // ignore
}
}); while (directorySize(dir) < 50_000_000) {
emitEvents(500_000);
}
System.out.println("Before setMaxSize(1_000_000)");
fileCount(dir);
e.setMaxSize(1_000_000);
System.out.println("After setMaxSize(1_000_000)"); long count = fileCount(dir); if (count > 3) { // Three files can happen when: // File 1: Header of new chunk is written to disk // File 2: Previous chunk is not yet finalized and added to list of DiskChunks // File 3: Previous previous file is in the list of DiskChunks. thrownew Exception("Expected at most three chunks with setMaxSize(1_000_000). Found " + count);
}
finished.set(true);
}
}
privatestaticvoid emitEvents(int count) throws InterruptedException { for (int i = 0; i < count; i++) {
Monkey m = new Monkey();
m.commit();
}
System.out.println("Emitted " + count + " events"); Thread.sleep(1000);
}
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.