LANG-1091: Shutdown thread pools in test cases. This fixes #58 from github. Thanks to Fabian Lange.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1669310 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0b7ef7f53f
commit
c8e96c0c73
|
@ -22,6 +22,7 @@
|
|||
<body>
|
||||
|
||||
<release version="3.4" date="tba" description="tba">
|
||||
<action issue="LANG-1091" type="update" dev="britter" due-to="Fabian Lange">Shutdown thread pools in test cases</action>
|
||||
<action issue="LANG-1101" type="update" dev="chas">FastDateParser and FastDatePrinter support 'X' format</action>
|
||||
<action issue="LANG-1100" type="update" dev="chas" due-to="mbracher">Avoid memory allocation when using date formating to StringBuffer</action>
|
||||
<action issue="LANG-935" type="update" dev="britter" due-to="Fabian Lange, Thomas Neidhart">Possible performance improvement on string escape functions</action>
|
||||
|
|
|
@ -27,9 +27,9 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -116,5 +116,7 @@ public class ReflectionToStringBuilderConcurrencyTest {
|
|||
for (final Future<Integer> future : futures) {
|
||||
Assert.assertEquals(REPEAT, future.get().intValue());
|
||||
}
|
||||
threadPool.shutdown();
|
||||
threadPool.awaitTermination(1, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -106,5 +107,7 @@ public class ToStringStyleConcurrencyTest {
|
|||
for (final Future<Integer> future : futures) {
|
||||
future.get();
|
||||
}
|
||||
threadPool.shutdown();
|
||||
threadPool.awaitTermination(1, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
package org.apache.commons.lang3.concurrent;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
@ -66,7 +68,7 @@ public class BackgroundInitializerTest {
|
|||
* Tests whether an external executor is correctly detected.
|
||||
*/
|
||||
@Test
|
||||
public void testGetActiveExecutorExternal() {
|
||||
public void testGetActiveExecutorExternal() throws InterruptedException {
|
||||
final ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl(
|
||||
|
@ -76,6 +78,7 @@ public class BackgroundInitializerTest {
|
|||
checkInitialize(init);
|
||||
} finally {
|
||||
exec.shutdown();
|
||||
exec.awaitTermination(1, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,14 +133,18 @@ public class BackgroundInitializerTest {
|
|||
* @throws org.apache.commons.lang3.concurrent.ConcurrentException because the test implementation may throw it
|
||||
*/
|
||||
@Test
|
||||
public void testSetExternalExecutorAfterStart() throws ConcurrentException {
|
||||
public void testSetExternalExecutorAfterStart() throws ConcurrentException, InterruptedException {
|
||||
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||
init.start();
|
||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
init.setExternalExecutor(Executors.newSingleThreadExecutor());
|
||||
init.setExternalExecutor(exec);
|
||||
fail("Could set executor after start()!");
|
||||
} catch (final IllegalStateException istex) {
|
||||
init.get();
|
||||
} finally {
|
||||
exec.shutdown();
|
||||
exec.awaitTermination(1, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,7 +242,7 @@ public class BackgroundInitializerTest {
|
|||
getThread.interrupt();
|
||||
latch1.await();
|
||||
exec.shutdownNow();
|
||||
exec.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||
exec.awaitTermination(1, TimeUnit.SECONDS);
|
||||
assertNotNull("No interrupted exception", iex.get());
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -47,11 +48,13 @@ public class CallableBackgroundInitializerTest {
|
|||
* class.
|
||||
*/
|
||||
@Test
|
||||
public void testInitExecutor() {
|
||||
public void testInitExecutor() throws InterruptedException {
|
||||
final ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
final CallableBackgroundInitializer<Integer> init = new CallableBackgroundInitializer<Integer>(
|
||||
new TestCallable(), exec);
|
||||
assertEquals("Executor not set", exec, init.getExternalExecutor());
|
||||
exec.shutdown();
|
||||
exec.awaitTermination(1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,9 +62,15 @@ public class CallableBackgroundInitializerTest {
|
|||
* This should cause an exception.
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testInitExecutorNullCallable() {
|
||||
public void testInitExecutorNullCallable() throws InterruptedException {
|
||||
final ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
new CallableBackgroundInitializer<Integer>(null, exec);
|
||||
try {
|
||||
new CallableBackgroundInitializer<Integer>(null, exec);
|
||||
} finally {
|
||||
exec.shutdown();
|
||||
exec.awaitTermination(1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.Iterator;
|
|||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -152,7 +153,7 @@ public class MultiBackgroundInitializerTest {
|
|||
* @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it
|
||||
*/
|
||||
@Test
|
||||
public void testInitializeExternalExec() throws ConcurrentException {
|
||||
public void testInitializeExternalExec() throws ConcurrentException, InterruptedException {
|
||||
final ExecutorService exec = Executors.newCachedThreadPool();
|
||||
try {
|
||||
initializer = new MultiBackgroundInitializer(exec);
|
||||
|
@ -162,6 +163,7 @@ public class MultiBackgroundInitializerTest {
|
|||
assertFalse("Executor was shutdown", exec.isShutdown());
|
||||
} finally {
|
||||
exec.shutdown();
|
||||
exec.awaitTermination(1, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +174,7 @@ public class MultiBackgroundInitializerTest {
|
|||
* @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it
|
||||
*/
|
||||
@Test
|
||||
public void testInitializeChildWithExecutor() throws ConcurrentException {
|
||||
public void testInitializeChildWithExecutor() throws ConcurrentException, InterruptedException {
|
||||
final String initExec = "childInitializerWithExecutor";
|
||||
final ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
|
@ -187,6 +189,7 @@ public class MultiBackgroundInitializerTest {
|
|||
checkChild(c2, exec);
|
||||
} finally {
|
||||
exec.shutdown();
|
||||
exec.awaitTermination(1, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ public class FastDateFormatTest {
|
|||
assertEquals(sdf.toPattern(), format.getPattern());
|
||||
|
||||
assertEquals(Locale.getDefault(), format.getLocale());
|
||||
assertEquals(TimeZone.getDefault(), format.getTimeZone());
|
||||
assertEquals(TimeZone.getDefault(), format.getTimeZone());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -208,7 +208,7 @@ public class FastDateFormatTest {
|
|||
|
||||
assertFalse(shortShort.equals(shortLong));
|
||||
assertFalse(shortShort.equals(longShort));
|
||||
assertFalse(shortShort.equals(longLong));
|
||||
assertFalse(shortShort.equals(longLong));
|
||||
assertFalse(shortLong.equals(longShort));
|
||||
assertFalse(shortLong.equals(longLong));
|
||||
assertFalse(longShort.equals(longLong));
|
||||
|
@ -308,11 +308,14 @@ public class FastDateFormatTest {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
pool.shutdown();
|
||||
if(!pool.awaitTermination(20, TimeUnit.SECONDS)) {
|
||||
pool.shutdown();
|
||||
// depending on the performance of the machine used to run the parsing,
|
||||
// the tests can run for a while. It should however complete within
|
||||
// 30 seconds. Might need increase on very slow machines.
|
||||
if(!pool.awaitTermination(30, TimeUnit.SECONDS)) {
|
||||
pool.shutdownNow();
|
||||
fail("did not complete tasks");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue