protected Appender<E> wrapAsync(Appender<E> appender, AsyncAppenderFactory<E> asyncAppenderFactory, Context context) { final AsyncAppenderBase<E> asyncAppender = asyncAppenderFactory.build(); if (asyncAppender instanceof AsyncAppender) { ((AsyncAppender) asyncAppender).setIncludeCallerData(includeCallerData); } asyncAppender.setQueueSize(queueSize); asyncAppender.setDiscardingThreshold(discardingThreshold); asyncAppender.setContext(context); asyncAppender.setName("async-" + appender.getName()); asyncAppender.addAppender(appender); asyncAppender.setNeverBlock(neverBlock); asyncAppender.start(); if (messageRate == null) { return asyncAppender; } else { return new ThrottlingAppenderWrapper<>(asyncAppender, messageRate.getQuantity(), messageRate.getUnit()); } }
protected Appender<E> wrapAsync(Appender<E> appender, AsyncAppenderFactory<E> asyncAppenderFactory, Context context) { final AsyncAppenderBase<E> asyncAppender = asyncAppenderFactory.build(); if (asyncAppender instanceof AsyncAppender) { ((AsyncAppender) asyncAppender).setIncludeCallerData(includeCallerData); } asyncAppender.setQueueSize(queueSize); asyncAppender.setDiscardingThreshold(discardingThreshold); asyncAppender.setContext(context); asyncAppender.setName("async-" + appender.getName()); asyncAppender.addAppender(appender); asyncAppender.setNeverBlock(neverBlock); asyncAppender.start(); return asyncAppender; }
@Test(timeout = 2000) public void noEventLoss() { int bufferSize = 10; int loopLen = bufferSize * 2; asyncAppenderBase.addAppender(delayingListAppender); asyncAppenderBase.setQueueSize(bufferSize); asyncAppenderBase.start(); for (int i = 0; i < loopLen; i++) { asyncAppenderBase.doAppend(i); } asyncAppenderBase.stop(); verify(delayingListAppender, loopLen); }
@Test public void invalidQueueCapacityShouldResultInNonStartedAppender() { asyncAppenderBase.addAppender(new NOPAppender<Integer>()); asyncAppenderBase.setQueueSize(0); assertEquals(0, asyncAppenderBase.getQueueSize()); asyncAppenderBase.start(); assertFalse(asyncAppenderBase.isStarted()); statusChecker.assertContainsMatch("Invalid queue size"); }
@Test(timeout = 2000) public void eventLossIfNeverBlock() { int bufferSize = 10; int loopLen = bufferSize * 2; delayingListAppender.setDelay(5000); // something greater than the test timeout asyncAppenderBase.addAppender(delayingListAppender); asyncAppenderBase.setQueueSize(bufferSize); asyncAppenderBase.setNeverBlock(true); asyncAppenderBase.start(); for (int i = 0; i < loopLen; i++) { asyncAppenderBase.doAppend(i); } asyncAppenderBase.stop(); // ListAppender size isn't a reliable test here, so just make sure we didn't // have any errors, and that we could complete the test in time. statusChecker.assertIsErrorFree(); }
asyncAppender = new AsyncAppenderBase<>(); asyncAppender.setContext(context); asyncAppender.setQueueSize(queueSize); asyncAppender.addAppender(fileAppender);
asyncAppender.setQueueSize(queueSize); asyncAppender.addAppender(fileAppender);
asyncAppender.setQueueSize(queueSize); asyncAppender.addAppender(fileAppender);