Package org.apache.avro.ipc

Examples of org.apache.avro.ipc.Server


    List<Server> servers = new ArrayList<Server>();
    StringBuilder hostList = new StringBuilder("");
    for (int i = 0; i < 3; i++) {
      LoadBalancedAvroHandler s = new LoadBalancedAvroHandler();
      hosts.add(s);
      Server srv = RpcTestUtils.startServer(s);
      servers.add(srv);
      String name = "h" + i;
      p.put("hosts." + name, "127.0.0.1:" + srv.getPort());
      hostList.append(name).append(" ");
    }
    p.put("hosts", hostList.toString().trim());
    p.put("client.type", "default_loadbalance");
    p.put("host-selector", "round_robin");
View Full Code Here


      LoadBalancedAvroHandler s = new LoadBalancedAvroHandler();
      hosts.add(s);
      if(i == 1) {
        s.setFailed();
      }
      Server srv = RpcTestUtils.startServer(s);
      servers.add(srv);
      String name = "h" + i;
      p.put("hosts." + name, "127.0.0.1:" + srv.getPort());
      hostList.append(name).append(" ");
    }
    p.put("hosts", hostList.toString().trim());
    p.put("client.type", "default_loadbalance");
    p.put("host-selector", "round_robin");
View Full Code Here

      LoadBalancedAvroHandler s = new LoadBalancedAvroHandler();
      hosts.add(s);
      if (i == 1) {
        s.setFailed();
      }
      Server srv = RpcTestUtils.startServer(s);
      servers.add(srv);
      String name = "h" + i;
      p.put("hosts." + name, "127.0.0.1:" + srv.getPort());
      hostList.append(name).append(" ");
    }
    p.put("hosts", hostList.toString().trim());
    p.put("client.type", "default_loadbalance");
    p.put("host-selector", "round_robin");
View Full Code Here

   * @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);
View Full Code Here

   * @throws EventDeliveryException
   */
  public static void handlerBatchAppendTest(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);

      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, int port, boolean enableCompression) {
    Responder responder = new SpecificResponder(AvroSourceProtocol.class,
        handler);
    Server server;
    if (enableCompression) {
      server = new NettyServer(responder,
          new InetSocketAddress(localhost, port),
          new NioServerSocketChannelFactory
          (Executors .newCachedThreadPool(), Executors.newCachedThreadPool()),
          new CompressionChannelPipelineFactory(), null);
    } else {
      server = new NettyServer(responder,
        new InetSocketAddress(localhost, port));
    }
    server.start();
    logger.info("Server started on hostname: {}, port: {}",
        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());
    Properties props = new Properties();
    props.setProperty(RpcClientConfigurationConstants.CONFIG_HOSTS, "localhost");
    props.setProperty(RpcClientConfigurationConstants.CONFIG_HOSTS_PREFIX + "localhost",
        localhost + ":" + server.getPort());
    props.setProperty(RpcClientConfigurationConstants.CONFIG_BATCH_SIZE, "" + batchSize);
    try {
      client = new NettyAvroRpcClient();
      client.configure(props);
View Full Code Here

   */
  @Test(expected=EventDeliveryException.class)
  public void testServerDisconnect() throws FlumeException,
      EventDeliveryException, InterruptedException {
    NettyAvroRpcClient client = null;
    Server server = RpcTestUtils.startServer(new OKAvroHandler());
    try {
      client = RpcTestUtils.getStockLocalClient(server.getPort());
      server.close();
      Thread.sleep(1000L); // wait a second for the close to occur
      try {
        server.join();
      } catch (InterruptedException ex) {
        logger.warn("Thread interrupted during join()", ex);
        Thread.currentThread().interrupt();
      }
      try {
View Full Code Here

   */
  @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 {
View Full Code Here

  @Test
  public void testFailover()
      throws FlumeException, EventDeliveryException,InterruptedException {
    FailoverRpcClient client = null;
    Server server1 = RpcTestUtils.startServer(new OKAvroHandler());
    Server server2 = RpcTestUtils.startServer(new OKAvroHandler());
    Server server3 = RpcTestUtils.startServer(new OKAvroHandler());
    Properties props = new Properties();
    int s1Port = server1.getPort();
    int s2Port = server2.getPort();
    int s3Port = server3.getPort();
    props.put("client.type", "default_failover");
    props.put("hosts", "host1 host2 host3");
    props.put("hosts.host1", "127.0.0.1:" + String.valueOf(s1Port));
    props.put("hosts.host2", "127.0.0.1:" + String.valueOf(s2Port));
    props.put("hosts.host3", "127.0.0.1:" + String.valueOf(s3Port));
    client = (FailoverRpcClient) RpcClientFactory.getInstance(props);
    List<Event> events = new ArrayList<Event>();
    for (int i = 0; i < 50; i++) {
      events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
    }
    client.appendBatch(events);
    Assert.assertEquals(client.getLastConnectedServerAddress(),
        new InetSocketAddress("127.0.0.1", server1.getPort()));
    server1.close();
    Thread.sleep(1000L); // wait a second for the close to occur
    events = new ArrayList<Event>();
    for (int i = 0; i < 50; i++) {
      events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
    }
    client.appendBatch(events);
    Assert.assertEquals(new InetSocketAddress("localhost", server2.getPort()),
        client.getLastConnectedServerAddress());
    server2.close();
    Thread.sleep(1000L); // wait a second for the close to occur
    client.append(EventBuilder.withBody("Had a sandwich?",
        Charset.forName("UTF8")));
    Assert.assertEquals(new InetSocketAddress("localhost", server3.getPort()),
        client.getLastConnectedServerAddress());
    // Bring server 2 back.
    Server server4 = RpcTestUtils.startServer(new OKAvroHandler(), s2Port);
    server3.close();
    Thread.sleep(1000L); // wait a second for the close to occur
    events = new ArrayList<Event>();
    for (int i = 0; i < 50; i++) {
      events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
    }
    client.appendBatch(events);
    Assert.assertEquals(new InetSocketAddress("localhost", s2Port),
        client.getLastConnectedServerAddress());

    Server server5 = RpcTestUtils.startServer(new OKAvroHandler(), s1Port);
    // Make sure we are still talking to server 4

    client
    .append(EventBuilder.withBody("Had a mango?", Charset.forName("UTF8")));
    Assert.assertEquals(new InetSocketAddress("localhost", s2Port),
        client.getLastConnectedServerAddress());
    server4.close();
    Thread.sleep(1000L); // wait a second for the close to occur
    events = new ArrayList<Event>();
    for (int i = 0; i < 50; i++) {
      events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
    }
    client.appendBatch(events);
    Assert.assertEquals(new InetSocketAddress("localhost", s1Port),
        client.getLastConnectedServerAddress());
    server5.close();
    Thread.sleep(1000L); // wait a second for the close to occur
    Server server6 = RpcTestUtils.startServer(new OKAvroHandler(), s1Port);
    client
    .append(EventBuilder.withBody("Had a whole watermelon?",
        Charset.forName("UTF8")));
    Assert.assertEquals(new InetSocketAddress("localhost", s1Port),
        client.getLastConnectedServerAddress());

    server6.close();
    Thread.sleep(1000L); // wait a second for the close to occur
    Server server7 = RpcTestUtils.startServer(new OKAvroHandler(), s3Port);
    events = new ArrayList<Event>();
    for (int i = 0; i < 50; i++) {
      events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
    }
    client.appendBatch(events);
    Assert.assertEquals(new InetSocketAddress("localhost", s3Port),
        client.getLastConnectedServerAddress());
    server7.close();
  }
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.