/* * Copyright (c) 2014, 2018, 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.
*/
// run the test with all possible combinations of setting java.io.tmpdir
runExperiment(null, null);
runExperiment(clientTmpDir, null);
runExperiment(clientTmpDir, targetTmpDir);
runExperiment(null, targetTmpDir);
}
privatestaticint counter = 0;
/* * The actual test is in the nested class TestMain. * The responsibility of this class is to: * 1. Start the Application class in a separate process. * 2. Find the pid and shutdown port of the running Application. * 3. Launches the tests in nested class TestMain that will attach to the Application. * 4. Shut down the Application.
*/ publicstaticvoid runExperiment(Path clientTmpDir, Path targetTmpDir) throws Throwable {
/** * Runs the actual tests in nested class TestMain. * The reason for running the tests in a separate process * is that we need to modify the class path and * the -Djava.io.tmpdir property.
*/ privatestaticvoid launchTests(long pid, Path clientTmpDir) throws Throwable { final String sep = File.separator;
/** * This is the actual test. It will attach to the running Application * and perform a number of basic attach tests.
*/ publicstaticclass TestMain { publicstaticvoid main(String args[]) throws Exception {
String pid = args[0];
// Test 1 - list method should list the target VM
System.out.println(" - Test: VirtualMachine.list");
List<VirtualMachineDescriptor> l = VirtualMachine.list(); boolean found = false; for (VirtualMachineDescriptor vmd: l) { if (vmd.id().equals(pid)) {
found = true; break;
}
} if (found) {
System.out.println(" - " + pid + " found.");
} else { thrownew RuntimeException(pid + " not found in VM list");
}
// Test 2 - try to attach and verify connection
System.out.println(" - Attaching to application ...");
VirtualMachine vm = VirtualMachine.attach(pid);
System.out.println(" - Test: system properties in target VM");
Properties props = vm.getSystemProperties();
String value = props.getProperty("attach.test"); if (value == null || !value.equals("true")) { thrownew RuntimeException("attach.test property not set");
}
System.out.println(" - attach.test property set as expected");
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 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.