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.io.asyncfs; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertTrue; 022 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.hbase.HBaseConfiguration; 025import org.apache.hadoop.hbase.io.asyncfs.monitor.ExcludeDatanodeManager; 026import org.apache.hadoop.hbase.io.asyncfs.monitor.StreamSlowMonitor; 027import org.apache.hadoop.hbase.testclassification.MiscTests; 028import org.apache.hadoop.hbase.testclassification.SmallTests; 029import org.apache.hadoop.hdfs.protocol.DatanodeInfo; 030import org.junit.jupiter.api.Tag; 031import org.junit.jupiter.api.Test; 032 033@Tag(MiscTests.TAG) 034@Tag(SmallTests.TAG) 035public class TestExcludeDatanodeManager { 036 037 @Test 038 public void testExcludeSlowDNBySpeed() { 039 Configuration conf = HBaseConfiguration.create(); 040 ExcludeDatanodeManager excludeDatanodeManager = new ExcludeDatanodeManager(conf); 041 StreamSlowMonitor streamSlowDNsMonitor = 042 excludeDatanodeManager.getStreamSlowMonitor("testMonitor"); 043 assertEquals(0, excludeDatanodeManager.getExcludeDNs().size()); 044 DatanodeInfo datanodeInfo = new DatanodeInfo.DatanodeInfoBuilder().setIpAddr("0.0.0.0") 045 .setHostName("hostname1").setDatanodeUuid("uuid1").setXferPort(111).setInfoPort(222) 046 .setInfoSecurePort(333).setIpcPort(444).setNetworkLocation("location1").build(); 047 streamSlowDNsMonitor.checkProcessTimeAndSpeed(datanodeInfo, 100000, 5100, 048 System.currentTimeMillis() - 5100, 0); 049 streamSlowDNsMonitor.checkProcessTimeAndSpeed(datanodeInfo, 100000, 5100, 050 System.currentTimeMillis() - 5100, 0); 051 streamSlowDNsMonitor.checkProcessTimeAndSpeed(datanodeInfo, 100000, 5100, 052 System.currentTimeMillis() - 5100, 0); 053 assertEquals(1, excludeDatanodeManager.getExcludeDNs().size()); 054 assertTrue(excludeDatanodeManager.getExcludeDNs().containsKey(datanodeInfo)); 055 } 056 057 @Test 058 public void testExcludeSlowDNByProcessTime() { 059 Configuration conf = HBaseConfiguration.create(); 060 ExcludeDatanodeManager excludeDatanodeManager = new ExcludeDatanodeManager(conf); 061 StreamSlowMonitor streamSlowDNsMonitor = 062 excludeDatanodeManager.getStreamSlowMonitor("testMonitor"); 063 assertEquals(0, excludeDatanodeManager.getExcludeDNs().size()); 064 DatanodeInfo datanodeInfo = new DatanodeInfo.DatanodeInfoBuilder().setIpAddr("0.0.0.0") 065 .setHostName("hostname1").setDatanodeUuid("uuid1").setXferPort(111).setInfoPort(222) 066 .setInfoSecurePort(333).setIpcPort(444).setNetworkLocation("location1").build(); 067 streamSlowDNsMonitor.checkProcessTimeAndSpeed(datanodeInfo, 5000, 7000, 068 System.currentTimeMillis() - 7000, 0); 069 streamSlowDNsMonitor.checkProcessTimeAndSpeed(datanodeInfo, 5000, 7000, 070 System.currentTimeMillis() - 7000, 0); 071 streamSlowDNsMonitor.checkProcessTimeAndSpeed(datanodeInfo, 5000, 7000, 072 System.currentTimeMillis() - 7000, 0); 073 assertEquals(1, excludeDatanodeManager.getExcludeDNs().size()); 074 assertTrue(excludeDatanodeManager.getExcludeDNs().containsKey(datanodeInfo)); 075 } 076}