@Override public void run() { while (running.get()) { switch (random.nextInt() % 2) { case 0: // start a server try { cluster.startServer(); } catch (Exception e) { LOG.warn(e); exception.compareAndSet(null, e); } break; case 1: // stop a server try { cluster.stopRandomServer(); } catch (Exception e) { LOG.warn(e); exception.compareAndSet(null, e); } default: } Threads.sleep(100); } }
public void testRpcWithChaosMonkey(boolean isSyncClient) throws Throwable { LOG.info("Starting test"); Cluster cluster = new Cluster(10, 100); for (int i = 0; i < 10; i++) { cluster.startServer(); } ArrayList<SimpleClient> clients = new ArrayList<>(); // all threads should share the same rpc client AbstractRpcClient<?> rpcClient = createRpcClient(conf, isSyncClient); for (int i = 0; i < 30; i++) { String clientId = "client_" + i + "_"; LOG.info("Starting client: " + clientId); SimpleClient client = new SimpleClient(cluster, rpcClient, clientId); client.start(); clients.add(client); } LOG.info("Starting MiniChaosMonkey"); MiniChaosMonkey cm = new MiniChaosMonkey(cluster); cm.start(); Threads.sleep(30000); LOG.info("Stopping MiniChaosMonkey"); cm.stopRunning(); cm.join(); cm.rethrowException(); LOG.info("Stopping clients"); for (SimpleClient client : clients) { LOG.info("Stopping client: " + client.id); LOG.info(client.id + " numCalls:" + client.numCalls); client.stopRunning(); client.join(); client.rethrowException(); assertTrue(client.numCalls > 10); } LOG.info("Stopping RpcClient"); rpcClient.close(); LOG.info("Stopping Cluster"); cluster.stopRunning(); }
/* Test that not started connections are successfully removed from connection pool when rpc client is closing. */ @Test(timeout = 30000) public void testRpcWithWriteThread() throws IOException, InterruptedException { LOG.info("Starting test"); Cluster cluster = new Cluster(1, 1); cluster.startServer(); conf.setBoolean(SPECIFIC_WRITE_THREAD, true); for (int i = 0; i < 1000; i++) { AbstractRpcClient<?> rpcClient = createRpcClient(conf, true); SimpleClient client = new SimpleClient(cluster, rpcClient, "Client1"); client.start(); while (!client.isSending()) { Thread.sleep(1); } client.stopRunning(); rpcClient.close(); } }