public static Server startServer(AvroSourceProtocol handler) { return startServer(handler, 0, false); }
/** * Helper method for constructing a Netty RPC client that talks to localhost. */ public static NettyAvroRpcClient getStockLocalClient(int port) { Properties props = new Properties(); return getStockLocalClient(port, props); }
public static void handlerBatchAppendTest(AvroSourceProtocol handler) throws FlumeException, EventDeliveryException { handlerBatchAppendTest(handler, false, false, 0); }
@Test public void testPropertiesBatchAppend() throws FlumeException, EventDeliveryException { int batchSize = 7; RpcClient client = null; Server server = RpcTestUtils.startServer(new OKAvroHandler()); try { Properties p = new Properties(); p.put("hosts", "host1"); p.put("hosts.host1", localhost + ":" + String.valueOf(server.getPort())); p.put("batch-size", String.valueOf(batchSize)); client = RpcClientFactory.getInstance(p); List<Event> events = new ArrayList<Event>(); for (int i = 0; i < batchSize; i++) { events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8"))); } client.appendBatch(events); } finally { RpcTestUtils.stopServer(server); if (client != null) client.close(); } }
/** * Helper method for testing simple (single) with compression level 6 appends on handlers * @param handler * @throws FlumeException * @throws EventDeliveryException */ public static void handlerSimpleAppendTest(AvroSourceProtocol handler, boolean enableServerCompression, boolean enableClientCompression, int compressionLevel) throws FlumeException, EventDeliveryException { NettyAvroRpcClient client = null; Server server = startServer(handler, 0, enableServerCompression); try { Properties starterProp = new Properties(); if (enableClientCompression) { starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_TYPE, "deflate"); starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_LEVEL, "" + compressionLevel); } else { starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_TYPE, "none"); } client = getStockLocalClient(server.getPort(), starterProp); boolean isActive = client.isActive(); Assert.assertTrue("Client should be active", isActive); client.append(EventBuilder.withBody("wheee!!!", Charset.forName("UTF8"))); } finally { stopServer(server); if (client != null) client.close(); } }
/** * Helper method for testing simple (single) appends on handlers * @param handler * @throws FlumeException * @throws EventDeliveryException */ public static void handlerSimpleAppendTest(AvroSourceProtocol handler) throws FlumeException, EventDeliveryException { handlerSimpleAppendTest(handler, false, false, 0); }
private void stop() { if (flumeServer != null) { RpcTestUtils.stopServer(flumeServer); flumeServer = null; } }
@Test public void testThreeParamBatchAppend() throws FlumeException, EventDeliveryException { int batchSize = 7; RpcClient client = null; Server server = RpcTestUtils.startServer(new OKAvroHandler()); try { client = RpcClientFactory.getDefaultInstance(localhost, server.getPort(), batchSize); List<Event> events = new ArrayList<Event>(); for (int i = 0; i < batchSize; i++) { events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8"))); } client.appendBatch(events); } finally { RpcTestUtils.stopServer(server); if (client != null) client.close(); } }
throws FlumeException, EventDeliveryException { NettyAvroRpcClient client = null; Server server = startServer(handler, 0 , enableServerCompression); try { client = getStockLocalClient(server.getPort(), starterProp); boolean isActive = client.isActive(); Assert.assertTrue("Client should be active", isActive); stopServer(server); if (client != null) client.close();
/** * Send an event to an online server that returns UNKNOWN. */ @Test(expected = EventDeliveryException.class) public void testUnknownServerSimple() throws FlumeException, EventDeliveryException { RpcTestUtils.handlerSimpleAppendTest(new UnknownAvroHandler()); logger.error("Unknown: I should never have gotten here!"); }
@Test public void testTwoParamDeprecatedAppend() throws FlumeException, EventDeliveryException { RpcClient client = null; Server server = RpcTestUtils.startServer(new OKAvroHandler()); try { client = RpcClientFactory.getInstance(localhost, server.getPort()); client.append(EventBuilder.withBody("wheee!!!", Charset.forName("UTF8"))); } finally { RpcTestUtils.stopServer(server); if (client != null) client.close(); } }
/** * First connect the client, then close the client, then send a request. * @throws FlumeException * @throws EventDeliveryException */ @Test(expected = EventDeliveryException.class) public void testClientClosedRequest() throws FlumeException, EventDeliveryException { NettyAvroRpcClient client = null; Server server = RpcTestUtils.startServer(new OKAvroHandler()); try { client = RpcTestUtils.getStockLocalClient(server.getPort()); client.close(); Assert.assertFalse("Client should not be active", client.isActive()); System.out.println("Yaya! I am not active after client close!"); client.append(EventBuilder.withBody("hello", Charset.forName("UTF8"))); } finally { RpcTestUtils.stopServer(server); if (client != null) client.close(); } }
public static Server startServer(AvroSourceProtocol handler, int port) { return startServer(handler, port, false); }
/** * Send an event to an online server that throws an exception. */ @Test(expected = EventDeliveryException.class) public void testThrowingServerSimple() throws FlumeException, EventDeliveryException { RpcTestUtils.handlerSimpleAppendTest(new ThrowingAvroHandler()); logger.error("Throwing: I should never have gotten here!"); }
/** * Send a batch of events to a server that returns UNKNOWN. */ @Test(expected = EventDeliveryException.class) public void testUnknownServerBatch() throws FlumeException, EventDeliveryException { RpcTestUtils.handlerBatchAppendTest(new UnknownAvroHandler()); logger.error("Unknown: I should never have gotten here!"); }
/** * configure the NettyAvroRpcClient with a non-default * NioClientSocketChannelFactory number of io worker threads * * @throws FlumeException * @throws EventDeliveryException */ @Test public void testAppendWithMaxIOWorkers() throws FlumeException, EventDeliveryException { NettyAvroRpcClient client = null; Server server = RpcTestUtils.startServer(new OKAvroHandler()); Properties props = new Properties(); props.setProperty(RpcClientConfigurationConstants.CONFIG_HOSTS, "localhost"); props.setProperty(RpcClientConfigurationConstants.CONFIG_HOSTS_PREFIX + "localhost", localhost + ":" + server.getPort()); props.setProperty(RpcClientConfigurationConstants.MAX_IO_WORKERS, Integer.toString(2)); try { client = new NettyAvroRpcClient(); client.configure(props); for (int i = 0; i < 5; i++) { client.append(EventBuilder.withBody("evt:" + i, Charset.forName("UTF8"))); } } finally { RpcTestUtils.stopServer(server); if (client != null) { client.close(); } } }
EventDeliveryException, InterruptedException { NettyAvroRpcClient client = null; Server server = RpcTestUtils.startServer(new OKAvroHandler()); try { client = RpcTestUtils.getStockLocalClient(server.getPort()); server.close(); RpcTestUtils.stopServer(server); if (client != null) client.close();
@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(); } }
/** * Send an event to an online server that returns FAILED. */ @Test(expected = EventDeliveryException.class) public void testFailedServerSimple() throws FlumeException, EventDeliveryException { RpcTestUtils.handlerSimpleAppendTest(new FailedAvroHandler()); logger.error("Failed: I should never have gotten here!"); }
/** * Send a batch of events to a server that returns FAILED. */ @Test(expected = EventDeliveryException.class) public void testFailedServerBatch() throws FlumeException, EventDeliveryException { RpcTestUtils.handlerBatchAppendTest(new FailedAvroHandler()); logger.error("Failed: I should never have gotten here!"); }