HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / quotas / TestSpaceQuotaRemoval.java
blobba89990a053b7f893b5bb58d0c63e885acbf0ff0
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
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.TableName;
24 import org.apache.hadoop.hbase.client.Put;
25 import org.apache.hadoop.hbase.testclassification.LargeTests;
26 import org.apache.hadoop.hbase.util.Bytes;
27 import org.junit.AfterClass;
28 import org.junit.Before;
29 import org.junit.BeforeClass;
30 import org.junit.ClassRule;
31 import org.junit.Rule;
32 import org.junit.Test;
33 import org.junit.experimental.categories.Category;
34 import org.junit.rules.TestName;
36 @Category(LargeTests.class)
37 public class TestSpaceQuotaRemoval {
39 @ClassRule
40 public static final HBaseClassTestRule CLASS_RULE =
41 HBaseClassTestRule.forClass(TestSpaceQuotaRemoval.class);
43 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
45 @Rule
46 public TestName testName = new TestName();
47 private SpaceQuotaHelperForTests helper;
49 @BeforeClass
50 public static void setUp() throws Exception {
51 Configuration conf = TEST_UTIL.getConfiguration();
52 SpaceQuotaHelperForTests.updateConfigForQuotas(conf);
53 TEST_UTIL.startMiniCluster(1);
56 @AfterClass
57 public static void tearDown() throws Exception {
58 TEST_UTIL.shutdownMiniCluster();
61 @Before
62 public void removeAllQuotas() throws Exception {
63 helper = new SpaceQuotaHelperForTests(TEST_UTIL, testName, new AtomicLong(0));
64 helper.removeAllQuotas();
67 @Test
68 public void testSetQuotaAndThenRemoveInOneWithNoInserts() throws Exception {
69 setQuotaAndThenRemoveInOneAmongTwoTables(SpaceViolationPolicy.NO_INSERTS);
72 @Test
73 public void testSetQuotaAndThenRemoveInOneWithNoWrite() throws Exception {
74 setQuotaAndThenRemoveInOneAmongTwoTables(SpaceViolationPolicy.NO_WRITES);
77 @Test
78 public void testSetQuotaAndThenRemoveInOneWithNoWritesCompaction() throws Exception {
79 setQuotaAndThenRemoveInOneAmongTwoTables(SpaceViolationPolicy.NO_WRITES_COMPACTIONS);
82 @Test
83 public void testSetQuotaAndThenRemoveInOneWithDisable() throws Exception {
84 setQuotaAndThenRemoveInOneAmongTwoTables(SpaceViolationPolicy.DISABLE);
87 @Test
88 public void testSetQuotaAndThenRemoveWithNoInserts() throws Exception {
89 setQuotaAndThenRemove(SpaceViolationPolicy.NO_INSERTS);
92 @Test
93 public void testSetQuotaAndThenRemoveWithNoWrite() throws Exception {
94 setQuotaAndThenRemove(SpaceViolationPolicy.NO_WRITES);
97 @Test
98 public void testSetQuotaAndThenRemoveWithNoWritesCompactions() throws Exception {
99 setQuotaAndThenRemove(SpaceViolationPolicy.NO_WRITES_COMPACTIONS);
102 @Test
103 public void testSetQuotaAndThenRemoveWithDisable() throws Exception {
104 setQuotaAndThenRemove(SpaceViolationPolicy.DISABLE);
107 @Test
108 public void testSetQuotaAndThenDisableIncrEnableWithNoInserts() throws Exception {
109 setQuotaNextDisableThenIncreaseFinallyEnable(SpaceViolationPolicy.NO_INSERTS);
112 @Test
113 public void testSetQuotaAndThenDisableIncrEnableWithNoWrite() throws Exception {
114 setQuotaNextDisableThenIncreaseFinallyEnable(SpaceViolationPolicy.NO_WRITES);
117 @Test
118 public void testSetQuotaAndThenDisableIncrEnableWithNoWritesCompaction() throws Exception {
119 setQuotaNextDisableThenIncreaseFinallyEnable(SpaceViolationPolicy.NO_WRITES_COMPACTIONS);
122 @Test
123 public void testSetQuotaAndThenDisableIncrEnableWithDisable() throws Exception {
124 setQuotaNextDisableThenIncreaseFinallyEnable(SpaceViolationPolicy.DISABLE);
127 private void setQuotaAndThenRemove(SpaceViolationPolicy policy) throws Exception {
128 Put put = new Put(Bytes.toBytes("to_reject"));
129 put.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"),
130 Bytes.toBytes("reject"));
132 // Do puts until we violate space policy
133 final TableName tn = helper.writeUntilViolationAndVerifyViolation(policy, put);
135 // Now, remove the quota
136 helper.removeQuotaFromtable(tn);
138 // Put some rows now: should not violate as quota settings removed
139 helper.verifyNoViolation(tn, put);
142 private void setQuotaAndThenRemoveInOneAmongTwoTables(SpaceViolationPolicy policy)
143 throws Exception {
144 Put put = new Put(Bytes.toBytes("to_reject"));
145 put.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"),
146 Bytes.toBytes("reject"));
148 // Do puts until we violate space policy on table tn1
149 final TableName tn1 = helper.writeUntilViolationAndVerifyViolation(policy, put);
151 // Do puts until we violate space policy on table tn2
152 final TableName tn2 = helper.writeUntilViolationAndVerifyViolation(policy, put);
154 // Now, remove the quota from table tn1
155 helper.removeQuotaFromtable(tn1);
157 // Put a new row now on tn1: should not violate as quota settings removed
158 helper.verifyNoViolation(tn1, put);
159 // Put a new row now on tn2: should violate as quota settings exists
160 helper.verifyViolation(policy, tn2, put);
163 private void setQuotaNextDisableThenIncreaseFinallyEnable(SpaceViolationPolicy policy)
164 throws Exception {
165 Put put = new Put(Bytes.toBytes("to_reject"));
166 put.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"),
167 Bytes.toBytes("reject"));
169 // Do puts until we violate space policy
170 final TableName tn = helper.writeUntilViolationAndVerifyViolation(policy, put);
172 // Disable the table; in case of SpaceViolationPolicy.DISABLE already disabled
173 if (!policy.equals(SpaceViolationPolicy.DISABLE)) {
174 TEST_UTIL.getAdmin().disableTable(tn);
175 TEST_UTIL.waitTableDisabled(tn, 10000);
178 // Now, increase limit and perform put
179 helper.setQuotaLimit(tn, policy, 4L);
181 // in case of disable policy quota manager will enable it
182 if (!policy.equals(SpaceViolationPolicy.DISABLE)) {
183 TEST_UTIL.getAdmin().enableTable(tn);
185 TEST_UTIL.waitTableEnabled(tn, 10000);
187 // Put some row now: should not violate as quota limit increased
188 helper.verifyNoViolation(tn, put);