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.testclassification.SmallTests;
025import org.junit.jupiter.api.AfterAll;
026import org.junit.jupiter.api.BeforeAll;
027import org.junit.jupiter.api.BeforeEach;
028import org.junit.jupiter.api.Tag;
029import org.junit.jupiter.api.Test;
030import org.junit.jupiter.api.TestInfo;
031
032@Tag(SmallTests.TAG)
033public class TestSpaceQuotaOnNonExistingTables {
034
035  private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
036
037  private final TableName NON_EXISTENT_TABLE = TableName.valueOf("NON_EXISTENT_TABLE");
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 testSetQuotaOnNonExistingTableWithNoInserts() throws Exception {
062    helper.setQuotaLimit(NON_EXISTENT_TABLE, SpaceViolationPolicy.NO_INSERTS, 2L);
063  }
064
065  @Test
066  public void testSetQuotaOnNonExistingTableWithNoWrites() throws Exception {
067    helper.setQuotaLimit(NON_EXISTENT_TABLE, SpaceViolationPolicy.NO_WRITES, 2L);
068  }
069
070  @Test
071  public void testSetQuotaOnNonExistingTableWithNoWritesCompaction() throws Exception {
072    helper.setQuotaLimit(NON_EXISTENT_TABLE, SpaceViolationPolicy.NO_WRITES_COMPACTIONS, 2L);
073  }
074
075  @Test
076  public void testSetQuotaOnNonExistingTableWithDisable() throws Exception {
077    helper.setQuotaLimit(NON_EXISTENT_TABLE, SpaceViolationPolicy.DISABLE, 2L);
078  }
079}