1 package org.apache.maven.surefire.junitcore;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.concurrent.ExecutionException;
26 import java.util.concurrent.ExecutorService;
27 import java.util.concurrent.Executors;
28 import java.util.concurrent.Future;
29
30 import org.junit.runners.model.RunnerScheduler;
31
32
33
34
35
36
37
38 @Deprecated
39 public class AsynchronousRunner
40 implements RunnerScheduler
41 {
42 private final List<Future<Object>> futures = Collections.synchronizedList( new ArrayList<Future<Object>>() );
43
44 private final ExecutorService fService;
45
46 public AsynchronousRunner( ExecutorService fService )
47 {
48 this.fService = fService;
49 }
50
51 @Override
52 public void schedule( final Runnable childStatement )
53 {
54 futures.add( fService.submit( Executors.callable( childStatement ) ) );
55 }
56
57
58 @Override
59 public void finished()
60 {
61 try
62 {
63 waitForCompletion();
64 }
65 catch ( ExecutionException e )
66 {
67 throw new RuntimeException( e );
68 }
69 }
70
71 public void waitForCompletion()
72 throws ExecutionException
73 {
74 for ( Future<Object> each : futures )
75 {
76 try
77 {
78 each.get();
79 }
80 catch ( InterruptedException e )
81 {
82 throw new RuntimeException( e );
83 }
84 }
85 }
86 }