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.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertNull; 022 023import org.apache.hadoop.hbase.ServerName; 024import org.apache.hadoop.hbase.client.backoff.ServerStatistics; 025import org.apache.hadoop.hbase.testclassification.ClientTests; 026import org.apache.hadoop.hbase.testclassification.SmallTests; 027import org.junit.jupiter.api.Tag; 028import org.junit.jupiter.api.Test; 029 030@Tag(ClientTests.TAG) 031@Tag(SmallTests.TAG) 032public class TestResultStatsUtil { 033 034 private static final RegionLoadStats regionLoadStats = new RegionLoadStats(100, 10, 90); 035 private static final byte[] regionName = { 80 }; 036 private static final ServerName server = ServerName.parseServerName("3.1.yg.n,50,1"); 037 038 @Test 039 public void testUpdateStats() { 040 // Create a tracker 041 ServerStatisticTracker serverStatisticTracker = new ServerStatisticTracker(); 042 043 // Pass in the tracker for update 044 ResultStatsUtil.updateStats(serverStatisticTracker, server, regionName, regionLoadStats); 045 046 // Check that the tracker was updated as expected 047 ServerStatistics stats = serverStatisticTracker.getStats(server); 048 049 assertEquals(regionLoadStats.memstoreLoad, 050 stats.getStatsForRegion(regionName).getMemStoreLoadPercent()); 051 assertEquals(regionLoadStats.compactionPressure, 052 stats.getStatsForRegion(regionName).getCompactionPressure()); 053 assertEquals(regionLoadStats.heapOccupancy, 054 stats.getStatsForRegion(regionName).getHeapOccupancyPercent()); 055 } 056 057 @Test 058 public void testUpdateStatsRegionNameNull() { 059 ServerStatisticTracker serverStatisticTracker = new ServerStatisticTracker(); 060 061 ResultStatsUtil.updateStats(serverStatisticTracker, server, null, regionLoadStats); 062 063 ServerStatistics stats = serverStatisticTracker.getStats(server); 064 assertNull(stats); 065 } 066 067 @Test 068 public void testUpdateStatsStatsNull() { 069 ServerStatisticTracker serverStatisticTracker = new ServerStatisticTracker(); 070 071 ResultStatsUtil.updateStats(serverStatisticTracker, server, regionName, null); 072 073 ServerStatistics stats = serverStatisticTracker.getStats(server); 074 assertNull(stats); 075 } 076 077 @Test 078 public void testUpdateStatsTrackerNull() { 079 ServerStatisticTracker serverStatisticTracker = new ServerStatisticTracker(); 080 081 ResultStatsUtil.updateStats(null, server, regionName, regionLoadStats); 082 083 ServerStatistics stats = serverStatisticTracker.getStats(server); 084 assertNull(stats); 085 } 086}