Search in sources :

Example 21 with Endpoint

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

the class V3HttpAPIMultiClusterTest method requireThatAllNonAcceptedVersionWorks.

@Test
public void requireThatAllNonAcceptedVersionWorks() throws Exception {
    try (Server serverA = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.DONT_ACCEPT_VERSION), 0);
        Server serverB = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.DONT_ACCEPT_VERSION), 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(1).build()).build())) {
        // cannot fail here, they are just enqueued
        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 22 with Endpoint

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

the class V3HttpAPIMultiClusterTest method requireThatAllImmediateDisconnectWorks.

@Test
public void requireThatAllImmediateDisconnectWorks() throws Exception {
    try (Server serverA = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.DISCONNECT_IMMEDIATELY), 0);
        Server serverB = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.DISCONNECT_IMMEDIATELY), 0);
        Server serverC = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.DISCONNECT_IMMEDIATELY), 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(1000).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).setMaxRetries(1).build()).build())) {
        // cannot fail here, they are just enqueued
        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 23 with Endpoint

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

the class V3HttpAPIMultiClusterTest method requireThatAllMbusErrorWorks.

@Test
public void requireThatAllMbusErrorWorks() throws Exception {
    try (Server serverA = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.MBUS_RETURNED_ERROR), 0);
        Server serverB = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.MBUS_RETURNED_ERROR), 0);
        Server serverC = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.MBUS_RETURNED_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).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).setMaxRetries(0).build()).build())) {
        // cannot fail here, they are just enqueued
        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.FATAL_ERROR));
            assertThat(details.get(Endpoint.create("localhost", serverB.getPort(), false)).getResultType(), is(Result.ResultType.FATAL_ERROR));
            assertThat(details.get(Endpoint.create("localhost", serverC.getPort(), false)).getResultType(), is(Result.ResultType.FATAL_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) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) Test(org.junit.Test)

Example 24 with Endpoint

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

the class V3HttpAPIMultiClusterTest method requireThatOneWrongSessionIdWorks.

@Test
public void requireThatOneWrongSessionIdWorks() 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.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(1000).setServerTimeout(2, TimeUnit.SECONDS).setClientTimeout(2, TimeUnit.SECONDS).setLocalQueueTimeOut(2000).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).setMaxRetries(0).build()).build())) {
        waitForHandshakesOk(2, 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(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 25 with Endpoint

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

the class EndpointResultQueueTest method testBasics.

@Test
public void testBasics() {
    Endpoint endpoint = Endpoint.create("a");
    OperationProcessor mockAggregator = mock(OperationProcessor.class);
    final AtomicInteger resultCount = new AtomicInteger(0);
    doAnswer(invocationOnMock -> {
        resultCount.getAndIncrement();
        return null;
    }).when(mockAggregator).resultReceived(anyObject(), eq(0));
    EndpointResultQueue q = new EndpointResultQueue(mockAggregator, endpoint, 0, new ScheduledThreadPoolExecutor(1), 100L * 1000L);
    q.operationSent("op1");
    assertThat(q.getPendingSize(), is(1));
    q.operationSent("op2");
    assertThat(q.getPendingSize(), is(2));
    q.operationSent("op3");
    assertThat(q.getPendingSize(), is(3));
    q.resultReceived(new EndpointResult("op1", new Result.Detail(endpoint)), 0);
    assertThat(q.getPendingSize(), is(2));
    q.resultReceived(new EndpointResult("op2", new Result.Detail(endpoint)), 0);
    assertThat(q.getPendingSize(), is(1));
    q.resultReceived(new EndpointResult("op3", new Result.Detail(endpoint)), 0);
    assertThat(q.getPendingSize(), is(0));
    q.resultReceived(new EndpointResult("op1", new Result.Detail(endpoint)), 0);
    assertThat(q.getPendingSize(), is(0));
    q.resultReceived(new EndpointResult("abc", new Result.Detail(endpoint)), 0);
    assertThat(q.getPendingSize(), is(0));
    assertThat(resultCount.get(), is(5));
    q.operationSent("op4");
    assertThat(q.getPendingSize(), is(1));
    q.operationSent("op5");
    assertThat(q.getPendingSize(), is(2));
    q.failPending(new RuntimeException());
    assertThat(resultCount.get(), is(7));
}
Also used : Endpoint(com.yahoo.vespa.http.client.config.Endpoint) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) OperationProcessor(com.yahoo.vespa.http.client.core.operationProcessor.OperationProcessor) 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