Merge branch 'cleanup-threadutils-test'

This commit is contained in:
Benedikt Ritter 2015-05-07 18:07:02 +02:00
commit b14c6e7a54
1 changed files with 7 additions and 12 deletions

View File

@ -29,11 +29,9 @@ import static org.junit.Assert.assertTrue;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
//import org.apache.commons.lang3.ThreadUtils.AlwaysTruePredicate;
import org.junit.Test; import org.junit.Test;
/** /**
@ -176,7 +174,7 @@ public class ThreadUtilsTest {
try { try {
t1.start(); t1.start();
t2.start(); t2.start();
assertEquals(t1.getName(), ThreadUtils.findThreadById(t1.getId()).getName()); assertSame(t1, ThreadUtils.findThreadById(t1.getId()));
assertSame(t2, ThreadUtils.findThreadById(t2.getId())); assertSame(t2, ThreadUtils.findThreadById(t2.getId()));
} finally { } finally {
t1.interrupt(); t1.interrupt();
@ -263,8 +261,8 @@ public class ThreadUtilsTest {
try { try {
t1.start(); t1.start();
t2.start(); t2.start();
assertEquals(t1.getName(), ThreadUtils.findThreadById(t1.getId(),"thread_group_DDZZ99__").getName()); assertSame(t1, ThreadUtils.findThreadById(t1.getId(),"thread_group_DDZZ99__"));
assertEquals(t2.getName(), ThreadUtils.findThreadById(t2.getId(),"thread_group_DDZZ99__").getName()); assertSame(t2, ThreadUtils.findThreadById(t2.getId(),"thread_group_DDZZ99__"));
assertNull(ThreadUtils.findThreadById(nonExistingId,"non_existent_thread_group_JJHHZZ__")); assertNull(ThreadUtils.findThreadById(nonExistingId,"non_existent_thread_group_JJHHZZ__"));
assertNull(ThreadUtils.findThreadById(nonExistingId,"thread_group_DDZZ99__")); assertNull(ThreadUtils.findThreadById(nonExistingId,"thread_group_DDZZ99__"));
} finally { } finally {
@ -313,8 +311,7 @@ public class ThreadUtilsTest {
final List<Thread> threads = Arrays.asList(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10, t11, t11Doubled); final List<Thread> threads = Arrays.asList(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10, t11, t11Doubled);
try { try {
for (final Iterator iterator = threads.iterator(); iterator.hasNext();) { for (final Thread thread : threads) {
final Thread thread = (Thread) iterator.next();
thread.start(); thread.start();
} }
assertTrue(ThreadUtils.getAllThreadGroups().size() >= 7); assertTrue(ThreadUtils.getAllThreadGroups().size() >= 7);
@ -324,14 +321,12 @@ public class ThreadUtilsTest {
assertEquals(0, ThreadUtils.findThreadsByName(t4.getName(), threadGroup2.getName()).size()); assertEquals(0, ThreadUtils.findThreadsByName(t4.getName(), threadGroup2.getName()).size());
assertEquals(2, ThreadUtils.findThreadsByName(t11.getName(), threadGroup7.getName()).size()); assertEquals(2, ThreadUtils.findThreadsByName(t11.getName(), threadGroup7.getName()).size());
}finally { }finally {
for (final Iterator iterator = threads.iterator(); iterator.hasNext();) { for (final Thread thread : threads) {
final Thread thread = (Thread) iterator.next();
thread.interrupt(); thread.interrupt();
thread.join(); thread.join();
} }
for (final Iterator iterator = threadGroups.iterator(); iterator.hasNext();) { for (final ThreadGroup threadGroup : threadGroups) {
final ThreadGroup threadGroup = (ThreadGroup) iterator.next(); if (!threadGroup.isDestroyed()) {
if(!threadGroup.isDestroyed()) {
threadGroup.destroy(); threadGroup.destroy();
} }
} }