int run2(PrintStream err) throws InterruptedException { latch.await(); err.println("Closing server."); server.close(); return 0; }
public void close() { if (clientTransceiver != null) try { clientTransceiver.close(); } catch (IOException e) {} // ignore if (subprocess != null) subprocess.destroy(); if (outputServer != null) outputServer.close(); }
@Override public void run() { server2.close(); } }).start();
private void close() { LOG.info("Closing the task"); task.close(); LOG.info("Finished closing the task."); if (inputServer != null) inputServer.close(); } }
@After public void tearDown() throws Exception { if( receive != null ) receive.server.close(); // force the server to finish }
/** * Request that the specified Server stop, and attempt to wait for it to exit. * @param server A running NettyServer */ public static void stopServer(Server server) { try { server.close(); server.join(); } catch (InterruptedException ex) { logger.error("Thread interrupted. Exception follows.", ex); Thread.currentThread().interrupt(); } }
@AfterClass public static void stopServer() throws Exception { server.close(); }
@Override public void stop() { logger.info("Avro source {} stopping: {}", getName(), this); if (server != null) { server.close(); try { server.join(); server = null; } catch (InterruptedException e) { logger.info("Avro source " + getName() + ": Interrupted while waiting " + "for Avro server to stop. Exiting. Exception follows.", e); Thread.currentThread().interrupt(); } } if (socketChannelFactory != null) { socketChannelFactory.releaseExternalResources(); socketChannelFactory = null; } sourceCounter.stop(); if (connectionCountUpdater != null) { connectionCountUpdater.shutdownNow(); connectionCountUpdater = null; } super.stop(); logger.info("Avro source {} stopped. Metrics: {}", getName(), sourceCounter); }
@After public void cleanUpAfter() throws Exception { try { if (transceiver != null) { transceiver.close(); } } catch (IOException e) { e.printStackTrace(); } try { if (server != null) { server.close(); } } catch (Exception e) { e.printStackTrace(); } }
@AfterClass public static void tearDownConnections() throws Exception{ transceiver.close(); server.close(); }
@AfterClass public static void tearDownConnections() throws Exception { if (transceiver != null) { transceiver.close(); } if (server != null) { server.close(); } }
@AfterClass public static void testStopServer() throws IOException { client.close(); server.close(); }
@AfterClass public static void testStopServer() throws IOException { client.close(); server.close(); server = null; }
@Test(expected = FlumeException.class) public void testCreatingLbClientSingleHost() { Server server1 = null; RpcClient c = null; try { server1 = RpcTestUtils.startServer(new OKAvroHandler()); Properties p = new Properties(); p.put("host1", "127.0.0.1:" + server1.getPort()); p.put("hosts", "host1"); p.put("client.type", "default_loadbalance"); RpcClientFactory.getInstance(p); } finally { if (server1 != null) server1.close(); if (c != null) c.close(); } }
@Test public void testLbDefaultClientTwoHostsBatch() throws Exception { Server s1 = null; Server s2 = null; RpcClient c = null; try { LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler(); LoadBalancedAvroHandler h2 = new LoadBalancedAvroHandler(); s1 = RpcTestUtils.startServer(h1); s2 = RpcTestUtils.startServer(h2); Properties p = new Properties(); p.put("hosts", "h1 h2"); p.put("client.type", "default_loadbalance"); p.put("hosts.h1", "127.0.0.1:" + s1.getPort()); p.put("hosts.h2", "127.0.0.1:" + s2.getPort()); c = RpcClientFactory.getInstance(p); Assert.assertTrue(c instanceof LoadBalancingRpcClient); for (int i = 0; i < 100; i++) { c.appendBatch(getBatchedEvent(i)); } Assert.assertEquals(50, h1.getAppendBatchCount()); Assert.assertEquals(50, h2.getAppendBatchCount()); } finally { if (s1 != null) s1.close(); if (s2 != null) s2.close(); if (c != null) c.close(); } }
@Test public void testLbDefaultClientTwoHosts() throws Exception { Server s1 = null; Server s2 = null; RpcClient c = null; try { LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler(); LoadBalancedAvroHandler h2 = new LoadBalancedAvroHandler(); s1 = RpcTestUtils.startServer(h1); s2 = RpcTestUtils.startServer(h2); Properties p = new Properties(); p.put("hosts", "h1 h2"); p.put("client.type", "default_loadbalance"); p.put("hosts.h1", "127.0.0.1:" + s1.getPort()); p.put("hosts.h2", "127.0.0.1:" + s2.getPort()); c = RpcClientFactory.getInstance(p); Assert.assertTrue(c instanceof LoadBalancingRpcClient); for (int i = 0; i < 100; i++) { c.append(getEvent(i)); } Assert.assertEquals(50, h1.getAppendCount()); Assert.assertEquals(50, h2.getAppendCount()); } finally { if (s1 != null) s1.close(); if (s2 != null) s2.close(); if (c != null) c.close(); } }
@Test(expected=SaslException.class) public void testAnonymousClient() throws Exception { Server s = new SaslSocketServer (new TestResponder(), new InetSocketAddress(0), DIGEST_MD5_MECHANISM, SERVICE, HOST, DIGEST_MD5_PROPS, new TestSaslCallbackHandler()); s.start(); Transceiver c = new SaslSocketTransceiver(new InetSocketAddress(s.getPort())); GenericRequestor requestor = new GenericRequestor(PROTOCOL, c); GenericRecord params = new GenericData.Record(PROTOCOL.getMessages().get("hello").getRequest()); params.put("greeting", "bob"); Utf8 response = (Utf8)requestor.request("hello", params); assertEquals(new Utf8("goodbye"), response); s.close(); c.close(); }
try { client = RpcTestUtils.getStockLocalClient(server.getPort()); server.close();
@Test(expected=SaslException.class) public void testWrongPassword() throws Exception { Server s = new SaslSocketServer (new TestResponder(), new InetSocketAddress(0), DIGEST_MD5_MECHANISM, SERVICE, HOST, DIGEST_MD5_PROPS, new TestSaslCallbackHandler()); s.start(); SaslClient saslClient = Sasl.createSaslClient (new String[]{DIGEST_MD5_MECHANISM}, PRINCIPAL, SERVICE, HOST, DIGEST_MD5_PROPS, new WrongPasswordCallbackHandler()); Transceiver c = new SaslSocketTransceiver (new InetSocketAddress(server.getPort()), saslClient); GenericRequestor requestor = new GenericRequestor(PROTOCOL, c); GenericRecord params = new GenericData.Record(PROTOCOL.getMessages().get("hello").getRequest()); params.put("greeting", "bob"); Utf8 response = (Utf8)requestor.request("hello", params); assertEquals(new Utf8("goodbye"), response); s.close(); c.close(); }