Search in sources :

Example 21 with StreamInput

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);
        }
    }
}
Also used : StreamInput(org.opensearch.common.io.stream.StreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 22 with StreamInput

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());
        }
    }
}
Also used : StreamInput(org.opensearch.common.io.stream.StreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 23 with StreamInput

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);
        }
    }
}
Also used : StreamInput(org.opensearch.common.io.stream.StreamInput) AliasActions(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 24 with StreamInput

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());
        }
    }
}
Also used : StreamInput(org.opensearch.common.io.stream.StreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 25 with StreamInput

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);
        }
    }
}
Also used : StreamInput(org.opensearch.common.io.stream.StreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Aggregations

StreamInput (org.opensearch.common.io.stream.StreamInput)206 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)139 IOException (java.io.IOException)42 NamedWriteableAwareStreamInput (org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)40 Version (org.opensearch.Version)27 OpenSearchException (org.opensearch.OpenSearchException)21 InputStreamStreamInput (org.opensearch.common.io.stream.InputStreamStreamInput)19 BytesReference (org.opensearch.common.bytes.BytesReference)18 Matchers.containsString (org.hamcrest.Matchers.containsString)17 Matchers.hasToString (org.hamcrest.Matchers.hasToString)17 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)17 UncheckedIOException (java.io.UncheckedIOException)15 CountDownLatch (java.util.concurrent.CountDownLatch)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)13 ArrayList (java.util.ArrayList)12 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 UnknownHostException (java.net.UnknownHostException)11 ExecutionException (java.util.concurrent.ExecutionException)11