LOG4J2-1080 updated tests after removing support for dropping events on partially full queue
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ba2ee521 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ba2ee521 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ba2ee521 Branch: refs/heads/LOG4J2-1116 Commit: ba2ee521bc0456fed21d420e63b17e2b8d1b8081 Parents: d1d9ac3 Author: rpopma <rpo...@apache.org> Authored: Tue Mar 15 01:58:00 2016 +1100 Committer: rpopma <rpo...@apache.org> Committed: Tue Mar 15 01:58:00 2016 +1100 ---------------------------------------------------------------------- .../core/async/AsyncEventRouterFactoryTest.java | 57 +++----------- .../core/async/DefaultAsyncEventRouterTest.java | 25 +------ .../async/DiscardingAsyncEventRouterTest.java | 79 +++++++------------- 3 files changed, 38 insertions(+), 123 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ba2ee521/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java index 804401b..cad81b7 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java @@ -40,13 +40,12 @@ public class AsyncEventRouterFactoryTest { private void clearProperties() { System.clearProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER); - System.clearProperty(AsyncEventRouterFactory.PROPERTY_NAME_DISCARDING_QUEUE_RATIO); System.clearProperty(AsyncEventRouterFactory.PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL); } @Test public void testCreateReturnsDefaultRouterByDefault() throws Exception { - AsyncEventRouter router = AsyncEventRouterFactory.create(256); + AsyncEventRouter router = AsyncEventRouterFactory.create(); assertEquals(DefaultAsyncEventRouter.class, router.getClass()); } @@ -54,34 +53,26 @@ public class AsyncEventRouterFactoryTest { public void testCreateReturnsDiscardingRouterIfSpecified() throws Exception { System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER, AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER); - assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create(256).getClass()); + assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create().getClass()); System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER, DiscardingAsyncEventRouter.class.getSimpleName()); - assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create(256).getClass()); + assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create().getClass()); System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER, DiscardingAsyncEventRouter.class.getName()); - assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create(256).getClass()); + assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create().getClass()); } @Test public void testCreateDiscardingRouterDefaultThresholdLevelInfo() throws Exception { System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER, AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER); - assertEquals(Level.INFO, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create(256)). + assertEquals(Level.INFO, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create()). getThresholdLevel()); } @Test - public void testCreateDiscardingRouterDefaultThresholdQueueRemainingCapacity() throws Exception { - System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER, - AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER); - assertEquals((int) (256 * (1.0 - 0.8)), ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create(256)). - getThresholdQueueRemainingCapacity()); - } - - @Test public void testCreateDiscardingRouterThresholdLevelCustomizable() throws Exception { System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER, AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER); @@ -89,43 +80,17 @@ public class AsyncEventRouterFactoryTest { for (Level level : Level.values()) { System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL, level.name()); - assertEquals(level, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create(256)). + assertEquals(level, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create()). getThresholdLevel()); } } - @Test - public void testCreateDiscardingRouterThresholdQueueCapacityCustomizable() throws Exception { - System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER, - AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER); - float[] ratios = new float[] {0.1f, 0.2f, 0.5f, 0.8f, 0.9f}; - for (final float ratio : ratios) { - System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_DISCARDING_QUEUE_RATIO, - String.valueOf(ratio)); - int expected = (int) (256 * (1.0 - ratio)); - assertEquals(expected, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create(256)). - getThresholdQueueRemainingCapacity()); - } - } - static class CustomRouterDefaultConstructor implements AsyncEventRouter { public CustomRouterDefaultConstructor() { } @Override - public EventRoute getRoute(final long backgroundThreadId, final Level level, final int queueSize, - final int queueRemainingCapacity) { - return null; - } - } - - static class CustomRouterIntConstructor implements AsyncEventRouter { - public CustomRouterIntConstructor(int queueSize) { - } - - @Override - public EventRoute getRoute(final long backgroundThreadId, final Level level, final int queueSize, - final int queueRemainingCapacity) { + public EventRoute getRoute(final long backgroundThreadId, final Level level) { return null; } } @@ -137,17 +102,13 @@ public class AsyncEventRouterFactoryTest { public void testCreateReturnsCustomRouterIfSpecified() throws Exception { System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER, CustomRouterDefaultConstructor.class.getName()); - assertEquals(CustomRouterDefaultConstructor.class, AsyncEventRouterFactory.create(256).getClass()); - - System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER, - CustomRouterIntConstructor.class.getName()); - assertEquals(CustomRouterIntConstructor.class, AsyncEventRouterFactory.create(256).getClass()); + assertEquals(CustomRouterDefaultConstructor.class, AsyncEventRouterFactory.create().getClass()); } @Test public void testCreateReturnsDefaultRouterIfSpecifiedCustomRouterFails() throws Exception { System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER, DoesNotImplementInterface.class.getName()); - assertEquals(DefaultAsyncEventRouter.class, AsyncEventRouterFactory.create(256).getClass()); + assertEquals(DefaultAsyncEventRouter.class, AsyncEventRouterFactory.create().getClass()); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ba2ee521/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java index dcec225..aa6fcbf 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java @@ -35,33 +35,16 @@ public class DefaultAsyncEventRouterTest { } @Test - public void testGetRouteEnqueuesIfQueueNotFull() throws Exception { - DefaultAsyncEventRouter router = new DefaultAsyncEventRouter(); - assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 256)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 256)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 256)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 256)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 255)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 255)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 255)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 255)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 1)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 1)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 1)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 1)); - } - - @Test public void testGetRouteEnqueuesIfQueueFullAndCalledFromDifferentThread() throws Exception { DefaultAsyncEventRouter router = new DefaultAsyncEventRouter(); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 512, 0)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 512, 0)); + assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL)); + assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF)); } @Test public void testGetRouteSynchronousIfQueueFullAndCalledFromSameThread() throws Exception { DefaultAsyncEventRouter router = new DefaultAsyncEventRouter(); - assertEquals(EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), Level.ALL, 512, 0)); - assertEquals(EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), Level.OFF, 512, 0)); + assertEquals(EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), Level.ALL)); + assertEquals(EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), Level.OFF)); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ba2ee521/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java index 1e9b66a..85667c1 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java @@ -36,111 +36,82 @@ public class DiscardingAsyncEventRouterTest { @Test(expected = NullPointerException.class) public void testConstructorDisallowsNullThresholdLevel() { - new DiscardingAsyncEventRouter(128, 0.5F, null); + new DiscardingAsyncEventRouter(null); } @Test public void testThresholdLevelIsConstructorValue() { - assertSame(Level.ALL, new DiscardingAsyncEventRouter(128, 0.5F, Level.ALL).getThresholdLevel()); - assertSame(Level.OFF, new DiscardingAsyncEventRouter(128, 0.5F, Level.OFF).getThresholdLevel()); - assertSame(Level.INFO, new DiscardingAsyncEventRouter(128, 0.5F, Level.INFO).getThresholdLevel()); - } - - @Test - public void testThresholdRemainingCapacityBasedOnConstructorValues() { - // discard when queue full - assertEquals(0, new DiscardingAsyncEventRouter(4, 1F, Level.ALL).getThresholdQueueRemainingCapacity()); - - // discard when queue half full - assertEquals(2, new DiscardingAsyncEventRouter(4, 0.5F, Level.ALL).getThresholdQueueRemainingCapacity()); - - // discard even if queue empty - assertEquals(4, new DiscardingAsyncEventRouter(4, 0F, Level.ALL).getThresholdQueueRemainingCapacity()); - } - - @Test - public void testGetRouteEnqueuesIfThresholdCapacityNotReached() throws Exception { - DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN); - assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 256)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 256)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 256)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 256)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 255)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 255)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 255)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 255)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.FATAL, 256, 129)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.FATAL, 256, 129)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.TRACE, 256, 129)); - assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.TRACE, 256, 129)); + assertSame(Level.ALL, new DiscardingAsyncEventRouter(Level.ALL).getThresholdLevel()); + assertSame(Level.OFF, new DiscardingAsyncEventRouter(Level.OFF).getThresholdLevel()); + assertSame(Level.INFO, new DiscardingAsyncEventRouter(Level.INFO).getThresholdLevel()); } @Test public void testGetRouteDiscardsIfThresholdCapacityReachedAndLevelEqualOrLessSpecificThanThreshold() throws Exception { - DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN); + DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(Level.WARN); for (Level level : new Level[] {Level.WARN, Level.INFO, Level.DEBUG, Level.TRACE, Level.ALL}) { - assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level, 256, 1)); - assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level, 256, 1)); - assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level, 256, 128)); - assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level, 256, 128)); + assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level)); + assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level)); + assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level)); + assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level)); } } @Test public void testGetRouteDiscardsIfQueueFullAndLevelEqualOrLessSpecificThanThreshold() throws Exception { - DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN); + DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(Level.WARN); for (Level level : new Level[] {Level.WARN, Level.INFO, Level.DEBUG, Level.TRACE, Level.ALL}) { - assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level, 256, 0)); - assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level, 256, 0)); + assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level)); + assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level)); } } @Test public void testGetRouteEnqueuesIfThresholdCapacityReachedButLevelMoreSpecificThanThreshold() throws Exception { - DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN); + DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(Level.WARN); for (Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) { - assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(currentThreadId(), level, 256, 1)); - assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level, 256, 1)); - assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(currentThreadId(), level, 256, 128)); - assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level, 256, 128)); + assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level)); + assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level)); + assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level)); + assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level)); } } @Test public void testGetRouteEnqueuesIfOtherThreadQueueFullAndLevelMoreSpecificThanThreshold() throws Exception { - DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN); + DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(Level.WARN); for (Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) { - assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level, 256, 0)); + assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level)); } } @Test public void testGetRouteSynchronousIfCurrentThreadQueueFullAndLevelMoreSpecificThanThreshold() throws Exception { - DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN); + DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(Level.WARN); for (Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) { - assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level, 256, 0)); + assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level)); } } @Test public void testGetDiscardCount() throws Exception { - DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(4, 0F, Level.INFO); + DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(Level.INFO); assertEquals("initially", 0, DiscardingAsyncEventRouter.getDiscardCount(router)); - assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO, 256, 0)); + assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO)); assertEquals("increase", 1, DiscardingAsyncEventRouter.getDiscardCount(router)); - assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO, 256, 0)); + assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO)); assertEquals("increase", 2, DiscardingAsyncEventRouter.getDiscardCount(router)); - assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO, 256, 0)); + assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO)); assertEquals("increase", 3, DiscardingAsyncEventRouter.getDiscardCount(router)); } } \ No newline at end of file