use of com.yahoo.vespa.http.client.config.FeedParams 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.FeedParams in project vespa by vespa-engine.
the class ApacheGatewayConnectionTest method testBadConfigParameters.
@Test(expected = RuntimeException.class)
public void testBadConfigParameters() 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 ApacheGatewayConnection.HttpClientFactory mockFactory = mock(ApacheGatewayConnection.HttpClientFactory.class);
new ApacheGatewayConnection(endpoint, feedParams, clusterSpecificRoute, connectionParams, mockFactory, null);
}
use of com.yahoo.vespa.http.client.config.FeedParams in project vespa by vespa-engine.
the class ApacheGatewayConnectionTest method testJsonDocumentHeader.
@Test
public void testJsonDocumentHeader() 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().setUseCompression(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, checks that DATA_FORMAT header is set properly.
ApacheGatewayConnection.HttpClientFactory mockFactory = mockHttpClientFactory(post -> {
final Header header = post.getFirstHeader(Headers.DATA_FORMAT);
if (requestsReceived.incrementAndGet() == 1) {
// This is handshake, it is not json.
assert (header == null);
return httpResponse("clientId", "3");
}
assertNotNull(header);
assertThat(header.getValue(), is(FeedParams.DataFormat.JSON_UTF8.name()));
// Test is done.
verifyContentSentLatch.countDown();
return httpResponse("clientId", "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.FeedParams 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.FeedParams 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));
}
Aggregations