Package org.apache.flume

Examples of org.apache.flume.Context


    Assert.fail();
  }

  @Test
  public void testCapacityBufferEmptyingAfterTakeCommit() {
    Context context = new Context();
    Map<String, String> parms = new HashMap<String, String>();
    parms.put("capacity", "3");
    parms.put("transactionCapacity", "3");
    context.putAll(parms);
    Configurables.configure(channel,  context);

    Transaction tx = channel.getTransaction();
    tx.begin();
    channel.put(EventBuilder.withBody("test".getBytes()));
View Full Code Here


    Assume.assumeNotNull(accessToken);

    String accessTokenSecret = System.getProperty("twitter.accessTokenSecret");
    Assume.assumeNotNull(accessTokenSecret);

    Context context = new Context();
    context.put("consumerKey", consumerKey);
    context.put("consumerSecret", consumerSecret);
    context.put("accessToken", accessToken);
    context.put("accessTokenSecret", accessTokenSecret);
    context.put("maxBatchDurationMillis", "1000");

    TwitterSource source = new TwitterSource();
    source.configure(context);

    Map<String, String> channelContext = new HashMap();
    channelContext.put("capacity", "1000000");
    channelContext.put("keep-alive", "0"); // for faster tests
    Channel channel = new MemoryChannel();
    Configurables.configure(channel, new Context(channelContext));

    Sink sink = new LoggerSink();
    sink.setChannel(channel);
    sink.start();
    DefaultSinkProcessor proc = new DefaultSinkProcessor();
View Full Code Here

    tx.close();
  }

  @Test
  public void testCapacityBufferEmptyingAfterRollback() {
    Context context = new Context();
    Map<String, String> parms = new HashMap<String, String>();
    parms.put("capacity", "3");
    parms.put("transactionCapacity", "3");
    context.putAll(parms);
    Configurables.configure(channel,  context);

    Transaction tx = channel.getTransaction();
    tx.begin();
    channel.put(EventBuilder.withBody("test".getBytes()));
View Full Code Here

    ///////////////////////////////////////////////////////
    // channel / source setup

    // set up channel to receive events
    MemoryChannel chan = new MemoryChannel();
    chan.configure(new Context());
    chan.start();
    ReplicatingChannelSelector sel = new ReplicatingChannelSelector();
    sel.setChannels(Lists.<Channel>newArrayList(chan));
    ChannelProcessor chanProc = new ChannelProcessor(sel);
View Full Code Here

    tx.close();
  }

  @Test(expected=ChannelException.class)
  public void testByteCapacityOverload() {
    Context context = new Context();
    Map<String, String> parms = new HashMap<String, String>();
    parms.put("byteCapacity", "2000");
    parms.put("byteCapacityBufferPercentage", "20");
    context.putAll(parms);
    Configurables.configure(channel,  context);

    byte[] eventBody = new byte[405];

    Transaction transaction = channel.getTransaction();
View Full Code Here

    Assert.fail();

  }

  public void testByteCapacityBufferEmptyingAfterTakeCommit() {
    Context context = new Context();
    Map<String, String> parms = new HashMap<String, String>();
    parms.put("byteCapacity", "2000");
    parms.put("byteCapacityBufferPercentage", "20");
    context.putAll(parms);
    Configurables.configure(channel,  context);

    byte[] eventBody = new byte[405];

    Transaction tx = channel.getTransaction();
View Full Code Here

    setUp();
    Server server = createServer(new MockAvroServer());

    server.start();

    Context context = new Context();

    context.put("hostname", hostname);
    context.put("port", String.valueOf(port));
    context.put("batch-size", String.valueOf(2));
    context.put("connect-timeout", String.valueOf(2000L));
    context.put("request-timeout", String.valueOf(3000L));
    context.put("reset-connection-interval", String.valueOf("5"));

    sink.setChannel(channel);
    Configurables.configure(sink, context);
    sink.start();
    RpcClient firstClient = sink.getUnderlyingClient();
    Thread.sleep(6000);
    Transaction t = channel.getTransaction();
    t.begin();
    channel.put(EventBuilder.withBody("This is a test", Charset.defaultCharset()));
    t.commit();
    t.close();
    sink.process();
    // Make sure they are not the same object, connection should be reset
    Assert.assertFalse(firstClient == sink.getUnderlyingClient());
    sink.stop();

    context.put("hostname", hostname);
    context.put("port", String.valueOf(port));
    context.put("batch-size", String.valueOf(2));
    context.put("connect-timeout", String.valueOf(2000L));
    context.put("request-timeout", String.valueOf(3000L));
    context.put("reset-connection-interval", String.valueOf("0"));

    sink.setChannel(channel);
    Configurables.configure(sink, context);
    sink.start();
    firstClient = sink.getUnderlyingClient();
    Thread.sleep(6000);
    // Make sure they are the same object, since connection should not be reset
    Assert.assertTrue(firstClient == sink.getUnderlyingClient());
    sink.stop();

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

    sink.setChannel(channel);
    Configurables.configure(sink, context);
    sink.start();
    firstClient = sink.getUnderlyingClient();
View Full Code Here

    tx.close();
  }

  @Test
  public void testByteCapacityBufferEmptyingAfterRollback() {
    Context context = new Context();
    Map<String, String> parms = new HashMap<String, String>();
    parms.put("byteCapacity", "2000");
    parms.put("byteCapacityBufferPercentage", "20");
    context.putAll(parms);
    Configurables.configure(channel,  context);

    byte[] eventBody = new byte[405];

    Transaction tx = channel.getTransaction();
View Full Code Here

    tx.close();
  }

  @Test
  public void testByteCapacityBufferChangeConfig() {
    Context context = new Context();
    Map<String, String> parms = new HashMap<String, String>();
    parms.put("byteCapacity", "2000");
    parms.put("byteCapacityBufferPercentage", "20");
    context.putAll(parms);
    Configurables.configure(channel,  context);

    byte[] eventBody = new byte[405];

    Transaction tx = channel.getTransaction();
    tx.begin();
    channel.put(EventBuilder.withBody(eventBody));
    tx.commit();
    tx.close();
    channel.stop();
    parms.put("byteCapacity", "1500");
    context.putAll(parms);
    Configurables.configure(channel,  context);
    channel.start();
    tx = channel.getTransaction();
    tx.begin();
    channel.put(EventBuilder.withBody(eventBody));
    try {
      channel.put(EventBuilder.withBody(eventBody));
      tx.commit();
      Assert.fail();
    } catch ( ChannelException e ) {
      //success
      tx.rollback();
    } finally {
      tx.close();
    }

    channel.stop();
    parms.put("byteCapacity", "250");
    parms.put("byteCapacityBufferPercentage", "20");
    context.putAll(parms);
    Configurables.configure(channel,  context);
    channel.start();
    tx = channel.getTransaction();
    tx.begin();
    channel.put(EventBuilder.withBody(eventBody));
    tx.commit();
    tx.close();
    channel.stop();

    parms.put("byteCapacity", "300");
    context.putAll(parms);
    Configurables.configure(channel,  context);
    channel.start();
    tx = channel.getTransaction();
    tx.begin();
    try {
      for(int i = 0; i < 2; i++) {
        channel.put(EventBuilder.withBody(eventBody));
      }
      tx.commit();
      Assert.fail();
    } catch ( ChannelException e ) {
      //success
      tx.rollback();
    } finally {
      tx.close();
    }

    channel.stop();
    parms.put("byteCapacity", "3300");
    context.putAll(parms);
    Configurables.configure(channel,  context);
    channel.start();
    tx = channel.getTransaction();
    tx.begin();

    try {
      for(int i = 0; i < 15; i++) {
        channel.put(EventBuilder.withBody(eventBody));
      }
      tx.commit();
      Assert.fail();
    } catch ( ChannelException e ) {
      //success
      tx.rollback();
    } finally {
      tx.close();
    }
    channel.stop();
    parms.put("byteCapacity", "4000");
    context.putAll(parms);
    Configurables.configure(channel,  context);
    channel.start();
    tx = channel.getTransaction();
    tx.begin();
View Full Code Here

  /*
   * This would cause a NPE without FLUME-1622.
   */
  @Test
  public void testNullEmptyEvent() {
    Context context = new Context();
    Map<String, String> parms = new HashMap<String, String>();
    parms.put("byteCapacity", "2000");
    parms.put("byteCapacityBufferPercentage", "20");
    context.putAll(parms);
    Configurables.configure(channel,  context);

    Transaction tx = channel.getTransaction();
    tx.begin();
    //This line would cause a NPE without FLUME-1622.
View Full Code Here

TOP

Related Classes of org.apache.flume.Context

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.