/** * Creates a handle for an app to be launched. This method will start a server if one hasn't been * started yet. The server is shared for multiple handles, and once all handles are disposed of, * the server is shut down. */ static synchronized ChildProcAppHandle newAppHandle() throws IOException { LauncherServer server = serverInstance != null ? serverInstance : new LauncherServer(); server.ref(); serverInstance = server; String secret = server.createSecret(); while (server.pending.containsKey(secret)) { secret = server.createSecret(); } return server.newAppHandle(secret); }
/** * Creates a handle for an app to be launched. This method will start a server if one hasn't been * started yet. The server is shared for multiple handles, and once all handles are disposed of, * the server is shut down. */ static synchronized ChildProcAppHandle newAppHandle() throws IOException { LauncherServer server = serverInstance != null ? serverInstance : new LauncherServer(); server.ref(); serverInstance = server; String secret = server.createSecret(); while (server.pending.containsKey(secret)) { secret = server.createSecret(); } return server.newAppHandle(secret); }
ChildProcAppHandle handle = LauncherServer.newAppHandle(); for (SparkAppHandle.Listener l : listeners) { handle.addListener(l);
ChildProcAppHandle handle = LauncherServer.newAppHandle(); for (SparkAppHandle.Listener l : listeners) { handle.addListener(l);
@Test public void testTimeout() throws Exception { ChildProcAppHandle handle = null; TestClient client = null; try { // LauncherServer will immediately close the server-side socket when the timeout is set // to 0. SparkLauncher.setConfig(SparkLauncher.CHILD_CONNECTION_TIMEOUT, "0"); handle = LauncherServer.newAppHandle(); Socket s = new Socket(InetAddress.getLoopbackAddress(), LauncherServer.getServerInstance().getPort()); client = new TestClient(s); waitForError(client, handle.getSecret()); } finally { SparkLauncher.launcherConfig.remove(SparkLauncher.CHILD_CONNECTION_TIMEOUT); kill(handle); close(client); } }
@Test public void testLauncherServerReuse() throws Exception { ChildProcAppHandle handle1 = null; ChildProcAppHandle handle2 = null; ChildProcAppHandle handle3 = null; try { handle1 = LauncherServer.newAppHandle(); handle2 = LauncherServer.newAppHandle(); LauncherServer server1 = handle1.getServer(); assertSame(server1, handle2.getServer()); handle1.kill(); handle2.kill(); handle3 = LauncherServer.newAppHandle(); assertNotSame(server1, handle3.getServer()); handle3.kill(); assertNull(LauncherServer.getServerInstance()); } finally { kill(handle1); kill(handle2); kill(handle3); } }
@Test public void testStreamFiltering() throws Exception { ChildProcAppHandle handle = LauncherServer.newAppHandle(); TestClient client = null; try { Socket s = new Socket(InetAddress.getLoopbackAddress(), LauncherServer.getServerInstance().getPort()); client = new TestClient(s); try { client.send(new EvilPayload()); } catch (SocketException se) { // SPARK-21522: this can happen if the server closes the socket before the full message has // been written, so it's expected. It may cause false positives though (socket errors // happening for other reasons). } waitForError(client, handle.getSecret()); assertEquals(0, EvilPayload.EVIL_BIT); } finally { kill(handle); close(client); client.clientThread.join(); } }
@Test public void testSparkSubmitVmShutsDown() throws Exception { ChildProcAppHandle handle = LauncherServer.newAppHandle(); TestClient client = null; final Semaphore semaphore = new Semaphore(0); try { Socket s = new Socket(InetAddress.getLoopbackAddress(), LauncherServer.getServerInstance().getPort()); handle.addListener(new SparkAppHandle.Listener() { public void stateChanged(SparkAppHandle handle) { semaphore.release(); } public void infoChanged(SparkAppHandle handle) { semaphore.release(); } }); client = new TestClient(s); client.send(new Hello(handle.getSecret(), "1.4.0")); assertTrue(semaphore.tryAcquire(30, TimeUnit.SECONDS)); // Make sure the server matched the client to the handle. assertNotNull(handle.getConnection()); close(client); assertTrue(semaphore.tryAcquire(30, TimeUnit.SECONDS)); assertEquals(SparkAppHandle.State.LOST, handle.getState()); } finally { kill(handle); close(client); client.clientThread.join(); } }
@Test public void testCommunication() throws Exception { ChildProcAppHandle handle = LauncherServer.newAppHandle(); TestClient client = null; try {