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();
}
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();
}
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();
}
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);
}
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);
}
Aggregations