Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
import java.io.IOException;
import java.util.List;
import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
import org.junit.Test;
import org.junit.jupiter.api.TestTemplate;

public class RestoreSnapshotFromClientAfterSplittingRegionsTestBase
extends RestoreSnapshotFromClientTestBase {

@Test
protected RestoreSnapshotFromClientAfterSplittingRegionsTestBase(int numReplicas) {
super(numReplicas);
}

@TestTemplate
public void testRestoreSnapshotAfterSplittingRegions() throws IOException, InterruptedException {
List<RegionInfo> regionInfos = admin.getRegions(tableName);
RegionReplicaUtil.removeNonDefaultRegions(regionInfos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,38 @@

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
import org.junit.Test;
import org.junit.jupiter.api.TestTemplate;

public class RestoreSnapshotFromClientAfterTruncateTestBase
extends RestoreSnapshotFromClientTestBase {

@Test
protected RestoreSnapshotFromClientAfterTruncateTestBase(int numReplicas) {
super(numReplicas);
}

@TestTemplate
public void testRestoreSnapshotAfterTruncate() throws Exception {
TableName tableName = TableName.valueOf(getValidMethodName());
SnapshotTestingUtils.createTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY);
SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY);
int numOfRows = 0;
SnapshotTestingUtils.createTable(TEST_UTIL, tableName, numReplicas, FAMILY);
try {
SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY);
int numOfRows = 0;

try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
numOfRows = countRows(table);
}
// take snapshot
admin.snapshot("snap", tableName);
admin.disableTable(tableName);
admin.truncateTable(tableName, false);
admin.disableTable(tableName);
admin.restoreSnapshot("snap");
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
numOfRows = countRows(table);
}
// take snapshot
admin.snapshot("snap", tableName);
admin.disableTable(tableName);
admin.truncateTable(tableName, false);
admin.disableTable(tableName);
admin.restoreSnapshot("snap");

admin.enableTable(tableName);
verifyRowCount(TEST_UTIL, tableName, numOfRows);
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
admin.enableTable(tableName);
verifyRowCount(TEST_UTIL, tableName, numOfRows);
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, numReplicas);
} finally {
TEST_UTIL.deleteTable(tableName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,47 @@
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.junit.Test;
import org.junit.jupiter.api.TestTemplate;

public class RestoreSnapshotFromClientCloneTestBase extends RestoreSnapshotFromClientTestBase {

@Test
protected RestoreSnapshotFromClientCloneTestBase(int numReplicas) {
super(numReplicas);
}

@TestTemplate
public void testCloneSnapshotOfCloned() throws IOException, InterruptedException {
TableName clonedTableName =
TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime());
admin.cloneSnapshot(snapshotName0, clonedTableName);
verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas());
SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, numReplicas);
admin.disableTable(clonedTableName);
admin.snapshot(snapshotName2, clonedTableName);
TEST_UTIL.deleteTable(clonedTableName);
waitCleanerRun();

admin.cloneSnapshot(snapshotName2, clonedTableName);
verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas());
SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, numReplicas);
TEST_UTIL.deleteTable(clonedTableName);
}

@Test
@TestTemplate
public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException {
TEST_UTIL.deleteTable(tableName);
waitCleanerRun();

admin.cloneSnapshot(snapshotName0, tableName);
verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, numReplicas);
waitCleanerRun();

admin.disableTable(tableName);
admin.restoreSnapshot(snapshotName0);
admin.enableTable(tableName);
verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, numReplicas);
}

private void waitCleanerRun() throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
*/
package org.apache.hadoop.hbase.client;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import org.junit.Test;
import org.junit.jupiter.api.TestTemplate;

