Search in sources :

Example 11 with V3MockParsingRequestHandler

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

the class V3HttpAPIMultiClusterTest method requireThatOneCouldNotFeedErrorWorks.

@Test
public void requireThatOneCouldNotFeedErrorWorks() 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.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.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) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) Test(org.junit.Test)

Example 12 with V3MockParsingRequestHandler

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

the class QueueBoundsTest method testErrorRecovery.

@Test
public void testErrorRecovery() throws Exception {
    V3MockParsingRequestHandler mockXmlParsingRequestHandler = new V3MockParsingRequestHandler();
    mockXmlParsingRequestHandler.setScenario(V3MockParsingRequestHandler.Scenario.DONT_ACCEPT_VERSION);
    try (Server server = new Server(mockXmlParsingRequestHandler, 0);
        Session session = new SessionImpl(new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", server.getPort(), false)).build()).setFeedParams(new FeedParams.Builder().setMaxChunkSizeBytes(1).setMaxInFlightRequests(1).setLocalQueueTimeOut(3000).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).setMaxRetries(1).build()).setClientQueueSize(1).build(), SessionFactory.createTimeoutExecutor())) {
        FeederThread feeder = new FeederThread(session);
        feeder.start();
        try {
            {
                System.out.println("We start with failed connection, post a document.");
                assertFeedNotBlocking(feeder, 0);
                assertThat(session.results().size(), is(0));
                CountDownLatch lastPostFeed = assertFeedBlocking(feeder, 1);
                System.out.println("No result so far.");
                assertThat(session.results().size(), is(0));
                System.out.println("Make connection ok.");
                mockXmlParsingRequestHandler.setScenario(V3MockParsingRequestHandler.Scenario.ALL_OK);
                assert (lastPostFeed.await(120, TimeUnit.SECONDS));
                assertThat(lastPostFeed.getCount(), equalTo(0L));
                assertResultQueueSize(session, 2, 120, TimeUnit.SECONDS);
            }
            System.out.println("Take down connection");
            mockXmlParsingRequestHandler.setScenario(V3MockParsingRequestHandler.Scenario.DONT_ACCEPT_VERSION);
            {
                assertFeedNotBlocking(feeder, 2);
                System.out.println("Fed one document, fit in queue.");
                assertThat(session.results().size(), is(2));
                System.out.println("Fed one document more, wait for failure.");
                assertFeedNotBlocking(feeder, 3);
                System.out.println("Wait for results for all three documents.");
                while (session.results().size() != 3) {
                    Thread.sleep(1);
                }
                System.out.println("Back to ok, test feeding again.");
                mockXmlParsingRequestHandler.setScenario(V3MockParsingRequestHandler.Scenario.ALL_OK);
                assertResultQueueSize(session, 4, 120, TimeUnit.SECONDS);
            }
            int errors = 0;
            for (Result result : session.results()) {
                assertThat(result.getDetails().size(), is(1));
                if (!result.isSuccess()) {
                    errors++;
                }
            }
            assertThat(errors, is(1));
        } finally {
            feeder.stop();
        }
    }
}
Also used : V3MockParsingRequestHandler(com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectionParams(com.yahoo.vespa.http.client.config.ConnectionParams) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) SessionImpl(com.yahoo.vespa.http.client.core.api.SessionImpl) Test(org.junit.Test)

Example 13 with V3MockParsingRequestHandler

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

the class QueueBoundsTest method requireThatFullIntermediateQueueBlocksAndUnblocks.

@Test
public void requireThatFullIntermediateQueueBlocksAndUnblocks() throws Exception {
    V3MockParsingRequestHandler slowHandler = new V3MockParsingRequestHandler("B", HttpServletResponse.SC_OK, V3MockParsingRequestHandler.Scenario.DELAYED_RESPONSE);
    try (Server serverA = new Server(new V3MockParsingRequestHandler("A"), 0);
        Server serverB = new Server(slowHandler, 0);
        SessionImpl session = new SessionImpl(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().setMaxChunkSizeBytes(1).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).build()).setClientQueueSize(// 3  per cluster
        6).build(), SessionFactory.createTimeoutExecutor())) {
        FeederThread feeder = new FeederThread(session);
        try {
            feeder.start();
            assertFeedNotBlocking(feeder, 0);
            assertFeedNotBlocking(feeder, 1);
            assertFeedNotBlocking(feeder, 2);
            // A input queue size now: 3
            // B input queue size now: 3
            // feeder thread not blocked
            // intermediate result queue size now: 3
            // result queue size now: 0
            assertResultQueueSize(session, 0, 60, TimeUnit.SECONDS);
            assertIncompleteResultQueueSize(session, 3, 60, TimeUnit.SECONDS);
            assertResultQueueSize(session, 0, 60, TimeUnit.SECONDS);
            assertIncompleteResultQueueSize(session, 3, 60, TimeUnit.SECONDS);
            // server B is slow, server A is fast
            // A input queue size now: 0
            // B input queue size now: 2, IOThread writing 1 and blocked because of no response yet
            // feeder thread still not blocked
            // intermediate result queue size now: 3
            // result queue size now: 0
            assertResultQueueSize(session, 0, 60, TimeUnit.SECONDS);
            assertIncompleteResultQueueSize(session, 3, 60, TimeUnit.SECONDS);
            CountDownLatch lastPostFeed = assertFeedBlocking(feeder, 3);
            // A input queue size now: 0
            // B input queue size now: 2, IOThread writing 1 and blocked because of no response yet
            // feeder thread blocking with 1 op
            // intermediate result queue size now: 3
            // result queue size now: 0
            slowHandler.poke();
            // A input queue size now: 0
            // B input queue size now: 2, IOThread writing 1 and blocked because of no response again
            // feeder thread unblocked
            // intermediate result queue size now: 3
            // result queue size now: 1
            lastPostFeed.await(60, TimeUnit.SECONDS);
            assertThat(lastPostFeed.getCount(), equalTo(0L));
            slowHandler.pokeAllAndUnblockFromNowOn();
            // A input queue size now: 0
            // B input queue size now: 0, IOThread not blocked
            // feeder thread unblocked
            // intermediate result queue size now: 0
            // result queue size now: 4
            assertResultQueueSize(session, 4, 60, TimeUnit.SECONDS);
        } finally {
            slowHandler.pokeAllAndUnblockFromNowOn();
            feeder.stop();
        }
    }
}
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) SessionImpl(com.yahoo.vespa.http.client.core.api.SessionImpl) CountDownLatch(java.util.concurrent.CountDownLatch) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) Test(org.junit.Test)

