-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gaurav Chandani <[email protected]>
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
server/src/test/java/org/opensearch/indices/store/ShardAttributesTests.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,49 @@ | ||
/* | ||
* 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.indices.store; | ||
|
||
import org.opensearch.core.common.io.stream.DataOutputStreamOutput; | ||
import org.opensearch.core.common.io.stream.InputStreamStreamInput; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.index.Index; | ||
import org.opensearch.core.index.shard.ShardId; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
|
||
public class ShardAttributesTests extends OpenSearchTestCase { | ||
|
||
Index index = new Index("index", "test-uid"); | ||
ShardId shardId = new ShardId(index, 0); | ||
String customDataPath = "/path/to/data"; | ||
|
||
public void testShardAttributesConstructor() { | ||
ShardAttributes attributes = new ShardAttributes(shardId, customDataPath); | ||
assertEquals(attributes.getShardId(), shardId); | ||
assertEquals(attributes.getCustomDataPath(), customDataPath); | ||
} | ||
|
||
public void testSerialization() throws IOException { | ||
ShardAttributes attributes1 = new ShardAttributes(shardId, customDataPath); | ||
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); | ||
StreamOutput output = new DataOutputStreamOutput(new DataOutputStream(bytes)); | ||
attributes1.writeTo(output); | ||
output.close(); | ||
StreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(bytes.toByteArray())); | ||
ShardAttributes attributes2 = new ShardAttributes(input); | ||
input.close(); | ||
assertEquals(attributes1.getShardId(), attributes2.getShardId()); | ||
assertEquals(attributes1.getCustomDataPath(), attributes2.getCustomDataPath()); | ||
} | ||
|
||
} |