Back to Repositories

Testing Inherited Fallback Patterns in Netflix Hystrix

This test suite validates the inheritance behavior of fallback mechanisms in Hystrix commands using Spring AOP and CGLIB proxies. It specifically tests how fallback methods are inherited and executed when extending base service classes.

Test Coverage Overview

The test suite covers inheritance patterns for Hystrix fallback implementations in Spring contexts.

Key areas tested include:
  • Fallback method inheritance in extended service classes
  • Spring AOP integration with CGLIB proxies
  • Proper autowiring of service components
  • Command configuration inheritance

Implementation Analysis

The testing approach leverages Spring’s testing framework with JUnit4 integration. It uses @RunWith(SpringJUnit4ClassRunner.class) for Spring context management and @ContextConfiguration for test configuration setup.

Notable patterns include:
  • Extension of BasicCommandFallbackTest for base functionality
  • Custom configuration class using @Configurable
  • Bean definition for service instantiation

Technical Details

Testing tools and configuration:
  • Spring Test Context Framework
  • JUnit 4 Test Runner
  • AOP CGLIB proxying
  • Spring Bean configuration
  • Autowired dependency injection
  • Custom test configuration class

Best Practices Demonstrated

The test implementation showcases several testing best practices for Spring-based Hystrix applications.

Notable practices include:
  • Proper separation of configuration and test logic
  • Clean inheritance structure for reusable test cases
  • Effective use of Spring’s testing infrastructure
  • Modular test configuration approach

netflix/hystrix

hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/spring/fallback/InheritedFallbackTest.java

            
package com.netflix.hystrix.contrib.javanica.test.spring.fallback;

import com.netflix.hystrix.contrib.javanica.test.common.fallback.BasicCommandFallbackTest;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Created by dmgcodevil.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AopCglibConfig.class, InheritedFallbackTest.CommandTestConfig.class})
public class InheritedFallbackTest extends BasicCommandFallbackTest {

    @Autowired
    private UserService userService;

    @Override
    protected BasicCommandFallbackTest.UserService createUserService() {
        return userService;
    }

    @Configurable
    public static class CommandTestConfig {
        @Bean
        public UserService userService() {
            return new SubClass();
        }
    }

    public static class SubClass extends BasicCommandFallbackTest.UserService {
    }

}