Skip to content

Commit

Permalink
add test verifying that refresh does not block closing
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed Oct 24, 2019
1 parent a8a5551 commit 37e1558
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.test.IndexSettingsModule;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.threadpool.ThreadPool;
import org.hamcrest.MatcherAssert;

import java.io.Closeable;
Expand Down Expand Up @@ -6137,4 +6138,41 @@ public void afterRefresh(boolean didRefresh) {
}
}
}

public void testRefreshDoesNotBlockClosing() throws Exception {
final CountDownLatch refreshStarted = new CountDownLatch(1);
final CountDownLatch engineClosed = new CountDownLatch(1);
final ReferenceManager.RefreshListener refreshListener = new ReferenceManager.RefreshListener() {

@Override
public void beforeRefresh() {
refreshStarted.countDown();
try {
engineClosed.await();
} catch (InterruptedException e) {
throw new AssertionError(e);
}
}

@Override
public void afterRefresh(boolean didRefresh) {
assertFalse(didRefresh);
}
};
try (Store store = createStore()) {
final EngineConfig config = config(defaultSettings, store, createTempDir(), newMergePolicy(), null,
refreshListener, null, null, engine.config().getCircuitBreakerService());
try (InternalEngine engine = createEngine(config)) {
if (randomBoolean()) {
engine.index(indexForDoc(createParsedDoc("id", null)));
}
threadPool.executor(ThreadPool.Names.REFRESH).execute(() ->
expectThrows(AlreadyClosedException.class,
() -> engine.refresh("test", randomFrom(Engine.SearcherScope.values()), true)));
refreshStarted.await();
engine.close();
engineClosed.countDown();
}
}
}
}

0 comments on commit 37e1558

Please sign in to comment.