Search in sources :

Example 11 with SessionParams

use of com.yahoo.vespa.http.client.config.SessionParams in project vespa by vespa-engine.

the class OperationProcessorTest method assertThatDuplicateResultsFromOneClusterWorks.

@Test
public void assertThatDuplicateResultsFromOneClusterWorks() {
    SessionParams sessionParams = new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).build();
    OperationProcessor q = new OperationProcessor(new IncompleteResultsThrottler(1000, 1000, null, null), (docId, documentResult) -> queue.add(documentResult), sessionParams, null);
    q.sendDocument(doc1);
    assertThat(queue.size(), is(0));
    q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("a"))), 0);
    assertThat(queue.size(), is(0));
    q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("b"))), 0);
    assertThat(queue.size(), is(0));
    q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("c"))), 0);
    assertThat(queue.size(), is(0));
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult) Cluster(com.yahoo.vespa.http.client.config.Cluster) Test(org.junit.Test)

Example 12 with SessionParams

use of com.yahoo.vespa.http.client.config.SessionParams in project vespa by vespa-engine.

the class OperationProcessorTest method testBasic.

@Test
public void testBasic() {
    SessionParams sessionParams = new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).build();
    OperationProcessor q = new OperationProcessor(new IncompleteResultsThrottler(1000, 1000, null, null), (docId, documentResult) -> queue.add(documentResult), sessionParams, null);
    q.resultReceived(new EndpointResult("foo", new Result.Detail(null)), 0);
    assertThat(queue.size(), is(0));
    q.sendDocument(doc1);
    assertThat(queue.size(), is(0));
    q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("a"))), 0);
    assertThat(queue.size(), is(0));
    q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("b"))), 1);
    assertThat(queue.size(), is(0));
    q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("c"))), 2);
    assertThat(queue.size(), is(0));
    q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("d"))), 3);
    assertThat(queue.size(), is(1));
    q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("e"))), 0);
    assertThat(queue.size(), is(1));
    // check a, b, c, d
    Result aggregated = queue.poll();
    assertThat(aggregated.getDocumentId(), equalTo("doc:a:b"));
    assertThat(aggregated.getDetails().size(), is(4));
    assertThat(aggregated.getDetails().get(0).getEndpoint().getHostname(), equalTo("a"));
    assertThat(aggregated.getDetails().get(1).getEndpoint().getHostname(), equalTo("b"));
    assertThat(aggregated.getDetails().get(2).getEndpoint().getHostname(), equalTo("c"));
    assertThat(aggregated.getDetails().get(3).getEndpoint().getHostname(), equalTo("d"));
    assertThat(aggregated.getDocumentDataAsCharSequence().toString(), is("data doc 1"));
    assertThat(queue.size(), is(0));
    q.sendDocument(doc2);
    assertThat(queue.size(), is(0));
    q.resultReceived(new EndpointResult(doc2.getOperationId(), new Result.Detail(Endpoint.create("a"))), 0);
    assertThat(queue.size(), is(0));
    q.resultReceived(new EndpointResult(doc2.getOperationId(), new Result.Detail(Endpoint.create("b"))), 1);
    assertThat(queue.size(), is(0));
    q.resultReceived(new EndpointResult(doc2.getOperationId(), new Result.Detail(Endpoint.create("c"))), 2);
    assertThat(queue.size(), is(0));
    q.resultReceived(new EndpointResult(doc2.getOperationId(), new Result.Detail(Endpoint.create("d"))), 3);
    assertThat(queue.size(), is(1));
    q.resultReceived(new EndpointResult(doc2.getOperationId(), new Result.Detail(Endpoint.create("e"))), 0);
    assertThat(queue.size(), is(1));
    // check a, b, c, d
    aggregated = queue.poll();
    assertThat(aggregated.getDocumentId(), equalTo("doc:a:b2"));
    assertThat(aggregated.getDetails().size(), is(4));
    assertThat(aggregated.getDetails().get(0).getEndpoint().getHostname(), equalTo("a"));
    assertThat(aggregated.getDetails().get(1).getEndpoint().getHostname(), equalTo("b"));
    assertThat(aggregated.getDetails().get(2).getEndpoint().getHostname(), equalTo("c"));
    assertThat(aggregated.getDetails().get(3).getEndpoint().getHostname(), equalTo("d"));
    assertThat(aggregated.getDocumentDataAsCharSequence().toString(), is("data doc 2"));
    assertThat(queue.size(), is(0));
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult) Cluster(com.yahoo.vespa.http.client.config.Cluster) Result(com.yahoo.vespa.http.client.Result) EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult) Test(org.junit.Test)

Example 13 with SessionParams

use of com.yahoo.vespa.http.client.config.SessionParams in project vespa by vespa-engine.

