Skip to content

Commit c71ee31

Browse files
committed
interrupt all sleeping tasks
1 parent 9f03d15 commit c71ee31

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/MetastoreHousekeepingLeaderTestBase.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars;
2727
import org.apache.hadoop.hive.metastore.leader.LeaderElection;
2828
import org.apache.hadoop.hive.metastore.leader.LeaderElectionContext;
29+
import org.apache.hadoop.hive.metastore.leader.LeaderElectionFactory;
2930
import org.apache.hadoop.hive.metastore.leader.LeaseLeaderElection;
3031
import org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge;
3132
import org.apache.hadoop.hive.ql.stats.StatsUpdaterThread;
@@ -43,6 +44,7 @@
4344
import java.util.Map;
4445
import java.util.Set;
4546
import java.util.concurrent.CountDownLatch;
47+
import java.util.concurrent.ScheduledExecutorService;
4648
import java.util.concurrent.TimeUnit;
4749

4850
/**
@@ -68,7 +70,7 @@ void setup(final String leaderHostName, Configuration configuration) throws Exce
6870
MetaStoreTestUtils.setConfForStandloneMode(conf);
6971
MetastoreConf.setVar(conf, ConfVars.THRIFT_BIND_HOST, "localhost");
7072
MetastoreConf.setVar(conf, ConfVars.METASTORE_HOUSEKEEPING_LEADER_ELECTION,
71-
leaderHostName != null ? "host" : "lock");
73+
leaderHostName != null ? LeaderElectionFactory.Method.HOST.name() : LeaderElectionFactory.Method.LOCK.name());
7274
if (leaderHostName != null) {
7375
MetastoreConf.setVar(conf, ConfVars.METASTORE_HOUSEKEEPING_LEADER_HOSTNAME, leaderHostName);
7476
}
@@ -286,6 +288,10 @@ public void setName(String name) {
286288

287289
@Override
288290
protected void notifyListener() {
291+
ScheduledExecutorService service = null;
292+
if (!isLeader) {
293+
service = ThreadPool.getPool();
294+
}
289295
super.notifyListener();
290296
if (isLeader) {
291297
if (!needRenewLease) {
@@ -298,10 +304,13 @@ protected void notifyListener() {
298304
heartbeater.startWatch();
299305
}
300306
} else {
307+
Assert.assertTrue(service.isShutdown());
308+
// Interrupt all sleeping tasks
309+
service.shutdownNow();
301310
try {
302311
// This is the last one get notified, sleep some time to make sure all other
303312
// services have been stopped before return
304-
Thread.sleep(12000);
313+
Thread.sleep(3000);
305314
} catch (InterruptedException ignore) {
306315
}
307316
}

0 commit comments

Comments
 (0)