Clean up update tests

This commit is contained in:
Martijn van Groningen 2013-06-30 18:28:24 +02:00
parent fdec15f204
commit 751d4ab68e

View File

@ -20,13 +20,10 @@
package org.elasticsearch.test.integration.update;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateRequestBuilder;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.index.VersionType;
@ -139,9 +136,7 @@ public class UpdateTests extends AbstractSharedClusterTest {
@Test
public void testUpsert() throws Exception {
createIndex();
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
ensureGreen();
UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1")
.setUpsertRequest(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject())
@ -170,9 +165,7 @@ public class UpdateTests extends AbstractSharedClusterTest {
@Test
public void testUpsertDoc() throws Exception {
createIndex();
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
ensureGreen();
UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1")
.setDoc(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject())
@ -184,11 +177,10 @@ public class UpdateTests extends AbstractSharedClusterTest {
}
@Test
// See: https://github.com/elasticsearch/elasticsearch/issues/3265
public void testNotUpsertDoc() throws Exception {
createIndex();
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
ensureGreen();
assertThrows(client().prepareUpdate("test", "type1", "1")
.setDoc(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject())
@ -200,9 +192,7 @@ public class UpdateTests extends AbstractSharedClusterTest {
@Test
public void testUpsertFields() throws Exception {
createIndex();
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
ensureGreen();
UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1")
.setUpsertRequest(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject())
@ -281,12 +271,6 @@ public class UpdateTests extends AbstractSharedClusterTest {
@Test
public void testIndexAutoCreation() throws Exception {
try {
client().admin().indices().prepareDelete("test").execute().actionGet();
} catch (Exception e) {
// ignore
}
UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1")
.setUpsertRequest(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject())
.setScript("ctx._source.extra = \"foo\"")
@ -301,9 +285,7 @@ public class UpdateTests extends AbstractSharedClusterTest {
@Test
public void testUpdate() throws Exception {
createIndex();
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
ensureGreen();
try {
client().prepareUpdate("test", "type1", "1").setScript("ctx._source.field++").execute().actionGet();
@ -361,9 +343,7 @@ public class UpdateTests extends AbstractSharedClusterTest {
.endObject())
.setRefresh(true)
.execute().actionGet();
clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
ensureGreen();
updateResponse = client().prepareUpdate("test", "type1", "1").setScript("ctx._source.field += 1").setPercolate("*").execute().actionGet();
assertThat(updateResponse.getMatches().size(), equalTo(1));
@ -446,9 +426,7 @@ public class UpdateTests extends AbstractSharedClusterTest {
@Test
public void testUpdateRequestWithBothScriptAndDoc() throws Exception {
createIndex();
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
ensureGreen();
try {
client().prepareUpdate("test", "type1", "1")
@ -466,9 +444,7 @@ public class UpdateTests extends AbstractSharedClusterTest {
@Test
public void testUpdateRequestWithScriptAndShouldUpsertDoc() throws Exception {
createIndex();
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
ensureGreen();
try {
client().prepareUpdate("test", "type1", "1")
.setScript("ctx._source.field += 1")
@ -477,8 +453,8 @@ public class UpdateTests extends AbstractSharedClusterTest {
fail("Should have thrown ActionRequestValidationException");
} catch (ActionRequestValidationException e) {
assertThat(e.validationErrors().size(), equalTo(1));
assertThat(e.validationErrors().get(0), containsString("can't say to upsert doc without providing doc"));
assertThat(e.getMessage(), containsString("can't say to upsert doc without providing doc"));
assertThat(e.validationErrors().get(0), containsString("doc must be specified if doc_as_upsert is enabled"));
assertThat(e.getMessage(), containsString("doc must be specified if doc_as_upsert is enabled"));
}
}
@ -494,9 +470,7 @@ public class UpdateTests extends AbstractSharedClusterTest {
private void concurrentUpdateWithRetryOnConflict(final boolean useBulkApi) throws Exception {
createIndex();
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
ensureGreen();
int numberOfThreads = 5;
final CountDownLatch latch = new CountDownLatch(numberOfThreads);