|
| 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.client; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | +import static org.junit.Assert.assertNull; |
| 22 | + |
| 23 | +import org.apache.hadoop.hbase.HBaseClassTestRule; |
| 24 | +import org.apache.hadoop.hbase.ServerName; |
| 25 | +import org.apache.hadoop.hbase.client.backoff.ServerStatistics; |
| 26 | +import org.apache.hadoop.hbase.testclassification.ClientTests; |
| 27 | +import org.apache.hadoop.hbase.testclassification.SmallTests; |
| 28 | +import org.junit.ClassRule; |
| 29 | +import org.junit.Test; |
| 30 | +import org.junit.experimental.categories.Category; |
| 31 | + |
| 32 | +@Category({ClientTests.class, SmallTests.class}) |
| 33 | +public class TestResultStatsUtil { |
| 34 | + @ClassRule |
| 35 | + public static final HBaseClassTestRule CLASS_RULE = |
| 36 | + HBaseClassTestRule.forClass(TestResultStatsUtil.class); |
| 37 | + |
| 38 | + private static final RegionLoadStats regionLoadStats = new RegionLoadStats(100, |
| 39 | + 10,90); |
| 40 | + private static final byte[] regionName = {80}; |
| 41 | + private static final ServerName server = ServerName.parseServerName("3.1.yg.n,50,1"); |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testUpdateStats() { |
| 45 | + // Create a tracker |
| 46 | + ServerStatisticTracker serverStatisticTracker = new ServerStatisticTracker(); |
| 47 | + |
| 48 | + // Pass in the tracker for update |
| 49 | + ResultStatsUtil.updateStats(serverStatisticTracker, server, regionName, regionLoadStats); |
| 50 | + |
| 51 | + // Check that the tracker was updated as expected |
| 52 | + ServerStatistics stats = serverStatisticTracker.getStats(server); |
| 53 | + |
| 54 | + assertEquals(regionLoadStats.memstoreLoad, stats.getStatsForRegion(regionName) |
| 55 | + .getMemStoreLoadPercent()); |
| 56 | + assertEquals(regionLoadStats.compactionPressure, stats.getStatsForRegion(regionName) |
| 57 | + .getCompactionPressure()); |
| 58 | + assertEquals(regionLoadStats.heapOccupancy, stats.getStatsForRegion(regionName) |
| 59 | + .getHeapOccupancyPercent()); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testUpdateStatsRegionNameNull() { |
| 64 | + ServerStatisticTracker serverStatisticTracker = new ServerStatisticTracker(); |
| 65 | + |
| 66 | + ResultStatsUtil.updateStats(serverStatisticTracker, server, null, regionLoadStats); |
| 67 | + |
| 68 | + ServerStatistics stats = serverStatisticTracker.getStats(server); |
| 69 | + assertNull(stats); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void testUpdateStatsStatsNull() { |
| 74 | + ServerStatisticTracker serverStatisticTracker = new ServerStatisticTracker(); |
| 75 | + |
| 76 | + ResultStatsUtil.updateStats(serverStatisticTracker, server, regionName, null); |
| 77 | + |
| 78 | + ServerStatistics stats = serverStatisticTracker.getStats(server); |
| 79 | + assertNull(stats); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + public void testUpdateStatsTrackerNull() { |
| 84 | + ServerStatisticTracker serverStatisticTracker = new ServerStatisticTracker(); |
| 85 | + |
| 86 | + ResultStatsUtil.updateStats(null, server, regionName, regionLoadStats); |
| 87 | + |
| 88 | + ServerStatistics stats = serverStatisticTracker.getStats(server); |
| 89 | + assertNull(stats); |
| 90 | + } |
| 91 | +} |
0 commit comments