|
136 | 136 | import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
137 | 137 | import org.elasticsearch.test.IndexSettingsModule;
|
138 | 138 | import org.elasticsearch.test.VersionUtils;
|
| 139 | +import org.elasticsearch.threadpool.ThreadPool; |
139 | 140 | import org.hamcrest.MatcherAssert;
|
140 | 141 |
|
141 | 142 | import java.io.Closeable;
|
@@ -6137,4 +6138,41 @@ public void afterRefresh(boolean didRefresh) {
|
6137 | 6138 | }
|
6138 | 6139 | }
|
6139 | 6140 | }
|
| 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 | + } |
6140 | 6178 | }
|
0 commit comments