use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.
the class ApacheGatewayConnectionTest method testServerReturnsBadSessionInV3.
@Test(expected = IllegalArgumentException.class)
public void testServerReturnsBadSessionInV3() 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();
// This is the fake server, returns wrong session Id.
ApacheGatewayConnection.HttpClientFactory mockFactory = mockHttpClientFactory(post -> httpResponse("Wrong Id from server", "3"));
ApacheGatewayConnection apacheGatewayConnection = new ApacheGatewayConnection(endpoint, feedParams, clusterSpecificRoute, connectionParams, mockFactory, "clientId");
apacheGatewayConnection.connect();
final List<Document> documents = new ArrayList<>();
apacheGatewayConnection.writeOperations(documents);
}
use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.
the class ApacheGatewayConnectionTest method testCompressedWriteOperations.
/**
* Mocks the HttpClient, and verifies that the compressed data is sent.
*/
@Test
public void testCompressedWriteOperations() throws Exception {
final Endpoint endpoint = Endpoint.create("hostname", 666, false);
final FeedParams feedParams = new FeedParams.Builder().build();
final String clusterSpecificRoute = "";
final ConnectionParams connectionParams = new ConnectionParams.Builder().setUseCompression(true).build();
final List<Document> documents = new ArrayList<>();
final CountDownLatch verifyContentSentLatch = new CountDownLatch(1);
final String vespaDocContent = "Hello, I am the document data.";
final String docId = "42";
final Document doc = createDoc(docId, vespaDocContent, false);
// When sending data on http client, check if it is compressed. If compressed, unzip, check result,
// and count down latch.
ApacheGatewayConnection.HttpClientFactory mockFactory = mockHttpClientFactory(post -> {
final Header header = post.getFirstHeader("Content-Encoding");
if (header != null && header.getValue().equals("gzip")) {
final String rawContent = TestUtils.zipStreamToString(post.getEntity().getContent());
final String vespaHeaderText = "<vespafeed>\n";
final String vespaFooterText = "</vespafeed>\n";
assertThat(rawContent, is(doc.getOperationId() + " 38\n" + vespaHeaderText + vespaDocContent + "\n" + vespaFooterText));
verifyContentSentLatch.countDown();
}
return httpResponse("clientId", "3");
});
StatusLine statusLineMock = mock(StatusLine.class);
when(statusLineMock.getStatusCode()).thenReturn(200);
ApacheGatewayConnection apacheGatewayConnection = new ApacheGatewayConnection(endpoint, feedParams, clusterSpecificRoute, connectionParams, mockFactory, "clientId");
apacheGatewayConnection.connect();
apacheGatewayConnection.handshake();
documents.add(doc);
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 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));
}
}
use of com.yahoo.vespa.http.client.config.Endpoint 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));
}
}
use of com.yahoo.vespa.http.client.config.Endpoint 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));
}
}
Aggregations