|
@@ -8,20 +8,28 @@
|
|
|
|
|
|
package org.elasticsearch.action.admin.indices.create;
|
|
|
|
|
|
+import io.netty.handler.codec.http.HttpMethod;
|
|
|
+
|
|
|
import org.elasticsearch.action.ActionListener;
|
|
|
import org.elasticsearch.action.ActionRequestBuilder;
|
|
|
import org.elasticsearch.action.UnavailableShardsException;
|
|
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
|
|
import org.elasticsearch.action.admin.indices.alias.Alias;
|
|
|
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
|
|
+import org.elasticsearch.action.support.ActionTestUtils;
|
|
|
import org.elasticsearch.action.support.ActiveShardCount;
|
|
|
import org.elasticsearch.action.support.IndicesOptions;
|
|
|
+import org.elasticsearch.action.support.PlainActionFuture;
|
|
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
|
|
+import org.elasticsearch.client.Response;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetadata;
|
|
|
import org.elasticsearch.cluster.metadata.MappingMetadata;
|
|
|
import org.elasticsearch.cluster.metadata.Metadata;
|
|
|
+import org.elasticsearch.cluster.service.ClusterService;
|
|
|
+import org.elasticsearch.common.Priority;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
+import org.elasticsearch.common.util.concurrent.FutureUtils;
|
|
|
import org.elasticsearch.core.TimeValue;
|
|
|
import org.elasticsearch.index.IndexNotFoundException;
|
|
|
import org.elasticsearch.index.IndexService;
|
|
@@ -31,17 +39,24 @@ import org.elasticsearch.indices.IndicesService;
|
|
|
import org.elasticsearch.test.ESIntegTestCase;
|
|
|
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
|
|
import org.elasticsearch.test.ESIntegTestCase.Scope;
|
|
|
+import org.elasticsearch.test.rest.ESRestTestCase;
|
|
|
import org.elasticsearch.xcontent.XContentFactory;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
+import java.util.concurrent.CyclicBarrier;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.function.BiFunction;
|
|
|
|
|
|
+import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
|
|
|
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_WAIT_FOR_ACTIVE_SHARDS;
|
|
|
+import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue;
|
|
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
|
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBlocked;
|
|
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailuresAndResponse;
|
|
|
+import static org.elasticsearch.test.rest.ESRestTestCase.entityAsMap;
|
|
|
import static org.hamcrest.Matchers.allOf;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
|
@@ -53,6 +68,11 @@ import static org.hamcrest.core.IsNull.notNullValue;
|
|
|
@ClusterScope(scope = Scope.TEST)
|
|
|
public class CreateIndexIT extends ESIntegTestCase {
|
|
|
|
|
|
+ @Override
|
|
|
+ protected boolean addMockHttpTransport() {
|
|
|
+ return false; // expose HTTP requests
|
|
|
+ }
|
|
|
+
|
|
|
public void testCreationDateGivenFails() {
|
|
|
try {
|
|
|
prepareCreate("test").setSettings(Settings.builder().put(IndexMetadata.SETTING_CREATION_DATE, 4L)).get();
|
|
@@ -370,4 +390,38 @@ public class CreateIndexIT extends ESIntegTestCase {
|
|
|
assertEquals("Should have index name in response", "foo", response.index());
|
|
|
}
|
|
|
|
|
|
+ public void testInfiniteAckTimeout() throws IOException {
|
|
|
+ final var clusterService = internalCluster().getInstance(ClusterService.class);
|
|
|
+ final var barrier = new CyclicBarrier(2);
|
|
|
+ clusterService.getClusterApplierService().runOnApplierThread("block for test", Priority.NORMAL, cs -> {
|
|
|
+ safeAwait(barrier);
|
|
|
+ safeAwait(barrier);
|
|
|
+ }, ActionListener.noop());
|
|
|
+
|
|
|
+ safeAwait(barrier);
|
|
|
+
|
|
|
+ final var request = ESRestTestCase.newXContentRequest(
|
|
|
+ HttpMethod.PUT,
|
|
|
+ "testindex",
|
|
|
+ (builder, params) -> builder.startObject("settings")
|
|
|
+ .field(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
|
|
|
+ .field(SETTING_NUMBER_OF_REPLICAS, internalCluster().numDataNodes() - 1)
|
|
|
+ .endObject()
|
|
|
+ );
|
|
|
+ request.addParameter("timeout", "-1");
|
|
|
+ final var responseFuture = new PlainActionFuture<Response>();
|
|
|
+ getRestClient().performRequestAsync(request, ActionTestUtils.wrapAsRestResponseListener(responseFuture));
|
|
|
+
|
|
|
+ if (randomBoolean()) {
|
|
|
+ safeSleep(scaledRandomIntBetween(1, 100));
|
|
|
+ }
|
|
|
+
|
|
|
+ assertFalse(responseFuture.isDone());
|
|
|
+ safeAwait(barrier);
|
|
|
+
|
|
|
+ final var response = FutureUtils.get(responseFuture, 10, TimeUnit.SECONDS);
|
|
|
+ assertEquals(200, response.getStatusLine().getStatusCode());
|
|
|
+ assertTrue((boolean) extractValue("acknowledged", entityAsMap(response)));
|
|
|
+ }
|
|
|
+
|
|
|
}
|