TESTING.asciidoc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 (default):
  16. ------------------------------------
  17. -Des.node.mode=network
  18. ------------------------------------
  19. Use local transport:
  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. === Seed and repetitions.
  44. Run with a given seed (seed is a hex-encoded long).
  45. ------------------------------
  46. mvn test -Dtests.seed=DEADBEEF
  47. ------------------------------
  48. === Repeats _all_ tests of ClassName N times.
  49. Every test repetition will have a different method seed
  50. (derived from a single random master seed).
  51. --------------------------------------------------
  52. mvn test -Dtests.iters=N -Dtests.class=*.ClassName
  53. --------------------------------------------------
  54. === Repeats _all_ tests of ClassName N times.
  55. Every test repetition will have exactly the same master (0xdead) and
  56. method-level (0xbeef) seed.
  57. ------------------------------------------------------------------------
  58. mvn test -Dtests.iters=N -Dtests.class=*.ClassName -Dtests.seed=DEAD:BEEF
  59. ------------------------------------------------------------------------
  60. === Repeats a given test N times
  61. (note the filters - individual test repetitions are given suffixes,
  62. ie: testFoo[0], testFoo[1], etc... so using testmethod or tests.method
  63. ending in a glob is necessary to ensure iterations are run).
  64. -------------------------------------------------------------------------
  65. mvn test -Dtests.iters=N -Dtests.class=*.ClassName -Dtests.method=mytest*
  66. -------------------------------------------------------------------------
  67. Repeats N times but skips any tests after the first failure or M initial failures.
  68. -------------------------------------------------------------
  69. mvn test -Dtests.iters=N -Dtests.failfast=true -Dtestcase=...
  70. mvn test -Dtests.iters=N -Dtests.maxfailures=M -Dtestcase=...
  71. -------------------------------------------------------------
  72. === Test groups.
  73. Test groups can be enabled or disabled (true/false).
  74. Default value provided below in [brackets].
  75. ------------------------------------------------------------------
  76. mvn test -Dtests.nightly=[false] - nightly test group (@Nightly)
  77. mvn test -Dtests.weekly=[false] - weekly tests (@Weekly)
  78. mvn test -Dtests.awaitsfix=[false] - known issue (@AwaitsFix)
  79. mvn test -Dtests.slow=[true] - slow tests (@Slow)
  80. ------------------------------------------------------------------
  81. === Load balancing and caches.
  82. By default, the tests run sequentially on a single forked JVM.
  83. To run with more forked JVMs than the default use:
  84. ----------------------------
  85. mvn test -Dtests.jvms=8 test
  86. ----------------------------
  87. Don't count hypercores for CPU-intense tests and leave some slack
  88. for JVM-internal threads (like the garbage collector). Make sure there is
  89. enough RAM to handle child JVMs.
  90. === Miscellaneous.
  91. Run all tests without stopping on errors (inspect log files).
  92. -----------------------------------------
  93. mvn test -Dtests.haltonfailure=false test
  94. -----------------------------------------
  95. Run more verbose output (slave JVM parameters, etc.).
  96. ----------------------
  97. mvn test -verbose test
  98. ----------------------
  99. Change the default suite timeout to 5 seconds for all
  100. tests (note the exclamation mark).
  101. ---------------------------------------
  102. mvn test -Dtests.timeoutSuite=5000! ...
  103. ---------------------------------------
  104. Change the logging level of ES (not mvn)
  105. --------------------------------
  106. mvn test -Des.logger.level=DEBUG
  107. --------------------------------
  108. Print all the logging output from the test runs to the commandline
  109. even if tests are passing.
  110. ------------------------------
  111. mvn test -Dtests.output=always
  112. ------------------------------
  113. == Testing the REST layer
  114. The available integration tests make use of the java API to communicate with
  115. the elasticsearch nodes, using the internal binary transport (port 9300 by
  116. default).
  117. The REST layer is tested through specific tests that are shared between all
  118. the elasticsearch official clients and consist of YAML files that describe the
  119. operations to be executed and the obtained results that need to be tested.
  120. The REST tests are run automatically when executing the maven test command. To run only the
  121. REST tests use the following command:
  122. ---------------------------------------------------------------------------
  123. mvn test -Dtests.class=org.elasticsearch.test.rest.ElasticsearchRestTests
  124. ---------------------------------------------------------------------------
  125. `ElasticsearchRestTests` is the executable test class that runs all the
  126. yaml suites available within the `rest-api-spec` folder.
  127. The REST tests support all the options provided by the randomized runner, plus the following:
  128. * `tests.rest[true|false]`: determines whether the REST tests need to be run (default) or not.
  129. * `tests.rest.suite`: comma separated paths of the test suites to be run
  130. (by default loaded from /rest-api-spec/test). It is possible to run only a subset
  131. of the tests providing a sub-folder or even a single yaml file (the default
  132. /rest-api-spec/test prefix is optional when files are loaded from classpath)
  133. e.g. -Dtests.rest.suite=index,get,create/10_with_id
  134. * `tests.rest.spec`: REST spec path (default /rest-api-spec/api)
  135. Note that the REST tests, like all the integration tests, can be run against an external
  136. cluster by specifying the `tests.cluster` property, which if present needs to contain a
  137. comma separated list of nodes to connect to (e.g. localhost:9300). A transport client will
  138. be created based on that and used for all the before|after test operations, and to extract
  139. the http addresses of the nodes so that REST requests can be sent to them.