ShardManager implements ShardManagerProtocol { @Override public boolean waitSlavesSynced(String shardId, long timeoutMs) throws ShardManagerException, InterruptedException { return waitLogApproach(shardId, timeoutMs, 0); } ShardManager(Gondola gondola, RoutingFilter filter, Config config, ShardManagerClient shardManagerClient); @Override void startObserving(String shardId, String observedShardId, long timeoutMs); @Override void stopObserving(String shardId, String masterShardId, long timeoutMs); @Override void migrateBuckets(Range<Integer> splitRange, String fromShardId,
                               String toShardId, long timeoutMs); @Override boolean waitSlavesSynced(String shardId, long timeoutMs); @Override boolean waitSlavesApproaching(String shardId, long timeoutMs); @Override void setBuckets(Range<Integer> splitRange, String fromShardId, String toShardId, boolean migrationComplete); @Override void rollbackBuckets(Range<Integer> splitRange); ShardManagerClient getShardManagerClient(); static final int POLLING_TIMES; static final int LOG_APPROACHING_DIFF; }
@Test public void testWaitSlavesSynced() throws Exception { when(shard.getCommitIndex()).thenReturn(2); when(shard.getLastSavedIndex()).thenReturn(1).thenReturn(2); when(shard.getMember(anyInt())).thenReturn(member); when(member.getSlaveStatus()).thenReturn(getSuccessSlaveStatus()); when(changeLogProcessor.getAppliedIndex(any())).thenReturn(100); assertTrue(shardManager.waitSlavesSynced(FROM_SHARD, 300)); }
@Test public void testWaitSlavesSynced_failed_never_catched_up() throws Exception { when(shard.getCommitIndex()).thenReturn(1+1); when(shard.getLastSavedIndex()).thenReturn(1); when(shard.getMember(anyInt())).thenReturn(member); when(member.getSlaveStatus()).thenReturn(getSuccessSlaveStatus()); assertFalse(shardManager.waitSlavesSynced(FROM_SHARD, 300)); }
@Test public void testWaitSlavesSynced_failed_never_approaching() throws Exception { when(shard.getCommitIndex()).thenReturn(1 + ShardManager.LOG_APPROACHING_DIFF + 1); when(shard.getLastSavedIndex()).thenReturn(1); when(shard.getMember(anyInt())).thenReturn(member); when(member.getSlaveStatus()).thenReturn(getSuccessSlaveStatus()); assertFalse(shardManager.waitSlavesSynced(FROM_SHARD, 300)); }