TESTING.asciidoc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. [[Testing Framework Cheatsheet]]
  2. = Testing
  3. [partintro]
  4. Elasticsearch uses jUnit for testing, it also uses randomness in the
  5. tests, that can be set using a seed, the following is a cheatsheet of
  6. options for running the tests for ES.
  7. == Creating packages
  8. To create a distribution without running the tests, simply run the
  9. following:
  10. -----------------------------
  11. mvn clean package -DskipTests
  12. -----------------------------
  13. == Other test options
  14. To disable and enable network transport, set the `Des.node.mode`.
  15. Use network transport:
  16. ------------------------------------
  17. -Des.node.mode=network
  18. ------------------------------------
  19. Use local transport (default since 1.3):
  20. -------------------------------------
  21. -Des.node.mode=local
  22. -------------------------------------
  23. Alternatively, you can set the `ES_TEST_LOCAL` environment variable:
  24. -------------------------------------
  25. export ES_TEST_LOCAL=true && mvn test
  26. -------------------------------------
  27. === Test case filtering.
  28. - `tests.class` is a class-filtering shell-like glob pattern,
  29. - `tests.method` is a method-filtering glob pattern.
  30. Run a single test case (variants)
  31. ----------------------------------------------------------
  32. mvn test -Dtests.class=org.elasticsearch.package.ClassName
  33. mvn test "-Dtests.class=*.ClassName"
  34. ----------------------------------------------------------
  35. Run all tests in a package and sub-packages
  36. ----------------------------------------------------
  37. mvn test "-Dtests.class=org.elasticsearch.package.*"
  38. ----------------------------------------------------
  39. Run any test methods that contain 'esi' (like: ...r*esi*ze...).
  40. -------------------------------
  41. mvn test "-Dtests.method=*esi*"
  42. -------------------------------
  43. You can also filter tests by certain annotations ie:
  44. * `@Slow` - tests that are know to take a long time to execute
  45. * `@Nightly` - tests that only run in nightly builds (disabled by default)
  46. * `@Integration` - integration tests
  47. * `@Backwards` - backwards compatibility tests (disabled by default)
  48. * `@AwaitsFix` - tests that are waiting for a bugfix (disabled by default)
  49. * `@BadApple` - tests that are known to fail randomly (disabled by default)
  50. Those annotation names can be combined into a filter expression like:
  51. ------------------------------------------------
  52. mvn test -Dtests.filter="@nightly and not @slow"
  53. ------------------------------------------------
  54. to run all nightly test but not the ones that are slow. `tests.filter` supports
  55. the boolean operators `and, or, not` and grouping ie:
  56. ---------------------------------------------------------------
  57. mvn test -Dtests.filter="@nightly and not(@slow or @backwards)"
  58. ---------------------------------------------------------------
  59. === Seed and repetitions.
  60. Run with a given seed (seed is a hex-encoded long).
  61. ------------------------------
  62. mvn test -Dtests.seed=DEADBEEF
  63. ------------------------------
  64. === Repeats _all_ tests of ClassName N times.
  65. Every test repetition will have a different method seed
  66. (derived from a single random master seed).
  67. --------------------------------------------------
  68. mvn test -Dtests.iters=N -Dtests.class=*.ClassName
  69. --------------------------------------------------
  70. === Repeats _all_ tests of ClassName N times.
  71. Every test repetition will have exactly the same master (0xdead) and
  72. method-level (0xbeef) seed.
  73. ------------------------------------------------------------------------
  74. mvn test -Dtests.iters=N -Dtests.class=*.ClassName -Dtests.seed=DEAD:BEEF
  75. ------------------------------------------------------------------------
  76. === Repeats a given test N times
  77. (note the filters - individual test repetitions are given suffixes,
  78. ie: testFoo[0], testFoo[1], etc... so using testmethod or tests.method
  79. ending in a glob is necessary to ensure iterations are run).
  80. -------------------------------------------------------------------------
  81. mvn test -Dtests.iters=N -Dtests.class=*.ClassName -Dtests.method=mytest*
  82. -------------------------------------------------------------------------
  83. Repeats N times but skips any tests after the first failure or M initial failures.
  84. -------------------------------------------------------------
  85. mvn test -Dtests.iters=N -Dtests.failfast=true -Dtestcase=...
  86. mvn test -Dtests.iters=N -Dtests.maxfailures=M -Dtestcase=...
  87. -------------------------------------------------------------
  88. === Test groups.
  89. Test groups can be enabled or disabled (true/false).
  90. Default value provided below in [brackets].
  91. ------------------------------------------------------------------
  92. mvn test -Dtests.nightly=[false] - nightly test group (@Nightly)
  93. mvn test -Dtests.weekly=[false] - weekly tests (@Weekly)
  94. mvn test -Dtests.awaitsfix=[false] - known issue (@AwaitsFix)
  95. mvn test -Dtests.slow=[true] - slow tests (@Slow)
  96. ------------------------------------------------------------------
  97. === Load balancing and caches.
  98. By default, the tests run sequentially on a single forked JVM.
  99. To run with more forked JVMs than the default use:
  100. ----------------------------
  101. mvn test -Dtests.jvms=8 test
  102. ----------------------------
  103. Don't count hypercores for CPU-intense tests and leave some slack
  104. for JVM-internal threads (like the garbage collector). Make sure there is
  105. enough RAM to handle child JVMs.
  106. === Test compatibility.
  107. It is possible to provide a version that allows to adapt the tests behaviour
  108. to older features or bugs that have been changed or fixed in the meantime.
  109. -----------------------------------------
  110. mvn test -Dtests.compatibility=1.0.0
  111. -----------------------------------------
  112. === Miscellaneous.
  113. Run all tests without stopping on errors (inspect log files).
  114. -----------------------------------------
  115. mvn test -Dtests.haltonfailure=false test
  116. -----------------------------------------
  117. Run more verbose output (slave JVM parameters, etc.).
  118. ----------------------
  119. mvn test -verbose test
  120. ----------------------
  121. Change the default suite timeout to 5 seconds for all
  122. tests (note the exclamation mark).
  123. ---------------------------------------
  124. mvn test -Dtests.timeoutSuite=5000! ...
  125. ---------------------------------------
  126. Change the logging level of ES (not mvn)
  127. --------------------------------
  128. mvn test -Des.logger.level=DEBUG
  129. --------------------------------
  130. Print all the logging output from the test runs to the commandline
  131. even if tests are passing.
  132. ------------------------------
  133. mvn test -Dtests.output=always
  134. ------------------------------
  135. Configure the heap size.
  136. ------------------------------
  137. mvn test -Dtests.heap.size=512m
  138. ------------------------------
  139. Pass arbitrary jvm arguments.
  140. ------------------------------
  141. mvn test -Dtests.jvm.argline="-XX:HeapDumpPath=/path/to/heapdumps"
  142. ------------------------------
  143. == Backwards Compatibility Tests
  144. Running backwards compatibility tests is disabled by default since it
  145. requires a release version of elasticsearch to be present on the test system.
  146. To run backwards compatibiilty tests untar or unzip a release and run the tests
  147. with the following command:
  148. ---------------------------------------------------------------------------
  149. mvn test -Dtests.filter="@backwards" -Dtests.bwc.version=x.y.z -Dtests.bwc.path=/path/to/elasticsearch
  150. ---------------------------------------------------------------------------
  151. If the elasticsearch release is placed under `./backwards/elasticsearch-x.y.z` the path
  152. can be omitted:
  153. ---------------------------------------------------------------------------
  154. mvn test -Dtests.filter="@backwards" -Dtests.bwc.version=x.y.z
  155. ---------------------------------------------------------------------------
  156. To setup the bwc test environment execute the following steps (provided you are
  157. already in your elasticsearch clone):
  158. ---------------------------------------------------------------------------
  159. $ mkdir backwards && cd backwards
  160. $ curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.2.1.tar.gz
  161. $ tar -xzf elasticsearch-1.2.1.tar.gz
  162. ---------------------------------------------------------------------------
  163. == Testing the REST layer
  164. The available integration tests make use of the java API to communicate with
  165. the elasticsearch nodes, using the internal binary transport (port 9300 by
  166. default).
  167. The REST layer is tested through specific tests that are shared between all
  168. the elasticsearch official clients and consist of YAML files that describe the
  169. operations to be executed and the obtained results that need to be tested.
  170. The REST tests are run automatically when executing the maven test command. To run only the
  171. REST tests use the following command:
  172. ---------------------------------------------------------------------------
  173. mvn test -Dtests.class=org.elasticsearch.test.rest.ElasticsearchRestTests
  174. ---------------------------------------------------------------------------
  175. `ElasticsearchRestTests` is the executable test class that runs all the
  176. yaml suites available within the `rest-api-spec` folder.
  177. The REST tests support all the options provided by the randomized runner, plus the following:
  178. * `tests.rest[true|false]`: determines whether the REST tests need to be run (default) or not.
  179. * `tests.rest.suite`: comma separated paths of the test suites to be run
  180. (by default loaded from /rest-api-spec/test). It is possible to run only a subset
  181. of the tests providing a sub-folder or even a single yaml file (the default
  182. /rest-api-spec/test prefix is optional when files are loaded from classpath)
  183. e.g. -Dtests.rest.suite=index,get,create/10_with_id
  184. * `tests.rest.blacklist`: comma separated globs that identify tests that are
  185. blacklisted and need to be skipped
  186. e.g. -Dtests.rest.blacklist=index/*/Index document,get/10_basic/*
  187. * `tests.rest.spec`: REST spec path (default /rest-api-spec/api)
  188. Note that the REST tests, like all the integration tests, can be run against an external
  189. cluster by specifying the `tests.cluster` property, which if present needs to contain a
  190. comma separated list of nodes to connect to (e.g. localhost:9300). A transport client will
  191. be created based on that and used for all the before|after test operations, and to extract
  192. the http addresses of the nodes so that REST requests can be sent to them.
  193. == Skip validate
  194. To disable validation step (forbidden API or `// NOCOMMIT`) use
  195. ---------------------------------------------------------------------------
  196. mvn test -Dvalidate.skip=true
  197. ---------------------------------------------------------------------------
  198. You can also skip this by using the "dev" profile:
  199. ---------------------------------------------------------------------------
  200. mvn test -Pdev
  201. ---------------------------------------------------------------------------