Search in sources :

Example 16 with V3MockParsingRequestHandler

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

the class V3HttpAPITest method requireThatTimeoutWorks.

@Test
public void requireThatTimeoutWorks() throws Exception {
    try (Server server = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.NEVER_RETURN_ANY_RESULTS), 0);
        Session session = SessionFactory.create(new SessionParams.Builder().setFeedParams(new FeedParams.Builder().setLocalQueueTimeOut(0).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).setMaxRetries(2).build()).setFeedParams(new FeedParams.Builder().setServerTimeout(500, TimeUnit.MILLISECONDS).setClientTimeout(500, TimeUnit.MILLISECONDS).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", server.getPort(), false)).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().iterator().next().getResultType(), is(Result.ResultType.TRANSITIVE_ERROR));
        }
        assertThat(results.isEmpty(), is(true));
    }
}
Also used : V3MockParsingRequestHandler(com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler) Cluster(com.yahoo.vespa.http.client.config.Cluster) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) Test(org.junit.Test)

Example 17 with V3MockParsingRequestHandler

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

the class ExampleUsageFeedClientTest method testExampleCode.

@Test
public void testExampleCode() {
    Server serverA = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.ALL_OK), 0);
    Server serverB = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.ALL_OK), 0);
    exampleCode("localhost", serverA.getPort(), "localhost", serverB.getPort());
    serverA.close();
    serverB.close();
}
Also used : V3MockParsingRequestHandler(com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler) Server(com.yahoo.vespa.http.client.Server) Test(org.junit.Test)

Example 18 with V3MockParsingRequestHandler

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

the class V3HttpAPIMultiClusterTest method requireThatAllCouldNotFeedErrorWorks.

@Test
public void requireThatAllCouldNotFeedErrorWorks() throws Exception {
    try (Server serverA = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.COULD_NOT_FEED), 0);
        Server serverB = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.COULD_NOT_FEED), 0);
        Server serverC = new Server(new V3MockParsingRequestHandler(200, V3MockParsingRequestHandler.Scenario.COULD_NOT_FEED), 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(1).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) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) Test(org.junit.Test)

Example 19 with V3MockParsingRequestHandler

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

the class V3HttpAPIMultiClusterTest method requireThatOneImmediateDisconnectWorks.

@Test
public void requireThatOneImmediateDisconnectWorks() 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.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.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 20 with V3MockParsingRequestHandler

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

the class V3HttpAPIMultiClusterTest method requireThatOneUnexpectedVersionWorks.

@Test
public void requireThatOneUnexpectedVersionWorks() 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_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())) {
        // 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.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)

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