1/* 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * 26 * 27 * A test "application" used by unit tests - 28 * LocalManagementTest.java, CustomLauncherTest.java. 29 * This application binds to some random port, prints the port number 30 * to standard output, waits for somebody to connect, and then shuts down. 31 */ 32import java.io.IOException; 33import java.net.ServerSocket; 34import java.net.Socket; 35 36public class TestApplication { 37 public static void main(String[] args) throws IOException { 38 // Some tests require the application to exit immediately 39 if (args.length > 0 && args[0].equals("-exit")) { 40 return; 41 } 42 43 // bind to a random port 44 ServerSocket ss = new ServerSocket(0); 45 int port = ss.getLocalPort(); 46 47 // signal test that we are started - do not remove these lines!! 48 System.out.println("port:" + port); 49 System.out.println("waiting for the manager ..."); 50 System.out.flush(); 51 52 // wait for manager to connect 53 Socket s = ss.accept(); 54 s.close(); 55 ss.close(); 56 } 57} 58