21
21
22
22
import org .apache .lucene .index .DirectoryReader ;
23
23
import org .apache .lucene .index .IndexReader ;
24
- import org .apache .lucene .index .MergePolicy ;
25
24
import org .apache .lucene .index .NoMergePolicy ;
26
25
import org .apache .lucene .store .LockObtainFailedException ;
27
26
import org .elasticsearch .cluster .routing .IndexShardRoutingTable ;
28
27
import org .elasticsearch .cluster .routing .ShardRouting ;
29
28
import org .elasticsearch .cluster .routing .ShardRoutingState ;
30
29
import org .elasticsearch .cluster .routing .TestShardRouting ;
31
- import org .elasticsearch .common .bytes .BytesArray ;
32
30
import org .elasticsearch .common .settings .Settings ;
33
31
import org .elasticsearch .core .internal .io .IOUtils ;
34
32
import org .elasticsearch .index .IndexSettings ;
37
35
import org .elasticsearch .index .seqno .SequenceNumbers ;
38
36
import org .elasticsearch .index .shard .DocsStats ;
39
37
import org .elasticsearch .index .store .Store ;
40
- import org .elasticsearch .index .translog .Translog ;
41
- import org .elasticsearch .index .translog .TranslogCorruptedException ;
42
38
import org .elasticsearch .index .translog .TranslogDeletionPolicy ;
43
39
import org .elasticsearch .test .IndexSettingsModule ;
44
40
50
46
51
47
import static org .hamcrest .Matchers .equalTo ;
52
48
import static org .hamcrest .Matchers .instanceOf ;
53
- import static org .hamcrest .Matchers .is ;
54
49
55
50
public class NoOpEngineTests extends EngineTestCase {
56
51
private static final IndexSettings INDEX_SETTINGS = IndexSettingsModule .newIndexSettings ("index" , Settings .EMPTY );
@@ -59,7 +54,6 @@ public void testNoopEngine() throws IOException {
59
54
engine .close ();
60
55
final NoOpEngine engine = new NoOpEngine (noOpConfig (INDEX_SETTINGS , store , primaryTranslogDir ));
61
56
expectThrows (UnsupportedOperationException .class , () -> engine .syncFlush (null , null ));
62
- expectThrows (UnsupportedOperationException .class , () -> engine .ensureTranslogSynced (null ));
63
57
assertThat (engine .refreshNeeded (), equalTo (false ));
64
58
assertThat (engine .shouldPeriodicallyFlush (), equalTo (false ));
65
59
engine .close ();
@@ -106,63 +100,6 @@ public void testNoopAfterRegularEngine() throws IOException {
106
100
noOpEngine .close ();
107
101
}
108
102
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
-
166
103
public void testNoOpEngineDocStats () throws Exception {
167
104
IOUtils .close (engine , store );
168
105
final AtomicLong globalCheckpoint = new AtomicLong (SequenceNumbers .NO_OPS_PERFORMED );
0 commit comments