use of com.yahoo.vespa.http.client.config.Endpoint 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
}
use of com.yahoo.vespa.http.client.config.Endpoint 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));
}
}
use of com.yahoo.vespa.http.client.config.Endpoint 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.config.Endpoint in project vespa by vespa-engine.
the class ApacheGatewayConnectionTest method testProtocolV3.
@Test
public void testProtocolV3() throws Exception {
final Endpoint endpoint = Endpoint.create("hostname", 666, false);
final FeedParams feedParams = new FeedParams.Builder().setDataFormat(FeedParams.DataFormat.JSON_UTF8).build();
final String clusterSpecificRoute = "";
final ConnectionParams connectionParams = new ConnectionParams.Builder().setEnableV3Protocol(true).build();
final List<Document> documents = new ArrayList<>();
final CountDownLatch verifyContentSentLatch = new CountDownLatch(1);
final String vespaDocContent = "Hello, I a JSON doc.";
final String docId = "42";
final AtomicInteger requestsReceived = new AtomicInteger(0);
// This is the fake server, takes header client ID and uses this as session Id.
ApacheGatewayConnection.HttpClientFactory mockFactory = mockHttpClientFactory(post -> {
final Header clientIdHeader = post.getFirstHeader(Headers.CLIENT_ID);
verifyContentSentLatch.countDown();
return httpResponse(clientIdHeader.getValue(), "3");
});
ApacheGatewayConnection apacheGatewayConnection = new ApacheGatewayConnection(endpoint, feedParams, clusterSpecificRoute, connectionParams, mockFactory, "clientId");
apacheGatewayConnection.connect();
apacheGatewayConnection.handshake();
documents.add(createDoc(docId, vespaDocContent, true));
apacheGatewayConnection.writeOperations(documents);
assertTrue(verifyContentSentLatch.await(10, TimeUnit.SECONDS));
}
use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.
the class EndpointResultQueueTest method testTimeout.
@Test
public void testTimeout() throws InterruptedException {
Endpoint endpoint = Endpoint.create("a");
OperationProcessor mockAggregator = mock(OperationProcessor.class);
CountDownLatch latch = new CountDownLatch(1);
doAnswer(invocationOnMock -> {
latch.countDown();
return null;
}).when(mockAggregator).resultReceived(anyObject(), eq(0));
EndpointResultQueue q = new EndpointResultQueue(mockAggregator, endpoint, 0, new ScheduledThreadPoolExecutor(1), 100L);
q.operationSent("1234");
assert (latch.await(120, TimeUnit.SECONDS));
}
Aggregations