Search in sources :

Example 1 with HttpServerTransport

use of org.elasticsearch.http.HttpServerTransport in project elasticsearch by elastic.

the class RestControllerTests method setup.

@Before
public void setup() {
    Settings settings = Settings.EMPTY;
    circuitBreakerService = new HierarchyCircuitBreakerService(Settings.builder().put(HierarchyCircuitBreakerService.IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), BREAKER_LIMIT).build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
    // we can do this here only because we know that we don't adjust breaker settings dynamically in the test
    inFlightRequestsBreaker = circuitBreakerService.getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
    HttpServerTransport httpServerTransport = new TestHttpServerTransport();
    restController = new RestController(settings, Collections.emptySet(), null, null, circuitBreakerService);
    restController.registerHandler(RestRequest.Method.GET, "/", (request, channel, client) -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)));
    restController.registerHandler(RestRequest.Method.GET, "/error", (request, channel, client) -> {
        throw new IllegalArgumentException("test error");
    });
    httpServerTransport.start();
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) Settings(org.elasticsearch.common.settings.Settings) HttpTransportSettings(org.elasticsearch.http.HttpTransportSettings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Before(org.junit.Before)

Example 2 with HttpServerTransport

use of org.elasticsearch.http.HttpServerTransport in project elasticsearch by elastic.

the class Netty4PipeliningDisabledIT method testThatNettyHttpServerDoesNotSupportPipelining.

public void testThatNettyHttpServerDoesNotSupportPipelining() throws Exception {
    ensureGreen();
    String[] requests = new String[] { "/", "/_nodes/stats", "/", "/_cluster/state", "/", "/_nodes", "/" };
    HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
    TransportAddress[] boundAddresses = httpServerTransport.boundAddress().boundAddresses();
    TransportAddress transportAddress = (TransportAddress) randomFrom(boundAddresses);
    try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
        Collection<FullHttpResponse> responses = nettyHttpClient.get(transportAddress.address(), requests);
        assertThat(responses, hasSize(requests.length));
        List<String> opaqueIds = new ArrayList<>(Netty4HttpClient.returnOpaqueIds(responses));
        assertResponsesOutOfOrder(opaqueIds);
    }
}
Also used : TransportAddress(org.elasticsearch.common.transport.TransportAddress) ArrayList(java.util.ArrayList) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) HttpServerTransport(org.elasticsearch.http.HttpServerTransport)

Example 3 with HttpServerTransport

use of org.elasticsearch.http.HttpServerTransport in project elasticsearch by elastic.

the class Netty4PipeliningEnabledIT method testThatNettyHttpServerSupportsPipelining.

public void testThatNettyHttpServerSupportsPipelining() throws Exception {
    String[] requests = new String[] { "/", "/_nodes/stats", "/", "/_cluster/state", "/" };
    HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
    TransportAddress[] boundAddresses = httpServerTransport.boundAddress().boundAddresses();
    TransportAddress transportAddress = (TransportAddress) randomFrom(boundAddresses);
    try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
        Collection<FullHttpResponse> responses = nettyHttpClient.get(transportAddress.address(), requests);
        assertThat(responses, hasSize(5));
        Collection<String> opaqueIds = Netty4HttpClient.returnOpaqueIds(responses);
        assertOpaqueIdsInOrder(opaqueIds);
    }
}
Also used : TransportAddress(org.elasticsearch.common.transport.TransportAddress) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) HttpServerTransport(org.elasticsearch.http.HttpServerTransport)

Example 4 with HttpServerTransport

use of org.elasticsearch.http.HttpServerTransport in project elasticsearch by elastic.

the class Netty4HttpRequestSizeLimitIT method testLimitsInFlightRequests.

public void testLimitsInFlightRequests() throws Exception {
    ensureGreen();
    // we use the limit size as a (very) rough indication on how many requests we should sent to hit the limit
    int numRequests = LIMIT.bytesAsInt() / 100;
    StringBuilder bulkRequest = new StringBuilder();
    for (int i = 0; i < numRequests; i++) {
        bulkRequest.append("{\"index\": {}}");
        bulkRequest.append(System.lineSeparator());
        bulkRequest.append("{ \"field\" : \"value\" }");
        bulkRequest.append(System.lineSeparator());
    }
    @SuppressWarnings("unchecked") Tuple<String, CharSequence>[] requests = new Tuple[150];
    for (int i = 0; i < requests.length; i++) {
        requests[i] = Tuple.tuple("/index/type/_bulk", bulkRequest);
    }
    HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
    TransportAddress transportAddress = (TransportAddress) randomFrom(httpServerTransport.boundAddress().boundAddresses());
    try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
        Collection<FullHttpResponse> singleResponse = nettyHttpClient.post(transportAddress.address(), requests[0]);
        assertThat(singleResponse, hasSize(1));
        assertAtLeastOnceExpectedStatus(singleResponse, HttpResponseStatus.OK);
        Collection<FullHttpResponse> multipleResponses = nettyHttpClient.post(transportAddress.address(), requests);
        assertThat(multipleResponses, hasSize(requests.length));
        assertAtLeastOnceExpectedStatus(multipleResponses, HttpResponseStatus.SERVICE_UNAVAILABLE);
    }
}
Also used : TransportAddress(org.elasticsearch.common.transport.TransportAddress) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) Tuple(org.elasticsearch.common.collect.Tuple)

Example 5 with HttpServerTransport

use of org.elasticsearch.http.HttpServerTransport in project elasticsearch by elastic.

the class Netty4HttpServerPipeliningTests method testThatHttpPipeliningWorksWhenEnabled.

public void testThatHttpPipeliningWorksWhenEnabled() throws Exception {
    final Settings settings = Settings.builder().put("http.pipelining", true).put("http.port", "0").build();
    try (HttpServerTransport httpServerTransport = new CustomNettyHttpServerTransport(settings)) {
        httpServerTransport.start();
        final TransportAddress transportAddress = randomFrom(httpServerTransport.boundAddress().boundAddresses());
        final int numberOfRequests = randomIntBetween(4, 16);
        final List<String> requests = new ArrayList<>(numberOfRequests);
        for (int i = 0; i < numberOfRequests; i++) {
            if (rarely()) {
                requests.add("/slow/" + i);
            } else {
                requests.add("/" + i);
            }
        }
        try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
            Collection<FullHttpResponse> responses = nettyHttpClient.get(transportAddress.address(), requests.toArray(new String[] {}));
            Collection<String> responseBodies = Netty4HttpClient.returnHttpResponseBodies(responses);
            assertThat(responseBodies, contains(requests.toArray()));
        }
    }
}
Also used : TransportAddress(org.elasticsearch.common.transport.TransportAddress) ArrayList(java.util.ArrayList) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

HttpServerTransport (org.elasticsearch.http.HttpServerTransport)18 Settings (org.elasticsearch.common.settings.Settings)7 TransportAddress (org.elasticsearch.common.transport.TransportAddress)7 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)6 ThreadPool (org.elasticsearch.threadpool.ThreadPool)5 Before (org.junit.Before)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)3 BlobAdminClient (io.crate.blob.v2.BlobAdminClient)2 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)2 InetSocketAddress (java.net.InetSocketAddress)2 Path (java.nio.file.Path)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)2 ClusterState (org.elasticsearch.cluster.ClusterState)2 ClusterStateObserver (org.elasticsearch.cluster.ClusterStateObserver)2 NodeConnectionsService (org.elasticsearch.cluster.NodeConnectionsService)2 MappingUpdatedAction (org.elasticsearch.cluster.action.index.MappingUpdatedAction)2