TestApplication.java revision 2362
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg/*
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg *
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * This code is free software; you can redistribute it and/or modify it
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * under the terms of the GNU General Public License version 2 only, as
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * published by the Free Software Foundation.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg *
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * This code is distributed in the hope that it will be useful, but WITHOUT
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * version 2 for more details (a copy is included in the LICENSE file that
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * accompanied this code).
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg *
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * You should have received a copy of the GNU General Public License version
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * 2 along with this work; if not, write to the Free Software Foundation,
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg *
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * or visit www.oracle.com if you need additional information or have any
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * questions.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg */
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg/*
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg *
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg *
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * A test "application" used by unit test LocalManagementTest.sh. This
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * application binds to some random port, prints the port number to
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * standard output, waits for somebody to connect, and then shuts down.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg */
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburgimport java.io.IOException;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburgimport java.net.ServerSocket;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburgimport java.net.Socket;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburgpublic class TestApplication {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg public static void main(String[] args) throws IOException {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg // Some tests require the application to exit immediately
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg if (args.length > 0 && args[0].equals("-exit")) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg return;
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg }
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg // bind to a random port
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg ServerSocket ss = new ServerSocket(0);
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg int port = ss.getLocalPort();
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg // signal test that we are started - do not remove this line!!
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg System.out.println(port);
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg System.out.flush();
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg // wait for manager to connect
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg Socket s = ss.accept();
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg s.close();
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg ss.close();
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg }
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg}
9798bfcb5c34f3b87217b619263fece5e9ffeec0Joe Bandenburg