Elasticsearch — Tests & Learning Path

Build, deploy, top files, risks, open questions

10. Tests

Framework

JUnit 4.13.2 on RandomizedTesting runner 2.8.2. Base class ESTestCase in test/framework. Lucene test framework for index-level tests.

Test tiers

TierGradle taskSource dirWhat it proves
Unittestsrc/test/javaClass-level logic with mocks
Internal clusterinternalClusterTestsrc/internalClusterTest/javaMulti-node in one JVM (ESIntegTestCase)
YAML RESTyamlRestTestsrc/yamlRestTest/REST API contract from JSON spec
Java RESTjavaRestTestsrc/javaRestTest/javaBlack-box cluster via HTTP
BWCbwcTestdistribution/bwc/Upgrade from old ES versions

Commands

./gradlew check                              # full verification
./gradlew test                               # all unit tests
./gradlew :server:test --tests 'org.elasticsearch.package.ClassName'
./gradlew internalClusterTest
./gradlew :rest-api-spec:yamlRestTest
./gradlew run                                # run ES from source
./gradlew localDistro                        # build tarball

What tests reveal

Likely gaps

11. Build, run, deploy

Build

export JAVA_HOME=/path/to/jdk-21
./gradlew localDistro          # platform tarball → distribution/archives/
./gradlew :distribution:archives:linux-tar:assemble
./gradlew buildDockerImage

Evidence: BUILDING.md, TESTING.asciidoc, CONTRIBUTING.md.

Run locally

./gradlew run
# default: basic license, security ON, elastic:password
./gradlew run -Dtests.es.xpack.security.enabled=false
./gradlew run --debug-jvm

Deploy

12. Most important files to understand first

#FileWhy
1bootstrap/Elasticsearch.javaJVM entry, 3-phase init
2node/Node.javaStart/stop ordering of all services
3node/NodeConstruction.javaGuice wiring, plugin registration
4cluster/ClusterState.javaCentral metadata object
5cluster/service/MasterService.javaCluster state mutation pipeline
6rest/RestController.javaHTTP routing & errors
7action/support/TransportAction.javaAction execution pattern
8action/bulk/TransportBulkAction.javaIndexing coordinator
9index/shard/IndexShard.javaShard-level operations hub
10index/engine/InternalEngine.javaLucene + translog integration
11search/SearchService.javaShard search execution
12action/search/TransportSearchAction.javaDistributed search coordinator
13indices/cluster/IndicesClusterStateService.javaApplies routing to local shards
14cluster/routing/allocation/AllocationService.javaShard placement
15plugins/Plugin.javaExtension model
16action/ActionModule.javaAction registration catalog
17cluster/coordination/Coordinator.javaElection & publication
18test/ESTestCase.javaTest conventions

13. Things that are confusing or risky

14. Suggested learning path

  1. Read README.asciidoc + CONTRIBUTING.md for build/run.
  2. Trace Elasticsearch.mainNode.start (startup mental model).
  3. Pick one REST call: set breakpoint in RestIndexAction, follow into InternalEngine.index.
  4. Read ClusterState javadoc + one executor (MetadataCreateIndexService).
  5. Run ./gradlew :server:test --tests InternalEngineTests and read tests as spec.
  6. Trace search: RestSearchActionSearchService.executeQueryPhase.
  7. Read IndicesClusterStateService for allocation → shard creation link.
  8. Explore one module (lang-painless) to learn plugin SPI.
  9. Skim x-pack core + security if touching auth.
  10. Read YAML REST test for your API in rest-api-spec.

15. Open questions

Items not fully determined from static code review alone:

Full pinned source: github.com/elastic/elasticsearch @ f96bad22

Runtime & Errors · Back to Overview