Back to Repositories

Testing MySQL Workflow Execution Persistence in conductor-oss/conductor

This test suite evaluates the MySQL implementation of Conductor’s ExecutionDAO, focusing on workflow persistence and retrieval operations. It validates database interactions and workflow correlation functionality using Spring Boot and JUnit test frameworks.

Test Coverage Overview

The test suite provides comprehensive coverage of MySQL-specific workflow execution persistence functionality.

  • Tests workflow correlation ID retrieval
  • Validates database cleanup and migration processes
  • Ensures proper workflow definition persistence
  • Verifies batch workflow generation and retrieval

Implementation Analysis

The testing approach utilizes Spring Boot’s test framework with JUnit integration. It implements database migration handling through Flyway, ensuring clean test environments between executions.

  • Uses Spring’s dependency injection for DAO components
  • Implements before-test database cleaning
  • Extends base ExecutionDAOTest for consistent testing patterns

Technical Details

  • Spring Boot Test framework
  • JUnit 4 test runner
  • Flyway for database migrations
  • MySQL database backend
  • Custom configuration classes for testing
  • Spring context configuration with TestObjectMapperConfiguration

Best Practices Demonstrated

The test suite exemplifies several testing best practices for database integration testing.

  • Proper test isolation through database cleaning
  • Consistent test data setup
  • Extended base test class for shared functionality
  • Clear assertion patterns
  • Proper Spring Boot test configuration

conductor-oss/conductor

mysql-persistence/src/test/java/com/netflix/conductor/mysql/dao/MySQLExecutionDAOTest.java

            
/*
 * Copyright 2023 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.mysql.dao;

import java.util.List;

import org.flywaydb.core.Flyway;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import com.netflix.conductor.common.config.TestObjectMapperConfiguration;
import com.netflix.conductor.common.metadata.workflow.WorkflowDef;
import com.netflix.conductor.dao.ExecutionDAO;
import com.netflix.conductor.dao.ExecutionDAOTest;
import com.netflix.conductor.model.WorkflowModel;
import com.netflix.conductor.mysql.config.MySQLConfiguration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

@ContextConfiguration(
        classes = {
            TestObjectMapperConfiguration.class,
            MySQLConfiguration.class,
            FlywayAutoConfiguration.class
        })
@RunWith(SpringRunner.class)
@SpringBootTest(properties = "spring.flyway.clean-disabled=false")
public class MySQLExecutionDAOTest extends ExecutionDAOTest {

    @Autowired private MySQLExecutionDAO executionDAO;

    @Autowired Flyway flyway;

    // clean the database between tests.
    @Before
    public void before() {
        flyway.clean();
        flyway.migrate();
    }

    @Test
    public void testPendingByCorrelationId() {

        WorkflowDef def = new WorkflowDef();
        def.setName("pending_count_correlation_jtest");

        WorkflowModel workflow = createTestWorkflow();
        workflow.setWorkflowDefinition(def);

        generateWorkflows(workflow, 10);

        List<WorkflowModel> bycorrelationId =
                getExecutionDAO()
                        .getWorkflowsByCorrelationId(
                                "pending_count_correlation_jtest", "corr001", true);
        assertNotNull(bycorrelationId);
        assertEquals(10, bycorrelationId.size());
    }

    @Override
    public ExecutionDAO getExecutionDAO() {
        return executionDAO;
    }
}