You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by js...@apache.org on 2015/12/01 15:38:55 UTC
svn commit: r1717440 -
/sling/trunk/bundles/commons/threads/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
Author: jsedding
Date: Tue Dec 1 14:38:54 2015
New Revision: 1717440
URL: http://svn.apache.org/viewvc?rev=1717440&view=rev
Log:
SLING-5343 - Meaningful thread names
- additional tests for ExtendedThreadFactory
Modified:
sling/trunk/bundles/commons/threads/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
Modified: sling/trunk/bundles/commons/threads/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/threads/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java?rev=1717440&r1=1717439&r2=1717440&view=diff
==============================================================================
--- sling/trunk/bundles/commons/threads/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java (original)
+++ sling/trunk/bundles/commons/threads/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java Tue Dec 1 14:38:54 2015
@@ -2,46 +2,67 @@ package org.apache.sling.commons.threads
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);
}
}