ES Learning Notes-simple Learning for Integration testing
The use of integration testing in es source code is relatively simple. My chosen entry point is the delete-by-query plug-in.
After importing the source code of the es plug-in into intellij, run the class DeleteByQueryRestIT directly, and all the integration test cases will be run.
-ea-Dtests.security.manager=false
The result of this operation will give me two questions:
There is no test annotated method in this class. Where is the entrance? There is only one yaml file in the resource/rest-api-spec directory. Where do these test cases come from?
By looking at its parent class ESRestTestCase, you can see the test method with test annotations in it, and by setting a breakpoint, you can determine that the method is the entrance to the test.
So where do more than 500 test cases come from?
See the method of the ESRestTestCase class @ BeforeClass annotation
BeforeClass public static void initExecutionContext () throws IOException, RestException {String [] specPaths = resolvePathsProperty (REST_TESTS_SPEC, DEFAULT_SPEC_PATH); RestSpec restSpec = null; FileSystem fileSystem = getFileSystem (); / / don't make a try-with, getFileSystem returns null / /. And you can't close () the default filesystem try {restSpec = RestSpec.parseFrom (fileSystem, DEFAULT_SPEC_PATH, specPaths);} finally {IOUtils.close (fileSystem);} validateSpec (restSpec); restTestExecutionContext = new RestTestExecutionContext (restSpec);}
By understanding the source code of this method, you can see that these test cases are integrated in elasticsearch-2.4.5-tests.jar.
The source code for these test cases is in the elasticsearch/rest-api-spec directory.
So how do you run only the test cases in the plug-in and ignore the test cases in the jar package?
-Dtests.rest.load_packaged=false
If you run it directly, you will find that the test case failed. It turns out that delete-by-query 's test cases are dependent. Compile the source code first:
Modify the elasticsearch/pom.xml file of the project source code before compilation, and you can't skip the integration test.
False
Then compile the delete-by-query plug-in
Elasticsearch/plugins/delete-by-query$ mvn install
Run the DeleteByQueryRestIT class after compilation to run the plug-in's test case successfully.
-ea-Dtests.security.manager=false-Dtests.rest.load_packaged=false
The test case here enables a separate es cluster to run the test case, and then shutdown. Its functionality is provided by the following script:
Elasticsearch/dev-tools/src/main/resources/integration-tests.xml
Reference:
Http://david.pilato.fr/blog/2016/10/18/elasticsearch-real-integration-tests-updated-for-ga/
Once you understand the running process of the integration test plug-in, you can implement the integration test function on your own when developing the plug-in. And through the way of yaml+json, test cases can be reused.