2424import java .util .HashMap ;
2525import java .util .List ;
2626import java .util .Map ;
27+ import java .util .stream .Collectors ;
2728
2829import static java .util .Collections .singletonList ;
30+ import static java .util .Map .entry ;
31+ import static java .util .Map .ofEntries ;
2932import static org .elasticsearch .xpack .deprecation .DeprecationChecks .DATA_STREAM_CHECKS ;
3033import static org .hamcrest .Matchers .equalTo ;
3134
3235public class DataStreamDeprecationChecksTests extends ESTestCase {
3336
3437 public void testOldIndicesCheck () {
35- long oldIndexCount = randomIntBetween (1 , 100 );
36- long newIndexCount = randomIntBetween (1 , 100 );
37- long oldSearchableSnapshotCount = 0 ;
38- long oldFullyManagedSearchableSnapshotCount = 0 ;
39- long oldPartiallyManagedSearchableSnapshotCount = 0 ;
38+ int oldIndexCount = randomIntBetween (1 , 100 );
39+ int newIndexCount = randomIntBetween (1 , 100 );
40+
4041 List <Index > allIndices = new ArrayList <>();
4142 Map <String , IndexMetadata > nameToIndexMetadata = new HashMap <>();
43+
4244 for (int i = 0 ; i < oldIndexCount ; i ++) {
4345 Settings .Builder settingsBuilder = settings (IndexVersion .fromId (7170099 ));
44- if (randomBoolean ()) {
45- settingsBuilder .put ("index.store.type" , "snapshot" );
46- if (randomBoolean ()) {
47- oldFullyManagedSearchableSnapshotCount ++;
48- } else {
49- settingsBuilder .put ("index.store.snapshot.partial" , true );
50- oldPartiallyManagedSearchableSnapshotCount ++;
51- }
52- oldSearchableSnapshotCount ++;
53- }
5446 IndexMetadata oldIndexMetadata = IndexMetadata .builder ("old-data-stream-index-" + i )
5547 .settings (settingsBuilder )
5648 .numberOfShards (1 )
@@ -59,11 +51,9 @@ public void testOldIndicesCheck() {
5951 allIndices .add (oldIndexMetadata .getIndex ());
6052 nameToIndexMetadata .put (oldIndexMetadata .getIndex ().getName (), oldIndexMetadata );
6153 }
54+
6255 for (int i = 0 ; i < newIndexCount ; i ++) {
6356 Settings .Builder settingsBuilder = settings (IndexVersion .current ());
64- if (randomBoolean ()) {
65- settingsBuilder .put ("index.store.type" , "snapshot" );
66- }
6757 IndexMetadata newIndexMetadata = IndexMetadata .builder ("new-data-stream-index-" + i )
6858 .settings (settingsBuilder )
6959 .numberOfShards (1 )
@@ -72,6 +62,7 @@ public void testOldIndicesCheck() {
7262 allIndices .add (newIndexMetadata .getIndex ());
7363 nameToIndexMetadata .put (newIndexMetadata .getIndex ().getName (), newIndexMetadata );
7464 }
65+
7566 DataStream dataStream = new DataStream (
7667 randomAlphaOfLength (10 ),
7768 allIndices ,
@@ -88,37 +79,33 @@ public void testOldIndicesCheck() {
8879 randomBoolean (),
8980 null
9081 );
82+
9183 Metadata metadata = Metadata .builder ().indices (nameToIndexMetadata ).build ();
9284 ClusterState clusterState = ClusterState .builder (ClusterName .DEFAULT ).metadata (metadata ).build ();
85+
9386 DeprecationIssue expected = new DeprecationIssue (
9487 DeprecationIssue .Level .CRITICAL ,
9588 "Old data stream with a compatibility version < 8.0" ,
9689 "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html" ,
9790 "This data stream has backing indices that were created before Elasticsearch 8.0.0" ,
9891 false ,
99- Map .of (
100- "backing_indices" ,
101- Map .of (
102- "count" ,
103- oldIndexCount + newIndexCount ,
104- "need_upgrading" ,
105- Map .of (
106- "count" ,
107- oldIndexCount ,
108- "searchable_snapshots" ,
109- Map .of (
110- "count" ,
111- oldSearchableSnapshotCount ,
112- "fully_mounted" ,
113- Map .of ("count" , oldFullyManagedSearchableSnapshotCount ),
114- "partially_mounted" ,
115- Map .of ("count" , oldPartiallyManagedSearchableSnapshotCount )
116- )
117- )
92+ ofEntries (
93+ entry ("reindex_required" , true ),
94+ entry ("total_backing_indicies" , oldIndexCount + newIndexCount ),
95+ entry ("indicies_requiring_upgrade_count" , oldIndexCount ),
96+ entry (
97+ "indicies_requiring_upgrade" ,
98+ nameToIndexMetadata .keySet ()
99+ .stream ()
100+ .filter (name -> name .startsWith ("old-data-stream-index-" ))
101+ .collect (Collectors .toUnmodifiableSet ())
118102 )
119103 )
120104 );
105+
121106 List <DeprecationIssue > issues = DeprecationChecks .filterChecks (DATA_STREAM_CHECKS , c -> c .apply (dataStream , clusterState ));
107+
122108 assertThat (issues , equalTo (singletonList (expected )));
123109 }
110+
124111}
0 commit comments