fixed hanging test

This commit is contained in:
Adrian Cole 2013-01-13 20:27:44 -08:00
parent c7ae36b852
commit 6a8ac673aa
2 changed files with 21 additions and 57 deletions

View File

@ -26,7 +26,6 @@ import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify; import static org.easymock.EasyMock.verify;
import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS; import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS;
import static org.jclouds.Constants.PROPERTY_USER_THREADS; import static org.jclouds.Constants.PROPERTY_USER_THREADS;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull; import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
@ -34,8 +33,8 @@ import java.io.IOException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import org.jclouds.lifecycle.Closer; import org.jclouds.lifecycle.Closer;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -53,7 +52,7 @@ public class ExecutorServiceModuleTest {
private Injector injector; private Injector injector;
@BeforeMethod @BeforeClass
private void setupExecutorModule() { private void setupExecutorModule() {
ExecutorServiceModule module = new ExecutorServiceModule() { ExecutorServiceModule module = new ExecutorServiceModule() {
@Override @Override
@ -69,9 +68,15 @@ public class ExecutorServiceModuleTest {
assertNull(module.ioExecutorFromConstructor); assertNull(module.ioExecutorFromConstructor);
} }
@AfterMethod @AfterClass
private void close() throws IOException { private void close() throws IOException {
ListeningExecutorService user = injector.getInstance(Key.get(ListeningExecutorService.class,
named(PROPERTY_USER_THREADS)));
ListeningExecutorService io = injector.getInstance(Key.get(ListeningExecutorService.class,
named(PROPERTY_IO_WORKER_THREADS)));
injector.getInstance(Closer.class).close(); injector.getInstance(Closer.class).close();
assertTrue(user.isShutdown());
assertTrue(io.isShutdown());
} }
@Test @Test
@ -90,24 +95,7 @@ public class ExecutorServiceModuleTest {
verify(executor); verify(executor);
} }
@Test @Test(timeOut = 5000)
public void testShutdownOnCloseThroughModule() throws IOException {
ListeningExecutorService user = injector.getInstance(Key.get(ListeningExecutorService.class,
named(PROPERTY_USER_THREADS)));
ListeningExecutorService io = injector.getInstance(Key.get(ListeningExecutorService.class,
named(PROPERTY_IO_WORKER_THREADS)));
assertFalse(user.isShutdown());
assertFalse(io.isShutdown());
injector.getInstance(Closer.class).close();
assertTrue(user.isShutdown());
assertTrue(io.isShutdown());
}
@Test
public void testExceptionInSubmitRunnableIncludesSubmissionTrace() throws Exception { public void testExceptionInSubmitRunnableIncludesSubmissionTrace() throws Exception {
ListeningExecutorService user = injector.getInstance(Key.get(ListeningExecutorService.class, ListeningExecutorService user = injector.getInstance(Key.get(ListeningExecutorService.class,
named(PROPERTY_USER_THREADS))); named(PROPERTY_USER_THREADS)));
@ -145,12 +133,9 @@ public class ExecutorServiceModuleTest {
static Runnable runnableThrowsRTE() { static Runnable runnableThrowsRTE() {
return new Runnable() { return new Runnable() {
@Override
public void run() { public void run() {
throw new RuntimeException(); throw new RuntimeException();
} }
}; };
} }
} }

View File

@ -26,7 +26,7 @@ import static org.easymock.EasyMock.verify;
import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS;
import static org.jclouds.concurrent.config.ExecutorServiceModuleTest.assertTraceHasSubmission; import static org.jclouds.concurrent.config.ExecutorServiceModuleTest.assertTraceHasSubmission;
import static org.jclouds.concurrent.config.ExecutorServiceModuleTest.incrementInitialElement; import static org.jclouds.concurrent.config.ExecutorServiceModuleTest.incrementInitialElement;
import static org.testng.Assert.assertFalse; import static org.jclouds.concurrent.config.ExecutorServiceModuleTest.runnableThrowsRTE;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
@ -34,8 +34,8 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.lifecycle.Closer; import org.jclouds.lifecycle.Closer;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -53,7 +53,7 @@ public class ScheduledExecutorServiceModuleTest {
private Injector injector; private Injector injector;
@BeforeMethod @BeforeClass
private void setupExecutorModule() { private void setupExecutorModule() {
ScheduledExecutorServiceModule module = new ScheduledExecutorServiceModule() { ScheduledExecutorServiceModule module = new ScheduledExecutorServiceModule() {
@Override @Override
@ -66,9 +66,12 @@ public class ScheduledExecutorServiceModuleTest {
injector = Guice.createInjector(module); injector = Guice.createInjector(module);
} }
@AfterMethod @AfterClass
private void close() throws IOException { private void close() throws IOException {
ListeningScheduledExecutorService sched = injector.getInstance(Key.get(ListeningScheduledExecutorService.class,
named(PROPERTY_SCHEDULER_THREADS)));
injector.getInstance(Closer.class).close(); injector.getInstance(Closer.class).close();
assertTrue(sched.isShutdown());
} }
@Test @Test
@ -87,20 +90,7 @@ public class ScheduledExecutorServiceModuleTest {
verify(executor); verify(executor);
} }
@Test @Test(timeOut = 5000)
public void testShutdownOnCloseThroughModule() throws IOException {
ListeningScheduledExecutorService sched = injector.getInstance(Key.get(ListeningScheduledExecutorService.class,
named(PROPERTY_SCHEDULER_THREADS)));
assertFalse(sched.isShutdown());
injector.getInstance(Closer.class).close();
assertTrue(sched.isShutdown());
}
@Test
public void testExceptionInSubmitRunnableIncludesSubmissionTrace() throws Exception { public void testExceptionInSubmitRunnableIncludesSubmissionTrace() throws Exception {
ListeningScheduledExecutorService sched = injector.getInstance(Key.get(ListeningScheduledExecutorService.class, ListeningScheduledExecutorService sched = injector.getInstance(Key.get(ListeningScheduledExecutorService.class,
named(PROPERTY_SCHEDULER_THREADS))); named(PROPERTY_SCHEDULER_THREADS)));
@ -117,7 +107,7 @@ public class ScheduledExecutorServiceModuleTest {
} }
} }
@Test @Test(timeOut = 5000)
public void testExceptionInScheduleWithFixedDelayRunnableIncludesSubmissionTrace() throws Exception { public void testExceptionInScheduleWithFixedDelayRunnableIncludesSubmissionTrace() throws Exception {
ListeningScheduledExecutorService sched = injector.getInstance(Key.get(ListeningScheduledExecutorService.class, ListeningScheduledExecutorService sched = injector.getInstance(Key.get(ListeningScheduledExecutorService.class,
named(PROPERTY_SCHEDULER_THREADS))); named(PROPERTY_SCHEDULER_THREADS)));
@ -133,15 +123,4 @@ public class ScheduledExecutorServiceModuleTest {
assertTraceHasSubmission(getStackTraceAsString(e.getCause()), submission); assertTraceHasSubmission(getStackTraceAsString(e.getCause()), submission);
} }
} }
static Runnable runnableThrowsRTE() {
return new Runnable() {
@Override
public void run() {
throw new RuntimeException();
}
};
}
} }