public void close() { if (clientTransceiver != null) try { clientTransceiver.close(); } catch (IOException e) {} // ignore if (subprocess != null) subprocess.destroy(); if (outputServer != null) outputServer.close(); }
void close() { LOG.info("Closing the transceiver"); if (clientTransceiver != null) try { clientTransceiver.close(); } catch (IOException e) {} // ignore }
transceiver.close(); } catch (IOException ex) { throw new FlumeException(this + ": Error closing transceiver.", ex);
public void run() { try { try { this.xc = getTransceiver(channel); while (true) { xc.writeBuffers(responder.respond(xc.readBuffers(), xc)); } } catch (EOFException e) { return; } catch (ClosedChannelException e) { return; } finally { xc.close(); } } catch (IOException e) { LOG.warn("unexpected error", e); } }
@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 testStopServer() throws IOException { client.close(); server.close(); } }
@AfterClass public static void testStopServer() throws IOException { client.close(); 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; }
@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(); } }
/** Sends RPCs and returns nanos elapsed. */ private static long sendRpcs(boolean withPlugin) throws IOException { HttpServer server = createServer(withPlugin); Transceiver t = new HttpTransceiver(new URL("http://127.0.0.1:"+server.getPort()+"/")); GenericRequestor requestor = new GenericRequestor(NULL_PROTOCOL, t); long now = System.nanoTime(); for (int i = 0; i < COUNT; ++i) { requestor.request("null", null); } long elapsed = System.nanoTime() - now; t.close(); server.close(); return elapsed; }
transceiver.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(); }
@Test public void testConnectionsCount() throws Exception { Transceiver transceiver2 = new NettyTransceiver(new InetSocketAddress( server.getPort()), CONNECT_TIMEOUT_MILLIS); Mail proxy2 = SpecificRequestor.getClient(Mail.class, transceiver2); proxy.fireandforget(createMessage()); proxy2.fireandforget(createMessage()); Assert.assertEquals(2, ((NettyServer) server).getNumActiveConnections()); transceiver2.close(); // Check the active connections with some retries as closing at the client // side might not take effect on the server side immediately int numActiveConnections = ((NettyServer) server).getNumActiveConnections(); for (int i = 0; i < 50 && numActiveConnections == 2; ++i) { System.out.println("Server still has 2 active connections; retrying..."); Thread.sleep(100); numActiveConnections = ((NettyServer) server).getNumActiveConnections(); } Assert.assertEquals(1, numActiveConnections); }
@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(); }
@Test /** Construct and use a protocol whose "hello" method has an extra argument to check that schema is sent to parse request. */ public void testParamVariation() throws Exception { Protocol protocol = new Protocol("Simple", "org.apache.avro.test"); List<Schema.Field> fields = new ArrayList<>(); fields.add(new Schema.Field("extra", Schema.create(Schema.Type.BOOLEAN), null, null)); fields.add(new Schema.Field("greeting", Schema.create(Schema.Type.STRING), null, null)); Protocol.Message message = protocol.createMessage("hello", null /* doc */, Schema.createRecord(fields), Schema.create(Schema.Type.STRING), Schema.createUnion(new ArrayList<>())); protocol.getMessages().put("hello", message); Transceiver t = createTransceiver(); try { GenericRequestor r = new GenericRequestor(protocol, t); addRpcPlugins(r); GenericRecord params = new GenericData.Record(message.getRequest()); params.put("extra", Boolean.TRUE); params.put("greeting", "bob"); String response = r.request("hello", params).toString(); assertEquals("goodbye", response); } finally { t.close(); } }
@Test /** Construct and use a different protocol whose "hello" method has an extra argument to check that schema is sent to parse request. */ public void testHandshake() throws IOException { Protocol protocol = new Protocol("Simple", "org.apache.avro.test"); List<Field> fields = new ArrayList<>(); fields.add(new Schema.Field("extra", Schema.create(Schema.Type.BOOLEAN), null, null)); fields.add(new Schema.Field("greeting", Schema.create(Schema.Type.STRING), null, null)); Protocol.Message message = protocol.createMessage("hello", null /* doc */, Schema.createRecord(fields), Schema.create(Schema.Type.STRING), Schema.createUnion(new ArrayList<>())); protocol.getMessages().put("hello", message); Transceiver t = new SocketTransceiver(new InetSocketAddress(server.getPort())); try { GenericRequestor r = new GenericRequestor(protocol, t); GenericRecord params = new GenericData.Record(message.getRequest()); params.put("extra", Boolean.TRUE); params.put("greeting", new Utf8("bob")); Utf8 response = (Utf8)r.request("hello", params); assertEquals(new Utf8("goodbye"), response); } finally { t.close(); } }
assertEquals(rec, response); } finally { t.close();
transceiver2.close();