Back to Repositories

Testing Redis Poll Data Persistence Implementation in Conductor OSS

This test suite validates the Redis implementation of the PollDataDAO interface in the Conductor OSS workflow engine. It focuses on verifying the persistence and retrieval of polling data using Redis as the backend storage system.

Test Coverage Overview

The test suite extends PollDataDAOTest to ensure complete coverage of Redis-specific polling data operations.

  • Validates Redis implementation of PollDataDAO interface
  • Tests data persistence and retrieval operations
  • Covers Redis connection handling and data serialization
  • Verifies integration with JedisMock for isolated testing

Implementation Analysis

The testing approach utilizes Spring’s test framework with JUnit for dependency injection and test execution.

Key implementation patterns include:
  • Mock Redis implementation using JedisMock
  • Spring context configuration for ObjectMapper injection
  • Inheritance-based test structure extending PollDataDAOTest
  • Dependency injection for configuration properties

Technical Details

Testing infrastructure includes:

  • SpringRunner for test execution
  • JUnit test framework
  • Mockito for mocking dependencies
  • Custom JedisMock implementation
  • Spring’s ContextConfiguration for test setup
  • ObjectMapper for JSON serialization

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Proper separation of concerns with dedicated DAO testing
  • Mock dependencies for isolated unit testing
  • Inheritance-based test organization
  • Clear test initialization setup
  • Spring-managed dependency injection
  • Consistent use of testing annotations

conductor-oss/conductor

redis-persistence/src/test/java/com/netflix/conductor/redis/dao/RedisPollDataDAOTest.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.redis.dao;

import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import com.netflix.conductor.common.config.TestObjectMapperConfiguration;
import com.netflix.conductor.core.config.ConductorProperties;
import com.netflix.conductor.dao.PollDataDAO;
import com.netflix.conductor.dao.PollDataDAOTest;
import com.netflix.conductor.redis.config.RedisProperties;
import com.netflix.conductor.redis.jedis.JedisMock;
import com.netflix.conductor.redis.jedis.JedisProxy;

import com.fasterxml.jackson.databind.ObjectMapper;
import redis.clients.jedis.commands.JedisCommands;

import static org.mockito.Mockito.mock;

@ContextConfiguration(classes = {TestObjectMapperConfiguration.class})
@RunWith(SpringRunner.class)
public class RedisPollDataDAOTest extends PollDataDAOTest {

    private PollDataDAO redisPollDataDAO;

    @Autowired private ObjectMapper objectMapper;

    @Before
    public void init() {
        ConductorProperties conductorProperties = mock(ConductorProperties.class);
        RedisProperties properties = mock(RedisProperties.class);
        JedisCommands jedisMock = new JedisMock();
        JedisProxy jedisProxy = new JedisProxy(jedisMock);

        redisPollDataDAO =
                new RedisPollDataDAO(jedisProxy, objectMapper, conductorProperties, properties);
    }

    @Override
    protected PollDataDAO getPollDataDAO() {
        return redisPollDataDAO;
    }
}