summaryrefslogtreecommitdiffstats
path: root/vespa-feed-client/src/test
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-05-27 00:46:23 +0200
committerJon Marius Venstad <venstad@gmail.com>2021-05-27 09:54:43 +0200
commitfce5c8dd2e6ddf3c2364f4308c1aff2ec2d3aa4a (patch)
treef3d5cd7a61075a79edca2a753b20b204ba748058 /vespa-feed-client/src/test
parent6b6e59869ab5259a8cd2e382cd2b5164a963a293 (diff)
WIP JSON parsing (probably works)
Diffstat (limited to 'vespa-feed-client/src/test')
-rw-r--r--vespa-feed-client/src/test/java/ai/vespa/feed/client/JsonStreamFeederTest.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/vespa-feed-client/src/test/java/ai/vespa/feed/client/JsonStreamFeederTest.java b/vespa-feed-client/src/test/java/ai/vespa/feed/client/JsonStreamFeederTest.java
new file mode 100644
index 00000000000..25f64e3c98a
--- /dev/null
+++ b/vespa-feed-client/src/test/java/ai/vespa/feed/client/JsonStreamFeederTest.java
@@ -0,0 +1,67 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package ai.vespa.feed.client;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class JsonStreamFeederTest {
+
+ @Test
+ void test() throws IOException {
+ int docs = 1 << 10;
+ String json = "[\n" +
+
+ IntStream.range(0, docs).mapToObj(i ->
+ " {\n" +
+ " \"id\": \"id:ns:type::abc" + i + "\",\n" +
+ " \"fields\": {\n" +
+ " \"lul\":\"lal\"\n" +
+ " }\n" +
+ " },\n"
+ ).collect(Collectors.joining()) +
+
+ " {\n" +
+ " \"id\": \"id:ns:type::abc" + docs + "\",\n" +
+ " \"fields\": {\n" +
+ " \"lul\":\"lal\"\n" +
+ " }\n" +
+ " }\n" +
+ "]";
+ ByteArrayInputStream in = new ByteArrayInputStream(json.getBytes(UTF_8));
+ Set<String> ids = new ConcurrentSkipListSet<>();
+ JsonStreamFeeder.builder(new FeedClient() {
+ @Override
+ public CompletableFuture<Result> put(DocumentId documentId, String documentJson, OperationParameters params) {
+ ids.add(documentId.userSpecific());
+ return new CompletableFuture<>();
+ }
+
+ @Override
+ public CompletableFuture<Result> update(DocumentId documentId, String updateJson, OperationParameters params) {
+ return new CompletableFuture<>();
+ }
+
+ @Override
+ public CompletableFuture<Result> remove(DocumentId documentId, OperationParameters params) {
+ return new CompletableFuture<>();
+ }
+
+ @Override
+ public void close() throws IOException {
+
+ }
+ }).build().feed(in, 1 << 7); // TODO: hangs on 1 << 6.
+ assertEquals(docs + 1, ids.size());
+ }
+
+}