Search in sources :

Example 1 with Endpoint

use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.

the class OperationProcessorTest method testMixOfBlockingAndNonBlocking.

@Test
public void testMixOfBlockingAndNonBlocking() {
    Endpoint endpoint = Endpoint.create("host");
    SessionParams sessionParams = new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(endpoint).build()).setConnectionParams(new ConnectionParams.Builder().setEnableV3Protocol(true).build()).build();
    OperationProcessor operationProcessor = new OperationProcessor(new IncompleteResultsThrottler(1000, 1000, null, null), (docId, documentResult) -> queue.add(documentResult), sessionParams, null);
    operationProcessor.sendDocument(doc1);
    // Blocked
    operationProcessor.sendDocument(doc1b);
    operationProcessor.sendDocument(doc2);
    operationProcessor.sendDocument(doc3);
    assertThat(queue.size(), is(0));
    assertThat(operationProcessor.getIncompleteResultQueueSize(), is(3));
    // This should have no effect since it should not be sent.
    operationProcessor.resultReceived(new EndpointResult(doc1b.getOperationId(), new Result.Detail(endpoint)), 0);
    assertThat(operationProcessor.getIncompleteResultQueueSize(), is(3));
    operationProcessor.resultReceived(new EndpointResult(doc3.getOperationId(), new Result.Detail(endpoint)), 0);
    assertThat(operationProcessor.getIncompleteResultQueueSize(), is(2));
    operationProcessor.resultReceived(new EndpointResult(doc2.getOperationId(), new Result.Detail(endpoint)), 0);
    assertThat(operationProcessor.getIncompleteResultQueueSize(), is(1));
    operationProcessor.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(endpoint)), 0);
    assertThat(operationProcessor.getIncompleteResultQueueSize(), is(1));
    operationProcessor.resultReceived(new EndpointResult(doc1b.getOperationId(), new Result.Detail(endpoint)), 0);
    assertThat(operationProcessor.getIncompleteResultQueueSize(), is(0));
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult) Cluster(com.yahoo.vespa.http.client.config.Cluster) Test(org.junit.Test)

Example 2 with Endpoint

use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.

the class V3HttpAPIMultiClusterTest method requireThatAllWrongSessionIdWorks.

@Test
public void requireThatAllWrongSessionIdWorks() throws Exception {
    try (Server serverA = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.RETURN_WRONG_SESSION_ID), 0);
        Server serverB = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.RETURN_WRONG_SESSION_ID), 0);
        Server serverC = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.RETURN_WRONG_SESSION_ID), 0);
        Session session = SessionFactory.create(new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", serverA.getPort(), false)).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", serverB.getPort(), false)).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", serverC.getPort(), false)).build()).setFeedParams(new FeedParams.Builder().setMaxSleepTimeMs(0).setMaxChunkSizeBytes(1).setServerTimeout(2, TimeUnit.SECONDS).setClientTimeout(2, TimeUnit.SECONDS).setLocalQueueTimeOut(2000).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).setMaxRetries(0).build()).build())) {
        writeDocuments(session);
        Map<String, Result> results = getResults(session, documents.size());
        assertThat(results.size(), is(documents.size()));
        for (TestDocument document : documents) {
            Result r = results.remove(document.getDocumentId());
            assertThat(r, not(nullValue()));
            // assertThat(r.getDetails().toString(), r.isSuccess(), is(false));
            assertThat(r.getDetails().size(), is(3));
            Map<Endpoint, Result.Detail> details = new HashMap<>();
            for (Result.Detail detail : r.getDetails()) {
                details.put(detail.getEndpoint(), detail);
            }
            assertThat(details.get(Endpoint.create("localhost", serverA.getPort(), false)).getResultType(), is(Result.ResultType.TRANSITIVE_ERROR));
            assertThat(details.get(Endpoint.create("localhost", serverB.getPort(), false)).getResultType(), is(Result.ResultType.TRANSITIVE_ERROR));
            assertThat(details.get(Endpoint.create("localhost", serverC.getPort(), false)).getResultType(), is(Result.ResultType.TRANSITIVE_ERROR));
        }
        assertThat(results.isEmpty(), is(true));
    }
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) V3MockParsingRequestHandler(com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler) HashMap(java.util.HashMap) Cluster(com.yahoo.vespa.http.client.config.Cluster) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) Test(org.junit.Test)

Example 3 with Endpoint

use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.

the class V3HttpAPIMultiClusterTest method requireThatOneNonAcceptedVersionWorks.

@Test
public void requireThatOneNonAcceptedVersionWorks() throws Exception {
    try (Server serverA = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.ALL_OK), 0);
        Server serverB = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.ALL_OK), 0);
        Server serverC = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.DONT_ACCEPT_VERSION), 0);
        Session session = SessionFactory.create(new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", serverA.getPort(), false)).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", serverB.getPort(), false)).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", serverC.getPort(), false)).build()).setFeedParams(new FeedParams.Builder().setMaxSleepTimeMs(0).setMaxChunkSizeBytes(1).setLocalQueueTimeOut(2000).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).setMaxRetries(0).build()).build())) {
        writeDocument(session);
        Map<String, Result> results = getResults(session, 1);
        assertThat(results.size(), is(1));
        Result r = results.values().iterator().next();
        assertThat(r, not(nullValue()));
        assertThat(r.getDetails().toString(), r.isSuccess(), is(false));
        Map<Endpoint, Result.Detail> details = new HashMap<>();
        for (Result.Detail detail : r.getDetails()) {
            details.put(detail.getEndpoint(), detail);
        }
        Result.Detail failed = details.remove(Endpoint.create("localhost", serverC.getPort(), false));
        assertThat(failed.getResultType(), is(Result.ResultType.TRANSITIVE_ERROR));
        for (Result.Detail detail : details.values()) {
            assertThat(detail.getResultType(), is(Result.ResultType.OPERATION_EXECUTED));
        }
    }
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) V3MockParsingRequestHandler(com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler) HashMap(java.util.HashMap) Cluster(com.yahoo.vespa.http.client.config.Cluster) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) Test(org.junit.Test)

