[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.
This commit is contained in:
parent
5343b87502
commit
5b459a0bdc
|
@ -21,6 +21,7 @@ package org.elasticsearch.test;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
||||||
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
|
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.action.RoutingMissingException;
|
import org.elasticsearch.action.RoutingMissingException;
|
||||||
import org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo;
|
import org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo;
|
||||||
|
@ -166,11 +167,11 @@ public final class RandomObjects {
|
||||||
for (int i = 0; i < numFields; i++) {
|
for (int i = 0; i < numFields; i++) {
|
||||||
if (currentDepth < 5 && random.nextBoolean()) {
|
if (currentDepth < 5 && random.nextBoolean()) {
|
||||||
if (random.nextBoolean()) {
|
if (random.nextBoolean()) {
|
||||||
builder.startObject(RandomStrings.randomAsciiOfLengthBetween(random, 3, 10));
|
builder.startObject(RandomStrings.randomAsciiOfLengthBetween(random, 4, 10));
|
||||||
addFields(random, builder, currentDepth + 1);
|
addFields(random, builder, currentDepth + 1);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
} else {
|
} else {
|
||||||
builder.startArray(RandomStrings.randomAsciiOfLengthBetween(random, 3, 10));
|
builder.startArray(RandomStrings.randomAsciiOfLengthBetween(random, 4, 10));
|
||||||
int numElements = randomIntBetween(random, 1, 5);
|
int numElements = randomIntBetween(random, 1, 5);
|
||||||
boolean object = random.nextBoolean();
|
boolean object = random.nextBoolean();
|
||||||
int dataType = -1;
|
int dataType = -1;
|
||||||
|
@ -189,7 +190,7 @@ public final class RandomObjects {
|
||||||
builder.endArray();
|
builder.endArray();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
builder.field(RandomStrings.randomAsciiOfLengthBetween(random, 3, 10),
|
builder.field(RandomStrings.randomAsciiOfLengthBetween(random, 4, 10),
|
||||||
randomFieldValue(random, randomDataType(random)));
|
randomFieldValue(random, randomDataType(random)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue