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.HBaseClassTestRule;
023import org.apache.hadoop.hbase.HBaseTestingUtility;
024import org.apache.hadoop.hbase.TableName;
025import org.apache.hadoop.hbase.client.Put;
026import org.apache.hadoop.hbase.testclassification.LargeTests;
027import org.apache.hadoop.hbase.util.Bytes;
028import org.junit.AfterClass;
029import org.junit.Before;
030import org.junit.BeforeClass;
031import org.junit.ClassRule;
032import org.junit.Rule;
033import org.junit.Test;
034import org.junit.experimental.categories.Category;
035import org.junit.rules.TestName;
036
037@Category(LargeTests.class)
038public class TestSpaceQuotaIncrease {
039
040  @ClassRule
041  public static final HBaseClassTestRule CLASS_RULE =
042    HBaseClassTestRule.forClass(TestSpaceQuotaIncrease.class);
043
044  private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
045
046  @Rule
047  public TestName testName = new TestName();
048  private SpaceQuotaHelperForTests helper;
049
050  @BeforeClass
051  public static void setUp() throws Exception {
052    Configuration conf = TEST_UTIL.getConfiguration();
053    SpaceQuotaHelperForTests.updateConfigForQuotas(conf);
054    TEST_UTIL.startMiniCluster(1);
055  }
056
057  @AfterClass
058  public static void tearDown() throws Exception {
059    TEST_UTIL.shutdownMiniCluster();
060  }
061
062  @Before
063  public void removeAllQuotas() throws Exception {
064    helper = new SpaceQuotaHelperForTests(TEST_UTIL, testName, new AtomicLong(0));
065    helper.removeAllQuotas();
066  }
067
068  @Test
069  public void testSetQuotaAndThenIncreaseQuotaWithNoInserts() throws Exception {
070    setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.NO_INSERTS);
071  }
072
073  @Test
074  public void testSetQuotaAndThenIncreaseQuotaWithNoWrite() throws Exception {
075    setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.NO_WRITES);
076  }
077
078  @Test
079  public void testSetQuotaAndThenIncreaseQuotaWithNoWritesCompactions() throws Exception {
080    setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.NO_WRITES_COMPACTIONS);
081  }
082
083  @Test
084  public void testSetQuotaAndThenIncreaseQuotaWithDisable() throws Exception {
085    setQuotaAndThenIncreaseQuota(SpaceViolationPolicy.DISABLE);
086  }
087
088  private void setQuotaAndThenIncreaseQuota(SpaceViolationPolicy policy) throws Exception {
089    Put put = new Put(Bytes.toBytes("to_reject"));
090    put.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"),
091      Bytes.toBytes("reject"));
092
093    // Do puts until we violate space policy
094    final TableName tn = helper.writeUntilViolationAndVerifyViolation(policy, put);
095
096    // Now, increase limit and perform put
097    helper.setQuotaLimit(tn, policy, 4L);
098
099    // Put some row now: should not violate as quota limit increased
100    helper.verifyNoViolation(tn, put);
101  }
102}