HBASE-26927 Add snapshot scanner UT with SFT and some cleanups to Tes… (#4322)
Signed-off-by: Duo Zhang <zhangduo@apache.org> Signed-off-by: Josh Elser <elserj@apache.org> (cherry picked from commit ae3718be0fa11127cb272ddf305f8a0753f4603d)
This commit is contained in:
parent
8ef1ae32e6
commit
1c14046ee0
@ -50,6 +50,7 @@ import org.apache.hadoop.hbase.util.HFileArchiveUtil;
|
|||||||
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
|
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -74,6 +75,7 @@ public class TestTableSnapshotScanner {
|
|||||||
|
|
||||||
private FileSystem fs;
|
private FileSystem fs;
|
||||||
private Path rootDir;
|
private Path rootDir;
|
||||||
|
private boolean clusterUp;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TestName name = new TestName();
|
public TestName name = new TestName();
|
||||||
@ -89,27 +91,28 @@ public class TestTableSnapshotScanner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
public void setupCluster() throws Exception {
|
public void setupCluster() throws Exception {
|
||||||
setupConf(UTIL.getConfiguration());
|
setupConf(UTIL.getConfiguration());
|
||||||
StartMiniClusterOption option = StartMiniClusterOption.builder()
|
StartMiniClusterOption option = StartMiniClusterOption.builder()
|
||||||
.numRegionServers(NUM_REGION_SERVERS).numDataNodes(NUM_REGION_SERVERS)
|
.numRegionServers(NUM_REGION_SERVERS).numDataNodes(NUM_REGION_SERVERS)
|
||||||
.createRootDir(true).build();
|
.createRootDir(true).build();
|
||||||
UTIL.startMiniCluster(option);
|
UTIL.startMiniCluster(option);
|
||||||
|
clusterUp = true;
|
||||||
rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir();
|
rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir();
|
||||||
fs = rootDir.getFileSystem(UTIL.getConfiguration());
|
fs = rootDir.getFileSystem(UTIL.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
public void tearDownCluster() throws Exception {
|
public void tearDownCluster() throws Exception {
|
||||||
|
if (clusterUp) {
|
||||||
UTIL.shutdownMiniCluster();
|
UTIL.shutdownMiniCluster();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setupConf(Configuration conf) {
|
|
||||||
// Enable snapshot
|
|
||||||
conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
protected void setupConf(Configuration conf) {
|
||||||
public void tearDown() throws Exception {
|
// Enable snapshot
|
||||||
|
conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createTableAndSnapshot(HBaseTestingUtility util, TableName tableName,
|
public static void createTableAndSnapshot(HBaseTestingUtility util, TableName tableName,
|
||||||
@ -149,7 +152,6 @@ public class TestTableSnapshotScanner {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoDuplicateResultsWhenSplitting() throws Exception {
|
public void testNoDuplicateResultsWhenSplitting() throws Exception {
|
||||||
setupCluster();
|
|
||||||
TableName tableName = TableName.valueOf("testNoDuplicateResultsWhenSplitting");
|
TableName tableName = TableName.valueOf("testNoDuplicateResultsWhenSplitting");
|
||||||
String snapshotName = "testSnapshotBug";
|
String snapshotName = "testSnapshotBug";
|
||||||
try {
|
try {
|
||||||
@ -195,14 +197,12 @@ public class TestTableSnapshotScanner {
|
|||||||
} finally {
|
} finally {
|
||||||
UTIL.getAdmin().deleteSnapshot(snapshotName);
|
UTIL.getAdmin().deleteSnapshot(snapshotName);
|
||||||
UTIL.deleteTable(tableName);
|
UTIL.deleteTable(tableName);
|
||||||
tearDownCluster();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScanLimit() throws Exception {
|
public void testScanLimit() throws Exception {
|
||||||
setupCluster();
|
|
||||||
final TableName tableName = TableName.valueOf(name.getMethodName());
|
final TableName tableName = TableName.valueOf(name.getMethodName());
|
||||||
final String snapshotName = tableName + "Snapshot";
|
final String snapshotName = tableName + "Snapshot";
|
||||||
TableSnapshotScanner scanner = null;
|
TableSnapshotScanner scanner = null;
|
||||||
@ -227,7 +227,6 @@ public class TestTableSnapshotScanner {
|
|||||||
}
|
}
|
||||||
UTIL.getAdmin().deleteSnapshot(snapshotName);
|
UTIL.getAdmin().deleteSnapshot(snapshotName);
|
||||||
UTIL.deleteTable(tableName);
|
UTIL.deleteTable(tableName);
|
||||||
tearDownCluster();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +247,6 @@ public class TestTableSnapshotScanner {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScannerWithRestoreScanner() throws Exception {
|
public void testScannerWithRestoreScanner() throws Exception {
|
||||||
setupCluster();
|
|
||||||
TableName tableName = TableName.valueOf("testScanner");
|
TableName tableName = TableName.valueOf("testScanner");
|
||||||
String snapshotName = "testScannerWithRestoreScanner";
|
String snapshotName = "testScannerWithRestoreScanner";
|
||||||
try {
|
try {
|
||||||
@ -288,19 +286,18 @@ public class TestTableSnapshotScanner {
|
|||||||
} finally {
|
} finally {
|
||||||
UTIL.getAdmin().deleteSnapshot(snapshotName);
|
UTIL.getAdmin().deleteSnapshot(snapshotName);
|
||||||
UTIL.deleteTable(tableName);
|
UTIL.deleteTable(tableName);
|
||||||
tearDownCluster();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testScanner(HBaseTestingUtility util, String snapshotName, int numRegions,
|
private void testScanner(HBaseTestingUtility util, String snapshotName, int numRegions,
|
||||||
boolean shutdownCluster) throws Exception {
|
boolean shutdownCluster) throws Exception {
|
||||||
setupCluster();
|
|
||||||
TableName tableName = TableName.valueOf("testScanner");
|
TableName tableName = TableName.valueOf("testScanner");
|
||||||
try {
|
try {
|
||||||
createTableAndSnapshot(util, tableName, snapshotName, numRegions);
|
createTableAndSnapshot(util, tableName, snapshotName, numRegions);
|
||||||
|
|
||||||
if (shutdownCluster) {
|
if (shutdownCluster) {
|
||||||
util.shutdownMiniHBaseCluster();
|
util.shutdownMiniHBaseCluster();
|
||||||
|
clusterUp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Path restoreDir = util.getDataTestDirOnTestFS(snapshotName);
|
Path restoreDir = util.getDataTestDirOnTestFS(snapshotName);
|
||||||
@ -312,10 +309,9 @@ public class TestTableSnapshotScanner {
|
|||||||
verifyScanner(scanner, bbb, yyy);
|
verifyScanner(scanner, bbb, yyy);
|
||||||
scanner.close();
|
scanner.close();
|
||||||
} finally {
|
} finally {
|
||||||
if (!shutdownCluster) {
|
if (clusterUp) {
|
||||||
util.getAdmin().deleteSnapshot(snapshotName);
|
util.getAdmin().deleteSnapshot(snapshotName);
|
||||||
util.deleteTable(tableName);
|
util.deleteTable(tableName);
|
||||||
tearDownCluster();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -359,7 +355,6 @@ public class TestTableSnapshotScanner {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMergeRegion() throws Exception {
|
public void testMergeRegion() throws Exception {
|
||||||
setupCluster();
|
|
||||||
TableName tableName = TableName.valueOf("testMergeRegion");
|
TableName tableName = TableName.valueOf("testMergeRegion");
|
||||||
String snapshotName = tableName.getNameAsString() + "_snapshot";
|
String snapshotName = tableName.getNameAsString() + "_snapshot";
|
||||||
Configuration conf = UTIL.getConfiguration();
|
Configuration conf = UTIL.getConfiguration();
|
||||||
@ -385,10 +380,13 @@ public class TestTableSnapshotScanner {
|
|||||||
for (RegionInfo region : regions) {
|
for (RegionInfo region : regions) {
|
||||||
Path regionDir = new Path(tableDir, region.getEncodedName());
|
Path regionDir = new Path(tableDir, region.getEncodedName());
|
||||||
for (Path familyDir : FSUtils.getFamilyDirs(fs, regionDir)) {
|
for (Path familyDir : FSUtils.getFamilyDirs(fs, regionDir)) {
|
||||||
if (fs.listStatus(familyDir).length != 1) {
|
for (FileStatus fs : fs.listStatus(familyDir)) {
|
||||||
return false;
|
if(!fs.getPath().getName().equals(".filelist")) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -462,17 +460,15 @@ public class TestTableSnapshotScanner {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("scan snapshot error", e);
|
LOG.error("scan snapshot error", e);
|
||||||
|
Assert.fail("Should not throw Exception: " + e.getMessage());
|
||||||
Assert.fail("Should not throw FileNotFoundException");
|
Assert.fail("Should not throw FileNotFoundException");
|
||||||
Assert.assertTrue(e.getCause() != null);
|
Assert.assertTrue(e.getCause() != null);
|
||||||
Assert.assertTrue(e.getCause().getCause() instanceof FileNotFoundException);
|
Assert.assertTrue(e.getCause().getCause() instanceof FileNotFoundException);
|
||||||
} finally {
|
|
||||||
tearDownCluster();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteTableWithMergedRegions() throws Exception {
|
public void testDeleteTableWithMergedRegions() throws Exception {
|
||||||
setupCluster();
|
|
||||||
final TableName tableName = TableName.valueOf(this.name.getMethodName());
|
final TableName tableName = TableName.valueOf(this.name.getMethodName());
|
||||||
String snapshotName = tableName.getNameAsString() + "_snapshot";
|
String snapshotName = tableName.getNameAsString() + "_snapshot";
|
||||||
Configuration conf = UTIL.getConfiguration();
|
Configuration conf = UTIL.getConfiguration();
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.hbase.client;
|
||||||
|
|
||||||
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||||
|
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
|
||||||
|
import org.apache.hadoop.hbase.testclassification.ClientTests;
|
||||||
|
import org.apache.hadoop.hbase.testclassification.LargeTests;
|
||||||
|
import org.junit.ClassRule;
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
|
@Category({ LargeTests.class, ClientTests.class})
|
||||||
|
public class TestTableSnapshotScannerWithSFT extends TestTableSnapshotScanner {
|
||||||
|
|
||||||
|
@ClassRule
|
||||||
|
public static final HBaseClassTestRule CLASS_RULE =
|
||||||
|
HBaseClassTestRule.forClass(TestTableSnapshotScannerWithSFT.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setupConf(Configuration conf) {
|
||||||
|
super.setupConf(conf);
|
||||||
|
// Enable snapshot
|
||||||
|
conf.set(StoreFileTrackerFactory.TRACKER_IMPL, StoreFileTrackerFactory.Trackers.FILE.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user