Example 14 with V3MockParsingRequestHandler

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

the class QueueBoundsTest method requireThatFullInputQueueBlocksAndUnblocks.

@Test
public void requireThatFullInputQueueBlocksAndUnblocks() throws Exception {
    V3MockParsingRequestHandler mockXmlParsingRequestHandler = new V3MockParsingRequestHandler();
    mockXmlParsingRequestHandler.setScenario(V3MockParsingRequestHandler.Scenario.DONT_ACCEPT_VERSION);
    try (Server server = new Server(mockXmlParsingRequestHandler, 0);
        Session session = new SessionImpl(new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("localhost", server.getPort(), false)).build()).setFeedParams(new FeedParams.Builder().setMaxChunkSizeBytes(1).setMaxInFlightRequests(1).setLocalQueueTimeOut(40000).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(1).build()).setClientQueueSize(2).build(), SessionFactory.createTimeoutExecutor())) {
        FeederThread feeder = new FeederThread(session);
        try {
            feeder.start();
            assertFeedNotBlocking(feeder, 0);
            assertThat(session.results().size(), is(0));
            assertFeedNotBlocking(feeder, 1);
            assertThat(session.results().size(), is(0));
            CountDownLatch lastPostFeed = assertFeedBlocking(feeder, 2);
            assertThat(session.results().size(), is(0));
            mockXmlParsingRequestHandler.setScenario(V3MockParsingRequestHandler.Scenario.ALL_OK);
            lastPostFeed.await(60, TimeUnit.SECONDS);
            assertThat(lastPostFeed.getCount(), equalTo(0L));
            assertResultQueueSize(session, 3, 60, TimeUnit.SECONDS);
        } finally {
            feeder.stop();
        }
    }
}
Also used : V3MockParsingRequestHandler(com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler) SessionImpl(com.yahoo.vespa.http.client.core.api.SessionImpl) CountDownLatch(java.util.concurrent.CountDownLatch) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) Test(org.junit.Test)

Example 15 with V3MockParsingRequestHandler

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

the class V3HttpAPITest method requireThatSingleDestinationWorks.

@Test
public void requireThatSingleDestinationWorks() throws Exception {
    try (Server server = new Server(new V3MockParsingRequestHandler(), 0);
        Session session = SessionFactory.create(Endpoint.create("localhost", server.getPort(), false))) {
        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(true));
        }
        assertThat(results.isEmpty(), is(true));
    }
}
Also used : V3MockParsingRequestHandler(com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler) 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