|
15 | 15 | @ContextConfiguration(classes = { SpringAsyncConfig.class }, loader = AnnotationConfigContextLoader.class) |
16 | 16 | public class AsyncAnnotationExampleTest { |
17 | 17 |
|
18 | | - @Autowired |
19 | | - AsyncAnnotationExample asyncAnnotationExample; |
20 | | - |
21 | | - @Test |
22 | | - public void testAsyncAnnotationForMethodsWithVoidReturnType() { |
23 | | - System.out.println("Start - invoking an asynchronous method. " |
24 | | - + Thread.currentThread().getName()); |
25 | | - asyncAnnotationExample.asyncMethodWithVoidReturnType(); |
26 | | - System.out.println("End - invoking an asynchronous method. "); |
27 | | - } |
28 | | - |
29 | | - @Test |
30 | | - public void testAsyncAnnotationForMethodsWithReturnType() |
31 | | - throws InterruptedException, ExecutionException { |
32 | | - System.out.println("Start - invoking an asynchronous method. " |
33 | | - + Thread.currentThread().getName()); |
34 | | - final Future<String> future = asyncAnnotationExample |
35 | | - .asyncMethodWithReturnType(); |
36 | | - |
37 | | - while (true) { |
38 | | - if (future.isDone()) { |
39 | | - System.out.println("Result from asynchronous process - " |
40 | | - + future.get()); |
41 | | - break; |
42 | | - } |
43 | | - System.out.println("Continue doing something else. "); |
44 | | - Thread.sleep(1000); |
45 | | - } |
46 | | - } |
47 | | - |
48 | | - @Test |
49 | | - public void testAsyncAnnotationForMethodsWithConfiguredExecutor() { |
50 | | - System.out.println("Start - invoking an asynchronous method. "); |
51 | | - asyncAnnotationExample.asyncMethodWithConfiguredExecutor(); |
52 | | - System.out.println("End - invoking an asynchronous method. "); |
53 | | - } |
54 | | - |
55 | | - @Test |
56 | | - public void testAsyncAnnotationForMethodsWithException() throws Exception { |
57 | | - System.out.println("Start - invoking an asynchronous method. "); |
58 | | - asyncAnnotationExample.asyncMethodWithExceptions(); |
59 | | - System.out.println("End - invoking an asynchronous method. "); |
60 | | - } |
| 18 | + @Autowired |
| 19 | + private AsyncComponent asyncAnnotationExample; |
| 20 | + |
| 21 | + // tests |
| 22 | + |
| 23 | + @Test |
| 24 | + public void testAsyncAnnotationForMethodsWithVoidReturnType() { |
| 25 | + System.out.println("Start - invoking an asynchronous method. " + Thread.currentThread().getName()); |
| 26 | + asyncAnnotationExample.asyncMethodWithVoidReturnType(); |
| 27 | + System.out.println("End - invoking an asynchronous method. "); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testAsyncAnnotationForMethodsWithReturnType() throws InterruptedException, ExecutionException { |
| 32 | + System.out.println("Start - invoking an asynchronous method. " + Thread.currentThread().getName()); |
| 33 | + final Future<String> future = asyncAnnotationExample.asyncMethodWithReturnType(); |
| 34 | + |
| 35 | + while (true) { |
| 36 | + if (future.isDone()) { |
| 37 | + System.out.println("Result from asynchronous process - " + future.get()); |
| 38 | + break; |
| 39 | + } |
| 40 | + System.out.println("Continue doing something else. "); |
| 41 | + Thread.sleep(1000); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testAsyncAnnotationForMethodsWithConfiguredExecutor() { |
| 47 | + System.out.println("Start - invoking an asynchronous method. "); |
| 48 | + asyncAnnotationExample.asyncMethodWithConfiguredExecutor(); |
| 49 | + System.out.println("End - invoking an asynchronous method. "); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testAsyncAnnotationForMethodsWithException() throws Exception { |
| 54 | + System.out.println("Start - invoking an asynchronous method. "); |
| 55 | + asyncAnnotationExample.asyncMethodWithExceptions(); |
| 56 | + System.out.println("End - invoking an asynchronous method. "); |
| 57 | + } |
| 58 | + |
61 | 59 | } |
0 commit comments