|
22 | 22 | import org.elasticsearch.xcontent.XContentParser;
|
23 | 23 |
|
24 | 24 | import java.io.IOException;
|
25 |
| -import java.util.Arrays; |
26 | 25 | import java.util.Collections;
|
27 | 26 | import java.util.HashMap;
|
28 | 27 | import java.util.List;
|
@@ -141,187 +140,52 @@ protected Predicate<String> getRandomFieldsExcludeFilter() {
|
141 | 140 |
|
142 | 141 | @Override
|
143 | 142 | protected ClusterIndexHealth mutateInstance(ClusterIndexHealth instance) {
|
144 |
| - String mutate = randomFrom( |
145 |
| - "index", |
146 |
| - "numberOfShards", |
147 |
| - "numberOfReplicas", |
148 |
| - "activeShards", |
149 |
| - "relocatingShards", |
150 |
| - "initializingShards", |
151 |
| - "unassignedShards", |
152 |
| - "unassignedPrimaryShards", |
153 |
| - "activePrimaryShards", |
154 |
| - "status", |
155 |
| - "shards" |
156 |
| - ); |
157 |
| - switch (mutate) { |
158 |
| - case "index": |
159 |
| - return new ClusterIndexHealth( |
160 |
| - instance.getIndex() + randomAlphaOfLengthBetween(2, 5), |
161 |
| - instance.getNumberOfShards(), |
162 |
| - instance.getNumberOfReplicas(), |
163 |
| - instance.getActiveShards(), |
164 |
| - instance.getRelocatingShards(), |
165 |
| - instance.getInitializingShards(), |
166 |
| - instance.getUnassignedShards(), |
167 |
| - instance.getUnassignedPrimaryShards(), |
168 |
| - instance.getActivePrimaryShards(), |
169 |
| - instance.getStatus(), |
170 |
| - instance.getShards() |
171 |
| - ); |
172 |
| - case "numberOfShards": |
173 |
| - return new ClusterIndexHealth( |
174 |
| - instance.getIndex(), |
175 |
| - instance.getNumberOfShards() + between(1, 10), |
176 |
| - instance.getNumberOfReplicas(), |
177 |
| - instance.getActiveShards(), |
178 |
| - instance.getRelocatingShards(), |
179 |
| - instance.getInitializingShards(), |
180 |
| - instance.getUnassignedShards(), |
181 |
| - instance.getUnassignedPrimaryShards(), |
182 |
| - instance.getActivePrimaryShards(), |
183 |
| - instance.getStatus(), |
184 |
| - instance.getShards() |
185 |
| - ); |
186 |
| - case "numberOfReplicas": |
187 |
| - return new ClusterIndexHealth( |
188 |
| - instance.getIndex(), |
189 |
| - instance.getNumberOfShards(), |
190 |
| - instance.getNumberOfReplicas() + between(1, 10), |
191 |
| - instance.getActiveShards(), |
192 |
| - instance.getRelocatingShards(), |
193 |
| - instance.getInitializingShards(), |
194 |
| - instance.getUnassignedShards(), |
195 |
| - instance.getUnassignedPrimaryShards(), |
196 |
| - instance.getActivePrimaryShards(), |
197 |
| - instance.getStatus(), |
198 |
| - instance.getShards() |
199 |
| - ); |
200 |
| - case "activeShards": |
201 |
| - return new ClusterIndexHealth( |
202 |
| - instance.getIndex(), |
203 |
| - instance.getNumberOfShards(), |
204 |
| - instance.getNumberOfReplicas(), |
205 |
| - instance.getActiveShards() + between(1, 10), |
206 |
| - instance.getRelocatingShards(), |
207 |
| - instance.getInitializingShards(), |
208 |
| - instance.getUnassignedShards(), |
209 |
| - instance.getUnassignedPrimaryShards(), |
210 |
| - instance.getActivePrimaryShards(), |
211 |
| - instance.getStatus(), |
212 |
| - instance.getShards() |
213 |
| - ); |
214 |
| - case "relocatingShards": |
215 |
| - return new ClusterIndexHealth( |
216 |
| - instance.getIndex(), |
217 |
| - instance.getNumberOfShards(), |
218 |
| - instance.getNumberOfReplicas(), |
219 |
| - instance.getActiveShards(), |
220 |
| - instance.getRelocatingShards() + between(1, 10), |
221 |
| - instance.getInitializingShards(), |
222 |
| - instance.getUnassignedShards(), |
223 |
| - instance.getUnassignedPrimaryShards(), |
224 |
| - instance.getActivePrimaryShards(), |
225 |
| - instance.getStatus(), |
226 |
| - instance.getShards() |
227 |
| - ); |
228 |
| - case "initializingShards": |
229 |
| - return new ClusterIndexHealth( |
230 |
| - instance.getIndex(), |
231 |
| - instance.getNumberOfShards(), |
232 |
| - instance.getNumberOfReplicas(), |
233 |
| - instance.getActiveShards(), |
234 |
| - instance.getRelocatingShards(), |
235 |
| - instance.getInitializingShards() + between(1, 10), |
236 |
| - instance.getUnassignedShards(), |
237 |
| - instance.getUnassignedPrimaryShards(), |
238 |
| - instance.getActivePrimaryShards(), |
239 |
| - instance.getStatus(), |
240 |
| - instance.getShards() |
241 |
| - ); |
242 |
| - case "unassignedShards": |
243 |
| - return new ClusterIndexHealth( |
244 |
| - instance.getIndex(), |
245 |
| - instance.getNumberOfShards(), |
246 |
| - instance.getNumberOfReplicas(), |
247 |
| - instance.getActiveShards(), |
248 |
| - instance.getRelocatingShards(), |
249 |
| - instance.getInitializingShards(), |
250 |
| - instance.getUnassignedShards() + between(1, 10), |
251 |
| - instance.getUnassignedPrimaryShards(), |
252 |
| - instance.getActivePrimaryShards(), |
253 |
| - instance.getStatus(), |
254 |
| - instance.getShards() |
255 |
| - ); |
256 |
| - case "unassignedPrimaryShards": |
257 |
| - return new ClusterIndexHealth( |
258 |
| - instance.getIndex(), |
259 |
| - instance.getNumberOfShards(), |
260 |
| - instance.getNumberOfReplicas(), |
261 |
| - instance.getActiveShards(), |
262 |
| - instance.getRelocatingShards(), |
263 |
| - instance.getInitializingShards(), |
264 |
| - instance.getUnassignedShards(), |
265 |
| - instance.getUnassignedPrimaryShards() + between(1, 10), |
266 |
| - instance.getActivePrimaryShards(), |
267 |
| - instance.getStatus(), |
268 |
| - instance.getShards() |
269 |
| - ); |
270 |
| - case "activePrimaryShards": |
271 |
| - return new ClusterIndexHealth( |
272 |
| - instance.getIndex(), |
273 |
| - instance.getNumberOfShards(), |
274 |
| - instance.getNumberOfReplicas(), |
275 |
| - instance.getActiveShards(), |
276 |
| - instance.getRelocatingShards(), |
277 |
| - instance.getInitializingShards(), |
278 |
| - instance.getUnassignedShards(), |
279 |
| - instance.getUnassignedPrimaryShards(), |
280 |
| - instance.getActivePrimaryShards() + between(1, 10), |
281 |
| - instance.getStatus(), |
282 |
| - instance.getShards() |
283 |
| - ); |
284 |
| - case "status": |
285 |
| - ClusterHealthStatus status = randomFrom( |
286 |
| - Arrays.stream(ClusterHealthStatus.values()).filter(value -> value.equals(instance.getStatus()) == false).toList() |
287 |
| - ); |
288 |
| - return new ClusterIndexHealth( |
289 |
| - instance.getIndex(), |
290 |
| - instance.getNumberOfShards(), |
291 |
| - instance.getNumberOfReplicas(), |
292 |
| - instance.getActiveShards(), |
293 |
| - instance.getRelocatingShards(), |
294 |
| - instance.getInitializingShards(), |
295 |
| - instance.getUnassignedShards(), |
296 |
| - instance.getUnassignedPrimaryShards(), |
297 |
| - instance.getActivePrimaryShards(), |
298 |
| - status, |
299 |
| - instance.getShards() |
300 |
| - ); |
301 |
| - case "shards": |
302 |
| - Map<Integer, ClusterShardHealth> map; |
| 143 | + String index = instance.getIndex(); |
| 144 | + int numberOfShards = instance.getNumberOfShards(); |
| 145 | + int numberOfReplicas = instance.getNumberOfReplicas(); |
| 146 | + int activeShards = instance.getActiveShards(); |
| 147 | + int relocatingShards = instance.getRelocatingShards(); |
| 148 | + int initializingShards = instance.getInitializingShards(); |
| 149 | + int unassignedShards = instance.getUnassignedShards(); |
| 150 | + int unassignedPrimaryShards = instance.getUnassignedPrimaryShards(); |
| 151 | + int activePrimaryShards = instance.getActivePrimaryShards(); |
| 152 | + ClusterHealthStatus status = instance.getStatus(); |
| 153 | + Map<Integer, ClusterShardHealth> shards = new HashMap<>(instance.getShards()); |
| 154 | + |
| 155 | + switch (randomIntBetween(0, 10)) { |
| 156 | + case 0 -> index += randomAlphaOfLengthBetween(2, 5); |
| 157 | + case 1 -> numberOfShards += between(1, 10); |
| 158 | + case 2 -> numberOfReplicas += between(1, 10); |
| 159 | + case 3 -> activeShards += between(1, 10); |
| 160 | + case 4 -> relocatingShards += between(1, 10); |
| 161 | + case 5 -> initializingShards += between(1, 10); |
| 162 | + case 6 -> unassignedShards += between(1, 10); |
| 163 | + case 7 -> unassignedPrimaryShards += between(1, 10); |
| 164 | + case 8 -> activePrimaryShards += between(1, 10); |
| 165 | + case 9 -> status = randomValueOtherThan(instance.getStatus(), () -> randomFrom(ClusterHealthStatus.values())); |
| 166 | + case 10 -> { |
303 | 167 | if (instance.getShards().isEmpty()) {
|
304 |
| - map = Collections.singletonMap(0, ClusterShardHealthTests.randomShardHealth(0)); |
| 168 | + shards = Map.of(0, ClusterShardHealthTests.randomShardHealth(0)); |
305 | 169 | } else {
|
306 |
| - map = new HashMap<>(instance.getShards()); |
307 |
| - map.remove(map.keySet().iterator().next()); |
| 170 | + shards.remove(shards.keySet().iterator().next()); |
308 | 171 | }
|
309 |
| - return new ClusterIndexHealth( |
310 |
| - instance.getIndex(), |
311 |
| - instance.getNumberOfShards(), |
312 |
| - instance.getNumberOfReplicas(), |
313 |
| - instance.getActiveShards(), |
314 |
| - instance.getRelocatingShards(), |
315 |
| - instance.getInitializingShards(), |
316 |
| - instance.getUnassignedShards(), |
317 |
| - instance.getUnassignedPrimaryShards(), |
318 |
| - instance.getActivePrimaryShards(), |
319 |
| - instance.getStatus(), |
320 |
| - map |
321 |
| - ); |
322 |
| - default: |
323 |
| - throw new UnsupportedOperationException(); |
| 172 | + } |
| 173 | + default -> throw new UnsupportedOperationException(); |
324 | 174 | }
|
| 175 | + |
| 176 | + return new ClusterIndexHealth( |
| 177 | + index, |
| 178 | + numberOfShards, |
| 179 | + numberOfReplicas, |
| 180 | + activeShards, |
| 181 | + relocatingShards, |
| 182 | + initializingShards, |
| 183 | + unassignedShards, |
| 184 | + unassignedPrimaryShards, |
| 185 | + activePrimaryShards, |
| 186 | + status, |
| 187 | + shards |
| 188 | + ); |
325 | 189 | }
|
326 | 190 |
|
327 | 191 | private static final ConstructingObjectParser<ClusterIndexHealth, String> PARSER = new ConstructingObjectParser<>(
|
|
0 commit comments