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