• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.ota.tests;
17 
18 import com.android.tradefed.testtype.IRemoteTest;
19 
20 import junit.framework.TestCase;
21 
22 import java.util.Collection;
23 import java.util.Iterator;
24 
25 /** Unit tests for {@link OtaStabilityTest} */
26 public class OtaStabilityTestTest extends TestCase {
27 
28     /**
29      * Test basic case {@link OtaStabilityTest#split()}, where iterations divide evenly into each
30      * shards.
31      */
testSplit_even()32     public void testSplit_even() {
33         OtaStabilityTest test = new OtaStabilityTest();
34         test.setIterations(10);
35         test.setShards(5);
36         Collection<IRemoteTest> shards = test.split();
37         assertEquals(5, shards.size());
38         for (IRemoteTest shardTest : shards) {
39             OtaStabilityTest otaShard = (OtaStabilityTest) shardTest;
40             assertEquals(2, otaShard.getIterations());
41         }
42     }
43 
44     /** Test {@link OtaStabilityTest#split()}, where there are more iterations than shards. */
testSplit_shards()45     public void testSplit_shards() {
46         OtaStabilityTest test = new OtaStabilityTest();
47         test.setIterations(5);
48         test.setShards(10);
49         Collection<IRemoteTest> shards = test.split();
50         assertEquals(5, shards.size());
51         for (IRemoteTest shardTest : shards) {
52             OtaStabilityTest otaShard = (OtaStabilityTest) shardTest;
53             assertEquals(1, otaShard.getIterations());
54         }
55     }
56 
57     /** Test {@link OtaStabilityTest#split()}, where iterations does not divide evenly */
testSplit_remainder()58     public void testSplit_remainder() {
59         OtaStabilityTest test = new OtaStabilityTest();
60         test.setIterations(10);
61         test.setShards(3);
62         Collection<IRemoteTest> shards = test.split();
63         assertEquals(3, shards.size());
64         Iterator<IRemoteTest> iterator = shards.iterator();
65         IRemoteTest first = iterator.next();
66         assertEquals(3, ((OtaStabilityTest) first).getIterations());
67 
68         IRemoteTest second = iterator.next();
69         assertEquals(3, ((OtaStabilityTest) second).getIterations());
70 
71         IRemoteTest three = iterator.next();
72         assertEquals(4, ((OtaStabilityTest) three).getIterations());
73     }
74 }
75