Skip to content

Commit

Permalink
Add unit tests for RemoteFsTimestampAwareTranslog.getMinPrimaryTermIn…
Browse files Browse the repository at this point in the history
…Remote

Signed-off-by: Sachin Kale <[email protected]>
  • Loading branch information
sachinpkale committed Sep 30, 2024
1 parent 2924dca commit a862aad
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ protected static void deleteStaleRemotePrimaryTerms(
}
}

private static Long getMinPrimaryTermInRemote(
protected static Long getMinPrimaryTermInRemote(
AtomicLong minPrimaryTermInRemote,
TranslogTransferManager translogTransferManager,
Logger logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1146,4 +1146,41 @@ public void testDeleteStaleRemotePrimaryTermsPrimaryTermInRemoteIsBigger() throw
assertEquals(2, minPrimaryTermInRemote.get());
}

public void testGetMinPrimaryTermInRemoteAlreadyFetched() {
Long expectedMinPrimaryTerm = 12L;
assertEquals(expectedMinPrimaryTerm, RemoteFsTimestampAwareTranslog.getMinPrimaryTermInRemote(new AtomicLong(12), null, null));
}

public void testGetMinPrimaryTermInRemoteNotFetchedEmpty() throws IOException {
TranslogTransferManager translogTransferManager = mock(TranslogTransferManager.class);
when(translogTransferManager.listPrimaryTermsInRemote()).thenReturn(Set.of());
Long expectedMinPrimaryTerm = Long.MAX_VALUE;
assertEquals(
expectedMinPrimaryTerm,
RemoteFsTimestampAwareTranslog.getMinPrimaryTermInRemote(new AtomicLong(Long.MAX_VALUE), translogTransferManager, null)
);
verify(translogTransferManager).listPrimaryTermsInRemote();
}

public void testGetMinPrimaryTermInRemoteNotFetchedException() throws IOException {
TranslogTransferManager translogTransferManager = mock(TranslogTransferManager.class);
when(translogTransferManager.listPrimaryTermsInRemote()).thenThrow(new IOException());
Long expectedMinPrimaryTerm = Long.MAX_VALUE;
assertEquals(
expectedMinPrimaryTerm,
RemoteFsTimestampAwareTranslog.getMinPrimaryTermInRemote(new AtomicLong(Long.MAX_VALUE), translogTransferManager, logger)
);
verify(translogTransferManager).listPrimaryTermsInRemote();
}

public void testGetMinPrimaryTermInRemoteNotFetched() throws IOException {
TranslogTransferManager translogTransferManager = mock(TranslogTransferManager.class);
when(translogTransferManager.listPrimaryTermsInRemote()).thenReturn(Set.of(12L, 23L, 34L, 4L, 89L));
Long expectedMinPrimaryTerm = 4L;
assertEquals(
expectedMinPrimaryTerm,
RemoteFsTimestampAwareTranslog.getMinPrimaryTermInRemote(new AtomicLong(Long.MAX_VALUE), translogTransferManager, logger)
);
verify(translogTransferManager).listPrimaryTermsInRemote();
}
}

0 comments on commit a862aad

Please sign in to comment.