@Override @Unstable public void close() throws Exception { stop(); }
/** * Stop a RPC client connection * A RPC client is closed only when its reference count becomes zero. */ public void stopClient(Client client) { if (Client.LOG.isDebugEnabled()) { Client.LOG.debug("stopping client from cache: " + client); } synchronized (this) { client.decCount(); if (client.isZeroReference()) { if (Client.LOG.isDebugEnabled()) { Client.LOG.debug("removing client from cache: " + client); } clients.remove(client.getSocketFactory()); } } if (client.isZeroReference()) { if (Client.LOG.isDebugEnabled()) { Client.LOG.debug("stopping actual client because no more references remain: " + client); } client.stop(); } } }
@Override @Unstable public void close() throws Exception { stop(); }
/** * Stop a RPC client connection * A RPC client is closed only when its reference count becomes zero. */ private void stopClient(Client client) { synchronized (this) { client.decCount(); if (client.isZeroReference()) { clients.remove(client.getSocketFactory()); } } if (client.isZeroReference()) { client.stop(); } } }
/** * Stop a RPC client connection * A RPC client is closed only when its reference count becomes zero. */ private void stopClient(Client client) { synchronized (this) { client.decCount(); if (client.isZeroReference()) { clients.remove(client.getSocketFactory()); } } if (client.isZeroReference()) { client.stop(); } } }
@Override public void run() { Client client = new Client(LongWritable.class, conf); try { client.call(new LongWritable(Thread.currentThread().getId()), addr, null, null, 60000, conf); } catch (Throwable e) { LOG.error(e); failures.incrementAndGet(); return; } finally { callFinishedLatch.countDown(); client.stop(); } } });
@Override public void run() { Client client = new Client(LongWritable.class, conf); try { client.call(new LongWritable(Thread.currentThread().getId()), addr, null, null, 60000, conf); } catch (Throwable e) { LOG.error(e); failures.incrementAndGet(); return; } finally { callFinishedLatch.countDown(); client.stop(); } } });
@Override public void run() { Client client = new Client(LongWritable.class, clientConf); try { client.call(new LongWritable(Thread.currentThread().getId()), addr, null, null, 0, clientConf); callReturned.countDown(); Thread.sleep(10000); } catch (IOException e) { LOG.error(e); } catch (InterruptedException e) { } finally { client.stop(); } } });
@Override public void run() { Client client = new Client(LongWritable.class, clientConf); try { client.call(new LongWritable(Thread.currentThread().getId()), addr, null, null, 0, clientConf); callReturned.countDown(); Thread.sleep(10000); } catch (IOException e) { LOG.error(e); } catch (InterruptedException e) { } finally { client.stop(); } } });
private void assertRetriesOnSocketTimeouts(Configuration conf, int maxTimeoutRetries) throws IOException { SocketFactory mockFactory = Mockito.mock(SocketFactory.class); doThrow(new ConnectTimeoutException("fake")).when(mockFactory).createSocket(); Client client = new Client(IntWritable.class, conf, mockFactory); InetSocketAddress address = new InetSocketAddress("127.0.0.1", 9090); try { client.call(new IntWritable(RANDOM.nextInt()), address, null, null, 0, conf); fail("Not throwing the SocketTimeoutException"); } catch (SocketTimeoutException e) { Mockito.verify(mockFactory, Mockito.times(maxTimeoutRetries)) .createSocket(); } client.stop(); }
private void assertRetriesOnSocketTimeouts(Configuration conf, int maxTimeoutRetries) throws IOException { SocketFactory mockFactory = Mockito.mock(SocketFactory.class); doThrow(new ConnectTimeoutException("fake")).when(mockFactory).createSocket(); Client client = new Client(IntWritable.class, conf, mockFactory); InetSocketAddress address = new InetSocketAddress("127.0.0.1", 9090); try { client.call(new IntWritable(RANDOM.nextInt()), address, null, null, 0, conf); fail("Not throwing the SocketTimeoutException"); } catch (SocketTimeoutException e) { Mockito.verify(mockFactory, Mockito.times(maxTimeoutRetries)) .createSocket(); } client.stop(); }
/** * Test that, if the socket factory throws an IOE, it properly propagates * to the client. */ @Test(timeout=60000) public void testSocketFactoryException() throws IOException { SocketFactory mockFactory = mock(SocketFactory.class); doThrow(new IOException("Injected fault")).when(mockFactory).createSocket(); Client client = new Client(LongWritable.class, conf, mockFactory); InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10); try { client.call(new LongWritable(RANDOM.nextLong()), address, null, null, 0, conf); fail("Expected an exception to have been thrown"); } catch (IOException e) { assertTrue(e.getMessage().contains("Injected fault")); } finally { client.stop(); } }
/** * Test that, if the socket factory throws an IOE, it properly propagates * to the client. */ @Test(timeout=60000) public void testSocketFactoryException() throws IOException { SocketFactory mockFactory = mock(SocketFactory.class); doThrow(new IOException("Injected fault")).when(mockFactory).createSocket(); Client client = new Client(LongWritable.class, conf, mockFactory); InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10); try { client.call(new LongWritable(RANDOM.nextLong()), address, null, null, 0, conf); fail("Expected an exception to have been thrown"); } catch (IOException e) { assertTrue(e.getMessage().contains("Injected fault")); } finally { client.stop(); } }
@Test(timeout=60000) public void testStandAloneClient() throws IOException { Client client = new Client(LongWritable.class, conf); InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10); try { client.call(new LongWritable(RANDOM.nextLong()), address, null, null, 0, conf); fail("Expected an exception to have been thrown"); } catch (IOException e) { String message = e.getMessage(); String addressText = address.getHostName() + ":" + address.getPort(); assertTrue("Did not find "+addressText+" in "+message, message.contains(addressText)); Throwable cause=e.getCause(); assertNotNull("No nested exception in "+e,cause); String causeText=cause.getMessage(); assertTrue("Did not find " + causeText + " in " + message, message.contains(causeText)); } finally { client.stop(); } }
/** * Make a call from a client and verify if header info is changed in server side */ private void callAndVerify(Server server, InetSocketAddress addr, int serviceClass, boolean noChanged) throws IOException{ Client client = new Client(LongWritable.class, conf); client.call(new LongWritable(RANDOM.nextLong()), addr, null, null, MIN_SLEEP_TIME, serviceClass, conf); Connection connection = server.getConnections()[0]; int serviceClass2 = connection.getServiceClass(); assertFalse(noChanged ^ serviceClass == serviceClass2); client.stop(); }
/** * Make a call from a client and verify if header info is changed in server side */ private void callAndVerify(Server server, InetSocketAddress addr, int serviceClass, boolean noChanged) throws IOException{ Client client = new Client(LongWritable.class, conf); client.call(new LongWritable(RANDOM.nextLong()), addr, null, null, MIN_SLEEP_TIME, serviceClass, conf); Connection connection = server.getConnections()[0]; int serviceClass2 = connection.getServiceClass(); assertFalse(noChanged ^ serviceClass == serviceClass2); client.stop(); }
@Test(timeout=30000, expected=IOException.class) public void testIpcAfterStopping() throws IOException { // start server Server server = new TestServer(5, false); InetSocketAddress addr = NetUtils.getConnectAddress(server); server.start(); // start client Client client = new Client(LongWritable.class, conf); client.call(new LongWritable(RANDOM.nextLong()), addr, null, null, MIN_SLEEP_TIME, 0, conf); client.stop(); // This call should throw IOException. client.call(new LongWritable(RANDOM.nextLong()), addr, null, null, MIN_SLEEP_TIME, 0, conf); }
@Test(timeout=30000, expected=IOException.class) public void testIpcAfterStopping() throws IOException { // start server Server server = new TestServer(5, false); InetSocketAddress addr = NetUtils.getConnectAddress(server); server.start(); // start client Client client = new Client(LongWritable.class, conf); client.call(new LongWritable(RANDOM.nextLong()), addr, null, null, MIN_SLEEP_TIME, 0, conf); client.stop(); // This call should throw IOException. client.call(new LongWritable(RANDOM.nextLong()), addr, null, null, MIN_SLEEP_TIME, 0, conf); }
@Test(timeout=60000) public void testIpcConnectTimeout() throws IOException { // start server Server server = new TestServer(1, true); InetSocketAddress addr = NetUtils.getConnectAddress(server); //Intentionally do not start server to get a connection timeout // start client Client.setConnectTimeout(conf, 100); Client client = new Client(LongWritable.class, conf); // set the rpc timeout to twice the MIN_SLEEP_TIME try { client.call(new LongWritable(RANDOM.nextLong()), addr, null, null, MIN_SLEEP_TIME*2, conf); fail("Expected an exception to have been thrown"); } catch (SocketTimeoutException e) { LOG.info("Get a SocketTimeoutException ", e); } client.stop(); }
@Test(timeout=60000) public void testIpcConnectTimeout() throws IOException { // start server Server server = new TestServer(1, true); InetSocketAddress addr = NetUtils.getConnectAddress(server); //Intentionally do not start server to get a connection timeout // start client Client.setConnectTimeout(conf, 100); Client client = new Client(LongWritable.class, conf); // set the rpc timeout to twice the MIN_SLEEP_TIME try { client.call(new LongWritable(RANDOM.nextLong()), addr, null, null, MIN_SLEEP_TIME*2, conf); fail("Expected an exception to have been thrown"); } catch (SocketTimeoutException e) { LOG.info("Get a SocketTimeoutException ", e); } client.stop(); }