use of org.opensearch.common.io.stream.StreamInput in project OpenSearch by opensearch-project.
the class TermsLookupTests method testSerialization.
public void testSerialization() throws IOException {
TermsLookup termsLookup = randomTermsLookup();
try (BytesStreamOutput output = new BytesStreamOutput()) {
termsLookup.writeTo(output);
try (StreamInput in = output.bytes().streamInput()) {
TermsLookup deserializedLookup = new TermsLookup(in);
assertEquals(deserializedLookup, termsLookup);
assertEquals(deserializedLookup.hashCode(), termsLookup.hashCode());
assertNotSame(deserializedLookup, termsLookup);
}
}
}
use of org.opensearch.common.io.stream.StreamInput in project OpenSearch by opensearch-project.
the class AnalyzeRequestTests method testSerialization.
public void testSerialization() throws IOException {
AnalyzeAction.Request request = new AnalyzeAction.Request("foo");
request.text("a", "b");
request.tokenizer("tokenizer");
request.addTokenFilter("tokenfilter");
request.addCharFilter("charfilter");
request.normalizer("normalizer");
try (BytesStreamOutput output = new BytesStreamOutput()) {
request.writeTo(output);
try (StreamInput in = output.bytes().streamInput()) {
AnalyzeAction.Request serialized = new AnalyzeAction.Request(in);
assertArrayEquals(request.text(), serialized.text());
assertEquals(request.tokenizer().name, serialized.tokenizer().name);
assertEquals(request.tokenFilters().get(0).name, serialized.tokenFilters().get(0).name);
assertEquals(request.charFilters().get(0).name, serialized.charFilters().get(0).name);
assertEquals(request.normalizer(), serialized.normalizer());
}
}
}
use of org.opensearch.common.io.stream.StreamInput in project OpenSearch by opensearch-project.
the class AliasActionsTests method testRoundTrip.
public void testRoundTrip() throws IOException {
AliasActions action = new AliasActions(randomFrom(AliasActions.Type.values()));
if (randomBoolean()) {
action.index(randomAlphaOfLength(5));
} else {
action.indices(generateRandomStringArray(5, 5, false, false));
}
if (action.actionType() != AliasActions.Type.REMOVE_INDEX) {
if (randomBoolean()) {
action.alias(randomAlphaOfLength(5));
} else {
action.aliases(generateRandomStringArray(5, 5, false, false));
}
}
if (action.actionType() == AliasActions.Type.ADD) {
if (randomBoolean()) {
action.filter(randomAlphaOfLength(10));
}
if (randomBoolean()) {
if (randomBoolean()) {
action.routing(randomAlphaOfLength(5));
} else {
action.searchRouting(randomAlphaOfLength(5));
action.indexRouting(randomAlphaOfLength(5));
}
}
}
try (BytesStreamOutput out = new BytesStreamOutput()) {
action.writeTo(out);
try (StreamInput in = out.bytes().streamInput()) {
AliasActions read = new AliasActions(in);
assertEquals(action, read);
}
}
}
use of org.opensearch.common.io.stream.StreamInput in project OpenSearch by opensearch-project.
the class DefaultShardOperationFailedExceptionTests method testSerialization.
public void testSerialization() throws Exception {
final DefaultShardOperationFailedException exception = randomInstance();
try (BytesStreamOutput out = new BytesStreamOutput()) {
exception.writeTo(out);
try (StreamInput in = out.bytes().streamInput()) {
final DefaultShardOperationFailedException deserializedException = new DefaultShardOperationFailedException(in);
assertNotSame(exception, deserializedException);
assertThat(deserializedException.index(), equalTo(exception.index()));
assertThat(deserializedException.shardId(), equalTo(exception.shardId()));
assertThat(deserializedException.reason(), equalTo(exception.reason()));
assertThat(deserializedException.getCause().getMessage(), equalTo(exception.getCause().getMessage()));
assertThat(deserializedException.getCause().getClass(), equalTo(exception.getCause().getClass()));
assertArrayEquals(deserializedException.getCause().getStackTrace(), exception.getCause().getStackTrace());
}
}
}
use of org.opensearch.common.io.stream.StreamInput in project OpenSearch by opensearch-project.
the class SearchScrollRequestTests method testSerialization.
public void testSerialization() throws Exception {
SearchScrollRequest searchScrollRequest = createSearchScrollRequest();
try (BytesStreamOutput output = new BytesStreamOutput()) {
searchScrollRequest.writeTo(output);
try (StreamInput in = output.bytes().streamInput()) {
SearchScrollRequest deserializedRequest = new SearchScrollRequest(in);
assertEquals(deserializedRequest, searchScrollRequest);
assertEquals(deserializedRequest.hashCode(), searchScrollRequest.hashCode());
assertNotSame(deserializedRequest, searchScrollRequest);
}
}
}
Aggregations