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.master.procedure;
019
020import java.io.IOException;
021import org.apache.hadoop.hbase.TestRefreshHFilesBase;
022import org.apache.hadoop.hbase.testclassification.MasterTests;
023import org.apache.hadoop.hbase.testclassification.MediumTests;
024import org.junit.jupiter.api.AfterEach;
025import org.junit.jupiter.api.BeforeEach;
026import org.junit.jupiter.api.Tag;
027import org.junit.jupiter.api.Test;
028
029@Tag(MasterTests.TAG)
030@Tag(MediumTests.TAG)
031public class TestRefreshHFilesProcedure extends TestRefreshHFilesBase {
032
033  @BeforeEach
034  public void setup() throws Exception {
035    baseSetup(false);
036  }
037
038  @AfterEach
039  public void tearDown() throws Exception {
040    baseTearDown();
041  }
042
043  @Test
044  public void testRefreshHFilesProcedureForTable() throws IOException {
045    try {
046      // Create table in default namespace
047      createTableAndWait(TEST_TABLE, TEST_FAMILY);
048
049      RefreshHFilesTableProcedure procedure =
050        new RefreshHFilesTableProcedure(procExecutor.getEnvironment(), TEST_TABLE);
051      submitProcedureAndAssertNotFailed(procedure);
052
053    } catch (Exception e) {
054      throw new RuntimeException(e);
055    } finally {
056      // Delete table name post test execution
057      deleteTable(TEST_TABLE);
058    }
059  }
060
061  @Test
062  public void testRefreshHFilesProcedureForNamespace() {
063    try {
064      createNamespace(TEST_NAMESPACE);
065
066      // Create table under test namespace
067      createTableInNamespaceAndWait(TEST_NAMESPACE, TEST_TABLE, TEST_FAMILY);
068
069      RefreshHFilesTableProcedure procedure =
070        new RefreshHFilesTableProcedure(procExecutor.getEnvironment(), TEST_NAMESPACE);
071      submitProcedureAndAssertNotFailed(procedure);
072
073    } catch (Exception e) {
074      throw new RuntimeException(e);
075    } finally {
076      // Delete namespace post test execution
077      // This will delete all tables under namespace hence no explicit table
078      // deletion for table under namespace is needed.
079      deleteNamespace(TEST_NAMESPACE);
080    }
081  }
082
083  @Test
084  public void testRefreshHFilesProcedureForAllTables() throws IOException {
085    try {
086      // Create table in default namespace
087      createTableAndWait(TEST_TABLE, TEST_FAMILY);
088
089      // Create test namespace
090      createNamespace(TEST_NAMESPACE);
091
092      // Create table under test namespace
093      createTableInNamespaceAndWait(TEST_NAMESPACE, TEST_TABLE, TEST_FAMILY);
094
095      RefreshHFilesTableProcedure procedure =
096        new RefreshHFilesTableProcedure(procExecutor.getEnvironment());
097      submitProcedureAndAssertNotFailed(procedure);
098
099    } catch (Exception e) {
100      throw new RuntimeException(e);
101    } finally {
102      // Delete table name post test execution
103      deleteTable(TEST_TABLE);
104
105      // Delete namespace post test execution
106      // This will delete all tables under namespace hence no explicit table
107      // deletion for table under namespace is needed.
108      deleteNamespace(TEST_NAMESPACE);
109    }
110  }
111}