|
| 1 | +/** |
| 2 | + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * <p>Modifications copyright (C) 2017 Uber Technologies, Inc. |
| 5 | + * |
| 6 | + * <p>Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file |
| 7 | + * except in compliance with the License. A copy of the License is located at |
| 8 | + * |
| 9 | + * <p>http://aws.amazon.com/apache2.0 |
| 10 | + * |
| 11 | + * <p>or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | + * specific language governing permissions and limitations under the License. |
| 14 | + */ |
| 15 | +package com.uber.cadence.internal.worker; |
| 16 | + |
| 17 | +import static org.junit.Assert.*; |
| 18 | + |
| 19 | +import java.time.Duration; |
| 20 | +import org.junit.Test; |
| 21 | + |
| 22 | +public class PollerAutoScalerOptionsTest { |
| 23 | + @Test |
| 24 | + public void testNewBuilder() { |
| 25 | + PollerAutoScalerOptions.Builder builder = PollerAutoScalerOptions.Builder.newBuilder(); |
| 26 | + |
| 27 | + assertNotNull(builder); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testNewBuilderWithOptions() { |
| 32 | + PollerAutoScalerOptions.Builder builder = PollerAutoScalerOptions.Builder.newBuilder(); |
| 33 | + PollerAutoScalerOptions options = builder.build(); |
| 34 | + |
| 35 | + assertNotNull(options); |
| 36 | + assertEquals(Duration.ofMinutes(1), options.getPollerScalingInterval()); |
| 37 | + assertEquals(1, options.getMinConcurrentPollers()); |
| 38 | + assertEquals(0.6f, options.getTargetPollerUtilisation(), 0.0); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testSetPollerScalingInterval() { |
| 43 | + PollerAutoScalerOptions.Builder builder = PollerAutoScalerOptions.Builder.newBuilder(); |
| 44 | + builder.setPollerScalingInterval(Duration.ofMinutes(2)); |
| 45 | + PollerAutoScalerOptions options = builder.build(); |
| 46 | + |
| 47 | + assertNotNull(options); |
| 48 | + assertEquals(Duration.ofMinutes(2), options.getPollerScalingInterval()); |
| 49 | + assertEquals(1, options.getMinConcurrentPollers()); |
| 50 | + assertEquals(0.6f, options.getTargetPollerUtilisation(), 0.0); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void testSetMinConcurrentPollers() { |
| 55 | + PollerAutoScalerOptions.Builder builder = PollerAutoScalerOptions.Builder.newBuilder(); |
| 56 | + builder.setMinConcurrentPollers(2); |
| 57 | + PollerAutoScalerOptions options = builder.build(); |
| 58 | + |
| 59 | + assertNotNull(options); |
| 60 | + assertEquals(Duration.ofMinutes(1), options.getPollerScalingInterval()); |
| 61 | + assertEquals(2, options.getMinConcurrentPollers()); |
| 62 | + assertEquals(0.6f, options.getTargetPollerUtilisation(), 0.0); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void testSetTargetPollerUtilisation() { |
| 67 | + PollerAutoScalerOptions.Builder builder = PollerAutoScalerOptions.Builder.newBuilder(); |
| 68 | + builder.setTargetPollerUtilisation(0.7f); |
| 69 | + PollerAutoScalerOptions options = builder.build(); |
| 70 | + |
| 71 | + assertNotNull(options); |
| 72 | + assertEquals(Duration.ofMinutes(1), options.getPollerScalingInterval()); |
| 73 | + assertEquals(1, options.getMinConcurrentPollers()); |
| 74 | + assertEquals(0.7f, options.getTargetPollerUtilisation(), 0.0); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + public void testEquals() { |
| 79 | + PollerAutoScalerOptions.Builder builder = PollerAutoScalerOptions.Builder.newBuilder(); |
| 80 | + builder.setPollerScalingInterval(Duration.ofMinutes(2)); |
| 81 | + builder.setMinConcurrentPollers(2); |
| 82 | + builder.setTargetPollerUtilisation(0.7f); |
| 83 | + PollerAutoScalerOptions options = builder.build(); |
| 84 | + PollerAutoScalerOptions options2 = builder.build(); |
| 85 | + |
| 86 | + assertTrue(options.equals(options)); |
| 87 | + assertFalse(options.equals(null)); |
| 88 | + assertTrue(options.equals(options2)); |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + public void testHashCode() { |
| 93 | + PollerAutoScalerOptions options = PollerAutoScalerOptions.Builder.newBuilder().build(); |
| 94 | + |
| 95 | + assertEquals(1058729812, options.hashCode()); |
| 96 | + } |
| 97 | + |
| 98 | + @Test |
| 99 | + public void testToString() { |
| 100 | + PollerAutoScalerOptions options = PollerAutoScalerOptions.Builder.newBuilder().build(); |
| 101 | + |
| 102 | + assertEquals( |
| 103 | + "PollerAutoScalerOptions{pollerScalingInterval=PT1M, minConcurrentPollers=1, targetPollerUtilisation=0.6}", |
| 104 | + options.toString()); |
| 105 | + } |
| 106 | +} |
0 commit comments