Search in sources :

Example 46 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project elasticsearch by elastic.

the class PublishClusterStateActionTests method buildPublishClusterStateAction.

private static MockPublishAction buildPublishClusterStateAction(Settings settings, MockTransportService transportService, Supplier<ClusterState> clusterStateSupplier, PublishClusterStateAction.NewPendingClusterStateListener listener) {
    DiscoverySettings discoverySettings = new DiscoverySettings(settings, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(ClusterModule.getNamedWriteables());
    return new MockPublishAction(settings, transportService, namedWriteableRegistry, clusterStateSupplier, listener, discoverySettings, CLUSTER_NAME);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) DiscoverySettings(org.elasticsearch.discovery.DiscoverySettings)

Example 47 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project elasticsearch by elastic.

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);
    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, false, 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.elasticsearch.common.io.stream.NamedWriteableRegistry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) Version(org.elasticsearch.Version) VersionUtils.randomVersion(org.elasticsearch.test.VersionUtils.randomVersion) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) SearchModule(org.elasticsearch.search.SearchModule) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput)

Example 48 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project elasticsearch by elastic.

the class AbstractSuggestionBuilderTestCase method init.

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

Example 49 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project elasticsearch by elastic.

the class FuzzyOptionsTests method testSerialization.

/**
     * Test serialization and deserialization
     */
public void testSerialization() throws IOException {
    for (int i = 0; i < NUMBER_OF_RUNS; i++) {
        FuzzyOptions testModel = randomFuzzyOptions();
        FuzzyOptions deserializedModel = copyWriteable(testModel, new NamedWriteableRegistry(Collections.emptyList()), FuzzyOptions::new);
        assertEquals(testModel, deserializedModel);
        assertEquals(testModel.hashCode(), deserializedModel.hashCode());
        assertNotSame(testModel, deserializedModel);
    }
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry)

Example 50 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project elasticsearch by elastic.

the class RegexOptionsTests method testSerialization.

/**
     * Test serialization and deserialization
     */
public void testSerialization() throws IOException {
    for (int i = 0; i < NUMBER_OF_RUNS; i++) {
        RegexOptions testOptions = randomRegexOptions();
        RegexOptions deserializedModel = copyWriteable(testOptions, new NamedWriteableRegistry(Collections.emptyList()), RegexOptions::new);
        assertEquals(testOptions, deserializedModel);
        assertEquals(testOptions.hashCode(), deserializedModel.hashCode());
        assertNotSame(testOptions, deserializedModel);
    }
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry)

Aggregations

NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)62 NetworkService (org.elasticsearch.common.network.NetworkService)25 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)23 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)20 Settings (org.elasticsearch.common.settings.Settings)18 MockTransportService (org.elasticsearch.test.transport.MockTransportService)17 Transport (org.elasticsearch.transport.Transport)17 ArrayList (java.util.ArrayList)16 ThreadPool (org.elasticsearch.threadpool.ThreadPool)16 BigArrays (org.elasticsearch.common.util.BigArrays)15 SearchModule (org.elasticsearch.search.SearchModule)15 MockTcpTransport (org.elasticsearch.transport.MockTcpTransport)15 TransportAddress (org.elasticsearch.common.transport.TransportAddress)14 NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)14 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)14 TransportService (org.elasticsearch.transport.TransportService)12 BeforeClass (org.junit.BeforeClass)11 Collections (java.util.Collections)10 HashMap (java.util.HashMap)10 List (java.util.List)10