Skip to content

Commit

Permalink
Fix broken UT
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Handalian <marc.handalian@gmail.com>
  • Loading branch information
mch2 committed Nov 30, 2023
1 parent e84a4e5 commit 33a7ec1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,11 @@ protected boolean processLatestReceivedCheckpoint(IndexShard replicaShard, Threa
protected void updateLatestReceivedCheckpoint(ReplicationCheckpoint receivedCheckpoint, IndexShard replicaShard) {
if (latestReceivedCheckpoint.get(replicaShard.shardId()) != null) {
if (receivedCheckpoint.isAheadOf(latestReceivedCheckpoint.get(replicaShard.shardId()))) {
logger.info("Setting cp to {}", receivedCheckpoint);
latestReceivedCheckpoint.replace(replicaShard.shardId(), receivedCheckpoint);
}
} else {
logger.info("Setting cp to {}", receivedCheckpoint);
latestReceivedCheckpoint.put(replicaShard.shardId(), receivedCheckpoint);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,22 @@ public void testStartReplicationListenerFailure() throws InterruptedException {
verify(spy, (never())).updateVisibleCheckpoint(eq(0L), eq(replicaShard));
}

public void testDoNotProcessLatestCheckpointIfItIsbehind() {
sut.updateLatestReceivedCheckpoint(replicaShard.getLatestReplicationCheckpoint(), replicaShard);
assertFalse(sut.processLatestReceivedCheckpoint(replicaShard, null));
public void testDoNotProcessLatestCheckpointIfCheckpointIsBehind() {
SegmentReplicationTargetService service = spy(sut);
doReturn(mock(SegmentReplicationTarget.class)).when(service).startReplication(any(), any(), any());
ReplicationCheckpoint checkpoint = replicaShard.getLatestReplicationCheckpoint();
service.updateLatestReceivedCheckpoint(checkpoint, replicaShard);
service.processLatestReceivedCheckpoint(replicaShard, null);
verify(service, times(0)).startReplication(eq(replicaShard), eq(checkpoint), any());
}

public void testProcessLatestCheckpointIfCheckpointAhead() {
SegmentReplicationTargetService service = spy(sut);
doNothing().when(service).startReplication(any());
doReturn(mock(SegmentReplicationTarget.class)).when(service).startReplication(any(), any(), any());
service.updateLatestReceivedCheckpoint(aheadCheckpoint, replicaShard);
service.processLatestReceivedCheckpoint(replicaShard, null);
verify(service, times(1)).startReplication(eq(replicaShard), eq(aheadCheckpoint), any());
}

public void testOnNewCheckpointInvokedOnClosedShardDoesNothing() throws IOException {
Expand Down

0 comments on commit 33a7ec1

Please sign in to comment.