2626import  org .apache .hadoop .hive .metastore .conf .MetastoreConf .ConfVars ;
2727import  org .apache .hadoop .hive .metastore .leader .LeaderElection ;
2828import  org .apache .hadoop .hive .metastore .leader .LeaderElectionContext ;
29+ import  org .apache .hadoop .hive .metastore .leader .LeaderElectionFactory ;
2930import  org .apache .hadoop .hive .metastore .leader .LeaseLeaderElection ;
3031import  org .apache .hadoop .hive .metastore .security .HadoopThriftAuthBridge ;
3132import  org .apache .hadoop .hive .ql .stats .StatsUpdaterThread ;
4344import  java .util .Map ;
4445import  java .util .Set ;
4546import  java .util .concurrent .CountDownLatch ;
47+ import  java .util .concurrent .ScheduledExecutorService ;
4648import  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