[TEST] make completion tests more resilient to delayed mapping

especially the tests that check for update of mapping, we need to make sure that the cluster is green so mappings won't get override, also, put mapping during index creation when possible
This commit is contained in:
Shay Banon 2014-07-09 22:18:55 +02:00
parent 610900b781
commit 94539979c7
1 changed files with 22 additions and 25 deletions

View File

@ -831,10 +831,9 @@ public class CompletionSuggestSearchTests extends ElasticsearchIntegrationTest {
} }
private void createIndexAndMappingAndSettings(Settings settings, CompletionMappingBuilder completionMappingBuilder) throws IOException { private void createIndexAndMappingAndSettings(Settings settings, CompletionMappingBuilder completionMappingBuilder) throws IOException {
client().admin().indices().prepareCreate(INDEX) assertAcked(client().admin().indices().prepareCreate(INDEX)
.setSettings(ImmutableSettings.settingsBuilder().put(indexSettings()).put(settings)) .setSettings(ImmutableSettings.settingsBuilder().put(indexSettings()).put(settings))
.get(); .addMapping(TYPE, jsonBuilder().startObject()
assertAcked(client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(jsonBuilder().startObject()
.startObject(TYPE).startObject("properties") .startObject(TYPE).startObject("properties")
.startObject(FIELD) .startObject(FIELD)
.field("type", "completion") .field("type", "completion")
@ -845,7 +844,8 @@ public class CompletionSuggestSearchTests extends ElasticsearchIntegrationTest {
.field("preserve_position_increments", completionMappingBuilder.preservePositionIncrements) .field("preserve_position_increments", completionMappingBuilder.preservePositionIncrements)
.endObject() .endObject()
.endObject().endObject() .endObject().endObject()
.endObject())); .endObject())
.get());
ensureYellow(); ensureYellow();
} }
@ -934,11 +934,12 @@ public class CompletionSuggestSearchTests extends ElasticsearchIntegrationTest {
@Test @Test
public void testMaxFieldLength() throws IOException { public void testMaxFieldLength() throws IOException {
client().admin().indices().prepareCreate(INDEX).get(); client().admin().indices().prepareCreate(INDEX).get();
ensureGreen();
int iters = scaledRandomIntBetween(10, 20); int iters = scaledRandomIntBetween(10, 20);
for (int i = 0; i < iters; i++) { for (int i = 0; i < iters; i++) {
int maxInputLen = between(3, 50); int maxInputLen = between(3, 50);
String str = replaceReservedChars(randomRealisticUnicodeOfCodepointLengthBetween(maxInputLen + 1, maxInputLen + scaledRandomIntBetween(2, 50)), (char) 0x01); String str = replaceReservedChars(randomRealisticUnicodeOfCodepointLengthBetween(maxInputLen + 1, maxInputLen + scaledRandomIntBetween(2, 50)), (char) 0x01);
ElasticsearchAssertions.assertAcked(client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(jsonBuilder().startObject() assertAcked(client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(jsonBuilder().startObject()
.startObject(TYPE).startObject("properties") .startObject(TYPE).startObject("properties")
.startObject(FIELD) .startObject(FIELD)
.field("type", "completion") .field("type", "completion")
@ -948,7 +949,6 @@ public class CompletionSuggestSearchTests extends ElasticsearchIntegrationTest {
.endObject() .endObject()
.endObject().endObject() .endObject().endObject()
.endObject())); .endObject()));
ensureYellow();
client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder() client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()
.startObject().startObject(FIELD) .startObject().startObject(FIELD)
.startArray("input").value(str).endArray() .startArray("input").value(str).endArray()
@ -972,14 +972,13 @@ public class CompletionSuggestSearchTests extends ElasticsearchIntegrationTest {
@Test @Test
// see #3596 // see #3596
public void testVeryLongInput() throws IOException { public void testVeryLongInput() throws IOException {
client().admin().indices().prepareCreate(INDEX).get(); assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, jsonBuilder().startObject()
ElasticsearchAssertions.assertAcked(client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(jsonBuilder().startObject()
.startObject(TYPE).startObject("properties") .startObject(TYPE).startObject("properties")
.startObject(FIELD) .startObject(FIELD)
.field("type", "completion") .field("type", "completion")
.endObject() .endObject()
.endObject().endObject() .endObject().endObject()
.endObject())); .endObject()).get());
ensureYellow(); ensureYellow();
// can cause stack overflow without the default max_input_length // can cause stack overflow without the default max_input_length
String longString = replaceReservedChars(randomRealisticUnicodeOfLength(randomIntBetween(5000, 10000)), (char) 0x01); String longString = replaceReservedChars(randomRealisticUnicodeOfLength(randomIntBetween(5000, 10000)), (char) 0x01);
@ -995,14 +994,13 @@ public class CompletionSuggestSearchTests extends ElasticsearchIntegrationTest {
// see #3648 // see #3648
@Test(expected = MapperParsingException.class) @Test(expected = MapperParsingException.class)
public void testReservedChars() throws IOException { public void testReservedChars() throws IOException {
client().admin().indices().prepareCreate(INDEX).get(); assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, jsonBuilder().startObject()
ElasticsearchAssertions.assertAcked(client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(jsonBuilder().startObject()
.startObject(TYPE).startObject("properties") .startObject(TYPE).startObject("properties")
.startObject(FIELD) .startObject(FIELD)
.field("type", "completion") .field("type", "completion")
.endObject() .endObject()
.endObject().endObject() .endObject().endObject()
.endObject())); .endObject()).get());
ensureYellow(); ensureYellow();
// can cause stack overflow without the default max_input_length // can cause stack overflow without the default max_input_length
String string = "foo" + (char) 0x00 + "bar"; String string = "foo" + (char) 0x00 + "bar";
@ -1016,14 +1014,13 @@ public class CompletionSuggestSearchTests extends ElasticsearchIntegrationTest {
@Test // see #5930 @Test // see #5930
public void testIssue5930() throws IOException { public void testIssue5930() throws IOException {
client().admin().indices().prepareCreate(INDEX).get(); assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, jsonBuilder().startObject()
ElasticsearchAssertions.assertAcked(client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(jsonBuilder().startObject()
.startObject(TYPE).startObject("properties") .startObject(TYPE).startObject("properties")
.startObject(FIELD) .startObject(FIELD)
.field("type", "completion") .field("type", "completion")
.endObject() .endObject()
.endObject().endObject() .endObject().endObject()
.endObject())); .endObject()).get());
ensureYellow(); ensureYellow();
String string = "foo bar"; String string = "foo bar";
client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder() client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()