Search in sources :

Example 6 with ConnectionParams

use of com.yahoo.vespa.http.client.config.ConnectionParams 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));
}
Also used : ArrayList(java.util.ArrayList) Document(com.yahoo.vespa.http.client.core.Document) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectionParams(com.yahoo.vespa.http.client.config.ConnectionParams) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) StatusLine(org.apache.http.StatusLine) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) Header(org.apache.http.Header) Test(org.junit.Test)

Aggregations

ConnectionParams (com.yahoo.vespa.http.client.config.ConnectionParams)6 Test (org.junit.Test)6 Endpoint (com.yahoo.vespa.http.client.config.Endpoint)5 FeedParams (com.yahoo.vespa.http.client.config.FeedParams)5 Document (com.yahoo.vespa.http.client.core.Document)5 ArrayList (java.util.ArrayList)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 Header (org.apache.http.Header)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 StatusLine (org.apache.http.StatusLine)1