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 * http://www.apache.org/licenses/LICENSE-2.0 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.apache.hadoop.hbase.quotas; 017 018import java.util.concurrent.atomic.AtomicLong; 019 020import org.apache.hadoop.conf.Configuration; 021import org.apache.hadoop.hbase.HBaseClassTestRule; 022import org.apache.hadoop.hbase.HBaseTestingUtility; 023import org.apache.hadoop.hbase.TableName; 024import org.apache.hadoop.hbase.client.Put; 025import org.apache.hadoop.hbase.testclassification.LargeTests; 026import org.apache.hadoop.hbase.util.Bytes; 027import org.junit.AfterClass; 028import org.junit.Before; 029import org.junit.BeforeClass; 030import org.junit.ClassRule; 031import org.junit.Rule; 032import org.junit.Test; 033import org.junit.experimental.categories.Category; 034import org.junit.rules.TestName; 035 036@Category(LargeTests.class) 037public class TestSpaceQuotaIncrease { 038 039 @ClassRule 040 public static final HBaseClassTestRule CLASS_RULE = 041 HBaseClassTestRule.forClass(TestSpaceQuotaIncrease.class); 042 043 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 044 045 @Rule 046 public TestName testName = new TestName(); 047 private SpaceQuotaHelperForTests helper; 048 049 @BeforeClass 050 public static void setUp() throws Exception { 051 Configuration conf = TEST_UTIL.getConfiguration(); 052 SpaceQuotaHelperForTests.updateConfigForQuotas(conf); 053 TEST_UTIL.startMiniCluster(1); 054 } 055 056 @AfterClass 057 public static void tearDown() throws Exception { 058 TEST_UTIL.shutdownMiniCluster(); 059 } 060 061 @Before 062 public void removeAllQuotas() throws Exception { 063 helper = new SpaceQuotaHelperForTests(TEST_UTIL, testName, new AtomicLong(0)); 064 helper.removeAllQuotas(); 065 } 066 067 @Test 068 public void testSetQuotaAndThenIncreaseQuotaWithNoInserts() throws Exception { 069 setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.NO_INSERTS); 070 } 071 072 @Test 073 public void testSetQuotaAndThenIncreaseQuotaWithNoWrite() throws Exception { 074 setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.NO_WRITES); 075 } 076 077 @Test 078 public void testSetQuotaAndThenIncreaseQuotaWithNoWritesCompactions() throws Exception { 079 setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.NO_WRITES_COMPACTIONS); 080 } 081 082 @Test 083 public void testSetQuotaAndThenIncreaseQuotaWithDisable() throws Exception { 084 setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.DISABLE); 085 } 086 087 private void setQuotaAndThenIncreaseQuota(SpaceViolationPolicy policy) throws Exception { 088 Put put = new Put(Bytes.toBytes("to_reject")); 089 put.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), 090 Bytes.toBytes("reject")); 091 092 // Do puts until we violate space policy 093 final TableName tn = helper.writeUntilViolationAndVerifyViolation(policy, put); 094 095 // Now, increase limit and perform put 096 helper.setQuotaLimit(tn, policy, 4L); 097 098 // Put some row now: should not violate as quota limit increased 099 helper.verifyNoViolation(tn, put); 100 } 101}