Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Himshikha Gupta <[email protected]>
  • Loading branch information
Himshikha Gupta committed Jun 3, 2024
1 parent 4167eeb commit b3c18d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
public class IndexRoutingTableHeaderTests extends OpenSearchTestCase {

public void testIndexRoutingTableHeader() throws IOException {
IndexRoutingTableHeader header = new IndexRoutingTableHeader("dummyIndex");
String indexName = randomAlphaOfLength(randomIntBetween(1, 50));
IndexRoutingTableHeader header = new IndexRoutingTableHeader(indexName);
try (BytesStreamOutput out = new BytesStreamOutput()) {
header.writeTo(out);

BytesStreamInput in = new BytesStreamInput(out.bytes().toBytesRef().bytes);
IndexRoutingTableHeader headerRead = new IndexRoutingTableHeader(in);
assertEquals("dummyIndex", headerRead.getIndexName());
assertEquals(indexName, headerRead.getIndexName());

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,37 @@
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

public class RemoteIndexRoutingTableObjectTests extends OpenSearchTestCase {
public class RemoteIndexRoutingTableTests extends OpenSearchTestCase {

public void testRoutingTableInput() {
String indexName = randomAlphaOfLength(randomIntBetween(1, 50));
int numberOfShards = randomIntBetween(1, 10);
int numberOfReplicas = randomIntBetween(1, 10);
Metadata metadata = Metadata.builder()
.put(
IndexMetadata.builder("test")
IndexMetadata.builder(indexName)
.settings(settings(Version.CURRENT))
.numberOfShards(numberOfShards)
.numberOfReplicas(numberOfReplicas)
)
.build();

RoutingTable initialRoutingTable = RoutingTable.builder().addAsNew(metadata.index("test")).build();
RoutingTable initialRoutingTable = RoutingTable.builder().addAsNew(metadata.index(indexName)).build();

initialRoutingTable.getIndicesRouting().values().forEach(indexShardRoutingTables -> {
RemoteIndexRoutingTable indexRouting = new RemoteIndexRoutingTable(indexShardRoutingTables);
try (BytesStreamOutput streamOutput = new BytesStreamOutput();) {
indexRouting.writeTo(streamOutput);
RemoteIndexRoutingTable remoteIndexRoutingTable = new RemoteIndexRoutingTable(
streamOutput.bytes().streamInput(),
metadata.index("test").getIndex()
metadata.index(indexName).getIndex()
);
IndexRoutingTable indexRoutingTable = remoteIndexRoutingTable.getIndexRoutingTable();
assertEquals(numberOfShards, indexRoutingTable.getShards().size());
assertEquals(indexRoutingTable.getIndex(), metadata.index("test").getIndex());
assertEquals(metadata.index(indexName).getIndex(), indexRoutingTable.getIndex());
assertEquals(
indexRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED).size(),
numberOfShards * (1 + numberOfReplicas)
numberOfShards * (1 + numberOfReplicas),
indexRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED).size()
);
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit b3c18d8

Please sign in to comment.