Move client stub to separate class
@@ -51,9 +51,32 @@ class JsonFeederTest {
try (InputStream in = Files.newInputStream(tmpFile, StandardOpenOption.READ, StandardOpenOption.DELETE_ON_CLOSE)) {
AtomicInteger resultsReceived = new AtomicInteger();
AtomicBoolean completedSuccessfully = new AtomicBoolean();
- Set<String> ids = new HashSet<>();
long startNanos = System.nanoTime();
- JsonFeeder.builder(new FeedClient() {
+ SimpleClient feedClient = new SimpleClient();
+ JsonFeeder.builder(feedClient).build()
+ .feedMany(in, 1 << 7,
+ new JsonFeeder.ResultCallback() { // TODO: hangs when buffer is smaller than largest document
+ @Override
+ public void onNextResult(Result result, Throwable error) { resultsReceived.incrementAndGet(); }
+
+ @Override
+ public void onError(Throwable error) { exceptionThrow.set(error); }
+
+ @Override
+ public void onComplete() { completedSuccessfully.set(true); }
+ })
+ .join();
+
+ System.err.println((json.length() / 1048576.0) + " MB in " + (System.nanoTime() - startNanos) * 1e-9 + " seconds");
+ assertEquals(docs + 1, feedClient.ids.size());
+ assertEquals(docs + 1, resultsReceived.get());
+ assertTrue(completedSuccessfully.get());
+ assertNull(exceptionThrow.get());
+ }
+ }
+
+ private static class SimpleClient implements FeedClient {
+ final Set<String> ids = new HashSet<>();
@Override
public CompletableFuture<Result> put(DocumentId documentId, String documentJson, OperationParameters params) {
@@ -80,24 +103,6 @@ class JsonFeederTest {
private CompletableFuture<Result> createSuccessResult(DocumentId documentId) {
return CompletableFuture.completedFuture(new Result(Result.Type.success, documentId, "success", null));
}
-
- }).build().feedMany(in, 1 << 7, new JsonFeeder.ResultCallback() { // TODO: hangs when buffer is smaller than largest document
- @Override
- public void onNextResult(Result result, Throwable error) { resultsReceived.incrementAndGet(); }
-
- @Override
- public void onError(Throwable error) { exceptionThrow.set(error); }
-
- @Override
- public void onComplete() { completedSuccessfully.set(true); }
- }).join();
-
- System.err.println((json.length() / 1048576.0) + " MB in " + (System.nanoTime() - startNanos) * 1e-9 + " seconds");
- assertEquals(docs + 1, ids.size());
- assertEquals(docs + 1, resultsReceived.get());
- assertTrue(completedSuccessfully.get());
- assertNull(exceptionThrow.get());
- }
}
}
