Back to Repositories

Testing Hystrix Command Default Properties Configuration in Netflix/Hystrix

This test suite validates default property configurations for Hystrix commands in a Spring context environment. It extends basic command property testing while incorporating Spring-specific dependency injection and AOP functionality.

Test Coverage Overview

The test suite focuses on verifying default Hystrix command properties within a Spring-managed environment.

Key areas covered include:
  • Command property inheritance and override behavior
  • Spring prototype scope bean initialization
  • Integration with Spring’s dependency injection
  • CGLIB-based AOP configuration validation

Implementation Analysis

The testing approach leverages Spring’s test context framework with JUnit4 integration. It implements a hierarchical test structure by extending BasicCommandDefaultPropertiesTest while utilizing Spring’s dependency injection for service instantiation.

Notable patterns include:
  • Use of @RunWith(SpringJUnit4ClassRunner.class) for Spring test context
  • Configuration class implementation with prototype-scoped beans
  • AOP configuration integration through AopCglibConfig

Technical Details

Testing tools and configuration:
  • Spring Test Context Framework
  • JUnit 4 test runner
  • CGLIB-based AOP proxying
  • @Configurable annotation for configuration management
  • Prototype-scoped bean definitions
  • Spring dependency injection via @Autowired

Best Practices Demonstrated

The test implementation showcases several testing best practices in the Spring ecosystem.

Notable practices include:
  • Clean separation of configuration and test logic
  • Proper use of Spring’s test context framework
  • Efficient dependency management through DI
  • Modular test configuration using @ContextConfiguration
  • Proper scoping of test dependencies

netflix/hystrix

hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/spring/configuration/command/CommandDefaultPropertiesTest.java

            
package com.netflix.hystrix.contrib.javanica.test.spring.configuration.command;

import com.netflix.hystrix.contrib.javanica.test.common.configuration.command.BasicCommandDefaultPropertiesTest;
import com.netflix.hystrix.contrib.javanica.test.spring.conf.AopCglibConfig;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Created by dmgcodevil.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AopCglibConfig.class, CommandDefaultPropertiesTest.Config.class})
public class CommandDefaultPropertiesTest extends BasicCommandDefaultPropertiesTest {

    @Autowired
    private Service service;

    @Override
    protected Service createService() {
        return service;
    }

    @Configurable
    public static class Config {
        @Bean
        @Scope(value = "prototype")
        public BasicCommandDefaultPropertiesTest.Service service() {
            return new BasicCommandDefaultPropertiesTest.Service();
        }
    }
}