Search in sources :

Example 56 with NamedWriteableRegistry

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

the class BasePipelineAggregationTestCase method setUp.

/**
     * Setup for the whole base test class.
     */
@Override
public void setUp() throws Exception {
    super.setUp();
    Settings settings = Settings.builder().put("node.name", AbstractQueryTestCase.class.toString()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
    IndicesModule indicesModule = new IndicesModule(Collections.emptyList());
    SearchModule searchModule = new SearchModule(settings, false, emptyList());
    List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
    entries.addAll(indicesModule.getNamedWriteables());
    entries.addAll(searchModule.getNamedWriteables());
    namedWriteableRegistry = new NamedWriteableRegistry(entries);
    xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
    //create some random type with some default field, those types will stick around for all of the subclasses
    currentTypes = new String[randomIntBetween(0, 5)];
    for (int i = 0; i < currentTypes.length; i++) {
        String type = randomAsciiOfLengthBetween(1, 10);
        currentTypes[i] = type;
    }
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) IndicesModule(org.elasticsearch.indices.IndicesModule) ArrayList(java.util.ArrayList) SearchModule(org.elasticsearch.search.SearchModule) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Settings(org.elasticsearch.common.settings.Settings) AbstractQueryTestCase(org.elasticsearch.test.AbstractQueryTestCase)

Example 57 with NamedWriteableRegistry

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

the class DocValueFormatTests method testSerialization.

public void testSerialization() throws Exception {
    List<Entry> entries = new ArrayList<>();
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.BOOLEAN.getWriteableName(), in -> DocValueFormat.BOOLEAN));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.DateTime.NAME, DocValueFormat.DateTime::new));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.Decimal.NAME, DocValueFormat.Decimal::new));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.GEOHASH.getWriteableName(), in -> DocValueFormat.GEOHASH));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.IP.getWriteableName(), in -> DocValueFormat.IP));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.RAW.getWriteableName(), in -> DocValueFormat.RAW));
    NamedWriteableRegistry registry = new NamedWriteableRegistry(entries);
    BytesStreamOutput out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.BOOLEAN);
    StreamInput in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.BOOLEAN, in.readNamedWriteable(DocValueFormat.class));
    DocValueFormat.Decimal decimalFormat = new DocValueFormat.Decimal("###.##");
    out = new BytesStreamOutput();
    out.writeNamedWriteable(decimalFormat);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    DocValueFormat vf = in.readNamedWriteable(DocValueFormat.class);
    assertEquals(DocValueFormat.Decimal.class, vf.getClass());
    assertEquals("###.##", ((DocValueFormat.Decimal) vf).pattern);
    DocValueFormat.DateTime dateFormat = new DocValueFormat.DateTime(Joda.forPattern("epoch_second"), DateTimeZone.forOffsetHours(1));
    out = new BytesStreamOutput();
    out.writeNamedWriteable(dateFormat);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    vf = in.readNamedWriteable(DocValueFormat.class);
    assertEquals(DocValueFormat.DateTime.class, vf.getClass());
    assertEquals("epoch_second", ((DocValueFormat.DateTime) vf).formatter.format());
    assertEquals(DateTimeZone.forOffsetHours(1), ((DocValueFormat.DateTime) vf).timeZone);
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.GEOHASH);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.GEOHASH, in.readNamedWriteable(DocValueFormat.class));
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.IP);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.IP, in.readNamedWriteable(DocValueFormat.class));
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.RAW);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.RAW, in.readNamedWriteable(DocValueFormat.class));
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) Joda(org.elasticsearch.common.joda.Joda) InetAddressPoint(org.apache.lucene.document.InetAddressPoint) BytesRef(org.apache.lucene.util.BytesRef) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) ArrayList(java.util.ArrayList) InetAddresses(org.elasticsearch.common.network.InetAddresses) List(java.util.List) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ESTestCase(org.elasticsearch.test.ESTestCase) Entry(org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) ArrayList(java.util.ArrayList) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Entry(org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput)

Example 58 with NamedWriteableRegistry

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

the class TransportServiceHandshakeTests method startServices.

private NetworkHandle startServices(String nodeNameAndId, Settings settings, Version version) {
    MockTcpTransport transport = new MockTcpTransport(settings, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), new NamedWriteableRegistry(Collections.emptyList()), new NetworkService(settings, Collections.emptyList()));
    TransportService transportService = new MockTransportService(settings, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, (boundAddress) -> new DiscoveryNode(nodeNameAndId, nodeNameAndId, boundAddress.publishAddress(), emptyMap(), emptySet(), version), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    transportServices.add(transportService);
    return new NetworkHandle(transportService, transportService.getLocalNode());
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportService(org.elasticsearch.test.transport.MockTransportService) MockTransportService(org.elasticsearch.test.transport.MockTransportService) NetworkService(org.elasticsearch.common.network.NetworkService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 59 with NamedWriteableRegistry

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

the class MockTransportService method createNewService.

public static MockTransportService createNewService(Settings settings, Version version, ThreadPool threadPool, @Nullable ClusterSettings clusterSettings) {
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(ClusterModule.getNamedWriteables());
    final Transport transport = new MockTcpTransport(settings, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(settings, Collections.emptyList()), version);
    return createNewService(settings, transport, version, threadPool, clusterSettings);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) NetworkService(org.elasticsearch.common.network.NetworkService) Transport(org.elasticsearch.transport.Transport) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 60 with NamedWriteableRegistry

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

the class AbstractSimpleTransportTestCase method testTcpHandshake.

public void testTcpHandshake() throws IOException, InterruptedException {
    assumeTrue("only tcp transport has a handshake method", serviceA.getOriginalTransport() instanceof TcpTransport);
    TcpTransport originalTransport = (TcpTransport) serviceA.getOriginalTransport();
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    try (MockTcpTransport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(Settings.EMPTY, Collections.emptyList())) {

        @Override
        protected String handleRequest(MockChannel mockChannel, String profileName, StreamInput stream, long requestId, int messageLengthBytes, Version version, InetSocketAddress remoteAddress, byte status) throws IOException {
            return super.handleRequest(mockChannel, profileName, stream, requestId, messageLengthBytes, version, remoteAddress, // we flip the isHandshake bit back and act like the handler is not found
            (byte) (status & ~(1 << 3)));
        }
    }) {
        transport.transportServiceAdapter(serviceA.new Adapter());
        transport.start();
        // this acts like a node that doesn't have support for handshakes
        DiscoveryNode node = new DiscoveryNode("TS_TPC", "TS_TPC", transport.boundAddress().publishAddress(), emptyMap(), emptySet(), version0);
        ConnectTransportException exception = expectThrows(ConnectTransportException.class, () -> serviceA.connectToNode(node));
        assertTrue(exception.getCause() instanceof IllegalStateException);
        assertEquals("handshake failed", exception.getCause().getMessage());
    }
    try (TransportService service = buildService("TS_TPC", Version.CURRENT, null);
        TcpTransport.NodeChannels connection = originalTransport.openConnection(new DiscoveryNode("TS_TPC", "TS_TPC", service.boundAddress().publishAddress(), emptyMap(), emptySet(), version0), null)) {
        Version version = originalTransport.executeHandshake(connection.getNode(), connection.channel(TransportRequestOptions.Type.PING), TimeValue.timeValueSeconds(10));
        assertEquals(version, Version.CURRENT);
    }
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) InetSocketAddress(java.net.InetSocketAddress) Version(org.elasticsearch.Version) MockTransportService(org.elasticsearch.test.transport.MockTransportService) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NetworkService(org.elasticsearch.common.network.NetworkService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

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