This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.commons.threads-3.2.4
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-threads.git

commit 683f952c98e958d477c92624dd4557e1f36cdd5f
Author: Julian Sedding <[email protected]>
AuthorDate: Tue Dec 1 14:38:54 2015 +0000

    SLING-5343 - Meaningful thread names
    
    - additional tests for ExtendedThreadFactory
    
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/threads@1717440 
13f79535-47bb-0310-9956-ffa450edef68
---
 .../threads/impl/ExtendedThreadFactoryTest.java    | 53 +++++++++++++++-------
 1 file changed, 37 insertions(+), 16 deletions(-)

diff --git 
a/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
 
b/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
index ecdc03b..7240d2d 100644
--- 
a/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
+++ 
b/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
@@ -2,46 +2,67 @@ package org.apache.sling.commons.threads.impl;
 
 import org.apache.sling.commons.threads.ThreadPoolConfig;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import java.util.concurrent.Executors;
 
+import static 
org.apache.sling.commons.threads.ThreadPoolConfig.ThreadPriority.MAX;
+import static 
org.apache.sling.commons.threads.ThreadPoolConfig.ThreadPriority.MIN;
+import static 
org.apache.sling.commons.threads.ThreadPoolConfig.ThreadPriority.NORM;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 public class ExtendedThreadFactoryTest {
 
-    private static final Logger LOG = 
LoggerFactory.getLogger(ExtendedThreadFactoryTest.class);
-
     @Test
     public void informativeThreadNames() {
-        final ExtendedThreadFactory tf = createExtendedThreadFactory("Test 
Pool");
+        final ExtendedThreadFactory tf = factory("Test Pool");
         assertEquals("Thread name", "Sling - Test Pool #1", 
tf.newThread(null).getName());
         assertEquals("Thread name", "Sling - Test Pool #2", 
tf.newThread(null).getName());
     }
 
     @Test
     public void shouldStripSlingPrefixFromThreadNames() {
-        final Thread thread = getFirstThreadFromNamedPool("Sling Test Pool");
+        final Thread thread = thread("Sling Test Pool");
         assertEquals("Thread name", "Sling - Test Pool #1", thread.getName());
     }
 
     @Test
     public void shouldStripApacheSlingPrefixFromThreadNames() {
-        final Thread thread = getFirstThreadFromNamedPool("Apache Sling Test 
Pool");
+        final Thread thread = thread("Apache Sling Test Pool");
         assertEquals("Thread name", "Sling - Test Pool #1", thread.getName());
     }
 
-    private Thread getFirstThreadFromNamedPool(final String poolName) {
-        return createExtendedThreadFactory(poolName).newThread(null);
+    @Test
+    public void shouldSetCorrectPriority() {
+        assertEquals("Thread min priority", Thread.MIN_PRIORITY, 
thread("Pool", MIN, false).getPriority());
+        assertEquals("Thread normnal priority", Thread.NORM_PRIORITY, 
thread("Pool", NORM, false).getPriority());
+        assertEquals("Thread max priority", Thread.MAX_PRIORITY, 
thread("Pool", MAX, false).getPriority());
+    }
+
+    @Test
+    public void shouldSetDaemonStatusCorrectly() {
+        assertFalse("Non-daemon thread", thread("Pool", NORM, 
false).isDaemon());
+        assertTrue("Daemon thread", thread("Pool", NORM, true).isDaemon());
+    }
+
+    private Thread thread(final String poolName) {
+        return factory(poolName).newThread(null);
+    }
+
+    private Thread thread(final String poolName,
+                          final ThreadPoolConfig.ThreadPriority priority,
+                          final boolean isDaemon) {
+        return factory(poolName, priority, isDaemon).newThread(null);
+    }
+
+    private ExtendedThreadFactory factory(final String poolName) {
+        return factory(poolName, NORM, false);
     }
 
-    private ExtendedThreadFactory createExtendedThreadFactory(final String 
poolName) {
-        return new ExtendedThreadFactory(
-                Executors.defaultThreadFactory(),
-                poolName,
-                ThreadPoolConfig.ThreadPriority.NORM,
-                false
-        );
+    private ExtendedThreadFactory factory(final String poolName,
+                                          final 
ThreadPoolConfig.ThreadPriority priority,
+                                          final boolean isDaemon) {
+        return new ExtendedThreadFactory(Executors.defaultThreadFactory(), 
poolName, priority, isDaemon);
     }
 }

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to