View Javadoc
1   package org.apache.maven.plugin.surefire.runorder;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import java.util.List;
22  
23  import junit.framework.TestCase;
24  
25  /**
26   * @author Kristian Rosenvold
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     } // 500 total
101 
102     class B
103     {
104     } // 700 total
105 
106     class C
107     {
108     } // 600  total
109 
110     class D
111     {
112     } // 400 total
113 
114     class E
115     {
116     } // 200 total
117 
118 }