Back to Repositories

Testing Elasticsearch 6.x Integration Framework in Conductor-OSS

A comprehensive test suite for Elasticsearch 6.x integration in the Conductor OSS workflow platform. This test class establishes the foundation for testing Elasticsearch indexing functionality using Spring Test framework and TestContainers for containerized testing.

Test Coverage Overview

The test suite provides essential coverage for Elasticsearch 6.x integration within Conductor.

Key areas covered include:
  • Elasticsearch container initialization and lifecycle management
  • Spring context configuration for testing
  • Property-based configuration validation
  • ObjectMapper integration testing
Integration points focus on Spring context initialization and Elasticsearch container management.

Implementation Analysis

The testing approach utilizes Spring’s test framework with TestContainers for isolated testing.

Key implementation patterns include:
  • Abstract base class design for reusable test infrastructure
  • Spring context configuration using @ContextConfiguration
  • Docker container management with ElasticsearchContainer
  • Property-based configuration using @TestPropertySource

Technical Details

Testing tools and configuration:
  • JUnit 4 test framework
  • Spring Test context framework
  • TestContainers for Elasticsearch 6.8.23
  • Custom TestConfiguration for ElasticSearchProperties
  • Automated container lifecycle management
  • Environment-specific configuration for M1/M2 Mac compatibility

Best Practices Demonstrated

The test implementation showcases several testing best practices.

Notable practices include:
  • Proper test isolation using containers
  • Clear separation of concerns in configuration
  • Automated resource management with @BeforeClass/@AfterClass
  • Configuration externalization
  • Platform compatibility considerations
  • Dependency injection for test components

conductor-oss/conductor

es6-persistence/src/test/java/com/netflix/conductor/es6/dao/index/ElasticSearchTest.java

            
/*
 * Copyright 2021 Conductor Authors.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package com.netflix.conductor.es6.dao.index;

import java.util.Map;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.testcontainers.elasticsearch.ElasticsearchContainer;
import org.testcontainers.utility.DockerImageName;

import com.netflix.conductor.common.config.TestObjectMapperConfiguration;
import com.netflix.conductor.es6.config.ElasticSearchProperties;

import com.fasterxml.jackson.databind.ObjectMapper;

@ContextConfiguration(
        classes = {TestObjectMapperConfiguration.class, ElasticSearchTest.TestConfiguration.class})
@RunWith(SpringRunner.class)
@TestPropertySource(
        properties = {"conductor.indexing.enabled=true", "conductor.elasticsearch.version=6"})
abstract class ElasticSearchTest {

    @Configuration
    static class TestConfiguration {

        @Bean
        public ElasticSearchProperties elasticSearchProperties() {
            return new ElasticSearchProperties();
        }
    }

    protected static final ElasticsearchContainer container =
            new ElasticsearchContainer(
                            DockerImageName.parse(
                                            "docker.elastic.co/elasticsearch/elasticsearch-oss")
                                    .withTag("6.8.23")) // this should match the client version
                    // Resolve issue with es container not starting on m1/m2 macs
                    .withEnv(Map.of("bootstrap.system_call_filter", "false"));

    @Autowired protected ObjectMapper objectMapper;

    @Autowired protected ElasticSearchProperties properties;

    @BeforeClass
    public static void startServer() {
        container.start();
    }

    @AfterClass
    public static void stopServer() {
        container.stop();
    }
}