001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.client; 019 020import static org.junit.Assert.assertEquals; 021import static org.junit.Assert.assertNull; 022 023import org.apache.hadoop.hbase.HBaseClassTestRule; 024import org.apache.hadoop.hbase.ServerName; 025import org.apache.hadoop.hbase.client.backoff.ServerStatistics; 026import org.apache.hadoop.hbase.testclassification.ClientTests; 027import org.apache.hadoop.hbase.testclassification.SmallTests; 028import org.junit.ClassRule; 029import org.junit.Test; 030import org.junit.experimental.categories.Category; 031 032@Category({ ClientTests.class, SmallTests.class }) 033public class TestResultStatsUtil { 034 @ClassRule 035 public static final HBaseClassTestRule CLASS_RULE = 036 HBaseClassTestRule.forClass(TestResultStatsUtil.class); 037 038 private static final RegionLoadStats regionLoadStats = new RegionLoadStats(100, 10, 90); 039 private static final byte[] regionName = { 80 }; 040 private static final ServerName server = ServerName.parseServerName("3.1.yg.n,50,1"); 041 042 @Test 043 public void testUpdateStats() { 044 // Create a tracker 045 ServerStatisticTracker serverStatisticTracker = new ServerStatisticTracker(); 046 047 // Pass in the tracker for update 048 ResultStatsUtil.updateStats(serverStatisticTracker, server, regionName, regionLoadStats); 049 050 // Check that the tracker was updated as expected 051 ServerStatistics stats = serverStatisticTracker.getStats(server); 052 053 assertEquals(regionLoadStats.memstoreLoad, 054 stats.getStatsForRegion(regionName).getMemStoreLoadPercent()); 055 assertEquals(regionLoadStats.compactionPressure, 056 stats.getStatsForRegion(regionName).getCompactionPressure()); 057 assertEquals(regionLoadStats.heapOccupancy, 058 stats.getStatsForRegion(regionName).getHeapOccupancyPercent()); 059 } 060 061 @Test 062 public void testUpdateStatsRegionNameNull() { 063 ServerStatisticTracker serverStatisticTracker = new ServerStatisticTracker(); 064 065 ResultStatsUtil.updateStats(serverStatisticTracker, server, null, regionLoadStats); 066 067 ServerStatistics stats = serverStatisticTracker.getStats(server); 068 assertNull(stats); 069 } 070 071 @Test 072 public void testUpdateStatsStatsNull() { 073 ServerStatisticTracker serverStatisticTracker = new ServerStatisticTracker(); 074 075 ResultStatsUtil.updateStats(serverStatisticTracker, server, regionName, null); 076 077 ServerStatistics stats = serverStatisticTracker.getStats(server); 078 assertNull(stats); 079 } 080 081 @Test 082 public void testUpdateStatsTrackerNull() { 083 ServerStatisticTracker serverStatisticTracker = new ServerStatisticTracker(); 084 085 ResultStatsUtil.updateStats(null, server, regionName, regionLoadStats); 086 087 ServerStatistics stats = serverStatisticTracker.getStats(server); 088 assertNull(stats); 089 } 090}