@@ -115,7 +115,7 @@ public void testRemoveBackingIndex() {
115
115
DataStream original = new DataStream (dataStreamName , createTimestampField ("@timestamp" ), indices );
116
116
DataStream updated = original .removeBackingIndex (indices .get (indexToRemove - 1 ));
117
117
assertThat (updated .getName (), equalTo (original .getName ()));
118
- assertThat (updated .getGeneration (), equalTo (original .getGeneration ()));
118
+ assertThat (updated .getGeneration (), equalTo (original .getGeneration () + 1 ));
119
119
assertThat (updated .getTimeStampField (), equalTo (original .getTimeStampField ()));
120
120
assertThat (updated .getIndices ().size (), equalTo (numBackingIndices - 1 ));
121
121
for (int k = 0 ; k < (numBackingIndices - 1 ); k ++) {
@@ -371,7 +371,7 @@ public void testReplaceBackingIndex() {
371
371
Index newBackingIndex = new Index ("replacement-index" , UUIDs .randomBase64UUID (random ()));
372
372
DataStream updated = original .replaceBackingIndex (indices .get (indexToReplace ), newBackingIndex );
373
373
assertThat (updated .getName (), equalTo (original .getName ()));
374
- assertThat (updated .getGeneration (), equalTo (original .getGeneration ()));
374
+ assertThat (updated .getGeneration (), equalTo (original .getGeneration () + 1 ));
375
375
assertThat (updated .getTimeStampField (), equalTo (original .getTimeStampField ()));
376
376
assertThat (updated .getIndices ().size (), equalTo (numBackingIndices ));
377
377
assertThat (updated .getIndices ().get (indexToReplace ), equalTo (newBackingIndex ));
@@ -407,10 +407,25 @@ public void testReplaceBackingIndexThrowsExceptionIfReplacingWriteIndex() {
407
407
for (int i = 1 ; i <= numBackingIndices ; i ++) {
408
408
indices .add (new Index (DataStream .getDefaultBackingIndexName (dataStreamName , i ), UUIDs .randomBase64UUID (random ())));
409
409
}
410
- DataStream original = new DataStream (dataStreamName , createTimestampField ("@timestamp" ), indices );
410
+ int generation = randomBoolean () ? numBackingIndices : numBackingIndices + randomIntBetween (1 , 5 );
411
+ DataStream original = new DataStream (dataStreamName , createTimestampField ("@timestamp" ), indices , generation , null );
411
412
412
413
Index newBackingIndex = new Index ("replacement-index" , UUIDs .randomBase64UUID (random ()));
413
- expectThrows (IllegalArgumentException .class , () -> original .replaceBackingIndex (indices .get (writeIndexPosition ), newBackingIndex ));
414
+ IllegalArgumentException e = expectThrows (
415
+ IllegalArgumentException .class ,
416
+ () -> original .replaceBackingIndex (indices .get (writeIndexPosition ), newBackingIndex )
417
+ );
418
+ assertThat (
419
+ e .getMessage (),
420
+ equalTo (
421
+ String .format (
422
+ Locale .ROOT ,
423
+ "cannot replace backing index [%s] of data stream [%s] because it is the write index" ,
424
+ indices .get (writeIndexPosition ).getName (),
425
+ dataStreamName
426
+ )
427
+ )
428
+ );
414
429
}
415
430
416
431
public void testSnapshot () {
0 commit comments