public class RestoreSnapshotFromClientGetCompactionStateTestBase
extends RestoreSnapshotFromClientTestBase {

@Test
protected RestoreSnapshotFromClientGetCompactionStateTestBase(int numReplicas) {
super(numReplicas);
}

@TestTemplate
public void testGetCompactionStateAfterRestoringSnapshot()
throws IOException, InterruptedException {
// Take a snapshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.client;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.util.HashSet;
Expand All @@ -31,11 +31,15 @@
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.util.FSUtils;
import org.junit.Test;
import org.junit.jupiter.api.TestTemplate;

public class RestoreSnapshotFromClientSchemaChangeTestBase
extends RestoreSnapshotFromClientTestBase {

protected RestoreSnapshotFromClientSchemaChangeTestBase(int numReplicas) {
super(numReplicas);
}

private Set<String> getFamiliesFromFS(final TableName tableName) throws IOException {
MasterFileSystem mfs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem();
Set<String> families = new HashSet<>();
Expand All @@ -52,7 +56,7 @@ protected ColumnFamilyDescriptor getTestRestoreSchemaChangeHCD() {
return ColumnFamilyDescriptorBuilder.of(TEST_FAMILY2);
}

@Test
@TestTemplate
public void testRestoreSchemaChange() throws Exception {
Table table = TEST_UTIL.getConnection().getTable(tableName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@
*/
package org.apache.hadoop.hbase.client;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException;
import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.junit.Test;
import org.junit.jupiter.api.TestTemplate;

public class RestoreSnapshotFromClientSimpleTestBase extends RestoreSnapshotFromClientTestBase {

@Test
protected RestoreSnapshotFromClientSimpleTestBase(int numReplicas) {
super(numReplicas);
}

@TestTemplate
public void testRestoreSnapshot() throws IOException {
verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
admin.disableTable(tableName);
Expand All @@ -38,30 +42,30 @@ public void testRestoreSnapshot() throws IOException {
admin.restoreSnapshot(snapshotName0);
admin.enableTable(tableName);
verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, numReplicas);

// Restore from emptySnapshot
admin.disableTable(tableName);
admin.restoreSnapshot(emptySnapshot);
admin.enableTable(tableName);
verifyRowCount(TEST_UTIL, tableName, 0);
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, numReplicas);

// Restore from snapshot-1
admin.disableTable(tableName);
admin.restoreSnapshot(snapshotName1);
admin.enableTable(tableName);
verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, numReplicas);

// Restore from snapshot-1
TEST_UTIL.deleteTable(tableName);
admin.restoreSnapshot(snapshotName1);
verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, numReplicas);
}

@Test
@TestTemplate
public void testCorruptedSnapshot() throws IOException, InterruptedException {
SnapshotTestingUtils.corruptSnapshot(TEST_UTIL, snapshotName0);
TableName cloneName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.client;

import java.io.IOException;
import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.HConstants;
Expand All @@ -26,12 +27,11 @@
import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.TestName;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.params.provider.Arguments;

/**
* Base class for testing restore snapshot
Expand All @@ -51,13 +51,16 @@ public class RestoreSnapshotFromClientTestBase {
protected int snapshot1Rows;
protected Admin admin;

@Rule
public TestName name = new TestName();
protected int numReplicas;

@BeforeClass
public static void setupCluster() throws Exception {
setupConf(TEST_UTIL.getConfiguration());
TEST_UTIL.startMiniCluster(3);
private String testName;

protected RestoreSnapshotFromClientTestBase(int numReplicas) {
this.numReplicas = numReplicas;
}

public static Stream<Arguments> parameters() {
return Stream.of(Arguments.of(1), Arguments.of(3));
}

protected static void setupConf(Configuration conf) {
Expand All @@ -69,7 +72,7 @@ protected static void setupConf(Configuration conf) {
TEST_UTIL.getConfiguration().setBoolean("hbase.master.enabletable.roundrobin", true);
}

@AfterClass
@AfterAll
public static void tearDownAfterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
Expand All @@ -79,10 +82,12 @@ public static void tearDownAfterClass() throws Exception {
* snapshotName1) of different states. The tableName, snapshotNames and the number of rows in the
* snapshot are initialized.
*/
@Before
public void setup() throws Exception {
@BeforeEach
public void setUp(TestInfo testInfo) throws Exception {
this.admin = TEST_UTIL.getAdmin();
long tid = EnvironmentEdgeManager.currentTime();
testName = testInfo.getTestMethod().get().getName()
+ testInfo.getDisplayName().replaceAll("[^0-9A-Za-z_]", "_");
tableName = TableName.valueOf(getValidMethodName() + "-" + tid);
emptySnapshot = "emptySnaptb-" + tid;
snapshotName0 = "snaptb0-" + tid;
Expand Down Expand Up @@ -116,22 +121,18 @@ public void setup() throws Exception {
}

protected void createTable() throws Exception {
SnapshotTestingUtils.createTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY);
SnapshotTestingUtils.createTable(TEST_UTIL, tableName, numReplicas, FAMILY);
}

@After
@AfterEach
public void tearDown() throws Exception {
TEST_UTIL.deleteTable(tableName);
SnapshotTestingUtils.deleteAllSnapshots(TEST_UTIL.getAdmin());
SnapshotTestingUtils.deleteArchiveDirectory(TEST_UTIL);
}

protected int getNumReplicas() {
return 1;
}

protected int countRows(Table table, byte[]... families) throws IOException {
return TEST_UTIL.countRows(table, families);
return HBaseTestingUtil.countRows(table, families);
}

protected void verifyRowCount(HBaseTestingUtil util, TableName tableName, long expectedRows)
Expand All @@ -145,6 +146,6 @@ protected final void splitRegion(RegionInfo regionInfo) throws IOException {
}

protected final String getValidMethodName() {
return name.getMethodName().replaceAll("[^0-9A-Za-z_]", "_");
return testName;
}
}
Loading