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.regionserver; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertNotEquals; 022import static org.junit.jupiter.api.Assertions.assertThrows; 023import static org.junit.jupiter.api.Assertions.assertTrue; 024 025import org.apache.hadoop.hbase.CompatibilitySingletonFactory; 026import org.apache.hadoop.hbase.testclassification.MetricsTests; 027import org.apache.hadoop.hbase.testclassification.SmallTests; 028import org.junit.jupiter.api.Tag; 029import org.junit.jupiter.api.Test; 030 031/** 032 * Test for MetricsTableSourceImpl 033 */ 034@Tag(MetricsTests.TAG) 035@Tag(SmallTests.TAG) 036public class TestMetricsTableSourceImpl { 037 038 @SuppressWarnings("SelfComparison") 039 @Test 040 public void testCompareToHashCode() throws Exception { 041 MetricsRegionServerSourceFactory metricsFact = 042 CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class); 043 044 MetricsTableSource one = 045 metricsFact.createTable("ONETABLE", new MetricsTableWrapperStub("ONETABLE")); 046 MetricsTableSource oneClone = 047 metricsFact.createTable("ONETABLE", new MetricsTableWrapperStub("ONETABLE")); 048 MetricsTableSource two = 049 metricsFact.createTable("TWOTABLE", new MetricsTableWrapperStub("TWOTABLE")); 050 051 assertEquals(0, one.compareTo(oneClone)); 052 assertEquals(one.hashCode(), oneClone.hashCode()); 053 assertNotEquals(one, two); 054 055 assertTrue(one.compareTo(two) != 0); 056 assertTrue(two.compareTo(one) != 0); 057 assertTrue(two.compareTo(one) != one.compareTo(two)); 058 assertTrue(two.compareTo(two) == 0); 059 } 060 061 @Test 062 public void testNoGetTableMetricsSourceImpl() { 063 // This should throw an exception because MetricsTableSourceImpl should only 064 // be created by a factory. 065 assertThrows(RuntimeException.class, () -> { 066 CompatibilitySingletonFactory.getInstance(MetricsTableSourceImpl.class); 067 }); 068 } 069 070 @Test 071 public void testGetTableMetrics() { 072 MetricsTableSource oneTbl = 073 CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class) 074 .createTable("ONETABLE", new MetricsTableWrapperStub("ONETABLE")); 075 assertEquals("ONETABLE", oneTbl.getTableName()); 076 } 077}