Example 4 with Endpoint

use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.

the class V3HttpAPIMultiClusterTest method requireThatOneInternalServerErrorWorks.

@Test
public void requireThatOneInternalServerErrorWorks() throws Exception {
    try (Server serverA = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.ALL_OK), 0);
        Server serverB = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.ALL_OK), 0);
        Server serverC = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.INTERNAL_SERVER_ERROR), 0);
        Session session = SessionFactory.create(new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", serverA.getPort(), false)).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", serverB.getPort(), false)).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", serverC.getPort(), false)).build()).setFeedParams(new FeedParams.Builder().setMaxSleepTimeMs(0).setMaxChunkSizeBytes(1).setLocalQueueTimeOut(2000).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).setMaxRetries(0).build()).build())) {
        writeDocument(session);
        Map<String, Result> results = getResults(session, 1);
        assertThat(results.size(), is(1));
        Result r = results.values().iterator().next();
        assertThat(r, not(nullValue()));
        assertThat(r.getDetails().toString(), r.isSuccess(), is(false));
        Map<Endpoint, Result.Detail> details = new HashMap<>();
        for (Result.Detail detail : r.getDetails()) {
            details.put(detail.getEndpoint(), detail);
        }
        Result.Detail failed = details.remove(Endpoint.create("localhost", serverC.getPort(), false));
        assertThat(failed.getResultType(), is(Result.ResultType.TRANSITIVE_ERROR));
        for (Result.Detail detail : details.values()) {
            assertThat(detail.getResultType(), is(Result.ResultType.OPERATION_EXECUTED));
        }
    }
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) V3MockParsingRequestHandler(com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler) HashMap(java.util.HashMap) Cluster(com.yahoo.vespa.http.client.config.Cluster) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) Test(org.junit.Test)

Example 5 with Endpoint

use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.

the class V3HttpAPIMultiClusterTest method requireThatOneTimeoutWorks.

@Test
public void requireThatOneTimeoutWorks() throws Exception {
    try (Server serverA = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.ALL_OK), 0);
        Server serverB = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.ALL_OK), 0);
        Server serverC = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.NEVER_RETURN_ANY_RESULTS), 0);
        Session session = SessionFactory.create(new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", serverA.getPort(), false)).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", serverB.getPort(), false)).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", serverC.getPort(), false)).build()).setFeedParams(new FeedParams.Builder().setMaxSleepTimeMs(0).setMaxChunkSizeBytes(10000).setServerTimeout(2, TimeUnit.SECONDS).setClientTimeout(2, TimeUnit.SECONDS).setLocalQueueTimeOut(2000).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).setMaxRetries(1).build()).build())) {
        waitForHandshakesOk(3, session);
        writeDocuments(session);
        Map<String, Result> results = getResults(session, documents.size());
        assertThat(results.size(), is(documents.size()));
        for (TestDocument document : documents) {
            Result r = results.remove(document.getDocumentId());
            assertThat(r, not(nullValue()));
            // assertThat(r.getDetails().toString(), r.isSuccess(), is(false));
            assertThat(r.getDetails().size(), is(3));
            Map<Endpoint, Result.Detail> details = new HashMap<>();
            for (Result.Detail detail : r.getDetails()) {
                details.put(detail.getEndpoint(), detail);
            }
            assertThat(details.get(Endpoint.create("localhost", serverA.getPort(), false)).getResultType(), is(Result.ResultType.OPERATION_EXECUTED));
            assertThat(details.get(Endpoint.create("localhost", serverB.getPort(), false)).getResultType(), is(Result.ResultType.OPERATION_EXECUTED));
            assertThat(details.get(Endpoint.create("localhost", serverC.getPort(), false)).getResultType(), is(Result.ResultType.TRANSITIVE_ERROR));
            assertThat(details.get(Endpoint.create("localhost", serverC.getPort(), false)).getResultType(), is(Result.ResultType.TRANSITIVE_ERROR));
        }
        assertThat(results.isEmpty(), is(true));
    }
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) V3MockParsingRequestHandler(com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler) HashMap(java.util.HashMap) Cluster(com.yahoo.vespa.http.client.config.Cluster) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) Test(org.junit.Test)

Aggregations

Endpoint (com.yahoo.vespa.http.client.config.Endpoint)25 Test (org.junit.Test)22 Cluster (com.yahoo.vespa.http.client.config.Cluster)16 SessionParams (com.yahoo.vespa.http.client.config.SessionParams)15 V3MockParsingRequestHandler (com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler)14 HashMap (java.util.HashMap)14 FeedParams (com.yahoo.vespa.http.client.config.FeedParams)10 ConnectionParams (com.yahoo.vespa.http.client.config.ConnectionParams)6 Document (com.yahoo.vespa.http.client.core.Document)4 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 EndpointResult (com.yahoo.vespa.http.client.core.EndpointResult)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Header (org.apache.http.Header)3 OperationProcessor (com.yahoo.vespa.http.client.core.operationProcessor.OperationProcessor)2 IOException (java.io.IOException)2 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 ServerResponseException (com.yahoo.vespa.http.client.core.ServerResponseException)1 Random (java.util.Random)1