Package org.apache.avro.ipc

Examples of org.apache.avro.ipc.Server


  @Test
  public void testSslSinkWithNonTrustedCert() throws InterruptedException,
      EventDeliveryException, InstantiationException, IllegalAccessException {
    setUp();
    Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
    Server server = createSslServer(new MockAvroServer());

    server.start();

    Context context = new Context();

    context.put("hostname", hostname);
    context.put("port", String.valueOf(port));
    context.put("ssl", String.valueOf(true));
    context.put("batch-size", String.valueOf(2));
    context.put("connect-timeout", String.valueOf(2000L));
    context.put("request-timeout", String.valueOf(3000L));

    Configurables.configure(sink, context);

    sink.start();
    Assert.assertTrue(LifecycleController.waitForOneOf(sink,
        LifecycleState.START_OR_ERROR, 5000));

    Transaction transaction = channel.getTransaction();

    transaction.begin();
    for (int i = 0; i < 10; i++) {
      channel.put(event);
    }
    transaction.commit();
    transaction.close();

    boolean failed = false;
    try {
      for (int i = 0; i < 5; i++) {
        sink.process();
        failed = true;
      }
    } catch (EventDeliveryException ex) {
      logger.info("Correctly failed to send event", ex);
    }


    sink.stop();
    Assert.assertTrue(LifecycleController.waitForOneOf(sink,
        LifecycleState.STOP_OR_ERROR, 5000));

    server.close();

    if (failed) {
      Assert.fail("SSL-enabled sink successfully connected to a server with an untrusted certificate when it should have failed");
    }
  }
View Full Code Here


  }

  private Server createSslServer(AvroSourceProtocol protocol)
      throws IllegalAccessException, InstantiationException {
    Server server = new NettyServer(new SpecificResponder(
        AvroSourceProtocol.class, protocol), new InetSocketAddress(hostname, port),
            new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool()),
            new SSLChannelPipelineFactory(),
View Full Code Here

  @Test
  public void testTwoParamSimpleAppend() 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();
    }
View Full Code Here

  @Test
  public void testThreeParamBatchAppend() throws FlumeException,
      EventDeliveryException {
    int batchSize = 7;
    RpcClient client = null;
    Server server = RpcTestUtils.startServer(new OKAvroHandler());
    try {
      client = RpcClientFactory.getInstance(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")));
View Full Code Here

  // we are supposed to handle this gracefully
  @Test
  public void testTwoParamBatchAppendOverflow() throws FlumeException,
      EventDeliveryException {
    RpcClient client = null;
    Server server = RpcTestUtils.startServer(new OKAvroHandler());
    try {
      client = RpcClientFactory.getInstance(localhost, server.getPort());
      int batchSize = client.getBatchSize();
      int moreThanBatch = batchSize + 1;
      List<Event> events = new ArrayList<Event>();
      for (int i = 0; i < moreThanBatch; i++) {
        events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
View Full Code Here

   * @throws EventDeliveryException
   */
  public static void handlerSimpleAppendTest(AvroSourceProtocol handler)
      throws FlumeException, EventDeliveryException {
    NettyAvroRpcClient client = null;
    Server server = startServer(handler);
    try {
      client = getStockLocalClient(server.getPort());
      boolean isActive = client.isActive();
      Assert.assertTrue("Client should be active", isActive);
      client.append(EventBuilder.withBody("wheee!!!", Charset.forName("UTF8")));
    } finally {
      stopServer(server);
View Full Code Here

   * @throws EventDeliveryException
   */
  public static void handlerBatchAppendTest(AvroSourceProtocol handler)
      throws FlumeException, EventDeliveryException {
    NettyAvroRpcClient client = null;
    Server server = startServer(handler);
    try {
      client = getStockLocalClient(server.getPort());
      boolean isActive = client.isActive();
      Assert.assertTrue("Client should be active", isActive);

      int batchSize = client.getBatchSize();
      List<Event> events = new ArrayList<Event>();
View Full Code Here

   * Start a NettyServer, wait a moment for it to spin up, and return it.
   */
  public static Server startServer(AvroSourceProtocol handler) {
    Responder responder = new SpecificResponder(AvroSourceProtocol.class,
        handler);
    Server server = new NettyServer(responder,
        new InetSocketAddress(localhost, 0));
    server.start();
    logger.log(Level.INFO, "Server started on hostname: {0}, port: {1}",
        new Object[] { localhost, Integer.toString(server.getPort()) });

    try {

      Thread.sleep(300L);

View Full Code Here

  public void testBatchOverrun() throws FlumeException, EventDeliveryException {

    int batchSize = 10;
    int moreThanBatchSize = batchSize + 1;
    NettyAvroRpcClient client = null;
    Server server = RpcTestUtils.startServer(new OKAvroHandler());
    try {
      client = new NettyAvroRpcClient.Builder()
          .hostname(localhost).port(server.getPort()).batchSize(batchSize)
          .build();

      // send one more than the batch size
      List<Event> events = new ArrayList<Event>();
      for (int i = 0; i < moreThanBatchSize; i++) {
View Full Code Here

   */
  @Test(expected=EventDeliveryException.class)
  public void testServerDisconnect() throws FlumeException,
      EventDeliveryException {
    NettyAvroRpcClient client = null;
    Server server = RpcTestUtils.startServer(new OKAvroHandler());
    try {
      client = RpcTestUtils.getStockLocalClient(server.getPort());
      server.close();
      try {
        server.join();
      } catch (InterruptedException ex) {
        logger.log(Level.WARNING, "Thread interrupted during join()", ex);
        Thread.currentThread().interrupt();
      }
      try {
View Full Code Here

TOP

Related Classes of org.apache.avro.ipc.Server

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.