Search in sources :

Example 21 with Transaction

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

the class FlumeAppenderTest method testLog4jAvroAppenderWithHostsParam.

@Test
public void testLog4jAvroAppenderWithHostsParam() throws IOException {
    final String hosts = String.format("localhost:%s", testPort);
    final FlumeAppender avroAppender = FlumeAppender.createAppender(null, null, hosts, "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 22 with Transaction

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

the class FlumeAppenderTest method testNotConnected.

@Test
public void testNotConnected() throws Exception {
    eventSource.stop();
    final String altPort = Integer.toString(Integer.parseInt(testPort) + 1);
    final Agent[] agents = new Agent[] { Agent.createAgent("localhost", testPort), Agent.createAgent("localhost", altPort) };
    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();
    Assert.assertTrue("Appender Not started", avroAppender.isStarted());
    avroLogger.addAppender(avroAppender);
    avroLogger.setLevel(Level.ALL);
    try {
        avroLogger.info("Test message");
        Assert.fail("Exception should have been thrown");
    } catch (final Exception ex) {
    }
    try {
        final Context context = new Context();
        context.put("port", altPort);
        context.put("bind", "0.0.0.0");
        Configurables.configure(eventSource, context);
        eventSource.start();
    } catch (final ChannelException e) {
        Assert.fail("Caught exception while resetting port to " + altPort + " : " + e.getMessage());
    }
    avroLogger.info("Test message 2");
    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 2"));
    transaction.commit();
    transaction.close();
}
Also used : ThreadContext(org.apache.logging.log4j.ThreadContext) Context(org.apache.flume.Context) Transaction(org.apache.flume.Transaction) Event(org.apache.flume.Event) IOException(java.io.IOException) ChannelException(org.apache.flume.ChannelException) ChannelException(org.apache.flume.ChannelException) Test(org.junit.Test)

Example 23 with Transaction

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

the class FlumeAppenderTest method testReconnect.

@Test
public void testReconnect() throws Exception {
    final String altPort = Integer.toString(Integer.parseInt(testPort) + 1);
    final Agent[] agents = new Agent[] { Agent.createAgent("localhost", testPort), Agent.createAgent("localhost", altPort) };
    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);
    avroLogger.info("Test message");
    Transaction transaction = channel.getTransaction();
    transaction.begin();
    Event event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertTrue("Channel contained event, but not expected message. Received : " + getBody(event), getBody(event).endsWith("Test message"));
    transaction.commit();
    transaction.close();
    eventSource.stop();
    try {
        final Context context = new Context();
        context.put("port", altPort);
        context.put("bind", "0.0.0.0");
        Configurables.configure(eventSource, context);
        eventSource.start();
    } catch (final ChannelException e) {
        Assert.fail("Caught exception while resetting port to " + altPort + " : " + e.getMessage());
    }
    avroLogger.info("Test message 2");
    transaction = channel.getTransaction();
    transaction.begin();
    event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertTrue("Channel contained event, but not expected message", getBody(event).endsWith("Test message 2"));
    transaction.commit();
    transaction.close();
}
Also used : ThreadContext(org.apache.logging.log4j.ThreadContext) Context(org.apache.flume.Context) Transaction(org.apache.flume.Transaction) Event(org.apache.flume.Event) ChannelException(org.apache.flume.ChannelException) Test(org.junit.Test)

Example 24 with Transaction

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

the class JsonEventSerializerIT method testDifferentColumnNames.

@Test
public void testDifferentColumnNames() throws EventDeliveryException, SQLException {
    final String fullTableName = "FLUME_JSON_TEST";
    String ddl = "CREATE TABLE IF NOT EXISTS " + fullTableName + "  (flume_time timestamp not null, col1 varchar , col2 double, col3 varchar[], col4 integer[]" + "  CONSTRAINT pk PRIMARY KEY (flume_time))\n";
    String columns = "col1,col2,col3,col4";
    String rowkeyType = DefaultKeyGenerator.TIMESTAMP.name();
    String columnsMapping = "{\"col1\":\"col1\",\"col2\":\"f2\",\"col3\":\"f3\",\"col4\":\"col4\"}";
    initSinkContext(fullTableName, ddl, columns, columnsMapping, rowkeyType, null);
    sink = new PhoenixSink();
    Configurables.configure(sink, sinkContext);
    assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
    final Channel channel = this.initChannel();
    sink.setChannel(channel);
    sink.start();
    final String eventBody = "{\"col1\" : \"kalyan\", \"f2\" : 10.5, \"f3\" : [\"abc\",\"pqr\",\"xyz\"], \"col4\" : [1,2,3,4]}";
    final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
    // put event in channel
    Transaction transaction = channel.getTransaction();
    transaction.begin();
    channel.put(event);
    transaction.commit();
    transaction.close();
    sink.process();
    int rowsInDb = countRows(fullTableName);
    assertEquals(1, 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)

Example 25 with Transaction

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

the class CsvEventSerializerIT method testKeyGenerator.

@Test
public void testKeyGenerator() throws EventDeliveryException, SQLException {
    final String fullTableName = "FLUME_CSV_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();
    final String eventBody = "kalyan,10.5,\"abc,pqr,xyz\",\"1,2,3,4\"";
    final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
    // put event in channel
    Transaction transaction = channel.getTransaction();
    transaction.begin();
    channel.put(event);
    transaction.commit();
    transaction.close();
    sink.process();
    int rowsInDb = countRows(fullTableName);
    assertEquals(1, 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)41 Event (org.apache.flume.Event)38 Test (org.junit.Test)34 Channel (org.apache.flume.Channel)29 MemoryChannel (org.apache.flume.channel.MemoryChannel)26 PhoenixSink (org.apache.phoenix.flume.sink.PhoenixSink)22 Context (org.apache.flume.Context)11 EventDeliveryException (org.apache.flume.EventDeliveryException)9 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 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Sink (org.apache.flume.Sink)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 FlumeException (org.apache.flume.FlumeException)2