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 */ 018 019package org.apache.hadoop.hbase.regionserver; 020 021import static org.junit.Assert.assertEquals; 022import static org.junit.Assert.assertNotEquals; 023import static org.junit.Assert.assertTrue; 024 025import org.apache.hadoop.hbase.CompatibilitySingletonFactory; 026import org.apache.hadoop.hbase.HBaseClassTestRule; 027import org.apache.hadoop.hbase.testclassification.MetricsTests; 028import org.apache.hadoop.hbase.testclassification.SmallTests; 029import org.junit.ClassRule; 030import org.junit.Test; 031import org.junit.experimental.categories.Category; 032 033@Category({MetricsTests.class, SmallTests.class}) 034public class TestMetricsUserSourceImpl { 035 036 @ClassRule 037 public static final HBaseClassTestRule CLASS_RULE = 038 HBaseClassTestRule.forClass(TestMetricsUserSourceImpl.class); 039 040 @SuppressWarnings("SelfComparison") 041 @Test 042 public void testCompareToHashCodeEquals() throws Exception { 043 MetricsRegionServerSourceFactory fact 044 = CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class); 045 046 MetricsUserSource one = fact.createUser("ONE"); 047 MetricsUserSource oneClone = fact.createUser("ONE"); 048 MetricsUserSource two = fact.createUser("TWO"); 049 050 assertEquals(0, one.compareTo(oneClone)); 051 assertEquals(one.hashCode(), oneClone.hashCode()); 052 assertNotEquals(one, two); 053 054 assertTrue(one.compareTo(two) != 0); 055 assertTrue(two.compareTo(one) != 0); 056 assertTrue(two.compareTo(one) != one.compareTo(two)); 057 assertTrue(two.compareTo(two) == 0); 058 } 059 060 061 @Test (expected = RuntimeException.class) 062 public void testNoGetRegionServerMetricsSourceImpl() throws Exception { 063 // This should throw an exception because MetricsUserSourceImpl should only 064 // be created by a factory. 065 CompatibilitySingletonFactory.getInstance(MetricsUserSource.class); 066 } 067 068 @Test 069 public void testGetUser() { 070 MetricsRegionServerSourceFactory fact 071 = CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class); 072 073 MetricsUserSource one = fact.createUser("ONE"); 074 assertEquals("ONE", one.getUser()); 075 } 076 077}