summaryrefslogtreecommitdiffstats
path: root/vespa-http-client
diff options
context:
space:
mode:
authorHarshil Shukla <harshil@oath.com>2019-04-30 14:32:03 -0700
committerHarshil Shukla <harshil@oath.com>2019-04-30 14:32:03 -0700
commite6fdabe56914c6ff1ec554ff433efd8adcdb8c83 (patch)
treec78e00f1da36acb8b15fb176e8ea3f9c57bd665b /vespa-http-client
parent6c93798b95d6a82102c9b363822a9f5e7483d31a (diff)
Allow client to pass custom operationId
Diffstat (limited to 'vespa-http-client')
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/SyncFeedClient.java11
-rw-r--r--vespa-http-client/src/test/java/com/yahoo/vespa/http/client/SyncFeedClientTest.java25
2 files changed, 32 insertions, 4 deletions
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/SyncFeedClient.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/SyncFeedClient.java
index c1e7f9f04c5..c4b9b1161b7 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/SyncFeedClient.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/SyncFeedClient.java
@@ -62,14 +62,19 @@ public class SyncFeedClient implements AutoCloseable {
private final String operationId;
public SyncOperation(String documentId, CharSequence documentData) {
- this(documentId, documentData, null);
+ this(documentId, documentData, null, null);
}
- public SyncOperation(String documentId, CharSequence documentData, Object context) {
+ public SyncOperation(String documentId, CharSequence documentData, String operationId) {
+ this(documentId, documentData, operationId, null);
+ }
+
+ private SyncOperation(String documentId, CharSequence documentData, String operationId, Object context) {
this.documentId = Objects.requireNonNull(documentId, "documentId");
this.documentData = Objects.requireNonNull(documentData, "documentData");
this.context = context;
- this.operationId = new BigInteger(64, ThreadLocalRandom.current()).toString(32);
+ this.operationId = Objects.isNull(operationId) ?
+ new BigInteger(64, ThreadLocalRandom.current()).toString(32) : operationId;
}
}
diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/SyncFeedClientTest.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/SyncFeedClientTest.java
index fce356e6677..562341d6d2a 100644
--- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/SyncFeedClientTest.java
+++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/SyncFeedClientTest.java
@@ -13,6 +13,7 @@ import com.yahoo.vespa.http.client.SyncFeedClient.SyncOperation;
import com.yahoo.vespa.http.client.SyncFeedClient.SyncResult;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
@@ -72,16 +73,38 @@ public class SyncFeedClientTest {
" \"title\": \"Title 4\"" +
" }" +
"}"));
+ operations.add(new SyncOperation("id::test::4",
+ "{" +
+ " \"put\": \"id::test::4\"," +
+ " \"fields\": {" +
+ " \"title\": \"Title 4\"" +
+ " }" +
+ "}", "opId_4"));
+ operations.add(new SyncOperation("id::test::4", // Another operation for the same document
+ "{" +
+ " \"put\": \"id::test::4\"," +
+ " \"fields\": {" +
+ " \"title\": \"Title 44\"" +
+ " }" +
+ "}", "opId_44"));
SyncResult result = feedClient.stream(operations);
assertTrue(result.isSuccess());
- assertEquals(4, result.results().size());
+ assertEquals(6, result.results().size());
assertNull(result.exception());
assertEquals("id::test::1", result.results().get(0).getDocumentId());
assertEquals("id::test::2", result.results().get(1).getDocumentId());
assertEquals("id::test::3", result.results().get(2).getDocumentId());
assertEquals("id::test::3", result.results().get(3).getDocumentId());
+ assertEquals("id::test::4", result.results().get(4).getDocumentId());
+ assertEquals("id::test::4", result.results().get(5).getDocumentId());
+ assertEquals("opId_4", result.results().get(4).getOperationId());
+ assertEquals("opId_44", result.results().get(5).getOperationId());
+ assertTrue(result.results().get(4).getDocumentDataAsCharSequence().toString().contains("\"Title 4\""));
+ assertTrue(result.results().get(5).getDocumentDataAsCharSequence().toString().contains("\"Title 44\""));
+
+ result.results().forEach(r -> assertNotNull(r.getOperationId()));
}
}