diff --git a/hbase-backup/pom.xml b/hbase-backup/pom.xml
index 00a996f..3f2e588 100644
--- a/hbase-backup/pom.xml
+++ b/hbase-backup/pom.xml
@@ -65,6 +65,11 @@
+
+ 4
+ 4
+ 2
+
diff --git a/hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupBase.java b/hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupBase.java
index 94c2271..cc8aa44 100644
--- a/hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupBase.java
+++ b/hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupBase.java
@@ -38,6 +38,7 @@ import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.NamespaceDescriptor;
+import org.apache.hadoop.hbase.Stoppable;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.backup.BackupInfo.BackupPhase;
import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
@@ -59,6 +60,7 @@ import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.master.cleaner.LogCleaner;
import org.apache.hadoop.hbase.master.cleaner.TimeToLiveLogCleaner;
+import org.apache.hadoop.hbase.regionserver.ShutdownHook;
import org.apache.hadoop.hbase.security.HadoopSecurityEnabledUserProviderForTesting;
import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.hbase.security.access.SecureTestUtil;
@@ -66,7 +68,6 @@ import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.wal.WALFactory;
-import org.junit.AfterClass;
import org.junit.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -299,13 +300,7 @@ public class TestBackupBase {
conf1.set(WALFactory.WAL_PROVIDER, provider);
TEST_UTIL.startMiniCluster();
- if (useSecondCluster) {
- conf2 = HBaseConfiguration.create(conf1);
- conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
- TEST_UTIL2 = new HBaseTestingUtility(conf2);
- TEST_UTIL2.setZkCluster(TEST_UTIL.getZkCluster());
- TEST_UTIL2.startMiniCluster();
- }
+ checkSecondCluster();
conf1 = TEST_UTIL.getConfiguration();
TEST_UTIL.startMiniMapReduceCluster();
@@ -321,9 +316,41 @@ public class TestBackupBase {
}
createTables();
populateFromMasterConfig(TEST_UTIL.getHBaseCluster().getMaster().getConfiguration(), conf1);
+ installShutdownHook();
setupIsDone = true;
}
+ private static void installShutdownHook() throws IOException {
+ ShutdownHook.install(TEST_UTIL.getConfiguration(), TEST_UTIL.getDFSCluster().getFileSystem(),
+ new Stoppable() {
+ @Override
+ public void stop(String why) {
+ try {
+ tearDown();
+ } catch (Exception e) {
+ LOG.debug("Encountered exception during shutdown", e);
+ }
+ }
+
+ @Override
+ public boolean isStopped() {
+ return false;
+ }
+ }, Thread.currentThread());
+ }
+
+ private void checkSecondCluster() throws Exception {
+ if (useSecondCluster) {
+ if (TEST_UTIL2 != null) {
+ return;
+ }
+ conf2 = HBaseConfiguration.create(conf1);
+ conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
+ TEST_UTIL2 = new HBaseTestingUtility(conf2);
+ TEST_UTIL2.setZkCluster(TEST_UTIL.getZkCluster());
+ TEST_UTIL2.startMiniCluster();
+ }
+ }
private static void populateFromMasterConfig(Configuration masterConf, Configuration conf) {
Iterator> it = masterConf.iterator();
while (it.hasNext()) {
@@ -335,8 +362,8 @@ public class TestBackupBase {
/**
* @throws Exception if deleting the archive directory or shutting down the mini cluster fails
*/
- @AfterClass
- public static void tearDown() throws Exception {
+ private static void tearDown() throws Exception {
+ LOG.debug("tearing down");
try{
SnapshotTestingUtils.deleteAllSnapshots(TEST_UTIL.getHBaseAdmin());
} catch (Exception e) {