or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

assertions-matchers.mdcluster-management.mdcore-testing.mddata-generation.mdindex.mdmock-implementations.mdspecialized-testing.md
tile.json

tessl/maven-org-elasticsearch--elasticsearch-test-framework

Test framework library for Elasticsearch providing comprehensive testing utilities, base test classes, cluster management, and assertion helpers for unit and integration testing of Elasticsearch plugins and applications

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.elasticsearch/elasticsearch-test-framework@9.0.x

To install, run

npx @tessl/cli install tessl/maven-org-elasticsearch--elasticsearch-test-framework@9.0.0

index.mddocs/

Elasticsearch Test Framework

The Elasticsearch Test Framework (org.elasticsearch.test:framework) provides comprehensive testing utilities for Elasticsearch development. This framework includes 386+ classes organized into specialized testing packages, offering everything from basic unit test utilities to complex multi-node integration testing capabilities.

Package Information

  • Package Name: elasticsearch-test-framework

  • Package Type: maven

  • Language: Java

  • Group ID: org.elasticsearch

  • Artifact ID: elasticsearch-test-framework

  • Installation: Add to Maven pom.xml:

    <dependency>
      <groupId>org.elasticsearch</groupId>
      <artifactId>elasticsearch-test-framework</artifactId>
      <version>9.0.3</version>
      <scope>test</scope>
    </dependency>

    Or to Gradle build.gradle:

    testImplementation 'org.elasticsearch:elasticsearch-test-framework:9.0.3'

Overview

This testing framework is built on top of Apache Lucene's testing infrastructure and extends it with Elasticsearch-specific functionality. It provides mock implementations, specialized assertion utilities, cluster management capabilities, and data generation tools designed specifically for testing Elasticsearch functionality.

// Core package structure
org.elasticsearch.test
├── ESTestCase                    // Base class for all Elasticsearch unit tests  
├── ESIntegTestCase              // Base class for integration tests
├── InternalTestCluster          // Multi-node test cluster management
├── SingleNodeTestCase           // Single node test scenarios
└── hamcrest/                    // Custom Hamcrest matchers
    └── ElasticsearchAssertions  // Elasticsearch-specific assertions

Architecture

The framework follows a layered architecture:

  1. Base Layer: Core test classes extending Lucene's testing infrastructure
  2. Cluster Management: Multi-node cluster lifecycle and node management
  3. Mock Layer: Mock implementations for transport, storage, and security
  4. Assertion Layer: Custom matchers and validation utilities
  5. Specialization Layer: Domain-specific testing utilities (REST, XContent, etc.)
  6. Data Generation: Synthetic document and field data generators

Core Imports

Standard import patterns for using the Elasticsearch Test Framework:

// Core test base classes
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESSingleNodeTestCase;

// Cluster management
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.TestCluster;

// Custom assertions and matchers  
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;

// Common Hamcrest matchers
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;

// Mock implementations
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.common.settings.MockSecureSettings;
import org.elasticsearch.test.store.MockDirectoryWrapper;

Key Capabilities

Core Testing

  • Unit Testing: ESTestCase provides randomized testing with Elasticsearch-specific setup
  • Integration Testing: ESIntegTestCase manages full Elasticsearch clusters
  • Single Node Testing: SingleNodeTestCase for lightweight integration scenarios

Cluster Management

  • Multi-node Clusters: Start, stop, and configure multiple Elasticsearch nodes
  • Node Lifecycle: Control individual node startup, shutdown, and restart
  • Cluster State: Wait for cluster health, manage routing, and verify consistency

Mock Implementations

  • Transport Layer: Mock network communication and simulate failures
  • Storage Layer: Mock repositories, blob stores, and filesystem operations
  • Security: Mock secure settings and authentication mechanisms

Assertion Utilities

  • Custom Matchers: Elasticsearch-specific Hamcrest matchers for responses, documents, and cluster state
  • Fluent Assertions: Builder pattern for complex assertion scenarios
  • Async Testing: Utilities for testing asynchronous operations and futures

Specialized Testing

  • REST Testing: Framework for testing REST APIs with request/response validation
  • XContent Testing: JSON/XML serialization and deserialization testing
  • Query Testing: Query builder validation and Lucene query assertion
  • Disruption Testing: Network partition and service disruption simulation

Package Structure

Core Test Classes (org.elasticsearch.test)

import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.SingleNodeTestCase;

Assertion and Matching (org.elasticsearch.test.hamcrest)

import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.elasticsearch.test.hamcrest.OptionalMatchers;
import org.elasticsearch.test.hamcrest.TupleMatchers;

Mock Implementations (org.elasticsearch.test.transport, org.elasticsearch.common.settings)

import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.common.settings.MockSecureSettings;
import org.elasticsearch.test.store.MockDirectoryWrapper;

Disruption Testing (org.elasticsearch.test.disruption)

import org.elasticsearch.test.disruption.NetworkDisruption;
import org.elasticsearch.test.disruption.ServiceDisruptionScheme;
import org.elasticsearch.test.disruption.SingleNodeDisruption;

REST Testing (org.elasticsearch.test.rest)

import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.test.rest.RestTestExecutionContext;

Data Generation (org.elasticsearch.logsdb.datageneration)

import org.elasticsearch.logsdb.datageneration.DocumentGenerator;
import org.elasticsearch.logsdb.datageneration.FieldDataGenerator;
import org.elasticsearch.logsdb.datageneration.DataGenerator;

Basic Usage

Simple Unit Test

import org.elasticsearch.test.ESTestCase;

public class MyElasticsearchTest extends ESTestCase {
    
    public void testBasicFunctionality() {
        String randomValue = randomAlphaOfLength(10);
        int randomInt = randomIntBetween(1, 100);
        
        // Your test logic here
        assertThat(randomValue, notNullValue());
        assertThat(randomInt, allOf(greaterThan(0), lessThanOrEqualTo(100)));
    }
}

Integration Test with Cluster

import org.elasticsearch.test.ESIntegTestCase;

public class MyIntegrationTest extends ESIntegTestCase {
    
    public void testClusterOperations() {
        createIndex("test-index");
        ensureGreen("test-index");
        
        // Index a document
        client().prepareIndex("test-index")
            .setSource("field", "value")
            .get();
        
        // Search and verify
        SearchResponse response = client().prepareSearch("test-index")
            .get();
            
        assertThat(response.getHits().getTotalHits().value, equalTo(1L));
    }
}

Sub-Documentation

This comprehensive documentation is organized into focused areas:

  • Core Testing - ESTestCase, ESIntegTestCase, and fundamental test classes
  • Cluster Management - InternalTestCluster and node lifecycle management
  • Mock Implementations - Transport, storage, and security mocks
  • Assertions & Matchers - Custom Hamcrest matchers and assertion utilities
  • Specialized Testing - XContent, queries, REST, and disruption testing
  • Data Generation - Document and field data generation utilities

Each section provides detailed API documentation, usage examples, and best practices for effective Elasticsearch testing.

Design Philosophy

The Elasticsearch Test Framework is designed around several key principles:

  1. Randomized Testing: Extensive use of randomization to catch edge cases and improve test coverage
  2. Isolation: Tests are isolated from each other with proper setup/teardown lifecycle management
  3. Realism: Test environments closely mirror production Elasticsearch deployments
  4. Extensibility: Pluggable architecture allows custom test scenarios and mock implementations
  5. Performance: Optimized for fast test execution while maintaining thoroughness

This framework enables comprehensive testing of Elasticsearch functionality from simple unit tests to complex distributed scenarios, ensuring robust and reliable Elasticsearch deployments.