2121
2222import org .apache .lucene .index .DirectoryReader ;
2323import org .apache .lucene .index .IndexReader ;
24- import org .apache .lucene .index .MergePolicy ;
2524import org .apache .lucene .index .NoMergePolicy ;
2625import org .apache .lucene .store .LockObtainFailedException ;
2726import org .elasticsearch .cluster .routing .IndexShardRoutingTable ;
2827import org .elasticsearch .cluster .routing .ShardRouting ;
2928import org .elasticsearch .cluster .routing .ShardRoutingState ;
3029import org .elasticsearch .cluster .routing .TestShardRouting ;
31- import org .elasticsearch .common .bytes .BytesArray ;
3230import org .elasticsearch .common .settings .Settings ;
3331import org .elasticsearch .core .internal .io .IOUtils ;
3432import org .elasticsearch .index .IndexSettings ;
3735import org .elasticsearch .index .seqno .SequenceNumbers ;
3836import org .elasticsearch .index .shard .DocsStats ;
3937import org .elasticsearch .index .store .Store ;
40- import org .elasticsearch .index .translog .Translog ;
41- import org .elasticsearch .index .translog .TranslogCorruptedException ;
4238import org .elasticsearch .index .translog .TranslogDeletionPolicy ;
4339import org .elasticsearch .test .IndexSettingsModule ;
4440
5046
5147import static org .hamcrest .Matchers .equalTo ;
5248import static org .hamcrest .Matchers .instanceOf ;
53- import static org .hamcrest .Matchers .is ;
5449
5550public class NoOpEngineTests extends EngineTestCase {
5651 private static final IndexSettings INDEX_SETTINGS = IndexSettingsModule .newIndexSettings ("index" , Settings .EMPTY );
@@ -59,7 +54,6 @@ public void testNoopEngine() throws IOException {
5954 engine .close ();
6055 final NoOpEngine engine = new NoOpEngine (noOpConfig (INDEX_SETTINGS , store , primaryTranslogDir ));
6156 expectThrows (UnsupportedOperationException .class , () -> engine .syncFlush (null , null ));
62- expectThrows (UnsupportedOperationException .class , () -> engine .ensureTranslogSynced (null ));
6357 assertThat (engine .refreshNeeded (), equalTo (false ));
6458 assertThat (engine .shouldPeriodicallyFlush (), equalTo (false ));
6559 engine .close ();
@@ -106,63 +100,6 @@ public void testNoopAfterRegularEngine() throws IOException {
106100 noOpEngine .close ();
107101 }
108102
109- public void testNoopEngineWithInvalidTranslogUUID () throws IOException {
110- IOUtils .close (engine , store );
111- final AtomicLong globalCheckpoint = new AtomicLong (SequenceNumbers .NO_OPS_PERFORMED );
112- try (Store store = createStore ()) {
113- EngineConfig config = config (defaultSettings , store , createTempDir (), newMergePolicy (), null , null , globalCheckpoint ::get );
114- int numDocs = scaledRandomIntBetween (10 , 100 );
115- try (InternalEngine engine = createEngine (config )) {
116- for (int i = 0 ; i < numDocs ; i ++) {
117- ParsedDocument doc = testParsedDocument (Integer .toString (i ), null , testDocument (), new BytesArray ("{}" ), null );
118- engine .index (new Engine .Index (newUid (doc ), doc , i , primaryTerm .get (), 1 , null , Engine .Operation .Origin .REPLICA ,
119- System .nanoTime (), -1 , false , SequenceNumbers .UNASSIGNED_SEQ_NO , 0 ));
120- if (rarely ()) {
121- engine .flush ();
122- }
123- globalCheckpoint .set (engine .getLocalCheckpoint ());
124- }
125- flushAndTrimTranslog (engine );
126- }
127-
128- final Path newTranslogDir = createTempDir ();
129- // A new translog will have a different UUID than the existing store/noOp engine does
130- Translog newTranslog = createTranslog (newTranslogDir , () -> 1L );
131- newTranslog .close ();
132-
133- EngineCreationFailureException e = expectThrows (EngineCreationFailureException .class ,
134- () -> new NoOpEngine (noOpConfig (INDEX_SETTINGS , store , newTranslogDir )));
135- assertThat (e .getCause (), instanceOf (TranslogCorruptedException .class ));
136- }
137- }
138-
139- public void testNoopEngineWithNonZeroTranslogOperations () throws IOException {
140- IOUtils .close (engine , store );
141- final AtomicLong globalCheckpoint = new AtomicLong (SequenceNumbers .NO_OPS_PERFORMED );
142- try (Store store = createStore ()) {
143- final MergePolicy mergePolicy = NoMergePolicy .INSTANCE ;
144- EngineConfig config = config (defaultSettings , store , createTempDir (), mergePolicy , null , null , globalCheckpoint ::get );
145- int numDocs = scaledRandomIntBetween (10 , 100 );
146- try (InternalEngine engine = createEngine (config )) {
147- for (int i = 0 ; i < numDocs ; i ++) {
148- ParsedDocument doc = testParsedDocument (Integer .toString (i ), null , testDocument (), new BytesArray ("{}" ), null );
149- engine .index (new Engine .Index (newUid (doc ), doc , i , primaryTerm .get (), 1 , null , Engine .Operation .Origin .REPLICA ,
150- System .nanoTime (), -1 , false , SequenceNumbers .UNASSIGNED_SEQ_NO , 0 ));
151- if (rarely ()) {
152- engine .flush ();
153- }
154- globalCheckpoint .set (engine .getLocalCheckpoint ());
155- }
156- engine .syncTranslog ();
157- engine .flushAndClose ();
158- engine .close ();
159-
160- IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> new NoOpEngine (engine .engineConfig ));
161- assertThat (e .getMessage (), is ("Expected 0 translog operations but there were " + numDocs ));
162- }
163- }
164- }
165-
166103 public void testNoOpEngineDocStats () throws Exception {
167104 IOUtils .close (engine , store );
168105 final AtomicLong globalCheckpoint = new AtomicLong (SequenceNumbers .NO_OPS_PERFORMED );
0 commit comments