瀏覽代碼

Fix bogus assertion in testForceMergeOnReadOnlyEngine (#67242)

We were asserting that the index was created with >1 segment but this
isn't always the case. Instead, with this commit we permit it to contain
any number of segments and handle the rare case that it only has 1
segment specially.

Closes #67232
David Turner 4 年之前
父節點
當前提交
fcad2cae8b
共有 1 個文件被更改,包括 7 次插入7 次删除
  1. 7 7
      server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java

+ 7 - 7
server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java

@@ -189,7 +189,6 @@ public class ReadOnlyEngineTests extends EngineTestCase {
         }
     }
 
-    @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/67232")
     public void testForceMergeOnReadOnlyEngine() throws IOException {
         IOUtils.close(engine, store);
         final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
@@ -208,15 +207,16 @@ public class ReadOnlyEngineTests extends EngineTestCase {
                 engine.syncTranslog();
                 engine.flushAndClose();
                 numSegments = engine.getLastCommittedSegmentInfos().size();
-                assertTrue( numSegments > 1);
             }
 
             try (ReadOnlyEngine readOnlyEngine = new ReadOnlyEngine(config, null , null, true, Function.identity(), true)) {
-                UnsupportedOperationException exception = expectThrows(UnsupportedOperationException.class,
-                    () -> readOnlyEngine.forceMerge(
-                        true, numSegments-1, false, false, false, UUIDs.randomBase64UUID()));
-                assertThat(exception.getMessage(), equalTo("force merge is not supported on a read-only engine, " +
-                    "target max number of segments[" + (numSegments-1) + "], current number of segments[" + numSegments + "]."));
+                if (numSegments > 1) {
+                    final int target = between(1, numSegments - 1);
+                    UnsupportedOperationException exception = expectThrows(UnsupportedOperationException.class,
+                            () -> readOnlyEngine.forceMerge(true, target, false, false, false, UUIDs.randomBase64UUID()));
+                    assertThat(exception.getMessage(), equalTo("force merge is not supported on a read-only engine, " +
+                            "target max number of segments[" + target + "], current number of segments[" + numSegments + "]."));
+                }
 
                 readOnlyEngine.forceMerge(true, ForceMergeRequest.Defaults.MAX_NUM_SEGMENTS,
                     false, false, false, UUIDs.randomBase64UUID());