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
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.apache
.hadoop
.hbase
.quotas
;
18 import java
.util
.concurrent
.atomic
.AtomicLong
;
20 import org
.apache
.hadoop
.conf
.Configuration
;
21 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
22 import org
.apache
.hadoop
.hbase
.HBaseTestingUtility
;
23 import org
.apache
.hadoop
.hbase
.NamespaceDescriptor
;
24 import org
.apache
.hadoop
.hbase
.TableName
;
25 import org
.apache
.hadoop
.hbase
.client
.Put
;
26 import org
.apache
.hadoop
.hbase
.testclassification
.LargeTests
;
27 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
28 import org
.junit
.AfterClass
;
29 import org
.junit
.Before
;
30 import org
.junit
.BeforeClass
;
31 import org
.junit
.ClassRule
;
32 import org
.junit
.Rule
;
33 import org
.junit
.Test
;
34 import org
.junit
.experimental
.categories
.Category
;
35 import org
.junit
.rules
.TestName
;
36 import org
.slf4j
.Logger
;
37 import org
.slf4j
.LoggerFactory
;
40 @Category(LargeTests
.class)
41 public class TestSpaceQuotasWithRegionReplicas
{
44 public static final HBaseClassTestRule CLASS_RULE
=
45 HBaseClassTestRule
.forClass(TestSpaceQuotasWithRegionReplicas
.class);
47 private static final Logger LOG
=
48 LoggerFactory
.getLogger(TestSpaceQuotasWithRegionReplicas
.class);
49 private static final HBaseTestingUtility TEST_UTIL
= new HBaseTestingUtility();
52 public TestName testName
= new TestName();
53 private SpaceQuotaHelperForTests helper
;
56 public static void setUp() throws Exception
{
57 Configuration conf
= TEST_UTIL
.getConfiguration();
58 SpaceQuotaHelperForTests
.updateConfigForQuotas(conf
);
59 TEST_UTIL
.startMiniCluster(1);
63 public static void tearDown() throws Exception
{
64 TEST_UTIL
.shutdownMiniCluster();
68 public void removeAllQuotas() throws Exception
{
69 helper
= new SpaceQuotaHelperForTests(TEST_UTIL
, testName
, new AtomicLong(0));
70 helper
.removeAllQuotas();
74 public void testSetQuotaWithRegionReplicaSingleRegion() throws Exception
{
75 for (SpaceViolationPolicy policy
: SpaceViolationPolicy
.values()) {
76 setQuotaAndVerifyForRegionReplication(1, 2, policy
);
81 public void testSetQuotaWithRegionReplicaMultipleRegion() throws Exception
{
82 for (SpaceViolationPolicy policy
: SpaceViolationPolicy
.values()) {
83 setQuotaAndVerifyForRegionReplication(6, 3, policy
);
88 public void testSetQuotaWithSingleRegionZeroRegionReplica() throws Exception
{
89 for (SpaceViolationPolicy policy
: SpaceViolationPolicy
.values()) {
90 setQuotaAndVerifyForRegionReplication(1, 0, policy
);
95 public void testSetQuotaWithMultipleRegionZeroRegionReplicas() throws Exception
{
96 for (SpaceViolationPolicy policy
: SpaceViolationPolicy
.values()) {
97 setQuotaAndVerifyForRegionReplication(6, 0, policy
);
101 private void setQuotaAndVerifyForRegionReplication(int region
, int replicatedRegion
,
102 SpaceViolationPolicy policy
) throws Exception
{
103 TableName tn
= helper
.createTableWithRegions(TEST_UTIL
.getAdmin(),
104 NamespaceDescriptor
.DEFAULT_NAMESPACE_NAME_STR
, region
, replicatedRegion
);
105 helper
.setQuotaLimit(tn
, policy
, 5L);
106 helper
.writeData(tn
, 5L * SpaceQuotaHelperForTests
.ONE_MEGABYTE
);
107 Put p
= new Put(Bytes
.toBytes("to_reject"));
108 p
.addColumn(Bytes
.toBytes(SpaceQuotaHelperForTests
.F1
), Bytes
.toBytes("to"),
109 Bytes
.toBytes("reject"));
110 helper
.verifyViolation(policy
, tn
, p
);