forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Unit Tests for RemoteSegmentMetadataHandler
Signed-off-by: Varun Bansal <[email protected]>
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
...st/java/org/opensearch/index/store/remote/metadata/RemoteSegmentMetadataHandlerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.index.store.remote.metadata; | ||
|
||
import org.apache.lucene.store.OutputStreamIndexOutput; | ||
import org.junit.Before; | ||
import org.opensearch.common.UUIDs; | ||
import org.opensearch.common.bytes.BytesReference; | ||
import org.opensearch.common.io.stream.BytesStreamOutput; | ||
import org.opensearch.common.lucene.store.ByteArrayIndexInput; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Unit Tests for {@link RemoteSegmentMetadataHandler} | ||
*/ | ||
public class RemoteSegmentMetadataHandlerTests extends OpenSearchTestCase { | ||
private RemoteSegmentMetadataHandler remoteSegmentMetadataHandler; | ||
|
||
@Before | ||
public void setup() throws IOException { | ||
remoteSegmentMetadataHandler = new RemoteSegmentMetadataHandler(); | ||
} | ||
|
||
public void testReadContent() throws IOException { | ||
BytesStreamOutput output = new BytesStreamOutput(); | ||
OutputStreamIndexOutput indexOutput = new OutputStreamIndexOutput("dummy bytes", "dummy stream", output, 4096); | ||
Map<String, String> expectedOutput = getDummyData(); | ||
indexOutput.writeMapOfStrings(expectedOutput); | ||
indexOutput.close(); | ||
RemoteSegmentMetadata metadata = remoteSegmentMetadataHandler.readContent( | ||
new ByteArrayIndexInput("dummy bytes", BytesReference.toBytes(output.bytes())) | ||
); | ||
assertEquals(expectedOutput, metadata.toMapOfStrings()); | ||
} | ||
|
||
public void testWriteContent() throws IOException { | ||
BytesStreamOutput output = new BytesStreamOutput(); | ||
OutputStreamIndexOutput indexOutput = new OutputStreamIndexOutput("dummy bytes", "dummy stream", output, 4096); | ||
Map<String, String> expectedOutput = getDummyData(); | ||
remoteSegmentMetadataHandler.writeContent(indexOutput, RemoteSegmentMetadata.fromMapOfStrings(expectedOutput)); | ||
indexOutput.close(); | ||
Map<String, String> actualOutput = new ByteArrayIndexInput("dummy bytes", BytesReference.toBytes(output.bytes())) | ||
.readMapOfStrings(); | ||
assertEquals(expectedOutput, actualOutput); | ||
} | ||
|
||
private Map<String, String> getDummyData() { | ||
Map<String, String> expectedOutput = new HashMap<>(); | ||
String prefix = "_0"; | ||
expectedOutput.put( | ||
prefix + ".cfe", | ||
prefix + ".cfe::" + prefix + ".cfe__" + UUIDs.base64UUID() + "::" + randomIntBetween(1000, 5000) | ||
); | ||
expectedOutput.put( | ||
prefix + ".cfs", | ||
prefix + ".cfs::" + prefix + ".cfs__" + UUIDs.base64UUID() + "::" + randomIntBetween(1000, 5000) | ||
); | ||
return expectedOutput; | ||
} | ||
} |