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));
}
}
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();
}
}
}
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();
}
}
}
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();
}
}
}
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));
}
}
Aggregations