Skip to content

Conversation

@loesak
Copy link
Owner

@loesak loesak commented Jan 31, 2026

Summary

This PR adds comprehensive integration tests for the Esque migration framework using Testcontainers to manage an Elasticsearch container and JUnit 5 as the testing framework.

Key Changes

  • Testing Framework Upgrade: Migrated from JUnit 4 to JUnit 5 (Jupiter) with AssertJ for fluent assertions
  • Testcontainers Integration: Added Elasticsearch Testcontainers support for isolated, containerized integration tests
  • Maven Configuration:
    • Added test dependencies: JUnit 5, AssertJ, Testcontainers (core, Elasticsearch, JUnit integration)
    • Configured maven-failsafe-plugin to run integration tests (*IT classes)
    • Added BOM imports for JUnit and Testcontainers for consistent dependency management
  • Base Test Class: Created AbstractElasticsearchIT that manages a shared singleton Elasticsearch container and provides cleanup between tests
  • Integration Tests:
    • EsqueIT: Tests core migration execution, idempotency, history recording, and multi-key independence
    • ElasticsearchDocumentLockIT: Tests distributed locking mechanism with concurrent scenarios
    • RestClientOperationsIT: Tests low-level Elasticsearch operations (index creation, migration records, lock management)
    • MigrationFileLoaderIT: Tests migration file discovery and parsing from classpath resources
  • Test Resources: Added sample migration YAML files (V1.0.0__CreateTestIndex.yml, etc.) and logback test configuration

Notable Implementation Details

  • Shared Elasticsearch container uses a static initializer to avoid startup overhead per test class
  • Tests use separate RestClient instances to simulate concurrent/multi-process scenarios
  • Migration files are discovered from src/test/resources/es.migration/ directory
  • Lock tests verify both single-process and multi-process locking behavior
  • All integration tests clean up their state via @BeforeEach to ensure test isolation

https://claude.ai/code/session_01TXc3z5cZfH1omt6ys9uc6H

Adds a comprehensive integration test suite using JUnit 5, Testcontainers
(Elasticsearch 8.17.0), and AssertJ. Tests cover:

- RestClientOperations: index creation, lock CRUD, migration record CRUD,
  query execution against real Elasticsearch
- ElasticsearchDocumentLock: lock/unlock, tryLock with timeout, cross-thread
  contention behavior
- MigrationFileLoader: YAML file discovery, version ordering, checksum
  stability, metadata parsing
- Esque (end-to-end): full migration execution, idempotency, independent
  migration keys, user tracking, history recording

Infrastructure:
- Shared singleton ElasticsearchContainer via AbstractElasticsearchIT base class
- maven-failsafe-plugin for *IT.java test execution during mvn verify
- JUnit 5 BOM (5.11.4) and Testcontainers BOM (1.20.4) in parent POM
- Test migration YAML files and logback-test.xml configuration

https://claude.ai/code/session_01TXc3z5cZfH1omt6ys9uc6H
- Fix HttpHost construction to include explicit "http" scheme.
  getHttpHostAddress() returns host:port without a scheme, so
  HttpHost.create() produced a null-scheme host that failed to connect.
- Fix execute_differentKeysAreIndependent test: two keys running the same
  migration files tried to PUT the same ES indices, causing
  resource_already_exists_exception on the second run. Restructured to
  verify key isolation by checking one key has records and the other doesn't.
- Remove unused assertThatThrownBy import from EsqueIT.

https://claude.ai/code/session_01TXc3z5cZfH1omt6ys9uc6H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants