Skip to content

Commit

Permalink
Rename random ASCII helper methods
Browse files Browse the repository at this point in the history
This commit renames the random ASCII helper methods in ESTestCase. This
is because this method ultimately uses the random ASCII methods from
randomized runner, but these methods actually only produce random
strings generated from [a-zA-Z].

Relates #23886
  • Loading branch information
jasontedor authored Apr 4, 2017
1 parent a01f772 commit 3136ed1
Show file tree
Hide file tree
Showing 335 changed files with 1,156 additions and 1,222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public void testGet() {
}

public void testDelete() throws IOException {
String index = randomAsciiOfLengthBetween(3, 10);
String type = randomAsciiOfLengthBetween(3, 10);
String id = randomAsciiOfLengthBetween(3, 10);
String index = randomAlphaOfLengthBetween(3, 10);
String type = randomAlphaOfLengthBetween(3, 10);
String id = randomAlphaOfLengthBetween(3, 10);
DeleteRequest deleteRequest = new DeleteRequest(index, type, id);

Map<String, String> expectedParams = new HashMap<>();
Expand All @@ -93,12 +93,12 @@ public void testDelete() throws IOException {

if (frequently()) {
if (randomBoolean()) {
String routing = randomAsciiOfLengthBetween(3, 10);
String routing = randomAlphaOfLengthBetween(3, 10);
deleteRequest.routing(routing);
expectedParams.put("routing", routing);
}
if (randomBoolean()) {
String parent = randomAsciiOfLengthBetween(3, 10);
String parent = randomAlphaOfLengthBetween(3, 10);
deleteRequest.parent(parent);
expectedParams.put("parent", parent);
}
Expand All @@ -116,20 +116,20 @@ public void testExists() {
}

private static void getAndExistsTest(Function<GetRequest, Request> requestConverter, String method) {
String index = randomAsciiOfLengthBetween(3, 10);
String type = randomAsciiOfLengthBetween(3, 10);
String id = randomAsciiOfLengthBetween(3, 10);
String index = randomAlphaOfLengthBetween(3, 10);
String type = randomAlphaOfLengthBetween(3, 10);
String id = randomAlphaOfLengthBetween(3, 10);
GetRequest getRequest = new GetRequest(index, type, id);

Map<String, String> expectedParams = new HashMap<>();
if (randomBoolean()) {
if (randomBoolean()) {
String preference = randomAsciiOfLengthBetween(3, 10);
String preference = randomAlphaOfLengthBetween(3, 10);
getRequest.preference(preference);
expectedParams.put("preference", preference);
}
if (randomBoolean()) {
String routing = randomAsciiOfLengthBetween(3, 10);
String routing = randomAlphaOfLengthBetween(3, 10);
getRequest.routing(routing);
expectedParams.put("routing", routing);
}
Expand Down Expand Up @@ -166,7 +166,7 @@ private static void getAndExistsTest(Function<GetRequest, Request> requestConver
String[] storedFields = new String[numStoredFields];
StringBuilder storedFieldsParam = new StringBuilder();
for (int i = 0; i < numStoredFields; i++) {
String storedField = randomAsciiOfLengthBetween(3, 10);
String storedField = randomAlphaOfLengthBetween(3, 10);
storedFields[i] = storedField;
storedFieldsParam.append(storedField);
if (i < numStoredFields - 1) {
Expand All @@ -188,11 +188,11 @@ private static void getAndExistsTest(Function<GetRequest, Request> requestConver
}

public void testIndex() throws IOException {
String index = randomAsciiOfLengthBetween(3, 10);
String type = randomAsciiOfLengthBetween(3, 10);
String index = randomAlphaOfLengthBetween(3, 10);
String type = randomAlphaOfLengthBetween(3, 10);
IndexRequest indexRequest = new IndexRequest(index, type);

String id = randomBoolean() ? randomAsciiOfLengthBetween(3, 10) : null;
String id = randomBoolean() ? randomAlphaOfLengthBetween(3, 10) : null;
indexRequest.id(id);

Map<String, String> expectedParams = new HashMap<>();
Expand All @@ -219,17 +219,17 @@ public void testIndex() throws IOException {

if (frequently()) {
if (randomBoolean()) {
String routing = randomAsciiOfLengthBetween(3, 10);
String routing = randomAlphaOfLengthBetween(3, 10);
indexRequest.routing(routing);
expectedParams.put("routing", routing);
}
if (randomBoolean()) {
String parent = randomAsciiOfLengthBetween(3, 10);
String parent = randomAlphaOfLengthBetween(3, 10);
indexRequest.parent(parent);
expectedParams.put("parent", parent);
}
if (randomBoolean()) {
String pipeline = randomAsciiOfLengthBetween(3, 10);
String pipeline = randomAlphaOfLengthBetween(3, 10);
indexRequest.setPipeline(pipeline);
expectedParams.put("pipeline", pipeline);
}
Expand Down Expand Up @@ -270,9 +270,9 @@ public void testUpdate() throws IOException {
XContentType xContentType = randomFrom(XContentType.values());

Map<String, String> expectedParams = new HashMap<>();
String index = randomAsciiOfLengthBetween(3, 10);
String type = randomAsciiOfLengthBetween(3, 10);
String id = randomAsciiOfLengthBetween(3, 10);
String index = randomAlphaOfLengthBetween(3, 10);
String type = randomAlphaOfLengthBetween(3, 10);
String id = randomAlphaOfLengthBetween(3, 10);

UpdateRequest updateRequest = new UpdateRequest(index, type, id);
updateRequest.detectNoop(randomBoolean());
Expand All @@ -295,12 +295,12 @@ public void testUpdate() throws IOException {
updateRequest.upsert(new IndexRequest().source(source, xContentType));
}
if (randomBoolean()) {
String routing = randomAsciiOfLengthBetween(3, 10);
String routing = randomAlphaOfLengthBetween(3, 10);
updateRequest.routing(routing);
expectedParams.put("routing", routing);
}
if (randomBoolean()) {
String parent = randomAsciiOfLengthBetween(3, 10);
String parent = randomAlphaOfLengthBetween(3, 10);
updateRequest.parent(parent);
expectedParams.put("parent", parent);
}
Expand Down Expand Up @@ -416,9 +416,9 @@ public void testBulk() throws IOException {

int nbItems = randomIntBetween(10, 100);
for (int i = 0; i < nbItems; i++) {
String index = randomAsciiOfLength(5);
String type = randomAsciiOfLength(5);
String id = randomAsciiOfLength(5);
String index = randomAlphaOfLength(5);
String type = randomAlphaOfLength(5);
String id = randomAlphaOfLength(5);

BytesReference source = RandomObjects.randomSource(random(), xContentType);
DocWriteRequest.OpType opType = randomFrom(DocWriteRequest.OpType.values());
Expand All @@ -428,16 +428,16 @@ public void testBulk() throws IOException {
IndexRequest indexRequest = new IndexRequest(index, type, id).source(source, xContentType);
docWriteRequest = indexRequest;
if (randomBoolean()) {
indexRequest.setPipeline(randomAsciiOfLength(5));
indexRequest.setPipeline(randomAlphaOfLength(5));
}
if (randomBoolean()) {
indexRequest.parent(randomAsciiOfLength(5));
indexRequest.parent(randomAlphaOfLength(5));
}
} else if (opType == DocWriteRequest.OpType.CREATE) {
IndexRequest createRequest = new IndexRequest(index, type, id).source(source, xContentType).create(true);
docWriteRequest = createRequest;
if (randomBoolean()) {
createRequest.parent(randomAsciiOfLength(5));
createRequest.parent(randomAlphaOfLength(5));
}
} else if (opType == DocWriteRequest.OpType.UPDATE) {
final UpdateRequest updateRequest = new UpdateRequest(index, type, id).doc(new IndexRequest().source(source, xContentType));
Expand All @@ -449,14 +449,14 @@ public void testBulk() throws IOException {
randomizeFetchSourceContextParams(updateRequest::fetchSource, new HashMap<>());
}
if (randomBoolean()) {
updateRequest.parent(randomAsciiOfLength(5));
updateRequest.parent(randomAlphaOfLength(5));
}
} else if (opType == DocWriteRequest.OpType.DELETE) {
docWriteRequest = new DeleteRequest(index, type, id);
}

if (randomBoolean()) {
docWriteRequest.routing(randomAsciiOfLength(10));
docWriteRequest.routing(randomAlphaOfLength(10));
}
if (randomBoolean()) {
docWriteRequest.version(randomNonNegativeLong());
Expand Down Expand Up @@ -591,7 +591,7 @@ public void testParams() {
Map<String, String> expectedParams = new HashMap<>();
for (int i = 0; i < nbParams; i++) {
String paramName = "p_" + i;
String paramValue = randomAsciiOfLength(5);
String paramValue = randomAlphaOfLength(5);
params.putParam(paramName, paramValue);
expectedParams.put(paramName, paramValue);
}
Expand Down Expand Up @@ -665,7 +665,7 @@ private static void randomizeFetchSourceContextParams(Consumer<FetchSourceContex
String[] includes = new String[numIncludes];
StringBuilder includesParam = new StringBuilder();
for (int i = 0; i < numIncludes; i++) {
String include = randomAsciiOfLengthBetween(3, 10);
String include = randomAlphaOfLengthBetween(3, 10);
includes[i] = include;
includesParam.append(include);
if (i < numIncludes - 1) {
Expand All @@ -679,7 +679,7 @@ private static void randomizeFetchSourceContextParams(Consumer<FetchSourceContex
String[] excludes = new String[numExcludes];
StringBuilder excludesParam = new StringBuilder();
for (int i = 0; i < numExcludes; i++) {
String exclude = randomAsciiOfLengthBetween(3, 10);
String exclude = randomAlphaOfLengthBetween(3, 10);
excludes[i] = exclude;
excludesParam.append(exclude);
if (i < numExcludes - 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ private void testRandomAsciiTextCase(BreakIterator bi, int maxLen) {
String[] vocabulary = new String[maxSize];
for (int i = 0; i < maxSize; i++) {
if (rarely()) {
vocabulary[i] = randomAsciiOfLengthBetween(50, 200);
vocabulary[i] = randomAlphaOfLengthBetween(50, 200);
} else {
vocabulary[i] = randomAsciiOfLengthBetween(1, 30);
vocabulary[i] = randomAlphaOfLengthBetween(1, 30);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/org/elasticsearch/BuildTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testEqualsAndHashCode() {
assertEquals(build, another);
assertEquals(build.hashCode(), another.hashCode());

Build differentHash = new Build(randomAsciiOfLengthBetween(3, 10), build.date(), build.isSnapshot());
Build differentHash = new Build(randomAlphaOfLengthBetween(3, 10), build.date(), build.isSnapshot());
assertNotEquals(build, differentHash);

Build differentDate = new Build(build.shortHash(), "1970-01-01", build.isSnapshot());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ public static Tuple<Throwable, ElasticsearchException> randomExceptions() {

int nbValues = randomIntBetween(1, 3);
for (int j = 0; j < nbValues; j++) {
values.add(frequently() ? randomAsciiOfLength(5) : "");
values.add(frequently() ? randomAlphaOfLength(5) : "");
}
randomHeaders.put("header_" + i, values);
}
Expand All @@ -943,7 +943,7 @@ public static Tuple<Throwable, ElasticsearchException> randomExceptions() {

int nbValues = randomIntBetween(1, 3);
for (int j = 0; j < nbValues; j++) {
values.add(frequently() ? randomAsciiOfLength(5) : "");
values.add(frequently() ? randomAlphaOfLength(5) : "");
}
randomMetadata.put("es.metadata_" + i, values);
}
Expand All @@ -965,7 +965,7 @@ public static Tuple<Throwable, ElasticsearchException> randomExceptions() {
String resourceType = "type_" + i;
String[] resourceIds = new String[randomIntBetween(1, 3)];
for (int j = 0; j < resourceIds.length; j++) {
resourceIds[j] = frequently() ? randomAsciiOfLength(5) : "";
resourceIds[j] = frequently() ? randomAlphaOfLength(5) : "";
}
actualException.setResources(resourceType, resourceIds);
expected.setResources(resourceType, resourceIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ public void testWithRestHeadersException() throws IOException {
}

public void testNoLongerPrimaryShardException() throws IOException {
ShardId shardId = new ShardId(new Index(randomAsciiOfLength(4), randomAsciiOfLength(4)), randomIntBetween(0, Integer.MAX_VALUE));
String msg = randomAsciiOfLength(4);
ShardId shardId = new ShardId(new Index(randomAlphaOfLength(4), randomAlphaOfLength(4)), randomIntBetween(0, Integer.MAX_VALUE));
String msg = randomAlphaOfLength(4);
ShardStateAction.NoLongerPrimaryShardException ex = serialize(new ShardStateAction.NoLongerPrimaryShardException(shardId, msg));
assertEquals(shardId, ex.getShardId());
assertEquals(msg, ex.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static OriginalIndices randomOriginalIndices() {
int numIndices = randomInt(10);
String[] indices = new String[numIndices];
for (int j = 0; j < indices.length; j++) {
indices[j] = randomAsciiOfLength(randomIntBetween(1, 10));
indices[j] = randomAlphaOfLength(randomIntBetween(1, 10));
}
IndicesOptions indicesOptions = randomFrom(indicesOptionsValues);
return new OriginalIndices(indices, indicesOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class ClusterAllocationExplainRequestTests extends ESTestCase {

public void testSerialization() throws Exception {
ClusterAllocationExplainRequest request =
new ClusterAllocationExplainRequest(randomAsciiOfLength(4), randomIntBetween(0, Integer.MAX_VALUE), randomBoolean(),
randomBoolean() ? randomAsciiOfLength(5) : null);
new ClusterAllocationExplainRequest(randomAlphaOfLength(4), randomIntBetween(0, Integer.MAX_VALUE), randomBoolean(),
randomBoolean() ? randomAlphaOfLength(5) : null);
request.includeYesDecisions(randomBoolean());
request.includeDiskInfo(randomBoolean());
BytesStreamOutput output = new BytesStreamOutput();
Expand Down
Loading

0 comments on commit 3136ed1

Please sign in to comment.