Skip to content

Commit

Permalink
Change
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Brooks committed Jun 8, 2023
1 parent a7096f9 commit 3d54150
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,14 @@ public void testPendingRefreshWithIntervalChange() throws Exception {
ensureGreen();
client().prepareIndex("test").setId("0").setSource("{\"foo\" : \"bar\"}", XContentType.JSON).get();
IndexShard shard = indexService.getShard(0);
PlainActionFuture<Boolean> future = PlainActionFuture.newFuture();
shard.scheduledRefresh(future);
assertFalse(future.actionGet());
scheduleRefresh(shard, false);
assertTrue(shard.isSearchIdle());
CountDownLatch refreshLatch = new CountDownLatch(1);
// async on purpose to make sure it happens concurrently
client().admin().indices().prepareRefresh().execute(ActionListener.running(refreshLatch::countDown));
assertHitCount(client().prepareSearch().get(), 1);
client().prepareIndex("test").setId("1").setSource("{\"foo\" : \"bar\"}", XContentType.JSON).get();
PlainActionFuture<Boolean> future2 = PlainActionFuture.newFuture();
shard.scheduledRefresh(future2);
assertFalse(future2.actionGet());
scheduleRefresh(shard, false);
assertTrue(shard.hasRefreshPending());

// now disable background refresh and make sure the refresh happens
Expand All @@ -182,9 +178,7 @@ public void testPendingRefreshWithIntervalChange() throws Exception {
// otherwise, it will compete to call `Engine#maybeRefresh` with the `scheduledRefresh` that we are going to verify.
ensureNoPendingScheduledRefresh(indexService.getThreadPool());
client().prepareIndex("test").setId("2").setSource("{\"foo\" : \"bar\"}", XContentType.JSON).get();
PlainActionFuture<Boolean> future3 = PlainActionFuture.newFuture();
shard.scheduledRefresh(future3);
assertTrue(future3.actionGet());
scheduleRefresh(shard, true);
assertFalse(shard.hasRefreshPending());
assertTrue(shard.isSearchIdle());
assertHitCount(client().prepareSearch().get(), 3);
Expand All @@ -196,6 +190,16 @@ public void testPendingRefreshWithIntervalChange() throws Exception {
}
}

private static void scheduleRefresh(IndexShard shard, boolean expectRefresh) {
PlainActionFuture<Boolean> future = PlainActionFuture.newFuture();
shard.scheduledRefresh(future);
if (expectRefresh) {
assertTrue(future.actionGet());
} else {
assertFalse(future.actionGet());
}
}

private void ensureNoPendingScheduledRefresh(ThreadPool threadPool) {
// We can make sure that all scheduled refresh tasks are done by submitting *maximumPoolSize* blocking tasks,
// then wait until all of them completed. Note that using ThreadPoolStats is not watertight as both queue and
Expand Down

0 comments on commit 3d54150

Please sign in to comment.