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 */ 018package org.apache.hadoop.hbase.quotas; 019 020import java.util.concurrent.atomic.AtomicLong; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.hbase.HBaseTestingUtil; 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.jupiter.api.AfterAll; 028import org.junit.jupiter.api.BeforeAll; 029import org.junit.jupiter.api.BeforeEach; 030import org.junit.jupiter.api.Tag; 031import org.junit.jupiter.api.Test; 032import org.junit.jupiter.api.TestInfo; 033 034@Tag(LargeTests.TAG) 035public class TestSpaceQuotaIncrease { 036 037 private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 038 039 private SpaceQuotaHelperForTests helper; 040 041 @BeforeAll 042 public static void setUp() throws Exception { 043 Configuration conf = TEST_UTIL.getConfiguration(); 044 SpaceQuotaHelperForTests.updateConfigForQuotas(conf); 045 TEST_UTIL.startMiniCluster(1); 046 } 047 048 @AfterAll 049 public static void tearDown() throws Exception { 050 TEST_UTIL.shutdownMiniCluster(); 051 } 052 053 @BeforeEach 054 public void removeAllQuotas(TestInfo testInfo) throws Exception { 055 helper = new SpaceQuotaHelperForTests(TEST_UTIL, () -> testInfo.getTestMethod().get().getName(), 056 new AtomicLong(0)); 057 helper.removeAllQuotas(); 058 } 059 060 @Test 061 public void testSetQuotaAndThenIncreaseQuotaWithNoInserts() throws Exception { 062 setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.NO_INSERTS); 063 } 064 065 @Test 066 public void testSetQuotaAndThenIncreaseQuotaWithNoWrite() throws Exception { 067 setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.NO_WRITES); 068 } 069 070 @Test 071 public void testSetQuotaAndThenIncreaseQuotaWithNoWritesCompactions() throws Exception { 072 setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.NO_WRITES_COMPACTIONS); 073 } 074 075 @Test 076 public void testSetQuotaAndThenIncreaseQuotaWithDisable() throws Exception { 077 setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.DISABLE); 078 } 079 080 private void setQuotaAndThenIncreaseQuota(SpaceViolationPolicy policy) throws Exception { 081 Put put = new Put(Bytes.toBytes("to_reject")); 082 put.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), 083 Bytes.toBytes("reject")); 084 085 // Do puts until we violate space policy 086 final TableName tn = helper.writeUntilViolationAndVerifyViolation(policy, put); 087 088 // Now, increase limit and perform put 089 helper.setQuotaLimit(tn, policy, 4L); 090 091 // Put some row now: should not violate as quota limit increased 092 helper.verifyNoViolation(tn, put); 093 } 094}