|
8 | 8 |
|
9 | 9 | package org.elasticsearch.action.admin.indices.create;
|
10 | 10 |
|
| 11 | +import org.elasticsearch.action.ActionListener; |
11 | 12 | import org.elasticsearch.action.admin.indices.alias.Alias;
|
12 | 13 | import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
13 | 14 | import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
|
|
17 | 18 | import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
|
18 | 19 | import org.elasticsearch.action.admin.indices.template.delete.DeleteComposableIndexTemplateAction;
|
19 | 20 | import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction;
|
| 21 | +import org.elasticsearch.action.bulk.BulkRequest; |
| 22 | +import org.elasticsearch.action.bulk.BulkResponse; |
| 23 | +import org.elasticsearch.action.index.IndexRequest; |
20 | 24 | import org.elasticsearch.action.support.IndicesOptions;
|
| 25 | +import org.elasticsearch.client.internal.Client; |
21 | 26 | import org.elasticsearch.cluster.metadata.AliasMetadata;
|
22 | 27 | import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
|
23 | 28 | import org.elasticsearch.cluster.metadata.MappingMetadata;
|
|
40 | 45 | import java.util.List;
|
41 | 46 | import java.util.Map;
|
42 | 47 | import java.util.Set;
|
| 48 | +import java.util.concurrent.CountDownLatch; |
| 49 | +import java.util.concurrent.TimeUnit; |
43 | 50 | import java.util.stream.Collectors;
|
44 | 51 |
|
45 | 52 | import static org.elasticsearch.indices.TestSystemIndexDescriptor.INDEX_NAME;
|
@@ -201,6 +208,31 @@ private void doCreateTest(Runnable runnable, String concreteIndex) {
|
201 | 208 | assertAliases(concreteIndex);
|
202 | 209 | }
|
203 | 210 |
|
| 211 | + public void testConcurrentAutoCreates() throws InterruptedException { |
| 212 | + internalCluster().startNodes(3); |
| 213 | + |
| 214 | + final Client client = client(); |
| 215 | + final int count = randomIntBetween(5, 30); |
| 216 | + final CountDownLatch latch = new CountDownLatch(count); |
| 217 | + final ActionListener<BulkResponse> listener = new ActionListener<>() { |
| 218 | + @Override |
| 219 | + public void onResponse(BulkResponse o) { |
| 220 | + latch.countDown(); |
| 221 | + assertFalse(o.hasFailures()); |
| 222 | + } |
| 223 | + |
| 224 | + @Override |
| 225 | + public void onFailure(Exception e) { |
| 226 | + latch.countDown(); |
| 227 | + throw new AssertionError(e); |
| 228 | + } |
| 229 | + }; |
| 230 | + for (int i = 0; i < count; i++) { |
| 231 | + client.bulk(new BulkRequest().add(new IndexRequest(INDEX_NAME).source(Map.of("foo", "bar"))), listener); |
| 232 | + } |
| 233 | + assertTrue(latch.await(30L, TimeUnit.SECONDS)); |
| 234 | + } |
| 235 | + |
204 | 236 | /**
|
205 | 237 | * Make sure that aliases are created hidden
|
206 | 238 | */
|
|
0 commit comments