List of usage examples for org.apache.hadoop.ipc Server stop
public synchronized void stop()
From source file:com.datatorrent.stram.StramRecoveryTest.java
License:Apache License
@Test public void testRpcFailover() throws Exception { String appPath = testMeta.dir; Configuration conf = new Configuration(false); final AtomicBoolean timedout = new AtomicBoolean(); StreamingContainerUmbilicalProtocol impl = MockitoUtil .mockProtocol(StreamingContainerUmbilicalProtocol.class); Mockito.doAnswer(new org.mockito.stubbing.Answer<Void>() { @Override/*from ww w . jav a 2 s. c o m*/ public Void answer(InvocationOnMock invocation) { LOG.debug("got call: " + invocation.getMethod()); if (!timedout.get()) { try { timedout.set(true); Thread.sleep(1000); } catch (Exception e) { } //throw new RuntimeException("fail"); } return null; } }).when(impl).log("containerId", "timeout"); Server server = new RPC.Builder(conf).setProtocol(StreamingContainerUmbilicalProtocol.class) .setInstance(impl).setBindAddress("0.0.0.0").setPort(0).setNumHandlers(1).setVerbose(false).build(); server.start(); InetSocketAddress address = NetUtils.getConnectAddress(server); LOG.info("Mock server listening at " + address); int rpcTimeoutMillis = 500; int retryDelayMillis = 100; int retryTimeoutMillis = 500; FSRecoveryHandler recoveryHandler = new FSRecoveryHandler(appPath, conf); URI uri = RecoverableRpcProxy.toConnectURI(address, rpcTimeoutMillis, retryDelayMillis, retryTimeoutMillis); recoveryHandler.writeConnectUri(uri.toString()); RecoverableRpcProxy rp = new RecoverableRpcProxy(appPath, conf); StreamingContainerUmbilicalProtocol protocolProxy = rp.getProxy(); protocolProxy.log("containerId", "msg"); // simulate socket read timeout try { protocolProxy.log("containerId", "timeout"); Assert.fail("expected socket timeout"); } catch (java.net.SocketTimeoutException e) { // expected } Assert.assertTrue("timedout", timedout.get()); rp.close(); // test success on retry timedout.set(false); retryTimeoutMillis = 1500; uri = RecoverableRpcProxy.toConnectURI(address, rpcTimeoutMillis, retryDelayMillis, retryTimeoutMillis); recoveryHandler.writeConnectUri(uri.toString()); protocolProxy.log("containerId", "timeout"); Assert.assertTrue("timedout", timedout.get()); rp.close(); server.stop(); }
From source file:edu.illinois.enforcemop.examples.hadoop.TestRPC.java
License:Apache License
@Test //@Schedule(name = "slowDone", value = "slowrpcDone@SlowRPC->beforeStop@main") public void testSlowRpc() throws Exception { System.out.println("Testing Slow RPC"); // create a server with two handlers Server server = RPC.getServer(TestProtocol.class, new TestImpl(), ADDRESS, 0, 2, false, conf, null); TestProtocol proxy = null;//from w ww. jav a 2s .c o m try { server.start(); InetSocketAddress addr = NetUtils.getConnectAddress(server); // create a client proxy = (TestProtocol) RPC.getProxy(TestProtocol.class, TestProtocol.versionID, addr, conf); SlowRPC slowrpc = new SlowRPC(proxy); Thread thread = new Thread(slowrpc, "SlowRPC"); thread.start(); // send a slow RPC, which won't return until two fast pings assertTrue("slowDone", !slowrpc.isDone()); proxy.slowPing(false); // first fast ping // verify that the first RPC is still stuck assertTrue("slowDone", !slowrpc.isDone()); proxy.slowPing(false); // second fast ping // Now the slow ping should be able to be executed //Original code : //OPWAIT while (!slowrpc.isDone()) { //OPWAIT System.out.println("Waiting for slow RPC to get done."); //OPWAIT try { // Thread.sleep(1000); //OPWAIT } catch (Exception e) {} //OPWAIT } try { Thread.sleep(1000); } catch (Exception e) { } } finally { server.stop(); if (proxy != null) { RPC.stopProxy(proxy); } System.out.println("Down slow rpc testing"); } //Interrupt thread manually Thread[] t = new Thread[2]; Thread.enumerate(t); t[1].interrupt(); }
From source file:edu.illinois.imunit.examples.hadoop.TestRPC.java
License:Apache License
@Test @Schedule(name = "slowDone", value = "slowrpcDone@SlowRPC->beforeStop@main") public void testSlowRpc() throws Exception { System.out.println("Testing Slow RPC"); // create a server with two handlers Server server = RPC.getServer(TestProtocol.class, new TestImpl(), ADDRESS, 0, 2, false, conf, null); TestProtocol proxy = null;/* w w w . ja v a 2 s .c o m*/ try { server.start(); InetSocketAddress addr = NetUtils.getConnectAddress(server); // create a client proxy = (TestProtocol) RPC.getProxy(TestProtocol.class, TestProtocol.versionID, addr, conf); SlowRPC slowrpc = new SlowRPC(proxy); Thread thread = new Thread(slowrpc, "SlowRPC"); thread.start(); // send a slow RPC, which won't return until two fast pings assertTrue("slowDone", !slowrpc.isDone()); proxy.slowPing(false); // first fast ping // verify that the first RPC is still stuck assertTrue("slowDone", !slowrpc.isDone()); proxy.slowPing(false); // second fast ping // Now the slow ping should be able to be executed //Original code : //OPWAIT while (!slowrpc.isDone()) { //OPWAIT System.out.println("Waiting for slow RPC to get done."); //OPWAIT try { // Thread.sleep(1000); //OPWAIT } catch (Exception e) {} //OPWAIT } } finally { fireEvent("beforeStop"); server.stop(); if (proxy != null) { RPC.stopProxy(proxy); } System.out.println("Down slow rpc testing"); } //Interrupt thread manually Thread[] t = new Thread[2]; Thread.enumerate(t); t[1].interrupt(); }
From source file:org.apache.nutch.searcher.TestDistributedSearch.java
License:Apache License
public void testDistibutedSearch() throws IOException { Configuration conf = NutchConfiguration.create(); //set up server & start it Server server = DistributedSearch.Server.getServer(conf, searchdir, conf.getInt(DISTRIBUTED_SEARCH_TEST_PORT, DEFAULT_PORT)); server.start();/*w ww . j av a2 s. co m*/ int port = conf.getInt(DISTRIBUTED_SEARCH_TEST_PORT, DEFAULT_PORT); InetSocketAddress[] addresses = new InetSocketAddress[1]; addresses[0] = new InetSocketAddress("localhost", port); Client c = new DistributedSearch.Client(addresses, conf); Query query = Query.parse("apache", conf); Hits hits = c.search(query, 5, null, null, false); c.getDetails(hits.getHit(0)); assertTrue(hits.getTotal() > 0); if (server != null) { server.stop(); } }
From source file:org.apache.nutch.searcher.TestDistributedSearch.java
License:Apache License
public void testUpdateSegments() throws IOException { // Startup 2 search servers. One was already started in setup, start another // one at a different port Configuration conf = NutchConfiguration.create(); Server server1 = DistributedSearch.Server.getServer(conf, searchdir, conf.getInt(DISTRIBUTED_SEARCH_TEST_PORT1, DEFAULT_PORT1)); Server server2 = DistributedSearch.Server.getServer(conf, searchdir, conf.getInt(DISTRIBUTED_SEARCH_TEST_PORT2, DEFAULT_PORT2)); server1.start();//from www. j a va 2s. c o m server2.start(); /* create a new file search-servers.txt * with 1 server at port 60000 */ FileSystem fs = FileSystem.get(conf); Path testServersPath = new Path(searchdir, "search-server.txt"); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fs.create(testServersPath, true))); bw.write("localhost " + DEFAULT_PORT1 + "\n"); bw.flush(); bw.close(); /* * Check if it found the server */ Client c = new DistributedSearch.Client(testServersPath, conf); boolean[] liveServers = c.getLiveServer(); assertEquals(liveServers.length, 1); /* Add both the servers at ports 60000 & 60005 * to the search-server.txt file */ // give the servers a little time to wait for file modification try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } bw = new BufferedWriter(new OutputStreamWriter(fs.create(testServersPath, true))); bw.write("localhost " + DEFAULT_PORT1 + "\n"); bw.write("localhost " + DEFAULT_PORT2 + "\n"); bw.flush(); bw.close(); // Check if it found both the servers c.updateSegments(); liveServers = c.getLiveServer(); assertEquals(liveServers.length, 2); if (server1 != null) { server1.stop(); } if (server2 != null) { server2.stop(); } fs.delete(testServersPath, true); }
From source file:org.apache.tajo.rpc.benchmark.BenchmarkHadoopRPC.java
License:Apache License
public static void main(String[] args) throws InterruptedException, IOException { Server server = RPC.getServer(new BenchmarkImpl(), "localhost", 15000, new Configuration()); server.start();/* w w w. ja v a 2s . c om*/ Thread.sleep(1000); int numThreads = 1; ClientWrapper client[] = new ClientWrapper[numThreads]; for (int i = 0; i < numThreads; i++) { client[i] = new ClientWrapper(); } for (int i = 0; i < numThreads; i++) { client[i].start(); } for (int i = 0; i < numThreads; i++) { client[i].join(); } server.stop(); }
From source file:rpc.TestRPC.java
License:Apache License
@Test public void testConfRpc() throws IOException { Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class).setInstance(new TestImpl()) .setBindAddress(ADDRESS).setPort(0).setNumHandlers(1).setVerbose(false).build(); // Just one handler int confQ = conf.getInt(CommonConfigurationKeys.IPC_SERVER_HANDLER_QUEUE_SIZE_KEY, CommonConfigurationKeys.IPC_SERVER_HANDLER_QUEUE_SIZE_DEFAULT); assertEquals(confQ, server.getMaxQueueSize()); int confReaders = conf.getInt(CommonConfigurationKeys.IPC_SERVER_RPC_READ_THREADS_KEY, CommonConfigurationKeys.IPC_SERVER_RPC_READ_THREADS_DEFAULT); assertEquals(confReaders, server.getNumReaders()); server.stop(); server = new RPC.Builder(conf).setProtocol(TestProtocol.class).setInstance(new TestImpl()) .setBindAddress(ADDRESS).setPort(0).setNumHandlers(1).setnumReaders(3).setQueueSizePerHandler(200) .setVerbose(false).build();//from ww w . j a v a 2 s .c o m assertEquals(3, server.getNumReaders()); assertEquals(200, server.getMaxQueueSize()); server.stop(); }
From source file:rpc.TestRPC.java
License:Apache License
@Test public void testProxyAddress() throws IOException { Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class).setInstance(new TestImpl()) .setBindAddress(ADDRESS).setPort(0).build(); TestProtocol proxy = null;// w w w . j av a 2 s . c om try { server.start(); InetSocketAddress addr = NetUtils.getConnectAddress(server); // create a client proxy = RPC.getProxy(TestProtocol.class, TestProtocol.versionID, addr, conf); assertEquals(addr, RPC.getServerAddress(proxy)); } finally { server.stop(); if (proxy != null) { RPC.stopProxy(proxy); } } }
From source file:rpc.TestRPC.java
License:Apache License
@Test public void testSlowRpc() throws IOException { System.out.println("Testing Slow RPC"); // create a server with two handlers Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class).setInstance(new TestImpl()) .setBindAddress(ADDRESS).setPort(0).setNumHandlers(2).setVerbose(false).build(); TestProtocol proxy = null;//from w ww . j a va2 s . co m try { server.start(); InetSocketAddress addr = NetUtils.getConnectAddress(server); // create a client proxy = RPC.getProxy(TestProtocol.class, TestProtocol.versionID, addr, conf); SlowRPC slowrpc = new SlowRPC(proxy); Thread thread = new Thread(slowrpc, "SlowRPC"); thread.start(); // send a slow RPC, which won't return until two // fast pings assertTrue("Slow RPC should not have finished1.", !slowrpc.isDone()); proxy.slowPing(false); // first fast ping // verify that the first RPC is still stuck assertTrue("Slow RPC should not have finished2.", !slowrpc.isDone()); proxy.slowPing(false); // second fast ping // Now the slow ping should be able to be executed while (!slowrpc.isDone()) { System.out.println("Waiting for slow RPC to get done."); try { Thread.sleep(1000); } catch (InterruptedException e) { } } } finally { server.stop(); if (proxy != null) { RPC.stopProxy(proxy); } System.out.println("Down slow rpc testing"); } }
From source file:rpc.TestRPC.java
License:Apache License
private void testCallsInternal(Configuration conf) throws IOException { Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class).setInstance(new TestImpl()) .setBindAddress(ADDRESS).setPort(0).build(); TestProtocol proxy = null;/*from w ww . j a v a 2 s. com*/ try { server.start(); InetSocketAddress addr = NetUtils.getConnectAddress(server); proxy = RPC.getProxy(TestProtocol.class, TestProtocol.versionID, addr, conf); proxy.ping(); String stringResult = proxy.echo("foo"); assertEquals(stringResult, "foo"); stringResult = proxy.echo((String) null); assertEquals(stringResult, null); String[] stringResults = proxy.echo(new String[] { "foo", "bar" }); assertTrue(Arrays.equals(stringResults, new String[] { "foo", "bar" })); stringResults = proxy.echo((String[]) null); assertTrue(Arrays.equals(stringResults, null)); // create multiple threads and make them do large data transfers System.out.println("Starting multi-threaded RPC test..."); server.setSocketSendBufSize(1024); Thread threadId[] = new Thread[numThreads]; for (int i = 0; i < numThreads; i++) { Transactions trans = new Transactions(proxy, datasize); threadId[i] = new Thread(trans, "TransactionThread-" + i); threadId[i].start(); } // wait for all transactions to get over System.out.println("Waiting for all threads to finish RPCs..."); for (int i = 0; i < numThreads; i++) { try { threadId[i].join(); } catch (InterruptedException e) { i--; // retry } } } catch (Exception e) { e.printStackTrace(); } finally { server.stop(); if (proxy != null) RPC.stopProxy(proxy); } }