Skip to content

Commit

Permalink
Add test for serde of Feature.CONTEXT in GetIndexRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Mohit Godwani <[email protected]>
  • Loading branch information
mgodwan committed Sep 1, 2024
1 parent 54f6e32 commit ec7e527
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,51 @@

package org.opensearch.action.admin.indices.get;

import org.opensearch.Version;
import org.opensearch.action.support.master.info.ClusterInfoRequest;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.util.set.Sets;
import org.opensearch.core.common.io.stream.BytesStreamInput;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.test.OpenSearchTestCase;

import java.io.IOException;
import java.util.Arrays;

import static org.hamcrest.Matchers.is;

public class GetIndexRequestTests extends OpenSearchTestCase {
public void testGetIndexRequestExtendsClusterInfoRequestOfDeprecatedClassPath() {
GetIndexRequest getIndexRequest = new GetIndexRequest().indices("test");
assertThat(getIndexRequest instanceof ClusterInfoRequest, is(true));
}

public void testGetIndexRequestWriteableWithLatestNode() throws IOException {
// Write to 2.17 stream
try (BytesStreamOutput output = new BytesStreamOutput()) {
GetIndexRequest getIndexRequest = new GetIndexRequest().indices("test")
.addFeatures(GetIndexRequest.Feature.values());
output.setVersion(Version.V_2_17_0);
getIndexRequest.writeTo(output);
try (StreamInput in = output.bytes().streamInput()) {
GetIndexRequest getIndexRequestRead = new GetIndexRequest(in);
assertArrayEquals(getIndexRequestRead.features(), getIndexRequest.features());
}
}
}

public void testGetIndexRequestWriteableWithOldNode() throws IOException {
// Write to 2.1 stream
try (BytesStreamOutput output = new BytesStreamOutput()) {
GetIndexRequest getIndexRequest = new GetIndexRequest().indices("test")
.addFeatures(GetIndexRequest.Feature.values());
output.setVersion(Version.V_2_16_0);
getIndexRequest.writeTo(output);
try (StreamInput in = output.bytes().streamInput()) {
GetIndexRequest getIndexRequestRead = new GetIndexRequest(in);
assertTrue(Arrays.stream(getIndexRequestRead.features()).noneMatch(f -> f == GetIndexRequest.Feature.CONTEXT));
assertEquals(3, getIndexRequestRead.features().length);
}
}
}
}

0 comments on commit ec7e527

Please sign in to comment.