Skip to content

Commit

Permalink
[Remote Store] Add missing unit test in main (opensearch-project#9101)
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Singh <surajrider@gmail.com>
Signed-off-by: Ivan Brusic <ivan.brusic@flocksafety.com>
  • Loading branch information
dreamer-89 authored and brusic committed Sep 25, 2023
1 parent 4fd6c27 commit df6d9a5
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,35 @@ public void testUploadMetadataNonEmpty() throws IOException {
}
}

public void testUploadMetadataMissingSegment() throws IOException {
populateMetadata();
remoteSegmentStoreDirectory.init();

Directory storeDirectory = mock(Directory.class);
IndexOutput indexOutput = mock(IndexOutput.class);

String generation = RemoteStoreUtils.invertLong(segmentInfos.getGeneration());
long primaryTermLong = indexShard.getLatestReplicationCheckpoint().getPrimaryTerm();
String primaryTerm = RemoteStoreUtils.invertLong(primaryTermLong);
when(storeDirectory.createOutput(startsWith("metadata__" + primaryTerm + "__" + generation), eq(IOContext.DEFAULT))).thenReturn(
indexOutput
);

Collection<String> segmentFiles = List.of("_123.si");
assertThrows(
NoSuchFileException.class,
() -> remoteSegmentStoreDirectory.uploadMetadata(
segmentFiles,
segmentInfos,
storeDirectory,
12L,
indexShard.getLatestReplicationCheckpoint()
)
);
verify(indexOutput).close();
verify(storeDirectory).deleteFile(startsWith("metadata__" + primaryTerm + "__" + generation));
}

public void testUploadMetadataNoSegmentCommitInfos() throws IOException {
SegmentInfos segInfos = indexShard.store().readLastCommittedSegmentsInfo();
int numSegCommitInfos = segInfos.size();
Expand Down

0 comments on commit df6d9a5

Please sign in to comment.