Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Removed

### Fixed
- Fix `unitTest` task not running the tests in the `test` source set ([#2074](https://github.com/opensearch-project/opensearch-java/pull/2074))

### Security

Expand Down
2 changes: 1 addition & 1 deletion java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ if (runtimeJavaVersion >= JavaVersion.VERSION_21) {
}

tasks.named<Test>("unitTest") {
testClassesDirs += java21.output.classesDirs
testClassesDirs += java21.output.classesDirs + sourceSets.test.get().output.classesDirs
classpath = sourceSets["java21"].runtimeClasspath
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ public void sizeLimitTest() throws Exception {
assertEquals(5, ingester.requestCount());
}

/**
* Waits for the periodic flusher to have emitted {@code expected} requests. Tests that add operations
* spaced apart in time cannot rely on sleeping longer than the flush interval: under load two operations
* can land in the same flush window, which coalesces them into a single request.
*/
private static void awaitRequestCount(BulkIngester<?> ingester, long expected) throws InterruptedException {
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
while (ingester.requestCount() < expected) {
if (System.nanoTime() - deadline > 0) {
fail("Timed out waiting for " + expected + " requests, got " + ingester.requestCount());
}
Thread.sleep(5);
}
}

@Test
public void periodicFlushTest() throws Exception {
TestTransport transport = new TestTransport();
Expand All @@ -237,11 +252,11 @@ public void periodicFlushTest() throws Exception {
.maxConcurrentRequests(Integer.MAX_VALUE - 1)
);

// Add an operation every 100 ms to give time
// to the flushing timer to kick in.
// Add an operation at a time, waiting for the flushing timer to kick in
// before adding the next one so that each gets its own request.
for (int i = 0; i < 10; i++) {
ingester.add(operation);
Thread.sleep(100);
awaitRequestCount(ingester, i + 1);
}

ingester.close();
Expand Down Expand Up @@ -299,11 +314,11 @@ public void afterBulk(long executionId, BulkRequest request, List<Void> contexts
.listener(listener)
);

// Add an operation every 100 ms to give time
// to the flushing timer to kick in.
// Add an operation at a time, waiting for the flushing timer to kick in
// before adding the next one so that each gets its own request.
for (int i = 0; i < 10; i++) {
ingester.add(operation);
Thread.sleep(100);
awaitRequestCount(ingester, i + 1);
}

ingester.close();
Expand Down
Loading