spring async cleanup before publish

This commit is contained in:
eugenp
2014-12-07 18:26:58 +02:00
parent ef46c6f7d4
commit 393616f969
7 changed files with 114 additions and 120 deletions
@@ -15,47 +15,45 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@ContextConfiguration(classes = { SpringAsyncConfig.class }, loader = AnnotationConfigContextLoader.class)
public class AsyncAnnotationExampleTest {
@Autowired
AsyncAnnotationExample asyncAnnotationExample;
@Autowired
private AsyncComponent asyncAnnotationExample;
@Test
public void testAsyncAnnotationForMethodsWithVoidReturnType() {
System.out.println("Start - invoking an asynchronous method. "
+ Thread.currentThread().getName());
asyncAnnotationExample.asyncMethodWithVoidReturnType();
System.out.println("End - invoking an asynchronous method. ");
}
// tests
@Test
public void testAsyncAnnotationForMethodsWithReturnType()
throws InterruptedException, ExecutionException {
System.out.println("Start - invoking an asynchronous method. "
+ Thread.currentThread().getName());
final Future<String> future = asyncAnnotationExample
.asyncMethodWithReturnType();
@Test
public void testAsyncAnnotationForMethodsWithVoidReturnType() {
System.out.println("Start - invoking an asynchronous method. " + Thread.currentThread().getName());
asyncAnnotationExample.asyncMethodWithVoidReturnType();
System.out.println("End - invoking an asynchronous method. ");
}
while (true) {
if (future.isDone()) {
System.out.println("Result from asynchronous process - "
+ future.get());
break;
}
System.out.println("Continue doing something else. ");
Thread.sleep(1000);
}
}
@Test
public void testAsyncAnnotationForMethodsWithReturnType() throws InterruptedException, ExecutionException {
System.out.println("Start - invoking an asynchronous method. " + Thread.currentThread().getName());
final Future<String> future = asyncAnnotationExample.asyncMethodWithReturnType();
@Test
public void testAsyncAnnotationForMethodsWithConfiguredExecutor() {
System.out.println("Start - invoking an asynchronous method. ");
asyncAnnotationExample.asyncMethodWithConfiguredExecutor();
System.out.println("End - invoking an asynchronous method. ");
}
while (true) {
if (future.isDone()) {
System.out.println("Result from asynchronous process - " + future.get());
break;
}
System.out.println("Continue doing something else. ");
Thread.sleep(1000);
}
}
@Test
public void testAsyncAnnotationForMethodsWithConfiguredExecutor() {
System.out.println("Start - invoking an asynchronous method. ");
asyncAnnotationExample.asyncMethodWithConfiguredExecutor();
System.out.println("End - invoking an asynchronous method. ");
}
@Test
public void testAsyncAnnotationForMethodsWithException() throws Exception {
System.out.println("Start - invoking an asynchronous method. ");
asyncAnnotationExample.asyncMethodWithExceptions();
System.out.println("End - invoking an asynchronous method. ");
}
@Test
public void testAsyncAnnotationForMethodsWithException() throws Exception {
System.out.println("Start - invoking an asynchronous method. ");
asyncAnnotationExample.asyncMethodWithExceptions();
System.out.println("End - invoking an asynchronous method. ");
}
}
@@ -10,16 +10,17 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration("classpath:springAsync-config.xml")
public class AsyncWithXMLTest {
@Autowired
AsyncAnnotationExample asyncAnnotationExample;
@Autowired
private AsyncComponent asyncAnnotationExample;
// tests
@Test
public void testAsyncAnnotationForMethodsWithVoidReturnType() throws InterruptedException {
System.out.println("Start - invoking an asynchronous method. " + Thread.currentThread().getName());
asyncAnnotationExample.asyncMethodWithVoidReturnType();
Thread.sleep(2000);
System.out.println("End - invoking an asynchronous method. ");
}
@Test
public void testAsyncAnnotationForMethodsWithVoidReturnType()
throws InterruptedException {
System.out.println("Start - invoking an asynchronous method. "
+ Thread.currentThread().getName());
asyncAnnotationExample.asyncMethodWithVoidReturnType();
Thread.sleep(2000);
System.out.println("End - invoking an asynchronous method. ");
}
}