本文整理汇总了Java中jdk.testlibrary.Utils.getFreePort方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.getFreePort方法的具体用法?Java Utils.getFreePort怎么用?Java Utils.getFreePort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.testlibrary.Utils
的用法示例。
在下文中一共展示了Utils.getFreePort方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
protected void run() throws Exception {
OutputAnalyzer out;
int retries = 1;
boolean tryAgain;
do {
tryAgain = false;
jmxPort = Utils.getFreePort();
out = runVM();
try {
out.shouldNotContain("Port already in use");
} catch (RuntimeException e) {
if (retries < 3) {
retries++;
tryAgain = true;
}
}
} while (tryAgain);
}
示例2: run
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
protected void run() throws Exception {
int retries = 1;
boolean tryAgain;
do {
tryAgain = false;
jmxPort = Utils.getFreePort();
output = runVM();
try {
output.shouldNotContain("Port already in use");
} catch (RuntimeException e) {
if (retries < 3) {
retries++;
tryAgain = true;
}
}
} while (tryAgain);
output.shouldHaveExitValue(0);
// java.lang.Exception is thrown by JdpTestCase if something goes wrong
// for instance - see JdpTestCase::shutdown()
output.shouldNotContain("java.lang.Exception:");
output.shouldNotContain("Error: Could not find or load main class");
}
示例3: negativeTest
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
public static void negativeTest(String testName, String allowOpt)
throws InterruptedException, IOException {
System.err.println("\nStarting " + testName);
int port = Utils.getFreePort();
ArrayList<String> cmd = prepareCmd(port, allowOpt);
LingeredApp a = LingeredApp.startApp(cmd);
int res = handshake(port);
a.stopApp();
if (res > 0) {
System.err.println(testName + ": res=" + res);
throw new RuntimeException(testName + " FAILED");
}
System.err.println(testName + ": returned a negative code as expected: " + res);
System.err.println(testName + " PASSED");
}
示例4: main
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
String cmd = args[0];
if (cmd.equals("-getport")) {
port = Utils.getFreePort();
System.out.print(port);
} else if (cmd.equals("-runtest")) {
port = Integer.parseInt(args[1]);
SimpleNameService.put("allowedAndFound.com", "127.0.0.1");
SimpleNameService.put("notAllowedButFound.com", "99.99.99.99");
// name "notAllowedAndNotFound.com" is not in map
// name "allowedButNotfound.com" is not in map
try {
startServer();
System.setSecurityManager(new SecurityManager());
test("http://allowedAndFound.com:" + port + "/foo", false, false);
test("http://notAllowedButFound.com:" + port + "/foo", true, false);
test("http://allowedButNotfound.com:" + port + "/foo", false, true);
test("http://notAllowedAndNotFound.com:" + port + "/foo", true, false);
} finally {
serverSocket.close();
}
} else {
throw new RuntimeException("Bad invocation: " + cmd);
}
}
示例5: go
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
protected void go() throws Exception {
jmxPort = Utils.getFreePort();
occupyPort();
log.info("Attempting to start a VM using the same port.");
OutputAnalyzer out = this.runVM();
out.shouldContain("Port already in use");
log.info("Failed as expected.");
log.info("Trying again using retries.");
this.run();
}
示例6: testRemoteAgent
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
public static void testRemoteAgent(VirtualMachine vm) throws Exception {
int port = Utils.getFreePort();
// try to connect - should fail
tryConnect(port, false);
// start agent
System.out.println("Starting agent on port: " + port);
Properties mgmtProps = new Properties();
mgmtProps.put("com.sun.management.jmxremote.port", port);
mgmtProps.put("com.sun.management.jmxremote.authenticate", "false");
mgmtProps.put("com.sun.management.jmxremote.ssl", "false");
vm.startManagementAgent(mgmtProps);
// try to connect - should work
tryConnect(port, true);
// try to start again - should fail
boolean exception = false;
try {
vm.startManagementAgent(mgmtProps);
} catch(AttachOperationFailedException ex) {
// expected
exception = true;
}
if (!exception) {
throw new Exception("Expected the second call to vm.startManagementAgent() to fail");
}
}
示例7: initPort
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
private void initPort() {
try {
port = Utils.getFreePort();
} catch (Exception e) {
}
model.put("${getFreePort}", new Integer(port));
}
示例8: positiveTest
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
public static void positiveTest(String testName, String allowOpt)
throws InterruptedException, IOException {
System.err.println("\nStarting " + testName);
int port = Utils.getFreePort();
ArrayList<String> cmd = prepareCmd(port, allowOpt);
LingeredApp a = LingeredApp.startApp(cmd);
int res = handshake(port);
a.stopApp();
if (res < 0) {
throw new RuntimeException(testName + " FAILED");
}
System.err.println(testName + " PASSED");
}
示例9: badAllowOptionTest
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
public static void badAllowOptionTest(String testName, String allowOpt)
throws InterruptedException, IOException {
System.err.println("\nStarting " + testName);
int port = Utils.getFreePort();
ArrayList<String> cmd = prepareCmd(port, allowOpt);
try {
LingeredApp a = LingeredApp.startApp(cmd);
} catch (IOException ex) {
System.err.println(testName + ": caught expected IOException");
System.err.println(testName + " PASSED");
return;
}
throw new RuntimeException(testName + " FAILED");
}
示例10: main
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable {
int port = Utils.getFreePort();
String jdwpOption = "-agentlib:jdwp=transport=dt_socket"
+ ",server=y" + ",suspend=n" + ",address=*:" + String.valueOf(port);
OutputAnalyzer output = ProcessTools.executeTestJvm("-classpath",
TEST_CLASSES,
jdwpOption, // Notice jdwpOption specified twice
jdwpOption,
"Exit0");
output.shouldContain("Cannot load this JVM TI agent twice");
output.shouldHaveExitValue(1);
}
示例11: testRemoteAgent
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
public static void testRemoteAgent(VirtualMachine vm) throws Exception {
int port = Utils.getFreePort();
// try to connect - should fail
tryConnect(port, false);
// start agent
System.out.println("Starting agent on port: " + port);
Properties mgmtProps = new Properties();
mgmtProps.put("com.sun.management.jmxremote.port", port);
mgmtProps.put("com.sun.management.jmxremote.authenticate", "false");
mgmtProps.put("com.sun.management.jmxremote.ssl", "false");
System.err.println("Starting management agent ...");
vm.startManagementAgent(mgmtProps);
System.err.println("Started");
// try to connect - should work
tryConnect(port, true);
// try to start again - should fail
boolean exception = false;
try {
System.err.println("Starting management agent second time ...");
vm.startManagementAgent(mgmtProps);
System.err.println("Started");
} catch(AttachOperationFailedException ex) {
// expected
System.err.println("Got expected exception: " + ex.getMessage());
exception = true;
}
if (!exception) {
throw new Exception("Expected the second call to vm.startManagementAgent() to fail");
}
}
示例12: main
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
String cmd = args[0];
if (cmd.equals("-getport")) {
port = Utils.getFreePort();
System.out.print(port);
} else if (cmd.equals("-runtest")) {
port = Integer.parseInt(args[1]);
String hostsFileName = System.getProperty("test.src", ".") + "/LookupTestHosts";
System.setProperty("jdk.net.hosts.file", hostsFileName);
addMappingToHostsFile("allowedAndFound.com", "127.0.0.1", hostsFileName, false);
addMappingToHostsFile("notAllowedButFound.com", "99.99.99.99", hostsFileName, true);
// name "notAllowedAndNotFound.com" is not in map
// name "allowedButNotfound.com" is not in map
try {
startServer();
System.setSecurityManager(new SecurityManager());
test("http://allowedAndFound.com:" + port + "/foo", false, false);
test("http://notAllowedButFound.com:" + port + "/foo", true, false);
test("http://allowedButNotfound.com:" + port + "/foo", false, true);
test("http://notAllowedAndNotFound.com:" + port + "/foo", true, false);
} finally {
serverSocket.close();
}
} else {
throw new RuntimeException("Bad invocation: " + cmd);
}
}
示例13: main
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
// Launch the server debuggee
int port = 0;
Process process = null;
while (process == null) {
port = Utils.getFreePort();
String address = String.valueOf(port);
LaunchResult launchResult = launch(address, "Exit0");
process = launchResult.getProcess();
if (launchResult.isBindFailed()) {
System.out.println("Port " + port + " already in use. Trying to restart debuggee with a new one...");
Thread.sleep(100);
} else if (process == null ) {
throw new RuntimeException("Unable to start debugee");
}
}
// Connect to the debuggee and handshake with garbage
Socket s = new Socket("localhost", port);
s.getOutputStream().write("Here's a poke in the eye".getBytes("UTF-8"));
s.close();
// Re-connect and to a partial handshake - don't disconnect
s = new Socket("localhost", port);
s.getOutputStream().write("JDWP-".getBytes("UTF-8"));
// Attach to server debuggee and resume it so it can exit
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
Map<String, Argument> conn_args = conn.defaultArguments();
Connector.IntegerArgument port_arg =
(Connector.IntegerArgument)conn_args.get("port");
port_arg.setValue(port);
VirtualMachine vm = conn.attach(conn_args);
// The first event is always a VMStartEvent, and it is always in
// an EventSet by itself. Wait for it.
EventSet evtSet = vm.eventQueue().remove();
for (Event event: evtSet) {
if (event instanceof VMStartEvent) {
break;
}
throw new RuntimeException("Test failed - debuggee did not start properly");
}
vm.eventRequestManager().deleteAllBreakpoints();
vm.resume();
process.waitFor();
}
示例14: main
import jdk.testlibrary.Utils; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
int port = Utils.getFreePort();
String address = String.valueOf(port);
// launch the server debuggee
Process process = launch(address, "Exit0");
if (process == null) {
throw new RuntimeException("Unable to start debugee");
}
// Connect to the debuggee and handshake with garbage
Socket s = new Socket(InetAddress.getLocalHost(), port);
s.getOutputStream().write("Here's a poke in the eye".getBytes("UTF-8"));
s.close();
// Re-connect and to a partial handshake - don't disconnect
s = new Socket(InetAddress.getLocalHost(), port);
s.getOutputStream().write("JDWP-".getBytes("UTF-8"));
// attach to server debuggee and resume it so it can exit
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
Map conn_args = conn.defaultArguments();
Connector.IntegerArgument port_arg =
(Connector.IntegerArgument)conn_args.get("port");
port_arg.setValue(port);
VirtualMachine vm = conn.attach(conn_args);
// The first event is always a VMStartEvent, and it is always in
// an EventSet by itself. Wait for it.
EventSet evtSet = vm.eventQueue().remove();
for (Event event: evtSet) {
if (event instanceof VMStartEvent) {
break;
}
throw new RuntimeException("Test failed - debuggee did not start properly");
}
vm.eventRequestManager().deleteAllBreakpoints();
vm.resume();
process.waitFor();
}