From 5b459a0bdcb05e20d9d0cc0a0326f6fa5d0994c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Tue, 14 Feb 2017 11:31:17 +0100 Subject: [PATCH] [Tests] increase minimal field name when creating random objects I encountered several cases of duplicate field names when generating random fields using the RandomObjects helper. This leads to invalid json in some tests, so increasing the minimum field name length to four to make this less likely to happen. --- .../main/java/org/elasticsearch/test/RandomObjects.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/RandomObjects.java b/test/framework/src/main/java/org/elasticsearch/test/RandomObjects.java index 7611c17492e..54e1b779b6c 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/RandomObjects.java +++ b/test/framework/src/main/java/org/elasticsearch/test/RandomObjects.java @@ -21,6 +21,7 @@ package org.elasticsearch.test; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.carrotsearch.randomizedtesting.generators.RandomStrings; + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.RoutingMissingException; import org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo; @@ -166,11 +167,11 @@ public final class RandomObjects { for (int i = 0; i < numFields; i++) { if (currentDepth < 5 && random.nextBoolean()) { if (random.nextBoolean()) { - builder.startObject(RandomStrings.randomAsciiOfLengthBetween(random, 3, 10)); + builder.startObject(RandomStrings.randomAsciiOfLengthBetween(random, 4, 10)); addFields(random, builder, currentDepth + 1); builder.endObject(); } else { - builder.startArray(RandomStrings.randomAsciiOfLengthBetween(random, 3, 10)); + builder.startArray(RandomStrings.randomAsciiOfLengthBetween(random, 4, 10)); int numElements = randomIntBetween(random, 1, 5); boolean object = random.nextBoolean(); int dataType = -1; @@ -189,7 +190,7 @@ public final class RandomObjects { builder.endArray(); } } else { - builder.field(RandomStrings.randomAsciiOfLengthBetween(random, 3, 10), + builder.field(RandomStrings.randomAsciiOfLengthBetween(random, 4, 10), randomFieldValue(random, randomDataType(random))); } }