Repository: logging-log4j2 Updated Branches: refs/heads/master 3e56a7586 -> 7216d6495
duplicate code refactoring Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/bb8f2eeb Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/bb8f2eeb Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/bb8f2eeb Branch: refs/heads/master Commit: bb8f2eebf25a91cfdca62f3ae4713be908df8a79 Parents: 58a6a77 Author: prabh.simran <[email protected]> Authored: Wed Sep 28 11:31:32 2016 +0400 Committer: Mikael Ståldal <[email protected]> Committed: Sat Jul 8 21:32:47 2017 +0200 ---------------------------------------------------------------------- .../log4j/ThreadContextInheritanceTest.java | 16 +-- .../apache/logging/log4j/ThreadContextTest.java | 16 +-- .../log4j/ThreadContextUtilityClass.java | 100 +++++++++++++++++++ .../org/apache/logging/log4j/UtilityClass.java | 100 ------------------- 4 files changed, 116 insertions(+), 116 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bb8f2eeb/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java index 474725c..246a598 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java @@ -80,42 +80,42 @@ public class ThreadContextInheritanceTest { @Test public void perfTest() throws Exception { - UtilityClass.perfTest(); + ThreadContextUtilityClass.perfTest(); } @Test public void testGetContextReturnsEmptyMapIfEmpty() { - UtilityClass.testGetContextReturnsEmptyMapIfEmpty(); + ThreadContextUtilityClass.testGetContextReturnsEmptyMapIfEmpty(); } @Test public void testGetContextReturnsMutableCopy() { - UtilityClass.testGetContextReturnsMutableCopy(); + ThreadContextUtilityClass.testGetContextReturnsMutableCopy(); } @Test public void testGetImmutableContextReturnsEmptyMapIfEmpty() { - UtilityClass.testGetImmutableContextReturnsEmptyMapIfEmpty(); + ThreadContextUtilityClass.testGetImmutableContextReturnsEmptyMapIfEmpty(); } @Test(expected = UnsupportedOperationException.class) public void testGetImmutableContextReturnsImmutableMapIfNonEmpty() { - UtilityClass.testGetImmutableContextReturnsImmutableMapIfNonEmpty(); + ThreadContextUtilityClass.testGetImmutableContextReturnsImmutableMapIfNonEmpty(); } @Test(expected = UnsupportedOperationException.class) public void testGetImmutableContextReturnsImmutableMapIfEmpty() { - UtilityClass.testGetImmutableContextReturnsImmutableMapIfEmpty(); + ThreadContextUtilityClass.testGetImmutableContextReturnsImmutableMapIfEmpty(); } @Test public void testGetImmutableStackReturnsEmptyStackIfEmpty() { - UtilityClass.testGetImmutableStackReturnsEmptyStackIfEmpty(); + ThreadContextUtilityClass.testGetImmutableStackReturnsEmptyStackIfEmpty(); } @Test public void testPut() { - UtilityClass.testPut(); + ThreadContextUtilityClass.testPut(); } @Test http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bb8f2eeb/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java index 45aa098..ea98b36 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java @@ -62,42 +62,42 @@ public class ThreadContextTest { @Test public void perfTest() throws Exception { - UtilityClass.perfTest(); + ThreadContextUtilityClass.perfTest(); } @Test public void testGetContextReturnsEmptyMapIfEmpty() { - UtilityClass.testGetContextReturnsEmptyMapIfEmpty(); + ThreadContextUtilityClass.testGetContextReturnsEmptyMapIfEmpty(); } @Test public void testGetContextReturnsMutableCopy() { - UtilityClass.testGetContextReturnsMutableCopy(); + ThreadContextUtilityClass.testGetContextReturnsMutableCopy(); } @Test public void testGetImmutableContextReturnsEmptyMapIfEmpty() { - UtilityClass.testGetImmutableContextReturnsEmptyMapIfEmpty(); + ThreadContextUtilityClass.testGetImmutableContextReturnsEmptyMapIfEmpty(); } @Test(expected = UnsupportedOperationException.class) public void testGetImmutableContextReturnsImmutableMapIfNonEmpty() { - UtilityClass.testGetImmutableContextReturnsImmutableMapIfNonEmpty(); + ThreadContextUtilityClass.testGetImmutableContextReturnsImmutableMapIfNonEmpty(); } @Test(expected = UnsupportedOperationException.class) public void testGetImmutableContextReturnsImmutableMapIfEmpty() { - UtilityClass.testGetImmutableContextReturnsImmutableMapIfEmpty(); + ThreadContextUtilityClass.testGetImmutableContextReturnsImmutableMapIfEmpty(); } @Test public void testGetImmutableStackReturnsEmptyStackIfEmpty() { - UtilityClass.testGetImmutableStackReturnsEmptyStackIfEmpty(); + ThreadContextUtilityClass.testGetImmutableStackReturnsEmptyStackIfEmpty(); } @Test public void testPut() { - UtilityClass.testPut(); + ThreadContextUtilityClass.testPut(); } @Test http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bb8f2eeb/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextUtilityClass.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextUtilityClass.java b/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextUtilityClass.java new file mode 100644 index 0000000..21a9951 --- /dev/null +++ b/log4j-api/src/test/java/org/apache/logging/log4j/ThreadContextUtilityClass.java @@ -0,0 +1,100 @@ +package org.apache.logging.log4j; + +import java.util.Map; + +import org.apache.logging.log4j.Timer; +import org.apache.logging.log4j.spi.DefaultThreadContextMap; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.Assert.*; +import org.apache.logging.log4j.ThreadContext; +import static org.junit.Assert.*; + + + +public class ThreadContextUtilityClass { + + public static void perfTest() throws Exception { + ThreadContext.clearMap(); + final Timer complete = new Timer("ThreadContextTest"); + complete.start(); + ThreadContext.put("Var1", "value 1"); + ThreadContext.put("Var2", "value 2"); + ThreadContext.put("Var3", "value 3"); + ThreadContext.put("Var4", "value 4"); + ThreadContext.put("Var5", "value 5"); + ThreadContext.put("Var6", "value 6"); + ThreadContext.put("Var7", "value 7"); + ThreadContext.put("Var8", "value 8"); + ThreadContext.put("Var9", "value 9"); + ThreadContext.put("Var10", "value 10"); + final int loopCount = 1000000; + final Timer timer = new Timer("ThreadContextCopy", loopCount); + timer.start(); + for (int i = 0; i < loopCount; ++i) { + final Map<String, String> map = ThreadContext.getImmutableContext(); + assertNotNull(map); + } + timer.stop(); + complete.stop(); + System.out.println(timer.toString()); + System.out.println(complete.toString()); + } + + + public static void testGetContextReturnsEmptyMapIfEmpty() { + ThreadContext.clearMap(); + assertTrue(ThreadContext.getContext().isEmpty()); + } + + + public static void testGetContextReturnsMutableCopy() { + ThreadContext.clearMap(); + final Map<String, String> map1 = ThreadContext.getContext(); + assertTrue(map1.isEmpty()); + map1.put("K", "val"); + assertEquals("val", map1.get("K")); + assertTrue(ThreadContext.getContext().isEmpty()); + ThreadContext.put("key", "val2"); + final Map<String, String> map2 = ThreadContext.getContext(); + assertEquals(1, map2.size()); + assertEquals("val2", map2.get("key")); + map2.put("K", "val"); + assertEquals("val", map2.get("K")); + assertNotSame(map1, map2); + assertEquals(1, map1.size()); + } + + public static void testGetImmutableContextReturnsEmptyMapIfEmpty() { + ThreadContext.clearMap(); + assertTrue(ThreadContext.getImmutableContext().isEmpty()); + } + + + public static void testGetImmutableContextReturnsImmutableMapIfNonEmpty() { + ThreadContext.clearMap(); + ThreadContext.put("key", "val"); + final Map<String, String> immutable = ThreadContext.getImmutableContext(); + immutable.put("otherkey", "otherval"); + } + + public static void testGetImmutableContextReturnsImmutableMapIfEmpty() { + ThreadContext.clearMap(); + final Map<String, String> immutable = ThreadContext.getImmutableContext(); + immutable.put("otherkey", "otherval"); + } + + public static void testGetImmutableStackReturnsEmptyStackIfEmpty() { + ThreadContext.clearStack(); + assertTrue(ThreadContext.getImmutableStack().asList().isEmpty()); + } + + + public static void testPut() { + ThreadContext.clearMap(); + assertNull(ThreadContext.get("testKey")); + ThreadContext.put("testKey", "testValue"); + assertEquals("testValue", ThreadContext.get("testKey")); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bb8f2eeb/log4j-api/src/test/java/org/apache/logging/log4j/UtilityClass.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/UtilityClass.java b/log4j-api/src/test/java/org/apache/logging/log4j/UtilityClass.java deleted file mode 100644 index 4ba7624..0000000 --- a/log4j-api/src/test/java/org/apache/logging/log4j/UtilityClass.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.apache.logging.log4j; - -import java.util.Map; - -import org.apache.logging.log4j.Timer; -import org.apache.logging.log4j.spi.DefaultThreadContextMap; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.Assert.*; -import org.apache.logging.log4j.ThreadContext; -import static org.junit.Assert.*; - - - -public class UtilityClass { - - public static void perfTest() throws Exception { - ThreadContext.clearMap(); - final Timer complete = new Timer("ThreadContextTest"); - complete.start(); - ThreadContext.put("Var1", "value 1"); - ThreadContext.put("Var2", "value 2"); - ThreadContext.put("Var3", "value 3"); - ThreadContext.put("Var4", "value 4"); - ThreadContext.put("Var5", "value 5"); - ThreadContext.put("Var6", "value 6"); - ThreadContext.put("Var7", "value 7"); - ThreadContext.put("Var8", "value 8"); - ThreadContext.put("Var9", "value 9"); - ThreadContext.put("Var10", "value 10"); - final int loopCount = 1000000; - final Timer timer = new Timer("ThreadContextCopy", loopCount); - timer.start(); - for (int i = 0; i < loopCount; ++i) { - final Map<String, String> map = ThreadContext.getImmutableContext(); - assertNotNull(map); - } - timer.stop(); - complete.stop(); - System.out.println(timer.toString()); - System.out.println(complete.toString()); - } - - - public static void testGetContextReturnsEmptyMapIfEmpty() { - ThreadContext.clearMap(); - assertTrue(ThreadContext.getContext().isEmpty()); - } - - - public static void testGetContextReturnsMutableCopy() { - ThreadContext.clearMap(); - final Map<String, String> map1 = ThreadContext.getContext(); - assertTrue(map1.isEmpty()); - map1.put("K", "val"); - assertEquals("val", map1.get("K")); - assertTrue(ThreadContext.getContext().isEmpty()); - ThreadContext.put("key", "val2"); - final Map<String, String> map2 = ThreadContext.getContext(); - assertEquals(1, map2.size()); - assertEquals("val2", map2.get("key")); - map2.put("K", "val"); - assertEquals("val", map2.get("K")); - assertNotSame(map1, map2); - assertEquals(1, map1.size()); - } - - public static void testGetImmutableContextReturnsEmptyMapIfEmpty() { - ThreadContext.clearMap(); - assertTrue(ThreadContext.getImmutableContext().isEmpty()); - } - - - public static void testGetImmutableContextReturnsImmutableMapIfNonEmpty() { - ThreadContext.clearMap(); - ThreadContext.put("key", "val"); - final Map<String, String> immutable = ThreadContext.getImmutableContext(); - immutable.put("otherkey", "otherval"); - } - - public static void testGetImmutableContextReturnsImmutableMapIfEmpty() { - ThreadContext.clearMap(); - final Map<String, String> immutable = ThreadContext.getImmutableContext(); - immutable.put("otherkey", "otherval"); - } - - public static void testGetImmutableStackReturnsEmptyStackIfEmpty() { - ThreadContext.clearStack(); - assertTrue(ThreadContext.getImmutableStack().asList().isEmpty()); - } - - - public static void testPut() { - ThreadContext.clearMap(); - assertNull(ThreadContext.get("testKey")); - ThreadContext.put("testKey", "testValue"); - assertEquals("testValue", ThreadContext.get("testKey")); - } -}
