Skip to content

Reverting before bulk to being synch, unit test fixes #837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ public void flush() {

if (listener != null) {
BulkRequest finalRequest = request;
scheduler.submit(() -> listener.beforeBulk(id, finalRequest, requestContexts));
// synchronous execution to make sure it actually runs before
listener.beforeBulk(id, finalRequest, requestContexts);
}

CompletionStage<BulkResponse> result = client.bulk(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -102,11 +103,18 @@ private void multiThreadTest(int maxOperations, int maxRequests, int numThreads,
CountingListener listener = new CountingListener();
TestTransport transport = new TestTransport();
ElasticsearchAsyncClient client = new ElasticsearchAsyncClient(transport);
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(r -> {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setName("my-bulk-ingester-executor#" );
t.setDaemon(true);
return t;
});

BulkIngester<Void> ingester = BulkIngester.of(b -> b
.client(client)
.maxOperations(maxOperations)
.maxConcurrentRequests(maxRequests)
.scheduler(scheduler)
.listener(listener)
);

Expand All @@ -130,6 +138,7 @@ private void multiThreadTest(int maxOperations, int maxRequests, int numThreads,

ingester.close();
transport.close();
scheduler.shutdownNow();

printStats(ingester);
printStats(listener);
Expand Down Expand Up @@ -181,7 +190,7 @@ public void periodicFlushTest() throws Exception {
// Disable other flushing limits
.maxSize(-1)
.maxOperations(-1)
.maxConcurrentRequests(Integer.MAX_VALUE)
.maxConcurrentRequests(Integer.MAX_VALUE-1)
);

// Add an operation every 100 ms to give time
Expand Down Expand Up @@ -242,7 +251,7 @@ public void afterBulk(long executionId, BulkRequest request, List<Void> contexts
// Disable other flushing limits
.maxSize(-1)
.maxOperations(-1)
.maxConcurrentRequests(Integer.MAX_VALUE)
.maxConcurrentRequests(Integer.MAX_VALUE - 1)
.listener(listener)
);

Expand Down
Loading