Search in sources :

Example 1 with Transaction

use of org.apache.flume.Transaction in project logging-log4j2 by apache.

the class FlumeAppenderTest method testIncompleteBatch2.

@Test
public void testIncompleteBatch2() throws IOException {
    final Agent[] agents = new Agent[] { Agent.createAgent("localhost", testPort) };
    final FlumeAppender avroAppender = FlumeAppender.createAppender(agents, null, null, "false", "Avro", null, "1000", "1000", "1", "500", "avro", "false", null, null, null, null, null, "true", "10", null, null, null, null);
    avroAppender.start();
    avroLogger.addAppender(avroAppender);
    avroLogger.setLevel(Level.ALL);
    Assert.assertNotNull(avroLogger);
    avroLogger.info("Test message 0");
    final Transaction transaction = channel.getTransaction();
    transaction.begin();
    avroLogger.info("Test message 1");
    avroLogger.info("Test message 2");
    avroAppender.stop();
    for (int i = 0; i < 3; ++i) {
        final Event event = channel.take();
        Assert.assertNotNull("No event for item " + i, event);
        Assert.assertTrue("Channel contained event, but not expected message. Received : " + getBody(event), getBody(event).endsWith("Test message " + i));
    }
    transaction.commit();
    transaction.close();
    eventSource.stop();
}
Also used : Transaction(org.apache.flume.Transaction) Event(org.apache.flume.Event) Test(org.junit.Test)

Example 2 with Transaction

use of org.apache.flume.Transaction in project logging-log4j2 by apache.

the class FlumeAppenderTest method testIncompleteBatch.

//@Ignore //(Remko: this test hangs my build...)
@Test
public void testIncompleteBatch() throws IOException {
    final Agent[] agents = new Agent[] { Agent.createAgent("localhost", testPort) };
    final FlumeAppender avroAppender = FlumeAppender.createAppender(agents, null, null, "false", "Avro", null, "1000", "1000", "1", "500", "avro", "false", null, null, null, null, null, "true", "10", null, null, null, null);
    avroAppender.start();
    avroLogger.addAppender(avroAppender);
    avroLogger.setLevel(Level.ALL);
    Assert.assertNotNull(avroLogger);
    avroLogger.info("Test message 0");
    final Transaction transaction = channel.getTransaction();
    transaction.begin();
    Event event = channel.take();
    Assert.assertNull("Received event", event);
    try {
        Thread.sleep(500);
    } catch (final InterruptedException ie) {
    }
    avroLogger.info("Test message 1");
    for (int i = 0; i < 2; ++i) {
        event = channel.take();
        Assert.assertNotNull("No event for item " + i, event);
        Assert.assertTrue("Channel contained event, but not expected message", getBody(event).endsWith("Test message " + i));
    }
    transaction.commit();
    transaction.close();
    eventSource.stop();
}
Also used : Transaction(org.apache.flume.Transaction) Event(org.apache.flume.Event) Test(org.junit.Test)

Example 3 with Transaction

use of org.apache.flume.Transaction in project logging-log4j2 by apache.

the class FlumeAppenderTest method testLog4jAvroAppender.

@Test
public void testLog4jAvroAppender() throws IOException {
    final Agent[] agents = new Agent[] { Agent.createAgent("localhost", testPort) };
    final FlumeAppender avroAppender = FlumeAppender.createAppender(agents, null, null, "false", "Avro", null, "1000", "1000", "1", "1000", "avro", "false", null, null, null, null, null, "true", "1", null, null, null, null);
    avroAppender.start();
    avroLogger.addAppender(avroAppender);
    avroLogger.setLevel(Level.ALL);
    Assert.assertNotNull(avroLogger);
    avroLogger.info("Test message");
    final Transaction transaction = channel.getTransaction();
    transaction.begin();
    final Event event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertTrue("Channel contained event, but not expected message", getBody(event).endsWith("Test message"));
    transaction.commit();
    transaction.close();
    eventSource.stop();
}
Also used : Transaction(org.apache.flume.Transaction) Event(org.apache.flume.Event) Test(org.junit.Test)

