|
13 | 13 | import org.apache.lucene.store.IndexInput; |
14 | 14 | import org.apache.lucene.store.MMapDirectory; |
15 | 15 | import org.apache.lucene.store.SimpleFSLockFactory; |
16 | | -import org.opensearch.core.common.breaker.CircuitBreaker; |
17 | | -import org.opensearch.core.common.breaker.NoopCircuitBreaker; |
| 16 | +import org.opensearch.common.breaker.TestCircuitBreaker; |
| 17 | +import org.opensearch.core.common.breaker.CircuitBreakingException; |
18 | 18 | import org.opensearch.index.store.remote.file.CleanerDaemonThreadLeakFilter; |
19 | 19 | import org.opensearch.index.store.remote.filecache.FileCache; |
20 | 20 | import org.opensearch.index.store.remote.filecache.FileCacheFactory; |
|
38 | 38 | @ThreadLeakFilters(filters = CleanerDaemonThreadLeakFilter.class) |
39 | 39 | public abstract class TransferManagerTestCase extends OpenSearchTestCase { |
40 | 40 | protected static final int EIGHT_MB = 1024 * 1024 * 8; |
41 | | - protected final FileCache fileCache = FileCacheFactory.createConcurrentLRUFileCache( |
42 | | - EIGHT_MB * 2, |
43 | | - 1, |
44 | | - new NoopCircuitBreaker(CircuitBreaker.REQUEST) |
45 | | - ); |
| 41 | + protected final TestCircuitBreaker testCircuitBreaker = new TestCircuitBreaker(); |
| 42 | + protected final FileCache fileCache = FileCacheFactory.createConcurrentLRUFileCache(EIGHT_MB * 2, 1, testCircuitBreaker); |
46 | 43 | protected MMapDirectory directory; |
47 | 44 | protected TransferManager transferManager; |
48 | 45 |
|
@@ -156,6 +153,29 @@ public void testDownloadFails() throws Exception { |
156 | 153 | MatcherAssert.assertThat(fileCache.usage(), equalTo(0L)); |
157 | 154 | } |
158 | 155 |
|
| 156 | + public void testCircuitBreakerWhileDownloading() throws IOException { |
| 157 | + // fetch blob when circuit breaking is not tripping |
| 158 | + try (IndexInput i = fetchBlobWithName("1")) { |
| 159 | + assertIndexInputIsFunctional(i); |
| 160 | + MatcherAssert.assertThat(fileCache.activeUsage(), equalTo((long) EIGHT_MB)); |
| 161 | + } |
| 162 | + // should have entry in file cache |
| 163 | + MatcherAssert.assertThat(fileCache.activeUsage(), equalTo(0L)); |
| 164 | + MatcherAssert.assertThat(fileCache.usage(), equalTo((long) EIGHT_MB)); |
| 165 | + |
| 166 | + // start tripping the circuit breaker |
| 167 | + testCircuitBreaker.startBreaking(); |
| 168 | + |
| 169 | + // fetch blob which already had entry in file cache, should not encounter circuit breaking exceptions |
| 170 | + try (IndexInput i = fetchBlobWithName("1")) { |
| 171 | + assertIndexInputIsFunctional(i); |
| 172 | + MatcherAssert.assertThat(fileCache.activeUsage(), equalTo((long) EIGHT_MB)); |
| 173 | + } |
| 174 | + |
| 175 | + // fetch new blob - should encounter circuit breaking exception |
| 176 | + expectThrows(CircuitBreakingException.class, () -> fetchBlobWithName("2")); |
| 177 | + } |
| 178 | + |
159 | 179 | public void testFetchesToDifferentBlobsDoNotBlockOnEachOther() throws Exception { |
160 | 180 | // Mock a call for a blob that will block until the latch is released, |
161 | 181 | // then start the fetch for that blob on a separate thread |
|
0 commit comments