Search in sources :

Example 16 with Document

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

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

the class ApacheGatewayConnection method getDataWithStartAndEndOfFeed.

private ByteBuffer[] getDataWithStartAndEndOfFeed(List<Document> docs, int version) {
    List<ByteBuffer> data = new ArrayList<ByteBuffer>();
    if (version == 2 || version == 3) {
        for (Document doc : docs) {
            int operationSize = doc.size() + startOfFeed.length + endOfFeed.length;
            StringBuilder envelope = new StringBuilder();
            Encoder.encode(doc.getOperationId(), envelope);
            envelope.append(' ');
            envelope.append(Integer.toHexString(operationSize));
            envelope.append('\n');
            data.add(StandardCharsets.US_ASCII.encode(envelope.toString()));
            data.add(ByteBuffer.wrap(startOfFeed));
            data.add(doc.getData());
            data.add(ByteBuffer.wrap(endOfFeed));
        }
    } else {
        throw new IllegalArgumentException("Protocol version " + version + " unsupported by client.");
    }
    return data.toArray(new ByteBuffer[data.size()]);
}
Also used : ArrayList(java.util.ArrayList) Document(com.yahoo.vespa.http.client.core.Document) ByteBuffer(java.nio.ByteBuffer) Endpoint(com.yahoo.vespa.http.client.config.Endpoint)

Example 18 with Document

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

the class MultiClusterSessionOutputStream method close.

@Override
public void close() throws IOException {
    Document document = new Document(documentId.toString(), toByteArray(), context);
    operationProcessor.sendDocument(document);
    super.close();
}
Also used : Document(com.yahoo.vespa.http.client.core.Document)

Aggregations

Document (com.yahoo.vespa.http.client.core.Document)18 Endpoint (com.yahoo.vespa.http.client.config.Endpoint)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 ConnectionParams (com.yahoo.vespa.http.client.config.ConnectionParams)5 FeedParams (com.yahoo.vespa.http.client.config.FeedParams)4 EndpointResult (com.yahoo.vespa.http.client.core.EndpointResult)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Header (org.apache.http.Header)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Result (com.yahoo.vespa.http.client.Result)1 Cluster (com.yahoo.vespa.http.client.config.Cluster)1 SessionParams (com.yahoo.vespa.http.client.config.SessionParams)1 OperationStatus (com.yahoo.vespa.http.client.core.OperationStatus)1 ServerResponseException (com.yahoo.vespa.http.client.core.ServerResponseException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 CharsetEncoder (java.nio.charset.CharsetEncoder)1 ArrayDeque (java.util.ArrayDeque)1