the class OperationProcessorTest method testBlockingOfOperationsToSameDocIdMany.

@Test
public void testBlockingOfOperationsToSameDocIdMany() {
    SessionParams sessionParams = new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).setConnectionParams(new ConnectionParams.Builder().setEnableV3Protocol(true).build()).build();
    OperationProcessor operationProcessor = new OperationProcessor(new IncompleteResultsThrottler(1000, 1000, null, null), (docId, documentResult) -> queue.add(documentResult), sessionParams, null);
    Queue<Document> documentQueue = new ArrayDeque<>();
    for (int x = 0; x < 100; x++) {
        Document document = new Document("doc:a:b", String.valueOf(x), null);
        operationProcessor.sendDocument(document);
        documentQueue.add(document);
    }
    for (int x = 0; x < 100; x++) {
        assertThat(queue.size(), is(x));
        // Only one operations should be in flight.
        assertThat(operationProcessor.getIncompleteResultQueueSize(), is(1));
        Document document = documentQueue.poll();
        operationProcessor.resultReceived(new EndpointResult(document.getOperationId(), new Result.Detail(Endpoint.create("host"))), 0);
        assertThat(queue.size(), is(x + 1));
        if (x < 99) {
            assertThat(operationProcessor.getIncompleteResultQueueSize(), is(1));
        } else {
            assertThat(operationProcessor.getIncompleteResultQueueSize(), is(0));
        }
    }
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult) Cluster(com.yahoo.vespa.http.client.config.Cluster) Document(com.yahoo.vespa.http.client.core.Document) ArrayDeque(java.util.ArrayDeque) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) Test(org.junit.Test)

Example 14 with SessionParams

use of com.yahoo.vespa.http.client.config.SessionParams in project vespa by vespa-engine.

the class OperationProcessorTest method testWaitBlocks.

@Test
public void testWaitBlocks() throws InterruptedException {
    SessionParams sessionParams = new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).build();
    OperationProcessor operationProcessor = new OperationProcessor(new IncompleteResultsThrottler(1, 1, null, null), (docId, documentResult) -> {
    }, sessionParams, null);
    operationProcessor.sendDocument(doc1);
    final CountDownLatch started = new CountDownLatch(1);
    final CountDownLatch done = new CountDownLatch(1);
    Thread shouldWait = new Thread(() -> {
        started.countDown();
        operationProcessor.sendDocument(doc2);
        done.countDown();
    });
    shouldWait.start();
    started.await();
    // We want the test to pass fast so we only wait 40mS to see that it is blocking. This might lead to
    // some false positives, but that is ok.
    assertThat(done.await(40, TimeUnit.MILLISECONDS), is(false));
    operationProcessor.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("d"))), 0);
    assertThat(done.await(120, TimeUnit.SECONDS), is(true));
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 15 with SessionParams

use of com.yahoo.vespa.http.client.config.SessionParams in project vespa by vespa-engine.

the class OperationProcessorTest method testSendsResponseToQueuedDocumentOnClose.

@Test
public void testSendsResponseToQueuedDocumentOnClose() throws InterruptedException {
    SessionParams sessionParams = new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("#$#")).build()).build();
    ScheduledThreadPoolExecutor executor = mock(ScheduledThreadPoolExecutor.class);
    when(executor.awaitTermination(anyLong(), any())).thenReturn(true);
    CountDownLatch countDownLatch = new CountDownLatch(3);
    OperationProcessor operationProcessor = new OperationProcessor(new IncompleteResultsThrottler(19, 19, null, null), (docId, documentResult) -> {
        countDownLatch.countDown();
    }, sessionParams, executor);
    // Will fail due to bogus host name, but will be retried.
    operationProcessor.sendDocument(doc1);
    operationProcessor.sendDocument(doc2);
    operationProcessor.sendDocument(doc3);
    // Will create fail results.
    operationProcessor.close();
    countDownLatch.await();
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

SessionParams (com.yahoo.vespa.http.client.config.SessionParams)15 Test (org.junit.Test)12 Cluster (com.yahoo.vespa.http.client.config.Cluster)11 EndpointResult (com.yahoo.vespa.http.client.core.EndpointResult)8 Endpoint (com.yahoo.vespa.http.client.config.Endpoint)5 Result (com.yahoo.vespa.http.client.Result)2 FeedParams (com.yahoo.vespa.http.client.config.FeedParams)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 FeedClient (com.yahoo.vespa.http.client.FeedClient)1 ConnectionParams (com.yahoo.vespa.http.client.config.ConnectionParams)1 Document (com.yahoo.vespa.http.client.core.Document)1 IOException (java.io.IOException)1 ArrayDeque (java.util.ArrayDeque)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 StringTokenizer (java.util.StringTokenizer)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 XMLStreamException (javax.xml.stream.XMLStreamException)1