Back to Repositories

Testing Hystrix Collapser Properties with AspectJ Weaving in Netflix/Hystrix

This test suite validates the configuration properties of Hystrix request collapsing functionality using AspectJ weaving. It extends basic collapser property tests while implementing compile-time weaving mode for enhanced performance and reliability.

Test Coverage Overview

The test suite covers Hystrix request collapsing configuration properties in an AspectJ environment.

Key areas tested include:
  • Compile-time weaving mode configuration
  • User service creation and initialization
  • Inheritance of basic collapser property tests
  • Environment setup for AspectJ compilation

Implementation Analysis

The testing approach leverages AspectJ’s compile-time weaving for Hystrix command execution. The test class extends BasicCollapserPropertiesTest while implementing specific AspectJ configurations through system property settings and custom service initialization.

Technical patterns include:
  • Inheritance-based test structure
  • System property configuration for weaving mode
  • Factory method pattern for service creation

Technical Details

Testing tools and configuration:
  • JUnit test framework
  • AspectJ compile-time weaver
  • Hystrix Javanica contribution module
  • System property ‘weavingMode’ set to ‘compile’
  • Custom UserService implementation

Best Practices Demonstrated

The test implementation showcases several testing best practices for aspect-oriented programming with Hystrix.

Notable practices include:
  • Clean separation of concerns through inheritance
  • Explicit environment configuration in @BeforeClass
  • Factory method pattern for test subject creation
  • Clear test scope definition through class structure

netflix/hystrix

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

            
/**
 * Copyright 2016 Netflix, Inc.
 *
 * 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
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.aspectj.configuration.collapser;

import com.netflix.hystrix.contrib.javanica.test.common.configuration.collapser.BasicCollapserPropertiesTest;
import org.junit.BeforeClass;

/**
 * Created by dmgcodevil
 */
public class CollapserPropertiesTest extends BasicCollapserPropertiesTest {

    @BeforeClass
    public static void setUpEnv() {
        System.setProperty("weavingMode", "compile");
    }

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