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.testclassification.SmallTests;
026import org.junit.AfterClass;
027import org.junit.Before;
028import org.junit.BeforeClass;
029import org.junit.ClassRule;
030import org.junit.Rule;
031import org.junit.Test;
032import org.junit.experimental.categories.Category;
033import org.junit.rules.TestName;
034
035@Category(SmallTests.class)
036public class TestSpaceQuotaOnNonExistingTables {
037
038  @ClassRule
039  public static final HBaseClassTestRule CLASS_RULE =
040    HBaseClassTestRule.forClass(TestSpaceQuotaOnNonExistingTables.class);
041
042  private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
043
044  private final TableName NON_EXISTENT_TABLE = TableName.valueOf("NON_EXISTENT_TABLE");
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 testSetQuotaOnNonExistingTableWithNoInserts() throws Exception {
070    helper.setQuotaLimit(NON_EXISTENT_TABLE, SpaceViolationPolicy.NO_INSERTS, 2L);
071  }
072
073  @Test
074  public void testSetQuotaOnNonExistingTableWithNoWrites() throws Exception {
075    helper.setQuotaLimit(NON_EXISTENT_TABLE, SpaceViolationPolicy.NO_WRITES, 2L);
076  }
077
078  @Test
079  public void testSetQuotaOnNonExistingTableWithNoWritesCompaction() throws Exception {
080    helper.setQuotaLimit(NON_EXISTENT_TABLE, SpaceViolationPolicy.NO_WRITES_COMPACTIONS, 2L);
081  }
082
083  @Test
084  public void testSetQuotaOnNonExistingTableWithDisable() throws Exception {
085    helper.setQuotaLimit(NON_EXISTENT_TABLE, SpaceViolationPolicy.DISABLE, 2L);
086  }
087}