LOG4J2-1412 added test that Unbox ringbuffer size is configurable

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/739f8f39
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/739f8f39
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/739f8f39

Branch: refs/heads/LOG4J2-1395
Commit: 739f8f3916dda72916fe9eda1a1385ea0a3aac1a
Parents: 9bc15f0
Author: rpopma <[email protected]>
Authored: Mon Jun 6 22:10:15 2016 +0900
Committer: rpopma <[email protected]>
Committed: Mon Jun 6 22:10:15 2016 +0900

----------------------------------------------------------------------
 .../log4j/util/UnboxConfigurableTest.java       | 67 ++++++++++++++++++++
 1 file changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/739f8f39/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java
 
b/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java
new file mode 100644
index 0000000..30d6ddc
--- /dev/null
+++ 
b/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests that the Unbox ring buffer size is configurable.
+ * Must be run in a separate process as the other UnboxTest or the last-run 
test will fail.
+ */
+public class UnboxConfigurableTest {
+    @BeforeClass
+    public static void beforeClass() {
+        System.setProperty("log4j.unbox.ringbuffer.size", "65");
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        System.clearProperty("log4j.unbox.ringbuffer.size");
+    }
+
+    @Test
+    public void testBoxConfiguredTo128Slots() throws Exception {
+        // next power of 2 that is 65 or more
+        assertEquals(128, Unbox.getRingbufferSize());
+    }
+
+    @Test
+    public void testBoxSuccessfullyConfiguredTo128Slots() throws Exception {
+        final int MAX = 128;
+        final StringBuilder[] probe = new StringBuilder[MAX * 3];
+        for (int i = 0; i <= probe.length - 8; ) {
+            probe[i++] = Unbox.box(true);
+            probe[i++] = Unbox.box('c');
+            probe[i++] = Unbox.box(Byte.MAX_VALUE);
+            probe[i++] = Unbox.box(Double.MAX_VALUE);
+            probe[i++] = Unbox.box(Float.MAX_VALUE);
+            probe[i++] = Unbox.box(Integer.MAX_VALUE);
+            probe[i++] = Unbox.box(Long.MAX_VALUE);
+            probe[i++] = Unbox.box(Short.MAX_VALUE);
+        }
+        for (int i = 0; i < probe.length - MAX; i++) {
+            assertSame("probe[" + i +"], probe[" + (i + MAX) +"]", probe[i], 
probe[i + MAX]);
+            for (int j = 1; j < MAX - 1; j++) {
+                assertNotSame("probe[" + i +"], probe[" + (i + j) +"]", 
probe[i], probe[i + j]);
+            }
+        }
+    }
+}
\ No newline at end of file

Reply via email to