Search in sources :

Example 6 with V3MockParsingRequestHandler

use of com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler in project vespa by vespa-engine.

the class V3HttpAPIMultiClusterTest method testRetries.

@Test
public void testRetries() throws Exception {
    V3MockParsingRequestHandler unstableServer = new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.ALL_OK);
    V3MockParsingRequestHandler failedServer = new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.ALL_OK);
    try (Server serverA = new Server(failedServer, 0);
        Server serverB = new Server(unstableServer, 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()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).setMaxRetries(2).setMinTimeBetweenRetries(200, TimeUnit.MILLISECONDS).build()).build())) {
        waitForHandshakesOk(2, session);
        // Both servers worked fine so far, handshake established. Now fail transient when trying to send
        // data on both. This should cause the OperationProcessor to retry the document. One of the server
        // will come up, but not the other.
        unstableServer.setScenario(V3MockParsingRequestHandler.Scenario.SERVER_ERROR_TWICE_THEN_OK);
        // This will cause retries, but it will not come up.
        failedServer.setScenario(V3MockParsingRequestHandler.Scenario.COULD_NOT_FEED);
        writeDocuments(session);
        Map<String, Result> results = getResults(session, documents.size());
        assertThat("Results received: " + results.values(), 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(2));
            assert (r.getDetails().get(0).getResultType() != r.getDetails().get(1).getResultType());
        }
        assertThat(results.isEmpty(), is(true));
    }
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) V3MockParsingRequestHandler(com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler) Cluster(com.yahoo.vespa.http.client.config.Cluster) ConnectionParams(com.yahoo.vespa.http.client.config.ConnectionParams) Test(org.junit.Test)

Example 7 with V3MockParsingRequestHandler

use of com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler in project vespa by vespa-engine.

the class V3HttpAPIMultiClusterTest method requireThatBadVipBehaviorDoesNotFailBadly.

@Test
public void requireThatBadVipBehaviorDoesNotFailBadly() throws Exception {
    V3MockParsingRequestHandler handlerA = new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.BAD_REQUEST);
    V3MockParsingRequestHandler handlerB = new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.BAD_REQUEST);
    try (Server serverA = new Server(handlerA, 0);
        Server serverB = new Server(handlerB, 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()).setFeedParams(new FeedParams.Builder().setMaxSleepTimeMs(0).setMaxChunkSizeBytes(1).setLocalQueueTimeOut(1000).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).setMaxRetries(1).build()).build())) {
        // Set A in bad state => A returns bad request.
        handlerA.badRequestScenarioShouldReturnBadRequest.set(true);
        // write one document, should fail
        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));
        assertThat(r.getDetails().size(), is(2));
        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.OPERATION_EXECUTED));
        // Set B in bad state => B returns bad request.
        handlerB.badRequestScenarioShouldReturnBadRequest.set(true);
    }
// try to close session
}
Also used : 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 8 with V3MockParsingRequestHandler

use of com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler in project vespa by vespa-engine.

the class V3HttpAPIMultiClusterTest method requireThatAllInternalServerErrorWorks.

@Test
public void requireThatAllInternalServerErrorWorks() throws Exception {
    try (Server serverA = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.INTERNAL_SERVER_ERROR), 0);
        Server serverB = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.INTERNAL_SERVER_ERROR), 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));
        for (Result.Detail detail : r.getDetails()) {
            assertThat(detail.getResultType(), is(Result.ResultType.TRANSITIVE_ERROR));
        }
    }
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) V3MockParsingRequestHandler(com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler) Cluster(com.yahoo.vespa.http.client.config.Cluster) Test(org.junit.Test)

Example 9 with V3MockParsingRequestHandler

use of com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler in project vespa by vespa-engine.

the class V3HttpAPIMultiClusterTest method requireThatOneMbusErrorWorks.

@Test
public void requireThatOneMbusErrorWorks() throws Exception {
    final V3MockParsingRequestHandler unstableServer = new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.MBUS_RETURNED_ERROR);
    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(unstableServer, 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(100).build()).build())) {
        writeDocuments(session);
        // Make it fail, but it should still retry since it is a MBUS error that is transitive
        // for the client even though fatal for message bus.
        Thread.sleep(1000);
        assertThat(session.results().size(), is(0));
        unstableServer.setScenario(V3MockParsingRequestHandler.Scenario.ALL_OK);
        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(true));
            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.OPERATION_EXECUTED));
        }
        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 10 with V3MockParsingRequestHandler

use of com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler in project vespa by vespa-engine.

the class V3HttpAPIMultiClusterTest method requireThatAllUnexpectedVersionWorks.

@Test
public void requireThatAllUnexpectedVersionWorks() throws Exception {
    try (Server serverA = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.RETURN_UNEXPECTED_VERSION), 0);
        Server serverB = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.RETURN_UNEXPECTED_VERSION), 0);
        Server serverC = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.RETURN_UNEXPECTED_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));
        for (Result.Detail detail : r.getDetails()) {
            assertThat(detail.getResultType(), is(Result.ResultType.TRANSITIVE_ERROR));
        }
    }
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) V3MockParsingRequestHandler(com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler) Cluster(com.yahoo.vespa.http.client.config.Cluster) Test(org.junit.Test)

Aggregations

V3MockParsingRequestHandler (com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler)26 Test (org.junit.Test)26 Cluster (com.yahoo.vespa.http.client.config.Cluster)21 SessionParams (com.yahoo.vespa.http.client.config.SessionParams)19 Endpoint (com.yahoo.vespa.http.client.config.Endpoint)15 HashMap (java.util.HashMap)14 FeedParams (com.yahoo.vespa.http.client.config.FeedParams)8 SessionImpl (com.yahoo.vespa.http.client.core.api.SessionImpl)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ConnectionParams (com.yahoo.vespa.http.client.config.ConnectionParams)2 Server (com.yahoo.vespa.http.client.Server)1