Skip to content

Commit df6d9a5

Browse files
dreamer-89brusic
authored andcommitted
[Remote Store] Add missing unit test in main (opensearch-project#9101)
Signed-off-by: Suraj Singh <surajrider@gmail.com> Signed-off-by: Ivan Brusic <ivan.brusic@flocksafety.com>
1 parent 4fd6c27 commit df6d9a5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

server/src/test/java/org/opensearch/index/store/RemoteSegmentStoreDirectoryTests.java

+29
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,35 @@ public void testUploadMetadataNonEmpty() throws IOException {
758758
}
759759
}
760760

761+
public void testUploadMetadataMissingSegment() throws IOException {
762+
populateMetadata();
763+
remoteSegmentStoreDirectory.init();
764+
765+
Directory storeDirectory = mock(Directory.class);
766+
IndexOutput indexOutput = mock(IndexOutput.class);
767+
768+
String generation = RemoteStoreUtils.invertLong(segmentInfos.getGeneration());
769+
long primaryTermLong = indexShard.getLatestReplicationCheckpoint().getPrimaryTerm();
770+
String primaryTerm = RemoteStoreUtils.invertLong(primaryTermLong);
771+
when(storeDirectory.createOutput(startsWith("metadata__" + primaryTerm + "__" + generation), eq(IOContext.DEFAULT))).thenReturn(
772+
indexOutput
773+
);
774+
775+
Collection<String> segmentFiles = List.of("_123.si");
776+
assertThrows(
777+
NoSuchFileException.class,
778+
() -> remoteSegmentStoreDirectory.uploadMetadata(
779+
segmentFiles,
780+
segmentInfos,
781+
storeDirectory,
782+
12L,
783+
indexShard.getLatestReplicationCheckpoint()
784+
)
785+
);
786+
verify(indexOutput).close();
787+
verify(storeDirectory).deleteFile(startsWith("metadata__" + primaryTerm + "__" + generation));
788+
}
789+
761790
public void testUploadMetadataNoSegmentCommitInfos() throws IOException {
762791
SegmentInfos segInfos = indexShard.store().readLastCommittedSegmentsInfo();
763792
int numSegCommitInfos = segInfos.size();

0 commit comments

Comments
 (0)