31
31
32
32
package org .opensearch .cluster .health ;
33
33
34
+ import org .opensearch .Version ;
35
+ import org .opensearch .cluster .metadata .IndexMetadata ;
34
36
import org .opensearch .cluster .routing .IndexShardRoutingTable ;
35
37
import org .opensearch .cluster .routing .RecoverySource ;
36
38
import org .opensearch .cluster .routing .ShardRouting ;
37
39
import org .opensearch .cluster .routing .ShardRoutingState ;
38
40
import org .opensearch .cluster .routing .TestShardRouting ;
39
41
import org .opensearch .cluster .routing .UnassignedInfo ;
42
+ import org .opensearch .common .settings .Settings ;
40
43
import org .opensearch .core .common .io .stream .Writeable ;
41
44
import org .opensearch .core .index .Index ;
42
45
import org .opensearch .core .index .shard .ShardId ;
@@ -64,8 +67,18 @@ public void testClusterShardGreenHealth() {
64
67
indexShardRoutingBuilder .addShard (
65
68
TestShardRouting .newShardRouting (indexName , shardID , "node_1" , null , false , ShardRoutingState .STARTED )
66
69
);
70
+
71
+ IndexMetadata .Builder indexMetadataBuilder = IndexMetadata .builder (indexName )
72
+ .settings (Settings .builder ()
73
+ .put (IndexMetadata .SETTING_VERSION_CREATED , Version .CURRENT )
74
+ .put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
75
+ .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 1 )
76
+ )
77
+ .creationDate (System .currentTimeMillis ());
78
+ IndexMetadata indexMetadata = indexMetadataBuilder .build ();
67
79
IndexShardRoutingTable indexShardRoutingTable = indexShardRoutingBuilder .build ();
68
- ClusterShardHealth clusterShardHealth = new ClusterShardHealth (shardID , indexShardRoutingTable );
80
+
81
+ ClusterShardHealth clusterShardHealth = new ClusterShardHealth (shardID , indexShardRoutingTable , indexMetadata );
69
82
assertEquals (2 , clusterShardHealth .getActiveShards ());
70
83
assertEquals (0 , clusterShardHealth .getInitializingShards ());
71
84
assertEquals (0 , clusterShardHealth .getRelocatingShards ());
@@ -112,7 +125,17 @@ public void testClusterShardYellowHealth() {
112
125
)
113
126
);
114
127
IndexShardRoutingTable indexShardRoutingTable = indexShardRoutingBuilder .build ();
115
- ClusterShardHealth clusterShardHealth = new ClusterShardHealth (shardID , indexShardRoutingTable );
128
+
129
+ IndexMetadata .Builder indexMetadataBuilder = IndexMetadata .builder (indexName )
130
+ .settings (Settings .builder ()
131
+ .put (IndexMetadata .SETTING_VERSION_CREATED , Version .CURRENT )
132
+ .put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
133
+ .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 1 )
134
+ )
135
+ .creationDate (System .currentTimeMillis ());
136
+ IndexMetadata indexMetadata = indexMetadataBuilder .build ();
137
+
138
+ ClusterShardHealth clusterShardHealth = new ClusterShardHealth (shardID , indexShardRoutingTable , indexMetadata );
116
139
assertEquals (2 , clusterShardHealth .getActiveShards ());
117
140
assertEquals (1 , clusterShardHealth .getInitializingShards ());
118
141
assertEquals (1 , clusterShardHealth .getRelocatingShards ());
@@ -150,7 +173,17 @@ public void testClusterShardRedHealth() {
150
173
TestShardRouting .newShardRouting (indexName , shardID , null , null , false , ShardRoutingState .UNASSIGNED )
151
174
);
152
175
IndexShardRoutingTable indexShardRoutingTable = indexShardRoutingBuilder .build ();
153
- ClusterShardHealth clusterShardHealth = new ClusterShardHealth (shardID , indexShardRoutingTable );
176
+
177
+ IndexMetadata .Builder indexMetadataBuilder = IndexMetadata .builder (indexName )
178
+ .settings (Settings .builder ()
179
+ .put (IndexMetadata .SETTING_VERSION_CREATED , Version .CURRENT )
180
+ .put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
181
+ .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 1 )
182
+ )
183
+ .creationDate (System .currentTimeMillis ());
184
+ IndexMetadata indexMetadata = indexMetadataBuilder .build ();
185
+
186
+ ClusterShardHealth clusterShardHealth = new ClusterShardHealth (shardID , indexShardRoutingTable , indexMetadata );
154
187
assertEquals (0 , clusterShardHealth .getActiveShards ());
155
188
assertEquals (0 , clusterShardHealth .getInitializingShards ());
156
189
assertEquals (0 , clusterShardHealth .getRelocatingShards ());
@@ -161,7 +194,15 @@ public void testClusterShardRedHealth() {
161
194
}
162
195
163
196
public void testShardRoutingNullCheck () {
164
- assertThrows (AssertionError .class , () -> ClusterShardHealth .getShardHealth (null , 0 , 0 ));
197
+ IndexMetadata .Builder indexMetadataBuilder = IndexMetadata .builder ("test" )
198
+ .settings (Settings .builder ()
199
+ .put (IndexMetadata .SETTING_VERSION_CREATED , Version .CURRENT )
200
+ .put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
201
+ .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 1 )
202
+ );
203
+ IndexMetadata indexMetadata = indexMetadataBuilder .build ();
204
+
205
+ assertThrows (AssertionError .class , () -> ClusterShardHealth .getShardHealth (null , 0 , 0 , indexMetadata ));
165
206
}
166
207
167
208
@ Override
0 commit comments