Back to Repositories

Testing Error Propagation with AspectJ Integration in Netflix Hystrix

This test suite validates error propagation behavior in Hystrix’s AspectJ implementation for Java applications. It extends the BasicErrorPropagationTest class to ensure proper error handling and propagation through the Hystrix circuit breaker system.

Test Coverage Overview

The test suite focuses on error propagation scenarios in Hystrix’s Java implementation using AspectJ weaving.

Key areas covered include:
  • Error handling in UserService operations
  • Compile-time AspectJ weaving validation
  • Circuit breaker error propagation patterns
  • Integration with Hystrix’s core error handling mechanisms

Implementation Analysis

The testing approach utilizes inheritance from BasicErrorPropagationTest to leverage common error testing scenarios while implementing AspectJ-specific configurations.

Technical patterns include:
  • System property configuration for compile-time weaving
  • Service instantiation through factory method pattern
  • JUnit test framework integration
  • AspectJ compile-time weaving setup

Technical Details

Testing infrastructure includes:
  • JUnit testing framework
  • AspectJ compile-time weaver
  • Hystrix circuit breaker library
  • Custom UserService implementation
  • System property configuration for weaving mode

Best Practices Demonstrated

The test implementation showcases several testing best practices in Java ecosystem.

Notable practices include:
  • Clean separation of concerns through inheritance
  • Proper test environment setup using @BeforeClass
  • Factory method pattern for service creation
  • Clear test scope definition
  • Effective use of AspectJ compile-time weaving

netflix/hystrix

hystrix-contrib/hystrix-javanica/src/ajcTest/java/com/netflix/hystrix/contrib/javanica/test/aspectj/error/ErrorPropagationTest.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.error;

import com.netflix.hystrix.contrib.javanica.test.common.error.BasicErrorPropagationTest;
import org.junit.BeforeClass;

/**
 * Created by dmgcodevil
 */
public class ErrorPropagationTest extends BasicErrorPropagationTest {

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

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

}