DefaultPeerMasterStateAdjuster extends AbstractClusterShardPeriodicTask implements PeerMasterStateAdjuster { @Override protected void work() { if (!config.shouldCorrectPeerMasterPeriodically()) return; PeerMasterAdjustJob adjustJob = peerMasterAdjustJobFactory.buildPeerMasterAdjustJob(clusterId, shardId); if (null != adjustJob) peerMasterAdjustExecutor.execute(Pair.of(clusterId, shardId), adjustJob); } DefaultPeerMasterStateAdjuster(String clusterId, String shardId, DcMetaCache dcMetaCache, CurrentMetaManager currentMetaManager,
                                          MetaServerConfig config, PeerMasterAdjustJobFactory peerMasterAdjustJobFactory,
                                          KeyedOneThreadTaskExecutor<Pair<String, String> > peerMasterAdjustExecutor,
                                          ScheduledExecutorService scheduled);  DefaultPeerMasterStateAdjuster(String clusterId, String shardId, DcMetaCache dcMetaCache, CurrentMetaManager currentMetaManager,
                                          MetaServerConfig config, PeerMasterAdjustJobFactory peerMasterAdjustJobFactory,
                                          KeyedOneThreadTaskExecutor<Pair<String, String> > peerMasterAdjustExecutor,
                                          ScheduledExecutorService scheduled, int adjustIntervalSeconds);  static final int DEFAULT_PEER_MASTER_ADJUST_INTERVAL_SECONDS; }
@Test public void testForAdjust() { adjuster.work(); Mockito.verify(peerMasterAdjustJobFactory, Mockito.times(1)).buildPeerMasterAdjustJob(clusterId, shardId); Mockito.verify(peerMasterAdjustExecutor, Mockito.times(1)).execute(Pair.of(clusterId, shardId), job); }
@Test public void testForNotDoAdjust() { Mockito.when(metaServerConfig.shouldCorrectPeerMasterPeriodically()).thenReturn(false); adjuster.work(); Mockito.verify(peerMasterAdjustJobFactory, Mockito.never()).buildPeerMasterAdjustJob(clusterId, shardId); Mockito.verify(peerMasterAdjustExecutor, Mockito.never()).execute(Pair.of(clusterId, shardId), job); }