use of com.yahoo.vespa.http.client.core.Document in project vespa by vespa-engine.
the class DryRunGatewayConnection method writeOperations.
@Override
public InputStream writeOperations(List<Document> docs) throws ServerResponseException, IOException {
StringBuilder result = new StringBuilder();
for (Document doc : docs) {
OperationStatus operationStatus = new OperationStatus("ok", doc.getOperationId(), ErrorCode.OK, false, "");
result.append(operationStatus.render());
}
return new ByteArrayInputStream(result.toString().getBytes(StandardCharsets.UTF_8));
}
use of com.yahoo.vespa.http.client.core.Document in project vespa by vespa-engine.
the class OperationProcessor method process.
private Result process(EndpointResult endpointResult, int clusterId) {
synchronized (monitor) {
if (!docSendInfoByOperationId.containsKey(endpointResult.getOperationId())) {
log.finer("Received out-of-order or too late result, discarding: " + endpointResult);
return null;
}
DocumentSendInfo documentSendInfo = docSendInfoByOperationId.get(endpointResult.getOperationId());
if (retriedThis(endpointResult, documentSendInfo, clusterId)) {
return null;
}
if (!documentSendInfo.addIfNotAlreadyThere(endpointResult.getDetail(), clusterId)) {
// Duplicate message, we have seen this operation before.
return null;
}
// Is this the last operation we are waiting for?
if (documentSendInfo.detailCount() != numDestinations) {
return null;
}
Result result = documentSendInfo.createResult();
docSendInfoByOperationId.remove(endpointResult.getOperationId());
String documentId = documentSendInfo.getDocument().getDocumentId();
/**
* If we got a pending operation against this document
* dont't remove it from inflightDocuments and send blocked document operation
*/
List<Document> blockedDocuments = blockedDocumentsByDocumentId.get(documentId);
if (blockedDocuments.isEmpty()) {
inflightDocumentIds.remove(documentId);
} else {
sendToClusters(blockedDocuments.remove(0));
}
return result;
}
}
use of com.yahoo.vespa.http.client.core.Document 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.core.Document in project vespa by vespa-engine.
the class ApacheGatewayConnectionTest method dynamic_headers_are_added_to_the_response.
@Test
public void dynamic_headers_are_added_to_the_response() throws IOException, ServerResponseException, InterruptedException {
ConnectionParams.HeaderProvider headerProvider = mock(ConnectionParams.HeaderProvider.class);
when(headerProvider.getHeaderValue()).thenReturn("v1").thenReturn("v2").thenReturn("v3");
ConnectionParams connectionParams = new ConnectionParams.Builder().addDynamicHeader("foo", headerProvider).build();
CountDownLatch verifyContentSentLatch = new CountDownLatch(1);
AtomicInteger counter = new AtomicInteger(1);
ApacheGatewayConnection.HttpClientFactory mockFactory = mockHttpClientFactory(post -> {
Header[] fooHeader = post.getHeaders("foo");
assertEquals(1, fooHeader.length);
assertEquals("foo", fooHeader[0].getName());
assertEquals("v" + counter.getAndIncrement(), fooHeader[0].getValue());
verifyContentSentLatch.countDown();
return httpResponse("clientId", "3");
});
ApacheGatewayConnection apacheGatewayConnection = new ApacheGatewayConnection(Endpoint.create("hostname", 666, false), new FeedParams.Builder().build(), "", connectionParams, mockFactory, "clientId");
apacheGatewayConnection.connect();
apacheGatewayConnection.handshake();
List<Document> documents = new ArrayList<>();
documents.add(createDoc("42", "content", true));
apacheGatewayConnection.writeOperations(documents);
apacheGatewayConnection.writeOperations(documents);
assertTrue(verifyContentSentLatch.await(10, TimeUnit.SECONDS));
// 1x connect(), 2x writeOperations()
verify(headerProvider, times(3)).getHeaderValue();
}
use of com.yahoo.vespa.http.client.core.Document in project vespa by vespa-engine.
the class CloseableQTestCase method requestThatPutIsInterruptedOnClose.
@Test
public void requestThatPutIsInterruptedOnClose() throws InterruptedException {
final DocumentQueue q = new DocumentQueue(1);
q.put(new Document("id", "data", null));
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
}
q.close();
q.clear();
}
});
t.start();
try {
q.put(new Document("id2", "data2", null));
fail("This shouldn't have worked.");
} catch (IllegalStateException ise) {
// ok!
}
try {
t.join();
} catch (InterruptedException e) {
}
}
Aggregations