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 TestRefreshHFilesProcedureWithReadOnlyConf extends TestRefreshHFilesBase {
032
033  @BeforeEach
034  public void setup() throws Exception {
035    // When true is passed only setup for readonly property is done.
036    // The initial ReadOnly property will be false for table creation
037    baseSetup(true);
038  }
039
040  @AfterEach
041  public void tearDown() throws Exception {
042    baseTearDown();
043  }
044
045  @Test
046  public void testRefreshHFilesProcedureForTable() throws IOException {
047    try {
048      // Create table in default namespace
049      createTableAndWait(TEST_TABLE, TEST_FAMILY);
050
051      setReadOnlyMode(true);
052      RefreshHFilesTableProcedure procedure =
053        new RefreshHFilesTableProcedure(procExecutor.getEnvironment(), TEST_TABLE);
054      submitProcedureAndAssertNotFailed(procedure);
055
056    } catch (Exception e) {
057      throw new RuntimeException(e);
058    } finally {
059      setReadOnlyMode(false);
060      // Delete table name post test execution
061      deleteTable(TEST_TABLE);
062    }
063  }
064
065  @Test
066  public void testRefreshHFilesProcedureForNamespace() {
067    try {
068      createNamespace(TEST_NAMESPACE);
069
070      // Create table under test namespace
071      createTableInNamespaceAndWait(TEST_NAMESPACE, TEST_TABLE, TEST_FAMILY);
072
073      setReadOnlyMode(true);
074      RefreshHFilesTableProcedure procedure =
075        new RefreshHFilesTableProcedure(procExecutor.getEnvironment(), TEST_NAMESPACE);
076      submitProcedureAndAssertNotFailed(procedure);
077
078    } catch (Exception e) {
079      throw new RuntimeException(e);
080    } finally {
081      setReadOnlyMode(false);
082      // Delete namespace post test execution
083      // This will delete all tables under namespace hence no explicit table
084      // deletion for table under namespace is needed.
085      deleteNamespace(TEST_NAMESPACE);
086    }
087  }
088
089  @Test
090  public void testRefreshHFilesProcedureForAllTables() throws IOException {
091    try {
092      // Create table in default namespace
093      createTableAndWait(TEST_TABLE, TEST_FAMILY);
094
095      // Create test namespace
096      createNamespace(TEST_NAMESPACE);
097
098      // Create table under test namespace
099      createTableInNamespaceAndWait(TEST_NAMESPACE, TEST_TABLE, TEST_FAMILY);
100
101      setReadOnlyMode(true);
102      RefreshHFilesTableProcedure procedure =
103        new RefreshHFilesTableProcedure(procExecutor.getEnvironment());
104      submitProcedureAndAssertNotFailed(procedure);
105
106    } catch (Exception e) {
107      throw new RuntimeException(e);
108    } finally {
109      setReadOnlyMode(false);
110      // Delete table name post test execution
111      deleteTable(TEST_TABLE);
112
113      // Delete namespace post test execution
114      // This will delete all tables under namespace hence no explicit table
115      // deletion for table under namespace is needed.
116      deleteNamespace(TEST_NAMESPACE);
117    }
118  }
119}