Search in sources :

Example 11 with EndpointResult

use of com.yahoo.vespa.http.client.core.EndpointResult in project vespa by vespa-engine.

the class IOThread method drainFirstDocumentsInQueueIfOld.

private void drainFirstDocumentsInQueueIfOld() {
    while (true) {
        Optional<Document> document = documentQueue.pollDocumentIfTimedoutInQueue(localQueueTimeOut);
        if (!document.isPresent()) {
            return;
        }
        EndpointResult endpointResult = EndPointResultFactory.createTransientError(endpoint, document.get().getOperationId(), new Exception("Not sending document operation, timed out in queue after " + document.get().timeInQueueMillis() + " ms."));
        resultQueue.failOperation(endpointResult, clusterId);
    }
}
Also used : EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult) Document(com.yahoo.vespa.http.client.core.Document) IOException(java.io.IOException) ServerResponseException(com.yahoo.vespa.http.client.core.ServerResponseException)

Example 12 with EndpointResult

use of com.yahoo.vespa.http.client.core.EndpointResult 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 13 with EndpointResult

use of com.yahoo.vespa.http.client.core.EndpointResult 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 14 with EndpointResult

use of com.yahoo.vespa.http.client.core.EndpointResult 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 15 with EndpointResult

use of com.yahoo.vespa.http.client.core.EndpointResult 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)

Aggregations

EndpointResult (com.yahoo.vespa.http.client.core.EndpointResult)18 Test (org.junit.Test)9 SessionParams (com.yahoo.vespa.http.client.config.SessionParams)8 Cluster (com.yahoo.vespa.http.client.config.Cluster)7 Result (com.yahoo.vespa.http.client.Result)4 Endpoint (com.yahoo.vespa.http.client.config.Endpoint)4 Document (com.yahoo.vespa.http.client.core.Document)4 IOException (java.io.IOException)2 OperationStatus (com.yahoo.vespa.http.client.core.OperationStatus)1 ServerResponseException (com.yahoo.vespa.http.client.core.ServerResponseException)1 OperationProcessor (com.yahoo.vespa.http.client.core.operationProcessor.OperationProcessor)1 ArrayDeque (java.util.ArrayDeque)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1