Log4jAppender extends AppenderSkeleton { @Override public synchronized void append(LoggingEvent event) throws FlumeException { if (rpcClient == null) { String errorMsg = "Cannot Append to Appender! Appender either closed or" + " not setup correctly!"; LogLog.error(errorMsg); if (unsafeMode) { return; } throw new FlumeException(errorMsg); } if (!rpcClient.isActive()) { reconnect(); } List<Event> flumeEvents = parseEvents(event); try { switch (flumeEvents.size()) { case 0: break; case 1: rpcClient.append(flumeEvents.get(0)); break; default: rpcClient.appendBatch(flumeEvents); } } catch (EventDeliveryException e) { String msg = "Flume append() failed."; LogLog.error(msg); if (unsafeMode) { return; } throw new FlumeException(msg + " Exception follows.", e); } } Log4jAppender();  Log4jAppender(String hostname, int port); @Override synchronized void append(LoggingEvent event); @Override synchronized void close(); @Override boolean requiresLayout(); void setHostname(String hostname); void setPort(int port); void setUnsafeMode(boolean unsafeMode); boolean getUnsafeMode(); void setTimeout(long timeout); long getTimeout(); void setAvroReflectionEnabled(boolean avroReflectionEnabled); void setAvroSchemaUrl(String avroSchemaUrl); @Override void activateOptions();  }
@Test public void testLogBatch() { testBatchedSending(5); Mockito.verify(source, Mockito.times(1)).appendBatch(Mockito.anyList()); Mockito.verify(source, Mockito.times(0)).append(Mockito.any(AvroFlumeEvent.class)); }
@Test public void testLogSingleMessage() { configureSource(); PropertyConfigurator.configure(props); Logger logger = LogManager.getLogger(getClass()); logger.info("test"); Transaction tx = ch.getTransaction(); tx.begin(); Event e = ch.take(); Assert.assertNotNull(e); Assert.assertEquals("test", new String(e.getBody())); Mockito.verify(source, Mockito.times(0)).appendBatch(Mockito.anyList()); Mockito.verify(source, Mockito.times(1)).append(Mockito.any(AvroFlumeEvent.class)); }
@Test public void testLogSingleMessageInCollection() { testBatchedSending(1); Mockito.verify(source, Mockito.times(0)).appendBatch(Mockito.anyList()); Mockito.verify(source, Mockito.times(1)).append(Mockito.any(AvroFlumeEvent.class)); }
@Test public void testLogEmptyBatch() { testBatchedSending(0); Mockito.verify(source, Mockito.times(0)).appendBatch(Mockito.anyList()); Mockito.verify(source, Mockito.times(0)).append(Mockito.any(AvroFlumeEvent.class)); }