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 cdap-ingest by caskdata.
the class StreamSink method process.
@Override
public Status process() throws EventDeliveryException {
Status status = Status.READY;
Channel channel = getChannel();
Transaction transaction = channel.getTransaction();
try {
tryReopenClientConnection();
transaction.begin();
Event event = channel.take();
if (event != null) {
try {
writer.write(ByteBuffer.wrap(event.getBody()), event.getHeaders()).get();
LOG.trace("Success write to stream: {} ", streamName);
} catch (Throwable t) {
if (t instanceof ExecutionException) {
t = t.getCause();
}
LOG.error("Error during writing event to stream {}", streamName, t);
throw new EventDeliveryException("Failed to send events to stream: " + streamName, t);
}
}
transaction.commit();
} catch (Throwable t) {
transaction.rollback();
if (t instanceof Error) {
throw (Error) t;
} else if (t instanceof ChannelException) {
LOG.error("Stream Sink {}: Unable to get event from channel {} ", getName(), channel.getName());
status = Status.BACKOFF;
} else {
LOG.debug("Closing writer due to stream error ", t);
closeClientQuietly();
closeWriterQuietly();
throw new EventDeliveryException("Sink event sending error", t);
}
} finally {
transaction.close();
}
return status;
}
use of org.apache.flume.Transaction in project cdap-ingest by caskdata.
the class MockStreamSink method getMockChannel.
private Channel getMockChannel() {
Channel channel = Mockito.mock(Channel.class);
Transaction transaction = Mockito.mock(Transaction.class);
Mockito.doNothing().when(transaction).begin();
Mockito.doNothing().when(transaction).commit();
Mockito.doNothing().when(transaction).close();
Mockito.doNothing().when(transaction).rollback();
Mockito.when(channel.getTransaction()).thenReturn(transaction);
Mockito.when(channel.take()).thenReturn(new SimpleEvent());
return channel;
}
Aggregations