|
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;
|
@@ -5761,7 +5762,7 @@ public void testMaxSeqNoInCommitUserData() throws Exception {
|
5761 | 5762 | assertMaxSeqNoInCommitUserData(engine);
|
5762 | 5763 | }
|
5763 | 5764 |
|
5764 |
| - public void testRefreshAndFailEngineConcurrently() throws Exception { |
| 5765 | + public void testRefreshAndCloseEngineConcurrently() throws Exception { |
5765 | 5766 | AtomicBoolean stopped = new AtomicBoolean();
|
5766 | 5767 | Semaphore indexedDocs = new Semaphore(0);
|
5767 | 5768 | Thread indexer = new Thread(() -> {
|
@@ -5791,7 +5792,11 @@ public void testRefreshAndFailEngineConcurrently() throws Exception {
|
5791 | 5792 | refresher.start();
|
5792 | 5793 | indexedDocs.acquire(randomIntBetween(1, 100));
|
5793 | 5794 | try {
|
5794 |
| - engine.failEngine("test", new IOException("simulated error")); |
| 5795 | + if (randomBoolean()) { |
| 5796 | + engine.failEngine("test", new IOException("simulated error")); |
| 5797 | + } else { |
| 5798 | + engine.close(); |
| 5799 | + } |
5795 | 5800 | } finally {
|
5796 | 5801 | stopped.set(true);
|
5797 | 5802 | indexer.join();
|
@@ -6133,4 +6138,41 @@ public void afterRefresh(boolean didRefresh) {
|
6133 | 6138 | }
|
6134 | 6139 | }
|
6135 | 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 | + } |
6136 | 6178 | }
|
0 commit comments