|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hbase.quotas; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | + |
| 22 | +import java.util.Map; |
| 23 | +import org.apache.hadoop.hbase.HBaseClassTestRule; |
| 24 | +import org.apache.hadoop.hbase.testclassification.SmallTests; |
| 25 | +import org.junit.ClassRule; |
| 26 | +import org.junit.Test; |
| 27 | +import org.junit.experimental.categories.Category; |
| 28 | + |
| 29 | +import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap; |
| 30 | + |
| 31 | +@Category({ SmallTests.class }) |
| 32 | +public class TestRpcThrottlingException { |
| 33 | + |
| 34 | + @ClassRule |
| 35 | + public static final HBaseClassTestRule CLASS_RULE = |
| 36 | + HBaseClassTestRule.forClass(TestRpcThrottlingException.class); |
| 37 | + |
| 38 | + private static final Map<String, Long> STR_TO_MS_NEW_FORMAT = |
| 39 | + ImmutableMap.<String, Long> builder().put("0ms", 0L).put("50ms", 50L).put("1sec, 1ms", 1001L) |
| 40 | + .put("1min, 5sec, 15ms", 65_015L).put("5mins, 2sec, 0ms", 302000L) |
| 41 | + .put("1hr, 3mins, 5sec, 1ms", 3785001L).put("1hr, 5sec, 1ms", 3605001L) |
| 42 | + .put("1hr, 0ms", 3600000L).put("1hr, 1min, 1ms", 3660001L).build(); |
| 43 | + private static final Map<String, |
| 44 | + Long> STR_TO_MS_LEGACY_FORMAT = ImmutableMap.<String, Long> builder().put("0sec", 0L) |
| 45 | + .put("1sec", 1000L).put("2sec", 2000L).put("1mins, 5sec", 65_000L).put("5mins, 2sec", 302000L) |
| 46 | + .put("1hrs, 3mins, 5sec", 3785000L).build(); |
| 47 | + |
| 48 | + @Test |
| 49 | + public void itConvertsMillisToNewString() { |
| 50 | + for (Map.Entry<String, Long> strAndMs : STR_TO_MS_NEW_FORMAT.entrySet()) { |
| 51 | + String output = RpcThrottlingException.stringFromMillis(strAndMs.getValue()); |
| 52 | + assertEquals(strAndMs.getKey(), output); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void itConvertsNewStringToMillis() { |
| 58 | + for (Map.Entry<String, Long> strAndMs : STR_TO_MS_NEW_FORMAT.entrySet()) { |
| 59 | + Long output = RpcThrottlingException.timeFromString(strAndMs.getKey()); |
| 60 | + assertEquals(strAndMs.getValue(), output); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void itConvertsLegacyStringToMillis() { |
| 66 | + for (Map.Entry<String, Long> strAndMs : STR_TO_MS_LEGACY_FORMAT.entrySet()) { |
| 67 | + Long output = RpcThrottlingException.timeFromString(strAndMs.getKey()); |
| 68 | + assertEquals(strAndMs.getValue(), output); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | +} |
0 commit comments