From 02e540384d600f4134f52794f4a12371272453fc Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Sun, 14 Jun 2015 12:20:28 +0200 Subject: [PATCH] [TEST] Use NoMergePolicy in EngineTest#testVerboseSegments These tests rely on that there are no merges but since MP is now random this can break the test. --- .../index/engine/InternalEngineTests.java | 42 ++++++++++--------- .../index/engine/ShadowEngineTests.java | 3 ++ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index a3b88bed4e9..2cabd6d2fdd 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -384,29 +384,33 @@ public class InternalEngineTests extends ElasticsearchTestCase { } public void testVerboseSegments() throws Exception { - List segments = engine.segments(true); - assertThat(segments.isEmpty(), equalTo(true)); + IndexSettingsService indexSettingsService = new IndexSettingsService(shardId.index(), Settings.builder().put(defaultSettings).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build()); + try (Store store = createStore(); + Engine engine = createEngine(indexSettingsService, store, createTempDir(), new MergeSchedulerConfig(defaultSettings), NoMergePolicy.INSTANCE)) { + List segments = engine.segments(true); + assertThat(segments.isEmpty(), equalTo(true)); - ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, testDocumentWithTextField(), B_1, null); - engine.create(new Engine.Create(null, newUid("1"), doc)); - engine.refresh("test"); + ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, testDocumentWithTextField(), B_1, null); + engine.create(new Engine.Create(null, newUid("1"), doc)); + engine.refresh("test"); - segments = engine.segments(true); - assertThat(segments.size(), equalTo(1)); - assertThat(segments.get(0).ramTree, notNullValue()); + segments = engine.segments(true); + assertThat(segments.size(), equalTo(1)); + assertThat(segments.get(0).ramTree, notNullValue()); - ParsedDocument doc2 = testParsedDocument("2", "2", "test", null, -1, -1, testDocumentWithTextField(), B_2, null); - engine.create(new Engine.Create(null, newUid("2"), doc2)); - engine.refresh("test"); - ParsedDocument doc3 = testParsedDocument("3", "3", "test", null, -1, -1, testDocumentWithTextField(), B_3, null); - engine.create(new Engine.Create(null, newUid("3"), doc3)); - engine.refresh("test"); + ParsedDocument doc2 = testParsedDocument("2", "2", "test", null, -1, -1, testDocumentWithTextField(), B_2, null); + engine.create(new Engine.Create(null, newUid("2"), doc2)); + engine.refresh("test"); + ParsedDocument doc3 = testParsedDocument("3", "3", "test", null, -1, -1, testDocumentWithTextField(), B_3, null); + engine.create(new Engine.Create(null, newUid("3"), doc3)); + engine.refresh("test"); - segments = engine.segments(true); - assertThat(segments.size(), equalTo(3)); - assertThat(segments.get(0).ramTree, notNullValue()); - assertThat(segments.get(1).ramTree, notNullValue()); - assertThat(segments.get(2).ramTree, notNullValue()); + segments = engine.segments(true); + assertThat(segments.size(), equalTo(3)); + assertThat(segments.get(0).ramTree, notNullValue()); + assertThat(segments.get(1).ramTree, notNullValue()); + assertThat(segments.get(2).ramTree, notNullValue()); + } } diff --git a/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java index e8a0205448f..fe831a98fb3 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java @@ -440,6 +440,9 @@ public class ShadowEngineTests extends ElasticsearchTestCase { @Test public void testVerboseSegments() throws Exception { + IndexSettingsService indexSettingsService = new IndexSettingsService(shardId.index(), Settings.builder().put(defaultSettings).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build()); + primaryEngine.close(); // recreate without merging + primaryEngine = createInternalEngine(indexSettingsService, store, createTempDir(), NoMergePolicy.INSTANCE); List segments = primaryEngine.segments(true); assertThat(segments.isEmpty(), equalTo(true));