|
12 | 12 | import static org.mockito.ArgumentMatchers.anyString;
|
13 | 13 | import static org.mockito.ArgumentMatchers.eq;
|
14 | 14 | import static org.mockito.Mockito.doAnswer;
|
| 15 | +import static org.mockito.Mockito.doNothing; |
15 | 16 | import static org.mockito.Mockito.doReturn;
|
16 | 17 | import static org.mockito.Mockito.doThrow;
|
17 | 18 | import static org.mockito.Mockito.mock;
|
|
26 | 27 | import java.time.ZoneOffset;
|
27 | 28 | import java.time.ZonedDateTime;
|
28 | 29 | import java.time.format.DateTimeFormatter;
|
| 30 | +import java.util.Collections; |
29 | 31 | import java.util.List;
|
30 | 32 | import java.util.Locale;
|
31 | 33 | import java.util.Map;
|
32 | 34 | import java.util.concurrent.CompletableFuture;
|
33 | 35 | import java.util.concurrent.CountDownLatch;
|
34 | 36 | import java.util.concurrent.TimeUnit;
|
35 | 37 | import org.junit.Before;
|
| 38 | +import org.mockito.ArgumentCaptor; |
| 39 | +import org.opensearch.action.admin.indices.create.CreateIndexRequest; |
36 | 40 | import org.opensearch.action.admin.indices.exists.indices.IndicesExistsRequest;
|
37 | 41 | import org.opensearch.action.admin.indices.template.get.GetComposableIndexTemplateAction;
|
38 | 42 | import org.opensearch.action.admin.indices.template.put.PutComposableIndexTemplateAction;
|
@@ -371,4 +375,34 @@ public void testReadIndexMappingsWithEmptyMapping() throws IOException {
|
371 | 375 | LocalIndexExporter exporter = new LocalIndexExporter(client, clusterService, format, "", "id");
|
372 | 376 | assertEquals("{}", exporter.readIndexMappings());
|
373 | 377 | }
|
| 378 | + |
| 379 | + /** |
| 380 | + * Test that createIndex correctly sets auto_expand_replicas |
| 381 | + */ |
| 382 | + public void testCreateIndexWithAutoExpandReplicas() throws IOException { |
| 383 | + LocalIndexExporter exporterSpy = spy(new LocalIndexExporter(client, clusterService, format, "{}", "id")); |
| 384 | + |
| 385 | + ArgumentCaptor<CreateIndexRequest> requestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class); |
| 386 | + |
| 387 | + // Mock the client.admin().indices().create() call |
| 388 | + AdminClient adminClient = mock(AdminClient.class); |
| 389 | + IndicesAdminClient indicesClient = mock(IndicesAdminClient.class); |
| 390 | + when(client.admin()).thenReturn(adminClient); |
| 391 | + when(adminClient.indices()).thenReturn(indicesClient); |
| 392 | + |
| 393 | + doNothing().when(indicesClient).create(requestCaptor.capture(), any(ActionListener.class)); |
| 394 | + exporterSpy.createIndexAndBulk("test-index", Collections.emptyList()); |
| 395 | + |
| 396 | + // Verify the captured request |
| 397 | + CreateIndexRequest capturedRequest = requestCaptor.getValue(); |
| 398 | + Settings settings = capturedRequest.settings(); |
| 399 | + |
| 400 | + // Verify the settings use auto_expand_replicas |
| 401 | + assertEquals("test-index", capturedRequest.index()); |
| 402 | + assertEquals("0-2", settings.get("index.auto_expand_replicas")); |
| 403 | + assertEquals("1", settings.get("index.number_of_shards")); |
| 404 | + |
| 405 | + // Verify there is no number_of_replicas setting. |
| 406 | + assertNull(settings.get("index.number_of_replicas")); |
| 407 | + } |
374 | 408 | }
|
0 commit comments