HBASE-26416 Implement a new method for region replication instead of using replay...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / quotas / TestMasterQuotasObserverWithMocks.java
blobabb0d8b01d08d1d964243928977e8a4985fe4c01
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.quotas;
20 import static org.apache.hadoop.hbase.coprocessor.CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY;
21 import static org.apache.hadoop.hbase.quotas.MasterQuotasObserver.REMOVE_QUOTA_ON_TABLE_DELETE;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Mockito.doCallRealMethod;
27 import static org.mockito.Mockito.mock;
29 import java.util.HashSet;
30 import java.util.Set;
31 import org.apache.hadoop.conf.Configuration;
32 import org.apache.hadoop.hbase.HBaseClassTestRule;
33 import org.apache.hadoop.hbase.HBaseConfiguration;
34 import org.apache.hadoop.hbase.master.HMaster;
35 import org.apache.hadoop.hbase.security.access.AccessController;
36 import org.apache.hadoop.hbase.testclassification.SmallTests;
37 import org.junit.Before;
38 import org.junit.ClassRule;
39 import org.junit.Test;
40 import org.junit.experimental.categories.Category;
42 /**
43 * Test class for MasterQuotasObserver that does not require a cluster.
45 @Category(SmallTests.class)
46 public class TestMasterQuotasObserverWithMocks {
48 @ClassRule
49 public static final HBaseClassTestRule CLASS_RULE =
50 HBaseClassTestRule.forClass(TestMasterQuotasObserverWithMocks.class);
52 private HMaster master;
53 private Configuration conf;
55 @Before
56 public void setup() {
57 conf = HBaseConfiguration.create();
58 master = mock(HMaster.class);
59 doCallRealMethod().when(master).updateConfigurationForQuotasObserver(
60 any());
63 @Test
64 public void testAddDefaultObserver() {
65 master.updateConfigurationForQuotasObserver(conf);
66 assertEquals(MasterQuotasObserver.class.getName(), conf.get(MASTER_COPROCESSOR_CONF_KEY));
69 @Test
70 public void testDoNotAddDefaultObserver() {
71 conf.setBoolean(REMOVE_QUOTA_ON_TABLE_DELETE, false);
72 master.updateConfigurationForQuotasObserver(conf);
73 // Configuration#getStrings returns null when unset
74 assertNull(conf.getStrings(MASTER_COPROCESSOR_CONF_KEY));
77 @Test
78 public void testAppendsObserver() {
79 conf.set(MASTER_COPROCESSOR_CONF_KEY, AccessController.class.getName());
80 master.updateConfigurationForQuotasObserver(conf);
81 Set<String> coprocs = new HashSet<>(conf.getStringCollection(MASTER_COPROCESSOR_CONF_KEY));
82 assertEquals(2, coprocs.size());
83 assertTrue(
84 "Observed coprocessors were: " + coprocs,
85 coprocs.contains(AccessController.class.getName()));
86 assertTrue(
87 "Observed coprocessors were: " + coprocs,
88 coprocs.contains(MasterQuotasObserver.class.getName()));