Example 4 with Transaction

use of org.apache.flume.Transaction in project logging-log4j2 by apache.

the class FlumeAppenderTest method testBatch.

@Test
public void testBatch() throws IOException {
    final Agent[] agents = new Agent[] { Agent.createAgent("localhost", testPort) };
    final FlumeAppender avroAppender = FlumeAppender.createAppender(agents, null, null, "false", "Avro", null, "1000", "1000", "1", "1000", "avro", "false", null, null, null, null, null, "true", "10", null, null, null, null);
    avroAppender.start();
    avroLogger.addAppender(avroAppender);
    avroLogger.setLevel(Level.ALL);
    Assert.assertNotNull(avroLogger);
    for (int i = 0; i < 10; ++i) {
        avroLogger.info("Test message " + i);
    }
    final Transaction transaction = channel.getTransaction();
    transaction.begin();
    for (int i = 0; i < 10; ++i) {
        final Event event = channel.take();
        Assert.assertNotNull("No event for item " + i, event);
        Assert.assertTrue("Channel contained event, but not expected message", getBody(event).endsWith("Test message " + i));
    }
    transaction.commit();
    transaction.close();
    eventSource.stop();
}
Also used : Transaction(org.apache.flume.Transaction) Event(org.apache.flume.Event) Test(org.junit.Test)

Example 5 with Transaction

use of org.apache.flume.Transaction in project phoenix by apache.

the class JsonEventSerializerIT method testBatchEvents.

@Test
public void testBatchEvents() throws EventDeliveryException, SQLException {
    final String fullTableName = "FLUME_JSON_TEST";
    initSinkContextWithDefaults(fullTableName);
    sink = new PhoenixSink();
    Configurables.configure(sink, sinkContext);
    assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
    final Channel channel = this.initChannel();
    sink.setChannel(channel);
    sink.start();
    int numEvents = 150;
    String col1 = "val1";
    String a1 = "[aaa,bbb,ccc]";
    String a2 = "[1,2,3,4]";
    String eventBody = null;
    List<Event> eventList = Lists.newArrayListWithCapacity(numEvents);
    for (int i = 0; i < eventList.size(); i++) {
        eventBody = "{\"col1\" : \"" + (col1 + i) + "\", \"col2\" : " + i * 10.5 + " , \"col3\" : " + a1 + " , \"col4\" : " + a2 + "}";
        Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
        eventList.add(event);
    }
    // put event in channel
    Transaction transaction = channel.getTransaction();
    transaction.begin();
    for (Event event : eventList) {
        channel.put(event);
    }
    transaction.commit();
    transaction.close();
    sink.process();
    int rowsInDb = countRows(fullTableName);
    assertEquals(eventList.size(), rowsInDb);
    sink.stop();
    assertEquals(LifecycleState.STOP, sink.getLifecycleState());
    dropTable(fullTableName);
}
Also used : Transaction(org.apache.flume.Transaction) MemoryChannel(org.apache.flume.channel.MemoryChannel) Channel(org.apache.flume.Channel) Event(org.apache.flume.Event) PhoenixSink(org.apache.phoenix.flume.sink.PhoenixSink) Test(org.junit.Test)

Aggregations

Transaction (org.apache.flume.Transaction)36 Event (org.apache.flume.Event)33 Test (org.junit.Test)31 Channel (org.apache.flume.Channel)27 MemoryChannel (org.apache.flume.channel.MemoryChannel)23 PhoenixSink (org.apache.phoenix.flume.sink.PhoenixSink)22 Context (org.apache.flume.Context)8 EventDeliveryException (org.apache.flume.EventDeliveryException)6 Connection (java.sql.Connection)5 ResultSet (java.sql.ResultSet)5 Properties (java.util.Properties)5 SQLException (java.sql.SQLException)4 ChannelException (org.apache.flume.ChannelException)4 ThreadContext (org.apache.logging.log4j.ThreadContext)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 FlumeException (org.apache.flume.FlumeException)1 Sink (org.apache.flume.Sink)1