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.client;
019
020import static org.junit.jupiter.api.Assertions.assertThrows;
021import static org.junit.jupiter.api.Assertions.assertTrue;
022import static org.junit.jupiter.api.Assertions.fail;
023
024import org.apache.hadoop.hbase.NamespaceNotFoundException;
025import org.apache.hadoop.hbase.TableName;
026import org.apache.hadoop.hbase.TableNotFoundException;
027import org.apache.hadoop.hbase.TestRefreshHFilesBase;
028import org.apache.hadoop.hbase.testclassification.ClientTests;
029import org.apache.hadoop.hbase.testclassification.MediumTests;
030import org.junit.jupiter.api.AfterEach;
031import org.junit.jupiter.api.BeforeEach;
032import org.junit.jupiter.api.Tag;
033import org.junit.jupiter.api.Test;
034
035@Tag(MediumTests.TAG)
036@Tag(ClientTests.TAG)
037public class TestRefreshHFilesFromClient extends TestRefreshHFilesBase {
038
039  private static final TableName TEST_NONEXISTENT_TABLE =
040    TableName.valueOf("testRefreshHFilesNonExistentTable");
041  private static final String TEST_NONEXISTENT_NAMESPACE = "testRefreshHFilesNonExistentNamespace";
042
043  @BeforeEach
044  public void setup() throws Exception {
045    baseSetup(false);
046  }
047
048  @AfterEach
049  public void tearDown() throws Exception {
050    baseTearDown();
051  }
052
053  @Test
054  public void testRefreshHFilesForTable() throws Exception {
055    try {
056      // Create table in default namespace
057      createTableAndWait(TEST_TABLE, TEST_FAMILY);
058
059      // RefreshHFiles for table
060      Long procId = admin.refreshHFiles(TEST_TABLE);
061      assertTrue(procId >= 0);
062    } catch (Exception e) {
063      fail("RefreshHFilesForTable Should Not Throw Exception: " + e);
064      throw new RuntimeException(e);
065    } finally {
066      // Delete table name post test execution
067      deleteTable(TEST_TABLE);
068    }
069  }
070
071  // Not creating table hence refresh should throw exception
072  @Test
073  public void testRefreshHFilesForNonExistentTable() {
074    assertThrows(TableNotFoundException.class, () -> admin.refreshHFiles(TEST_NONEXISTENT_TABLE));
075  }
076
077  @Test
078  public void testRefreshHFilesForNamespace() {
079    try {
080      createNamespace(TEST_NAMESPACE);
081
082      // Create table under test namespace
083      createTableInNamespaceAndWait(TEST_NAMESPACE, TEST_TABLE, TEST_FAMILY);
084
085      // RefreshHFiles for namespace
086      Long procId = admin.refreshHFiles(TEST_NAMESPACE);
087      assertTrue(procId >= 0);
088
089    } catch (Exception e) {
090      fail("RefreshHFilesForAllNamespace Should Not Throw Exception: " + e);
091      throw new RuntimeException(e);
092    } finally {
093      // Delete namespace post test execution
094      // This will delete all tables under namespace hence no explicit table
095      // deletion for table under namespace is needed.
096      deleteNamespace(TEST_NAMESPACE);
097    }
098  }
099
100  @Test
101  public void testRefreshHFilesForNonExistentNamespace() {
102    // RefreshHFiles for namespace
103    assertThrows(NamespaceNotFoundException.class,
104      () -> admin.refreshHFiles(TEST_NONEXISTENT_NAMESPACE));
105  }
106
107  @Test
108  public void testRefreshHFilesForAllTables() throws Exception {
109    try {
110      // Create table in default namespace
111      createTableAndWait(TEST_TABLE, TEST_FAMILY);
112
113      // Create test namespace
114      createNamespace(TEST_NAMESPACE);
115
116      // Create table under test namespace
117      createTableInNamespaceAndWait(TEST_NAMESPACE, TEST_TABLE, TEST_FAMILY);
118
119      // RefreshHFiles for all the tables
120      Long procId = admin.refreshHFiles();
121      assertTrue(procId >= 0);
122
123    } catch (Exception e) {
124      fail("RefreshHFilesForAllTables Should Not Throw Exception: " + e);
125      throw new RuntimeException(e);
126    } finally {
127      // Delete table name post test execution
128      deleteTable(TEST_TABLE);
129
130      // Delete namespace post test execution
131      // This will delete all tables under namespace hence no explicit table
132      // deletion for table under namespace is needed.
133      deleteNamespace(TEST_NAMESPACE);
134    }
135  }
136}