Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 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 | */ |
Brett Chabot | fa4f667 | 2011-09-01 17:05:01 -0700 | [diff] [blame] | 16 | package com.android.ota.tests; |
| 17 | |
| 18 | import com.android.tradefed.testtype.IRemoteTest; |
Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 19 | |
Brett Chabot | 0eabebe | 2011-09-12 16:15:42 -0700 | [diff] [blame] | 20 | import junit.framework.TestCase; |
| 21 | |
Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 22 | import java.util.Collection; |
| 23 | import java.util.Iterator; |
| 24 | |
Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 25 | /** |
| 26 | * Unit tests for {@link OtaStabilityTest} |
| 27 | */ |
| 28 | public class OtaStabilityTestTest extends TestCase { |
| 29 | |
| 30 | /** |
| 31 | * Test basic case {@link OtaStabilityTest#split()}, where iterations divide evenly into each |
| 32 | * shards. |
| 33 | */ |
| 34 | public void testSplit_even() { |
| 35 | OtaStabilityTest test = new OtaStabilityTest(); |
| 36 | test.setIterations(10); |
| 37 | test.setShards(5); |
Brett Chabot | ccfda2e | 2011-02-09 14:39:59 -0800 | [diff] [blame] | 38 | Collection<IRemoteTest> shards = test.split(); |
Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 39 | assertEquals(5, shards.size()); |
Brett Chabot | ccfda2e | 2011-02-09 14:39:59 -0800 | [diff] [blame] | 40 | for (IRemoteTest shardTest : shards) { |
Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 41 | OtaStabilityTest otaShard = (OtaStabilityTest)shardTest; |
| 42 | assertEquals(2, otaShard.getIterations()); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Test {@link OtaStabilityTest#split()}, where there are more iterations than shards. |
| 48 | */ |
| 49 | public void testSplit_shards() { |
| 50 | OtaStabilityTest test = new OtaStabilityTest(); |
| 51 | test.setIterations(5); |
| 52 | test.setShards(10); |
Brett Chabot | ccfda2e | 2011-02-09 14:39:59 -0800 | [diff] [blame] | 53 | Collection<IRemoteTest> shards = test.split(); |
Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 54 | assertEquals(5, shards.size()); |
Brett Chabot | ccfda2e | 2011-02-09 14:39:59 -0800 | [diff] [blame] | 55 | for (IRemoteTest shardTest : shards) { |
Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 56 | OtaStabilityTest otaShard = (OtaStabilityTest)shardTest; |
| 57 | assertEquals(1, otaShard.getIterations()); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Test {@link OtaStabilityTest#split()}, where iterations does not divide evenly |
| 63 | */ |
| 64 | public void testSplit_remainder() { |
| 65 | OtaStabilityTest test = new OtaStabilityTest(); |
| 66 | test.setIterations(10); |
| 67 | test.setShards(3); |
Brett Chabot | ccfda2e | 2011-02-09 14:39:59 -0800 | [diff] [blame] | 68 | Collection<IRemoteTest> shards = test.split(); |
Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 69 | assertEquals(3, shards.size()); |
Brett Chabot | ccfda2e | 2011-02-09 14:39:59 -0800 | [diff] [blame] | 70 | Iterator<IRemoteTest> iterator = shards.iterator(); |
| 71 | IRemoteTest first = iterator.next(); |
Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 72 | assertEquals(3, ((OtaStabilityTest)first).getIterations()); |
| 73 | |
Brett Chabot | ccfda2e | 2011-02-09 14:39:59 -0800 | [diff] [blame] | 74 | IRemoteTest second = iterator.next(); |
Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 75 | assertEquals(3, ((OtaStabilityTest)second).getIterations()); |
| 76 | |
Brett Chabot | ccfda2e | 2011-02-09 14:39:59 -0800 | [diff] [blame] | 77 | IRemoteTest three = iterator.next(); |
Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 78 | assertEquals(4, ((OtaStabilityTest)three).getIterations()); |
| 79 | } |
Brett Chabot | e4be04d | 2011-01-21 23:33:22 -0800 | [diff] [blame] | 80 | } |