1 package org.apache.maven.plugin.surefire.runorder;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.util.List;
22
23 import junit.framework.TestCase;
24
25
26
27
28 public class ThreadedExecutionSchedulerTest
29 extends TestCase
30 {
31
32 private final RunEntryStatistics a1 = RunEntryStatistics.fromValues( 200, 2, A.class, "at1" );
33
34 private final RunEntryStatistics a2 = RunEntryStatistics.fromValues( 300, 2, A.class, "at2" );
35
36 private final RunEntryStatistics b1 = RunEntryStatistics.fromValues( 400, 2, B.class, "bt1" );
37
38 private final RunEntryStatistics b2 = RunEntryStatistics.fromValues( 300, 2, B.class, "bt2" );
39
40 private final RunEntryStatistics c1 = RunEntryStatistics.fromValues( 400, 2, C.class, "ct1" );
41
42 private final RunEntryStatistics c2 = RunEntryStatistics.fromValues( 200, 2, C.class, "ct2" );
43
44 private final RunEntryStatistics d1 = RunEntryStatistics.fromValues( 401, 2, D.class, "ct2" );
45
46 private final RunEntryStatistics e1 = RunEntryStatistics.fromValues( 200, 2, E.class, "ct2" );
47
48 public void testAddTest()
49 throws Exception
50 {
51 ThreadedExecutionScheduler threadedExecutionScheduler = new ThreadedExecutionScheduler( 2 );
52 addPrioritizedTests( threadedExecutionScheduler );
53 final List<Class<?>> result = threadedExecutionScheduler.getResult();
54 assertEquals( 5, result.size() );
55 assertEquals( B.class, result.get( 0 ) );
56 assertEquals( C.class, result.get( 1 ) );
57 assertEquals( D.class, result.get( 2 ) );
58 assertEquals( A.class, result.get( 3 ) );
59 assertEquals( E.class, result.get( 4 ) );
60
61 }
62
63 public void testAddTestJaggedResult()
64 throws Exception
65 {
66 ThreadedExecutionScheduler threadedExecutionScheduler = new ThreadedExecutionScheduler( 4 );
67 addPrioritizedTests( threadedExecutionScheduler );
68 final List result = threadedExecutionScheduler.getResult();
69 assertEquals( 5, result.size() );
70
71 }
72
73 private void addPrioritizedTests( ThreadedExecutionScheduler threadedExecutionScheduler )
74 {
75 threadedExecutionScheduler.addTest( new PrioritizedTest( B.class, createPriority( b1, b2 ) ) );
76 threadedExecutionScheduler.addTest( new PrioritizedTest( C.class, createPriority( c1, c2 ) ) );
77 threadedExecutionScheduler.addTest( new PrioritizedTest( A.class, createPriority( a1, a2 ) ) );
78 threadedExecutionScheduler.addTest( new PrioritizedTest( D.class, createPriority( d1 ) ) );
79 threadedExecutionScheduler.addTest( new PrioritizedTest( E.class, createPriority( e1 ) ) );
80 }
81
82 private Priority createPriority( RunEntryStatistics runEntryStatistics )
83 {
84 final Priority priority = new Priority( A.class.getName() );
85 priority.addItem( runEntryStatistics );
86 return priority;
87 }
88
89 private Priority createPriority( RunEntryStatistics runEntryStatistics, RunEntryStatistics runEntryStatistics2 )
90 {
91 final Priority priority = new Priority( A.class.getName() );
92 priority.addItem( runEntryStatistics );
93 priority.addItem( runEntryStatistics2 );
94 return priority;
95 }
96
97
98 class A
99 {
100 }
101
102 class B
103 {
104 }
105
106 class C
107 {
108 }
109
110 class D
111 {
112 }
113
114 class E
115 {
116 }
117
118 }