TESTING.asciidoc 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. [[TestingFrameworkCheatsheet]]
  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. ./gradlew assemble
  12. -----------------------------
  13. To create a platform-specific build including the x-pack modules, use the
  14. following depending on your operating system:
  15. -----------------------------
  16. ./gradlew :distribution:archives:linux-tar:assemble --parallel
  17. ./gradlew :distribution:archives:darwin-tar:assemble --parallel
  18. ./gradlew :distribution:archives:windows-zip:assemble --parallel
  19. -----------------------------
  20. === Running Elasticsearch from a checkout
  21. In order to run Elasticsearch from source without building a package, you can
  22. run it using Gradle:
  23. -------------------------------------
  24. ./gradlew run
  25. -------------------------------------
  26. ==== Launching and debugging from an IDE
  27. If you want to run Elasticsearch from your IDE, the `./gradlew run` task
  28. supports a remote debugging option:
  29. ---------------------------------------------------------------------------
  30. ./gradlew run --debug-jvm
  31. ---------------------------------------------------------------------------
  32. This will instruct all JVMs (including any that run cli tools such as creating the keyring or adding users)
  33. to suspend and initiate a debug connection on port incrementing from `5005`.
  34. As such the IDE needs to be instructed to listen for connections on this port.
  35. Since we might run multiple JVMs as part of configuring and starting the cluster it's
  36. recommended to configure the IDE to initiate multiple listening attempts. In case of IntelliJ, this option
  37. is called "Auto restart" and needs to be checked. In case of Eclipse, "Connection limit" setting
  38. needs to be configured with a greater value (ie 10 or more).
  39. ==== Distribution
  40. By default a node is started with the zip distribution.
  41. In order to start with a different distribution use the `-Drun.distribution` argument.
  42. To for example start the open source distribution:
  43. -------------------------------------
  44. ./gradlew run -Drun.distribution=oss
  45. -------------------------------------
  46. ==== License type
  47. By default a node is started with the `basic` license type.
  48. In order to start with a different license type use the `-Drun.license_type` argument.
  49. In order to start a node with a trial license execute the following command:
  50. -------------------------------------
  51. ./gradlew run -Drun.license_type=trial
  52. -------------------------------------
  53. This enables security and other paid features and adds a superuser with the username: `elastic-admin` and
  54. password: `elastic-password`.
  55. ==== Other useful arguments
  56. In order to start a node with a different max heap space add: `-Dtests.heap.size=4G`
  57. In order to disable assertions add: `-Dtests.asserts=false`
  58. In order to set an Elasticsearch setting, provide a setting with the following prefix: `-Dtests.es.`
  59. === Test case filtering.
  60. You can run a single test, provided that you specify the Gradle project. See the documentation on
  61. https://docs.gradle.org/current/userguide/userguide_single.html#simple_name_pattern[simple name pattern filtering].
  62. Run a single test case in the `server` project:
  63. ----------------------------------------------------------
  64. ./gradlew :server:test --tests org.elasticsearch.package.ClassName
  65. ----------------------------------------------------------
  66. Run all tests in a package and its sub-packages:
  67. ----------------------------------------------------
  68. ./gradlew :server:test --tests 'org.elasticsearch.package.*'
  69. ----------------------------------------------------
  70. Run all tests that are waiting for a bugfix (disabled by default)
  71. ------------------------------------------------
  72. ./gradlew test -Dtests.filter=@awaitsfix
  73. ------------------------------------------------
  74. === Seed and repetitions.
  75. Run with a given seed (seed is a hex-encoded long).
  76. ------------------------------
  77. ./gradlew test -Dtests.seed=DEADBEEF
  78. ------------------------------
  79. === Repeats _all_ tests of ClassName N times.
  80. Every test repetition will have a different method seed
  81. (derived from a single random master seed).
  82. --------------------------------------------------
  83. ./gradlew :server:test -Dtests.iters=N --tests org.elasticsearch.package.ClassName
  84. --------------------------------------------------
  85. === Repeats _all_ tests of ClassName N times.
  86. Every test repetition will have exactly the same master (0xdead) and
  87. method-level (0xbeef) seed.
  88. ------------------------------------------------------------------------
  89. ./gradlew :server:test -Dtests.iters=N -Dtests.seed=DEAD:BEEF --tests org.elasticsearch.package.ClassName
  90. ------------------------------------------------------------------------
  91. === Repeats a given test N times
  92. (note the filters - individual test repetitions are given suffixes,
  93. ie: testFoo[0], testFoo[1], etc... so using testmethod or tests.method
  94. ending in a glob is necessary to ensure iterations are run).
  95. -------------------------------------------------------------------------
  96. ./gradlew :server:test -Dtests.iters=N --tests org.elasticsearch.package.ClassName.methodName
  97. -------------------------------------------------------------------------
  98. Repeats N times but skips any tests after the first failure or M initial failures.
  99. -------------------------------------------------------------
  100. ./gradlew test -Dtests.iters=N -Dtests.failfast=true ...
  101. ./gradlew test -Dtests.iters=N -Dtests.maxfailures=M ...
  102. -------------------------------------------------------------
  103. === Test groups.
  104. Test groups can be enabled or disabled (true/false).
  105. Default value provided below in [brackets].
  106. ------------------------------------------------------------------
  107. ./gradlew test -Dtests.awaitsfix=[false] - known issue (@AwaitsFix)
  108. ------------------------------------------------------------------
  109. === Load balancing and caches.
  110. By default the tests run on multiple processes using all the available cores on all
  111. available CPUs. Not including hyper-threading.
  112. If you want to explicitly specify the number of JVMs you can do so on the command
  113. line:
  114. ----------------------------
  115. ./gradlew test -Dtests.jvms=8
  116. ----------------------------
  117. Or in `~/.gradle/gradle.properties`:
  118. ----------------------------
  119. systemProp.tests.jvms=8
  120. ----------------------------
  121. Its difficult to pick the "right" number here. Hypercores don't count for CPU
  122. intensive tests and you should leave some slack for JVM-internal threads like
  123. the garbage collector. And you have to have enough RAM to handle each JVM.
  124. === Test compatibility.
  125. It is possible to provide a version that allows to adapt the tests behaviour
  126. to older features or bugs that have been changed or fixed in the meantime.
  127. -----------------------------------------
  128. ./gradlew test -Dtests.compatibility=1.0.0
  129. -----------------------------------------
  130. === Miscellaneous.
  131. Run all tests without stopping on errors (inspect log files).
  132. -----------------------------------------
  133. ./gradlew test -Dtests.haltonfailure=false
  134. -----------------------------------------
  135. Run more verbose output (slave JVM parameters, etc.).
  136. ----------------------
  137. ./gradlew test -verbose
  138. ----------------------
  139. Change the default suite timeout to 5 seconds for all
  140. tests (note the exclamation mark).
  141. ---------------------------------------
  142. ./gradlew test -Dtests.timeoutSuite=5000! ...
  143. ---------------------------------------
  144. Change the logging level of ES (not Gradle)
  145. --------------------------------
  146. ./gradlew test -Dtests.es.logger.level=DEBUG
  147. --------------------------------
  148. Print all the logging output from the test runs to the commandline
  149. even if tests are passing.
  150. ------------------------------
  151. ./gradlew test -Dtests.output=always
  152. ------------------------------
  153. Configure the heap size.
  154. ------------------------------
  155. ./gradlew test -Dtests.heap.size=512m
  156. ------------------------------
  157. Pass arbitrary jvm arguments.
  158. ------------------------------
  159. # specify heap dump path
  160. ./gradlew test -Dtests.jvm.argline="-XX:HeapDumpPath=/path/to/heapdumps"
  161. # enable gc logging
  162. ./gradlew test -Dtests.jvm.argline="-verbose:gc"
  163. # enable security debugging
  164. ./gradlew test -Dtests.jvm.argline="-Djava.security.debug=access,failure"
  165. ------------------------------
  166. == Running verification tasks
  167. To run all verification tasks, including static checks, unit tests, and integration tests:
  168. ---------------------------------------------------------------------------
  169. ./gradlew check
  170. ---------------------------------------------------------------------------
  171. Note that this will also run the unit tests and precommit tasks first. If you want to just
  172. run the integration tests (because you are debugging them):
  173. ---------------------------------------------------------------------------
  174. ./gradlew integTest
  175. ---------------------------------------------------------------------------
  176. If you want to just run the precommit checks:
  177. ---------------------------------------------------------------------------
  178. ./gradlew precommit
  179. ---------------------------------------------------------------------------
  180. Some of these checks will require `docker-compose` installed for bringing up
  181. test fixtures. If it's not present those checks will be skipped automatically.
  182. The host running Docker (or VM if you're using Docker Desktop) needs 4GB of
  183. memory or some of the containers will fail to start. You can tell that you
  184. are short of memory if containers are exiting quickly after starting with
  185. code 137 (128 + 9, where 9 means SIGKILL).
  186. == Testing the REST layer
  187. The available integration tests make use of the java API to communicate with
  188. the elasticsearch nodes, using the internal binary transport (port 9300 by
  189. default).
  190. The REST layer is tested through specific tests that are shared between all
  191. the elasticsearch official clients and consist of YAML files that describe the
  192. operations to be executed and the obtained results that need to be tested.
  193. The YAML files support various operators defined in the link:/rest-api-spec/src/main/resources/rest-api-spec/test/README.asciidoc[rest-api-spec] and adhere to the link:/rest-api-spec/README.markdown[Elasticsearch REST API JSON specification]
  194. The REST tests are run automatically when executing the "./gradlew check" command. To run only the
  195. REST tests use the following command:
  196. ---------------------------------------------------------------------------
  197. ./gradlew :distribution:archives:integ-test-zip:integTest \
  198. -Dtests.class="org.elasticsearch.test.rest.*Yaml*IT"
  199. ---------------------------------------------------------------------------
  200. A specific test case can be run with
  201. ---------------------------------------------------------------------------
  202. ./gradlew :distribution:archives:integ-test-zip:integTest \
  203. -Dtests.class="org.elasticsearch.test.rest.*Yaml*IT" \
  204. -Dtests.method="test {p0=cat.shards/10_basic/Help}"
  205. ---------------------------------------------------------------------------
  206. `*Yaml*IT` are the executable test classes that runs all the
  207. yaml suites available within the `rest-api-spec` folder.
  208. The REST tests support all the options provided by the randomized runner, plus the following:
  209. * `tests.rest[true|false]`: determines whether the REST tests need to be run (default) or not.
  210. * `tests.rest.suite`: comma separated paths of the test suites to be run
  211. (by default loaded from /rest-api-spec/test). It is possible to run only a subset
  212. of the tests providing a sub-folder or even a single yaml file (the default
  213. /rest-api-spec/test prefix is optional when files are loaded from classpath)
  214. e.g. -Dtests.rest.suite=index,get,create/10_with_id
  215. * `tests.rest.blacklist`: comma separated globs that identify tests that are
  216. blacklisted and need to be skipped
  217. e.g. -Dtests.rest.blacklist=index/*/Index document,get/10_basic/*
  218. == Testing packaging
  219. The packaging tests use Vagrant virtual machines or cloud instances to verify
  220. that installing and running Elasticsearch distributions works correctly on
  221. supported operating systems. These tests should really only be run on ephemeral
  222. systems because they're destructive; that is, these tests install and remove
  223. packages and freely modify system settings, so you will probably regret it if
  224. you execute them on your development machine.
  225. When you run a packaging test, Gradle will set up the target VM and mount your
  226. repository directory in the VM. Once this is done, a Gradle task will issue a
  227. Vagrant command to run a *nested* Gradle task on the VM. This nested Gradle
  228. runs the actual "destructive" test classes.
  229. . Install Virtual Box and Vagrant.
  230. +
  231. . (Optional) Install https://github.com/fgrehm/vagrant-cachier[vagrant-cachier] to squeeze
  232. a bit more performance out of the process:
  233. +
  234. --------------------------------------
  235. vagrant plugin install vagrant-cachier
  236. --------------------------------------
  237. +
  238. . You can run all of the OS packaging tests with `./gradlew packagingTest`.
  239. This task includes our legacy `bats` tests. To run only the OS tests that are
  240. written in Java, run `.gradlew distroTest`, will cause Gradle to build the tar,
  241. zip, and deb packages and all the plugins. It will then run the tests on every
  242. available system. This will take a very long time.
  243. +
  244. Fortunately, the various systems under test have their own Gradle tasks under
  245. `qa/os`. To find out what packaging combinations can be tested on a system, run
  246. the `tasks` task. For example:
  247. +
  248. ----------------------------------
  249. ./gradlew :qa:os:ubuntu-1804:tasks
  250. ----------------------------------
  251. +
  252. If you want a quick test of the tarball and RPM packagings for Centos 7, you
  253. would run:
  254. +
  255. -------------------------------------------------------------------------------------------------
  256. ./gradlew :qa:os:centos-7:distroTest.default-rpm :qa:os:centos-7:distroTest.default-linux-archive
  257. -------------------------------------------------------------------------------------------------
  258. Note that if you interrupt Gradle in the middle of running these tasks, any boxes started
  259. will remain running and you'll have to stop them manually with `./gradlew --stop` or
  260. `vagrant halt`.
  261. All the regular vagrant commands should just work so you can get a shell in a
  262. VM running trusty by running
  263. `vagrant up ubuntu-1604 --provider virtualbox && vagrant ssh ubuntu-1604`.
  264. These are the linux flavors supported, all of which we provide images for
  265. * ubuntu-1604 aka xenial
  266. * ubuntu-1804 aka bionic beaver
  267. * debian-8 aka jessie
  268. * debian-9 aka stretch, the current debian stable distribution
  269. * centos-6
  270. * centos-7
  271. * rhel-8
  272. * fedora-28
  273. * fedora-29
  274. * oel-6 aka Oracle Enterprise Linux 6
  275. * oel-7 aka Oracle Enterprise Linux 7
  276. * sles-12
  277. * opensuse-42 aka Leap
  278. We're missing the following from the support matrix because there aren't high
  279. quality boxes available in vagrant atlas:
  280. * sles-11
  281. === Testing packaging on Windows
  282. The packaging tests also support Windows Server 2012R2 and Windows Server 2016.
  283. Unfortunately we're not able to provide boxes for them in open source use
  284. because of licensing issues. Any Virtualbox image that has WinRM and Powershell
  285. enabled for remote users should work.
  286. Specify the image IDs of the Windows boxes to gradle with the following project
  287. properties. They can be set in `~/.gradle/gradle.properties` like
  288. ------------------------------------
  289. vagrant.windows-2012r2.id=my-image-id
  290. vagrant.windows-2016.id=another-image-id
  291. ------------------------------------
  292. or passed on the command line like `-Pvagrant.windows-2012r2.id=my-image-id`
  293. `-Pvagrant.windows-2016=another-image-id`
  294. These properties are required for Windows support in all gradle tasks that
  295. handle packaging tests. Either or both may be specified.
  296. If you're running vagrant commands outside of gradle, specify the Windows boxes
  297. with the environment variables
  298. * `VAGRANT_WINDOWS_2012R2_BOX`
  299. * `VAGRANT_WINDOWS_2016_BOX`
  300. === Testing VMs are disposable
  301. It's important to think of VMs like cattle. If they become lame you just shoot
  302. them and let vagrant reprovision them. Say you've hosed your precise VM:
  303. ----------------------------------------------------
  304. vagrant ssh ubuntu-1604 -c 'sudo rm -rf /bin'; echo oops
  305. ----------------------------------------------------
  306. All you've got to do to get another one is
  307. ----------------------------------------------
  308. vagrant destroy -f ubuntu-1604 && vagrant up ubuntu-1604 --provider virtualbox
  309. ----------------------------------------------
  310. The whole process takes a minute and a half on a modern laptop, two and a half
  311. without vagrant-cachier.
  312. Its possible that some downloads will fail and it'll be impossible to restart
  313. them. This is a bug in vagrant. See the instructions here for how to work
  314. around it:
  315. https://github.com/mitchellh/vagrant/issues/4479
  316. Some vagrant commands will work on all VMs at once:
  317. ------------------
  318. vagrant halt
  319. vagrant destroy -f
  320. ------------------
  321. `vagrant up` would normally start all the VMs but we've prevented that because
  322. that'd consume a ton of ram.
  323. === Iterating on packaging tests
  324. Because our packaging tests are capable of testing many combinations of OS
  325. (e.g., Windows, Linux, etc.), package type (e.g., zip file, RPM, etc.),
  326. Elasticsearch distribution type (e.g., default or OSS), and so forth, it's
  327. faster to develop against smaller subsets of the tests. For example, to run
  328. tests for the default archive distribution on Fedora 28:
  329. -----------------------------------------------------------
  330. ./gradlew :qa:os:fedora-28:distroTest.default-linux-archive
  331. -----------------------------------------------------------
  332. These test tasks can use the `--tests`, `--info`, and `--debug` parameters just like
  333. non-OS tests can. For example:
  334. -----------------------------------------------------------
  335. ./gradlew :qa:os:fedora-28:distroTest.default-linux-archive \
  336. --tests "com.elasticsearch.packaging.test.ArchiveTests"
  337. -----------------------------------------------------------
  338. == Testing backwards compatibility
  339. Backwards compatibility tests exist to test upgrading from each supported version
  340. to the current version. To run them all use:
  341. -------------------------------------------------
  342. ./gradlew bwcTest
  343. -------------------------------------------------
  344. A specific version can be tested as well. For example, to test bwc with
  345. version 5.3.2 run:
  346. -------------------------------------------------
  347. ./gradlew v5.3.2#bwcTest
  348. -------------------------------------------------
  349. Tests are ran for versions that are not yet released but with which the current version will be compatible with.
  350. These are automatically checked out and built from source.
  351. See link:./buildSrc/src/main/java/org/elasticsearch/gradle/VersionCollection.java[VersionCollection]
  352. and link:./distribution/bwc/build.gradle[distribution/bwc/build.gradle]
  353. for more information.
  354. When running `./gradlew check`, minimal bwc checks are also run against compatible versions that are not yet released.
  355. ==== BWC Testing against a specific remote/branch
  356. Sometimes a backward compatibility change spans two versions. A common case is a new functionality
  357. that needs a BWC bridge in an unreleased versioned of a release branch (for example, 5.x).
  358. To test the changes, you can instruct Gradle to build the BWC version from a another remote/branch combination instead of
  359. pulling the release branch from GitHub. You do so using the `bwc.remote` and `bwc.refspec.BRANCH` system properties:
  360. -------------------------------------------------
  361. ./gradlew check -Dbwc.remote=${remote} -Dbwc.refspec.5.x=index_req_bwc_5.x
  362. -------------------------------------------------
  363. The branch needs to be available on the remote that the BWC makes of the
  364. repository you run the tests from. Using the remote is a handy trick to make
  365. sure that a branch is available and is up to date in the case of multiple runs.
  366. Example:
  367. Say you need to make a change to `master` and have a BWC layer in `5.x`. You
  368. will need to:
  369. . Create a branch called `index_req_change` off your remote `${remote}`. This
  370. will contain your change.
  371. . Create a branch called `index_req_bwc_5.x` off `5.x`. This will contain your bwc layer.
  372. . Push both branches to your remote repository.
  373. . Run the tests with `./gradlew check -Dbwc.remote=${remote} -Dbwc.refspec.5.x=index_req_bwc_5.x`.
  374. ==== Skip fetching latest
  375. For some BWC testing scenarios, you want to use the local clone of the
  376. repository without fetching latest. For these use cases, you can set the system
  377. property `tests.bwc.git_fetch_latest` to `false` and the BWC builds will skip
  378. fetching the latest from the remote.
  379. == How to write good tests?
  380. === Base classes for test cases
  381. There are multiple base classes for tests:
  382. * **`ESTestCase`**: The base class of all tests. It is typically extended
  383. directly by unit tests.
  384. * **`ESSingleNodeTestCase`**: This test case sets up a cluster that has a
  385. single node.
  386. * **`ESIntegTestCase`**: An integration test case that creates a cluster that
  387. might have multiple nodes.
  388. * **`ESRestTestCase`**: An integration tests that interacts with an external
  389. cluster via the REST API. For instance, YAML tests run via sub classes of
  390. `ESRestTestCase`.
  391. === Good practices
  392. ==== What kind of tests should I write?
  393. Unit tests are the preferred way to test some functionality: most of the time
  394. they are simpler to understand, more likely to reproduce, and unlikely to be
  395. affected by changes that are unrelated to the piece of functionality that is
  396. being tested.
  397. The reason why `ESSingleNodeTestCase` exists is that all our components used to
  398. be very hard to set up in isolation, which had led us to having a number of
  399. integration tests but close to no unit tests. `ESSingleNodeTestCase` is a
  400. workaround for this issue which provides an easy way to spin up a node and get
  401. access to components that are hard to instantiate like `IndicesService`.
  402. Whenever practical, you should prefer unit tests.
  403. Many tests extend `ESIntegTestCase`, mostly because this is how most tests used
  404. to work in the early days of Elasticsearch. However the complexity of these
  405. tests tends to make them hard to debug. Whenever the functionality that is
  406. being tested isn't intimately dependent on how Elasticsearch behaves as a
  407. cluster, it is recommended to write unit tests or REST tests instead.
  408. In short, most new functionality should come with unit tests, and optionally
  409. REST tests to test integration.
  410. ==== Refactor code to make it easier to test
  411. Unfortunately, a large part of our code base is still hard to unit test.
  412. Sometimes because some classes have lots of dependencies that make them hard to
  413. instantiate. Sometimes because API contracts make tests hard to write. Code
  414. refactors that make functionality easier to unit test are encouraged. If this
  415. sounds very abstract to you, you can have a look at
  416. https://github.com/elastic/elasticsearch/pull/16610[this pull request] for
  417. instance, which is a good example. It refactors `IndicesRequestCache` in such
  418. a way that:
  419. - it no longer depends on objects that are hard to instantiate such as
  420. `IndexShard` or `SearchContext`,
  421. - time-based eviction is applied on top of the cache rather than internally,
  422. which makes it easier to assert on what the cache is expected to contain at
  423. a given time.
  424. === Bad practices
  425. ==== Use randomized-testing for coverage
  426. In general, randomization should be used for parameters that are not expected
  427. to affect the behavior of the functionality that is being tested. For instance
  428. the number of shards should not impact `date_histogram` aggregations, and the
  429. choice of the `store` type (`niofs` vs `mmapfs`) does not affect the results of
  430. a query. Such randomization helps improve confidence that we are not relying on
  431. implementation details of one component or specifics of some setup.
  432. However it should not be used for coverage. For instance if you are testing a
  433. piece of functionality that enters different code paths depending on whether
  434. the index has 1 shards or 2+ shards, then we shouldn't just test against an
  435. index with a random number of shards: there should be one test for the 1-shard
  436. case, and another test for the 2+ shards case.
  437. ==== Abuse randomization in multi-threaded tests
  438. Multi-threaded tests are often not reproducible due to the fact that there is
  439. no guarantee on the order in which operations occur across threads. Adding
  440. randomization to the mix usually makes things worse and should be done with
  441. care.
  442. == Test coverage analysis
  443. Generating test coverage reports for Elasticsearch is currently not possible through Gradle.
  444. However, it _is_ possible to gain insight in code coverage using IntelliJ's built-in coverage
  445. analysis tool that can measure coverage upon executing specific tests. Eclipse may also be able
  446. to do the same using the EclEmma plugin.
  447. Test coverage reporting used to be possible with JaCoCo when Elasticsearch was using Maven
  448. as its build system. Since the switch to Gradle though, this is no longer possible, seeing as
  449. the code currently used to build Elasticsearch does not allow JaCoCo to recognize its tests.
  450. For more information on this, see the discussion in https://github.com/elastic/elasticsearch/issues/28867[issue #28867].
  451. == Debugging remotely from an IDE
  452. If you want to run Elasticsearch and be able to remotely attach the process
  453. for debugging purposes from your IDE, can start Elasticsearch using `ES_JAVA_OPTS`:
  454. ---------------------------------------------------------------------------
  455. ES_JAVA_OPTS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=y" ./bin/elasticsearch
  456. ---------------------------------------------------------------------------
  457. Read your IDE documentation for how to attach a debugger to a JVM process.
  458. == Building with extra plugins
  459. Additional plugins may be built alongside elasticsearch, where their
  460. dependency on elasticsearch will be substituted with the local elasticsearch
  461. build. To add your plugin, create a directory called elasticsearch-extra as
  462. a sibling of elasticsearch. Checkout your plugin underneath elasticsearch-extra
  463. and the build will automatically pick it up. You can verify the plugin is
  464. included as part of the build by checking the projects of the build.
  465. ---------------------------------------------------------------------------
  466. ./gradlew projects
  467. ---------------------------------------------------------------------------
  468. == Environment misc
  469. There is a known issue with macOS localhost resolve strategy that can cause
  470. some integration tests to fail. This is because integration tests have timings
  471. for cluster formation, discovery, etc. that can be exceeded if name resolution
  472. takes a long time.
  473. To fix this, make sure you have your computer name (as returned by `hostname`)
  474. inside `/etc/hosts`, e.g.:
  475. ....
  476. 127.0.0.1 localhost ElasticMBP.local
  477. 255.255.255.255 broadcasthost
  478. ::1 localhost ElasticMBP.local`
  479. ....
  480. == Benchmarking
  481. For changes that might affect the performance characteristics of Elasticsearch
  482. you should also run macrobenchmarks. We maintain a macrobenchmarking tool
  483. called https://github.com/elastic/rally[Rally]
  484. which you can use to measure the performance impact. It comes with a set of
  485. default benchmarks that we also
  486. https://elasticsearch-benchmarks.elastic.co/[run every night]. To get started,
  487. please see https://esrally.readthedocs.io/en/stable/[Rally's documentation].