Skip to content

Commit 37e1558

Browse files
committed
add test verifying that refresh does not block closing
1 parent a8a5551 commit 37e1558

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java

+38
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
137137
import org.elasticsearch.test.IndexSettingsModule;
138138
import org.elasticsearch.test.VersionUtils;
139+
import org.elasticsearch.threadpool.ThreadPool;
139140
import org.hamcrest.MatcherAssert;
140141

141142
import java.io.Closeable;
@@ -6137,4 +6138,41 @@ public void afterRefresh(boolean didRefresh) {
61376138
}
61386139
}
61396140
}
6141+
6142+
public void testRefreshDoesNotBlockClosing() throws Exception {
6143+
final CountDownLatch refreshStarted = new CountDownLatch(1);
6144+
final CountDownLatch engineClosed = new CountDownLatch(1);
6145+
final ReferenceManager.RefreshListener refreshListener = new ReferenceManager.RefreshListener() {
6146+
6147+
@Override
6148+
public void beforeRefresh() {
6149+
refreshStarted.countDown();
6150+
try {
6151+
engineClosed.await();
6152+
} catch (InterruptedException e) {
6153+
throw new AssertionError(e);
6154+
}
6155+
}
6156+
6157+
@Override
6158+
public void afterRefresh(boolean didRefresh) {
6159+
assertFalse(didRefresh);
6160+
}
6161+
};
6162+
try (Store store = createStore()) {
6163+
final EngineConfig config = config(defaultSettings, store, createTempDir(), newMergePolicy(), null,
6164+
refreshListener, null, null, engine.config().getCircuitBreakerService());
6165+
try (InternalEngine engine = createEngine(config)) {
6166+
if (randomBoolean()) {
6167+
engine.index(indexForDoc(createParsedDoc("id", null)));
6168+
}
6169+
threadPool.executor(ThreadPool.Names.REFRESH).execute(() ->
6170+
expectThrows(AlreadyClosedException.class,
6171+
() -> engine.refresh("test", randomFrom(Engine.SearcherScope.values()), true)));
6172+
refreshStarted.await();
6173+
engine.close();
6174+
engineClosed.countDown();
6175+
}
6176+
}
6177+
}
61406178
}

0 commit comments

Comments
 (0)