Search in sources :

Example 16 with SearchModule

use of org.opensearch.search.SearchModule in project OpenSearch by opensearch-project.

the class SignificanceHeuristicTests method testStreamResponse.

// test that stream output can actually be read - does not replace bwc test
public void testStreamResponse() throws Exception {
    Version version = randomVersion(random());
    InternalMappedSignificantTerms<?, ?> sigTerms = getRandomSignificantTerms(getRandomSignificanceheuristic());
    // write
    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer);
    out.setVersion(version);
    if (version.before(LegacyESVersion.V_7_8_0)) {
        sigTerms.mergePipelineTreeForBWCSerialization(PipelineAggregator.PipelineTree.EMPTY);
    }
    out.writeNamedWriteable(sigTerms);
    // read
    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    StreamInput in = new InputStreamStreamInput(inBuffer);
    // populates the registry through side effects
    SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
    NamedWriteableRegistry registry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    in = new NamedWriteableAwareStreamInput(in, registry);
    in.setVersion(version);
    InternalMappedSignificantTerms<?, ?> read = (InternalMappedSignificantTerms<?, ?>) in.readNamedWriteable(InternalAggregation.class);
    assertEquals(sigTerms.significanceHeuristic, read.significanceHeuristic);
    SignificantTerms.Bucket originalBucket = sigTerms.getBuckets().get(0);
    SignificantTerms.Bucket streamedBucket = read.getBuckets().get(0);
    assertThat(originalBucket.getKeyAsString(), equalTo(streamedBucket.getKeyAsString()));
    assertThat(originalBucket.getSupersetDf(), equalTo(streamedBucket.getSupersetDf()));
    assertThat(originalBucket.getSubsetDf(), equalTo(streamedBucket.getSubsetDf()));
    assertThat(streamedBucket.getSubsetSize(), equalTo(10L));
    assertThat(streamedBucket.getSupersetSize(), equalTo(20L));
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) OutputStreamStreamOutput(org.opensearch.common.io.stream.OutputStreamStreamOutput) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) VersionUtils.randomVersion(org.opensearch.test.VersionUtils.randomVersion) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStreamStreamInput(org.opensearch.common.io.stream.InputStreamStreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.opensearch.common.io.stream.StreamInput) SearchModule(org.opensearch.search.SearchModule) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) InputStreamStreamInput(org.opensearch.common.io.stream.InputStreamStreamInput)

Example 17 with SearchModule

use of org.opensearch.search.SearchModule in project OpenSearch by opensearch-project.

the class QueryRescorerBuilderTests method init.

/**
 * setup for the whole base test class
 */
@BeforeClass
public static void init() {
    SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) BeforeClass(org.junit.BeforeClass)

Example 18 with SearchModule

use of org.opensearch.search.SearchModule in project OpenSearch by opensearch-project.

the class AbstractSuggestionBuilderTestCase method init.

/**
 * setup for the whole base test class
 */
@BeforeClass
public static void init() {
    SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) BeforeClass(org.junit.BeforeClass)

Example 19 with SearchModule

use of org.opensearch.search.SearchModule in project OpenSearch by opensearch-project.

the class SuggestBuilderTests method init.

/**
 * Setup for the whole base test class.
 */
@BeforeClass
public static void init() {
    SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) BeforeClass(org.junit.BeforeClass)

Example 20 with SearchModule

use of org.opensearch.search.SearchModule in project OpenSearch by opensearch-project.

the class SuggestTests method testSerialization.

public void testSerialization() throws IOException {
    final Version bwcVersion = VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT);
    final Suggest suggest = createTestItem();
    final Suggest bwcSuggest;
    NamedWriteableRegistry registry = new NamedWriteableRegistry(new SearchModule(Settings.EMPTY, emptyList()).getNamedWriteables());
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        out.setVersion(bwcVersion);
        suggest.writeTo(out);
        try (NamedWriteableAwareStreamInput in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry)) {
            in.setVersion(bwcVersion);
            bwcSuggest = new Suggest(in);
        }
    }
    assertEquals(suggest, bwcSuggest);
    final Suggest backAgain;
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        out.setVersion(Version.CURRENT);
        bwcSuggest.writeTo(out);
        try (NamedWriteableAwareStreamInput in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry)) {
            in.setVersion(Version.CURRENT);
            backAgain = new Suggest(in);
        }
    }
    assertEquals(suggest, backAgain);
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) Version(org.opensearch.Version) SearchModule(org.opensearch.search.SearchModule) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Aggregations

SearchModule (org.opensearch.search.SearchModule)31 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)20 NamedXContentRegistry (org.opensearch.common.xcontent.NamedXContentRegistry)19 BeforeClass (org.junit.BeforeClass)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)6 NamedWriteableAwareStreamInput (org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)6 StreamInput (org.opensearch.common.io.stream.StreamInput)5 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)5 XContentParser (org.opensearch.common.xcontent.XContentParser)5 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)4 Version (org.opensearch.Version)3 Settings (org.opensearch.common.settings.Settings)3 IndicesModule (org.opensearch.indices.IndicesModule)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Before (org.junit.Before)2 InputStreamStreamInput (org.opensearch.common.io.stream.InputStreamStreamInput)2 User (org.opensearch.commons.authuser.User)2 SearchPlugin (org.opensearch.plugins.SearchPlugin)2 AsynchronousSearchContextId (org.opensearch.search.asynchronous.context.AsynchronousSearchContextId)2