Search in sources :

Example 6 with NamedWriteableRegistry

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

the class ClusterSerializationTests method testClusterStateSerialization.

public void testClusterStateSerialization() throws Exception {
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(10).numberOfReplicas(1)).build();
    RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test")).build();
    DiscoveryNodes nodes = DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).localNodeId("node1").masterNodeId("node2").build();
    ClusterState clusterState = ClusterState.builder(new ClusterName("clusterName1")).nodes(nodes).metaData(metaData).routingTable(routingTable).build();
    AllocationService strategy = createAllocationService();
    clusterState = ClusterState.builder(clusterState).routingTable(strategy.reroute(clusterState, "reroute").routingTable()).build();
    ClusterState serializedClusterState = ClusterState.Builder.fromBytes(ClusterState.Builder.toBytes(clusterState), newNode("node1"), new NamedWriteableRegistry(ClusterModule.getNamedWriteables()));
    assertThat(serializedClusterState.getClusterName().value(), equalTo(clusterState.getClusterName().value()));
    assertThat(serializedClusterState.routingTable().toString(), equalTo(clusterState.routingTable().toString()));
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) ClusterState(org.elasticsearch.cluster.ClusterState) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService)

Example 7 with NamedWriteableRegistry

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

the class SuggestBuilderTests method init.

/**
     * Setup for the whole base test class.
     */
@BeforeClass
public static void init() {
    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 8 with NamedWriteableRegistry

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

the class SmoothingModelTestCase method init.

/**
     * setup for the whole base test class
     */
@BeforeClass
public static void init() {
    if (namedWriteableRegistry == null) {
        List<NamedWriteableRegistry.Entry> namedWriteables = new ArrayList<>();
        SearchModule.registerSmoothingModels(namedWriteables);
        namedWriteableRegistry = new NamedWriteableRegistry(namedWriteables);
    }
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) ArrayList(java.util.ArrayList) BeforeClass(org.junit.BeforeClass)

Example 9 with NamedWriteableRegistry

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

the class TaskResultTests method testBinaryRoundTrip.

public void testBinaryRoundTrip() throws IOException {
    NamedWriteableRegistry registry = new NamedWriteableRegistry(Collections.singletonList(new NamedWriteableRegistry.Entry(Task.Status.class, RawTaskStatus.NAME, RawTaskStatus::new)));
    TaskResult result = randomTaskResult();
    TaskResult read;
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        result.writeTo(out);
        try (StreamInput in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry)) {
            read = new TaskResult(in);
        }
    } catch (IOException e) {
        throw new IOException("Error processing [" + result + "]", e);
    }
    assertEquals(result, read);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) IOException(java.io.IOException) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 10 with NamedWriteableRegistry

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

the class SimpleNetty4TransportTests method nettyFromThreadPool.

public static MockTransportService nettyFromThreadPool(Settings settings, ThreadPool threadPool, final Version version, ClusterSettings clusterSettings, boolean doHandshake) {
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    Transport transport = new Netty4Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()), BigArrays.NON_RECYCLING_INSTANCE, namedWriteableRegistry, new NoneCircuitBreakerService()) {

        @Override
        protected Version executeHandshake(DiscoveryNode node, Channel channel, TimeValue timeout) throws IOException, InterruptedException {
            if (doHandshake) {
                return super.executeHandshake(node, channel, timeout);
            } else {
                return version.minimumCompatibilityVersion();
            }
        }

        @Override
        protected Version getCurrentVersion() {
            return version;
        }
    };
    MockTransportService mockTransportService = MockTransportService.createNewService(Settings.EMPTY, transport, version, threadPool, clusterSettings);
    mockTransportService.start();
    return mockTransportService;
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportService(org.elasticsearch.test.transport.MockTransportService) Channel(io.netty.channel.Channel) NetworkService(org.elasticsearch.common.network.NetworkService) Transport(org.elasticsearch.transport.Transport) TimeValue(org.elasticsearch.common.unit.TimeValue) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Aggregations

NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)71 NetworkService (org.elasticsearch.common.network.NetworkService)27 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)25 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)23 Settings (org.elasticsearch.common.settings.Settings)21 ThreadPool (org.elasticsearch.threadpool.ThreadPool)19 ArrayList (java.util.ArrayList)18 MockTransportService (org.elasticsearch.test.transport.MockTransportService)18 Transport (org.elasticsearch.transport.Transport)18 IOException (java.io.IOException)15 Collections (java.util.Collections)15 TransportAddress (org.elasticsearch.common.transport.TransportAddress)15 BigArrays (org.elasticsearch.common.util.BigArrays)15 SearchModule (org.elasticsearch.search.SearchModule)15 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)15 MockTcpTransport (org.elasticsearch.transport.MockTcpTransport)15 NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)14 TransportService (org.elasticsearch.transport.TransportService)14 List (java.util.List)13 ESTestCase (org.elasticsearch.test.ESTestCase)13