Tabnine Logo
RpcTestUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
RpcTestUtils
in
org.apache.flume.api

Best Java code snippets using org.apache.flume.api.RpcTestUtils (Showing top 20 results out of 315)

origin: apache/flume

public static Server startServer(AvroSourceProtocol handler) {
 return startServer(handler, 0, false);
}
origin: apache/flume

/**
 * 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);
}
origin: apache/flume

public static void handlerBatchAppendTest(AvroSourceProtocol handler)
  throws FlumeException, EventDeliveryException {
 handlerBatchAppendTest(handler, false, false, 0);
}
origin: apache/flume

@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();
 }
}
origin: apache/flume

/**
 * 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();
 }
}
origin: apache/flume

/**
 * 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);
}
origin: apache/incubator-htrace

private void stop() {
 if (flumeServer != null) {
  RpcTestUtils.stopServer(flumeServer);
  flumeServer = null;
 }
}
origin: apache/flume

@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();
 }
}
origin: apache/flume

 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();
origin: apache/flume

/**
 * 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!");
}
origin: apache/flume

@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();
 }
}
origin: apache/flume

/**
 * 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();
 }
}
origin: apache/flume

public static Server startServer(AvroSourceProtocol handler, int port) {
 return startServer(handler, port, false);
}
origin: apache/flume

/**
 * 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!");
}
origin: apache/flume

/**
 * 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!");
}
origin: apache/flume

/**
 * 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();
  }
 }
}
origin: apache/flume

 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();
origin: apache/flume

@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();
 }
}
origin: apache/flume

/**
 * 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!");
}
origin: apache/flume

/**
 * 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!");
}
org.apache.flume.apiRpcTestUtils

Javadoc

Helpers for Netty Avro RPC testing

Most used methods

  • startServer
    Start a NettyServer, wait a moment for it to spin up, and return it.
  • stopServer
    Request that the specified Server stop, and attempt to wait for it to exit.
  • getStockLocalClient
  • handlerBatchAppendTest
    Helper method for testing batch appends on handlers
  • handlerSimpleAppendTest
    Helper method for testing simple (single) with compression level 6 appends on handlers

Popular in Java

  • Reading from database using SQL prepared statement
  • notifyDataSetChanged (ArrayAdapter)
  • putExtra (Intent)
  • getApplicationContext (Context)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • JButton (javax.swing)
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now