forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The REST layer can now be tested through tests that are shared between all the elasticsearch official clients. The tests are based on REST specification that can be found on the elasticsearch-rest-api-spec project and consist of YAML files that describe the operations to be executed and the obtained results that need to be tested. REST tests can be executed through the ElasticsearchRestTests class, which relies on the rest-spec git submodule that contains the rest spec and tests pulled from the elasticsearch-rest-spec-api project. The rest-spec submodule gets automatically initialized and updated through maven (generate-test-resources phase). The REST runner and the needed classes are distributed within the test artifact. The following are the options supported by the REST tests runner: - tests.rest[true|false|host:port]: determines whether the REST tests need to be run and if so whether to rely on an external cluster (providing host and port) or fire a test cluster (default) - tests.rest.suite: comma separated paths of the test suites to be run (by default loaded from /rest-spec/test classpath). it is possible to run only a subset of the tests providing a sub-folder or even a single yaml file (the default /rest-spec/test prefix is optional when files are loaded from classpath) e.g. -Dtests.rest.suite=index,get,create/10_with_id - tests.rest.spec: REST spec path (default /rest-spec/api from classpath) - tests.iters: runs multiple iterations - tests.seed: seed to base the random behaviours on - tests.appendseed[true|false]: enables adding the seed to each test section's description (default false) - tests.cluster_seed: seed used to create the test cluster (if enabled) Closes elastic#4469
- Loading branch information
Showing
71 changed files
with
6,869 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "rest-spec"] | ||
path = rest-spec | ||
url = [email protected]:elasticsearch/elasticsearch-rest-api-spec.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/test/java/com/carrotsearch/randomizedtesting/StandaloneRandomizedContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to ElasticSearch and Shay Banon under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. ElasticSearch licenses this | ||
* file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.carrotsearch.randomizedtesting; | ||
|
||
/** | ||
* Exposes methods that allow to use a {@link RandomizedContext} without using a {@link RandomizedRunner} | ||
* This was specifically needed by the REST tests since they run with a custom junit runner ({@link org.elasticsearch.test.rest.junit.RestTestSuiteRunner}) | ||
*/ | ||
public final class StandaloneRandomizedContext { | ||
|
||
private StandaloneRandomizedContext() { | ||
|
||
} | ||
|
||
/** | ||
* Creates a new {@link RandomizedContext} associated to the current thread | ||
*/ | ||
public static void createRandomizedContext(Class<?> testClass, Randomness runnerRandomness) { | ||
//the randomized runner is passed in as null, which is fine as long as we don't try to access it afterwards | ||
RandomizedContext randomizedContext = RandomizedContext.create(Thread.currentThread().getThreadGroup(), testClass, null); | ||
randomizedContext.push(runnerRandomness.clone(Thread.currentThread())); | ||
} | ||
|
||
/** | ||
* Destroys the {@link RandomizedContext} associated to the current thread | ||
*/ | ||
public static void disposeRandomizedContext() { | ||
RandomizedContext.current().dispose(); | ||
} | ||
|
||
public static void pushRandomness(Randomness randomness) { | ||
RandomizedContext.current().push(randomness); | ||
} | ||
|
||
public static void popAndDestroy() { | ||
RandomizedContext.current().popAndDestroy(); | ||
} | ||
|
||
/** | ||
* Returns the string formatted seed associated to the current thread's randomized context | ||
*/ | ||
public static String getSeedAsString() { | ||
return SeedUtils.formatSeed(RandomizedContext.current().getRandomness().getSeed()); | ||
} | ||
|
||
/** | ||
* Util method to extract the seed out of a {@link Randomness} instance | ||
*/ | ||
public static long getSeed(Randomness randomness) { | ||
return randomness.getSeed(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.