Back to Repositories

Testing Hystrix Collapser Properties Configuration in Netflix/Hystrix

This test suite validates Hystrix request collapser properties within a Spring context environment. It extends basic collapser functionality testing while incorporating Spring-specific configurations and dependency injection mechanisms.

Test Coverage Overview

The test suite covers Spring-based configuration and integration of Hystrix request collapser properties.

  • Validates collapser property configurations in Spring context
  • Tests dependency injection of UserService components
  • Verifies proper inheritance of basic collapser functionality
  • Ensures Spring AOP integration with CGLIB proxies

Implementation Analysis

The implementation leverages Spring’s testing framework with JUnit integration. It utilizes Spring’s context configuration capabilities through annotations and configuration classes.

  • Uses @RunWith(SpringJUnit4ClassRunner.class) for Spring test context
  • Implements @ContextConfiguration for AOP and collapser configurations
  • Employs @Autowired for dependency injection
  • Extends BasicCollapserPropertiesTest for core functionality

Technical Details

  • Spring Framework testing infrastructure
  • JUnit test runner integration
  • CGLIB-based AOP configuration
  • Spring context configuration classes
  • Hystrix collapser property management
  • Dependency injection configuration

Best Practices Demonstrated

The test suite exemplifies proper Spring testing practices and configuration management.

  • Clear separation of concerns between basic and Spring-specific testing
  • Proper use of Spring testing annotations and configurations
  • Effective inheritance structure for test organization
  • Clean dependency management through Spring IoC

netflix/hystrix

hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/spring/configuration/collapser/CollapserPropertiesTest.java

            
/**
 * Copyright 2015 Netflix, Inc.
 * <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.hystrix.contrib.javanica.test.spring.configuration.collapser;

import com.netflix.hystrix.contrib.javanica.test.common.configuration.collapser.BasicCollapserPropertiesTest;
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;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AopCglibConfig.class, CollapserPropertiesTest.CollapserPropertiesTestConfig.class})
public class CollapserPropertiesTest extends BasicCollapserPropertiesTest {

    @Autowired
    private UserService userService;

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


    @Configurable
    public static class CollapserPropertiesTestConfig {

        @Bean
        public BasicCollapserPropertiesTest.UserService userService() {
            return new UserService();
        }
    }
}