Harden FrozenEngineTests#testCircuitBreakerAccounting
This test tries to compare the CB stats from an InternalEngine
and a FrozenEngine but is subject to segement merges that might finish
and get committed after we read the breaker stats. This can cause
occational test failures.
Closes
@@ -7,6 +7,7 @@ package org.elasticsearch.index.engine;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.FilterDirectoryReader;
+import org.apache.lucene.index.NoMergePolicy;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.ReferenceManager;
import org.apache.lucene.search.TopDocs;
@@ -139,16 +140,17 @@ public class FrozenEngineTests extends EngineTestCase {
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
try (Store store = createStore()) {
CountingRefreshListener listener = new CountingRefreshListener();
- EngineConfig config = config(defaultSettings, store, createTempDir(), newMergePolicy(), null, listener, null,
- globalCheckpoint::get, new HierarchyCircuitBreakerService(defaultSettings.getSettings(),
+ EngineConfig config = config(defaultSettings, store, createTempDir(),
+ NoMergePolicy.INSTANCE, // we don't merge we want no background merges to happen to ensure we have consistent breaker stats
+ null, listener, null, globalCheckpoint::get, new HierarchyCircuitBreakerService(defaultSettings.getSettings(),
new ClusterSettings(defaultSettings.getNodeSettings(), ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)));
CircuitBreaker breaker = config.getCircuitBreakerService().getBreaker(CircuitBreaker.ACCOUNTING);
long expectedUse;
try (InternalEngine engine = createEngine(config)) {
addDocuments(globalCheckpoint, engine);
- engine.refresh("test"); // pull the reader
+ engine.flush(false, true); // first flush to make sure we have a commit that we open in the frozen engine blow.
+ engine.refresh("test"); // pull the reader to account for RAM in the breaker.
expectedUse = breaker.getUsed();
- engine.flushAndClose();
}
assertTrue(expectedUse > 0);
assertEquals(0, breaker.getUsed());
