Skip to content

Commit

Permalink
Merge pull request #945 from dmgcodevil/javanica-iss-907
Browse files Browse the repository at this point in the history
Javanica iss 907
  • Loading branch information
mattrjacobs committed Oct 21, 2015
2 parents bb903ff + fe366ac commit 4dec35d
Show file tree
Hide file tree
Showing 45 changed files with 2,186 additions and 1,235 deletions.
8 changes: 8 additions & 0 deletions hystrix-contrib/hystrix-javanica/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ It doesn't matter which approach you use to create proxies in Spring, javanica w

More about Spring AOP + AspectJ read [here] (http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html)

## Aspect weaving
Javanica supports two weaving modes: compile and runtime. Load time weaving hasn't been tested but it should work. If you tried LTW mode and got any problems then raise javanica issue or create pull request with fix.
- CTW. To use CTW mode you need to use specific jar version: **hystrix-javanica-ctw-X.Y.Z** . This jar is assembled with aspects compiled with using [AJC](https://eclipse.org/aspectj/doc/next/devguide/ajc-ref.html) compiler. If you will try to use regular hystrix-javanica-X.Y.Z with CTW then you get ``` NoSuchMethodError aspectOf() ``` at runtime from building with iajc. Also, you need to start your app with using java property: ```-DWeavingMode=compile```.
**NOTE**: Javanica depends on aspectj library and uses internal features of aspectj and these features aren't provided as a part of open API thus it can change from version to version. Javanica tested with latest aspectj version 1.8.7. If you updated aspectj version and noticed any issues then please don't hestitate to create new issue or contribute.
- RTW works, you can use regular hystrix-javanica-X.Y.Z
- LTM hasn't been tested but it should work fine.


# How to use

## Hystrix command
Expand Down
92 changes: 91 additions & 1 deletion hystrix-contrib/hystrix-javanica/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,106 @@
apply plugin: 'osgi'

configurations {
ajtools
ajcTestCompile.extendsFrom testCompile
ajcTestRuntime.extendsFrom testRuntime
ajc
}


sourceSets {
ajcTest {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}

ajc {
def main = sourceSets.main
java.srcDirs = main.java.srcDirs
resources.srcDirs = main.resources.srcDirs
compileClasspath = main.compileClasspath
runtimeClasspath = main.runtimeClasspath
}
}



compileAjcTestJava {

sourceCompatibility = "1.6"
targetCompatibility = "1.6"

doLast {
ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajtools.asPath)
ant.iajc(source: "1.6", target: "1.6",
destDir: "${sourceSets.ajcTest.output.classesDir.absolutePath}", maxmem: "512m", fork: "true",
classpath: "${sourceSets.main.output.classesDir.absolutePath};${configurations.testCompile.asPath}")
{
sourceroots {
files("src/ajcTest/java/com/netflix/hystrix/contrib/javanica/test/aspectj", "src/test/java/com/netflix/hystrix/contrib/javanica/test/common", "src/main/java/com/netflix/hystrix/contrib/javanica/aop/aspectj").each {
File file -> pathelement(location: file.absolutePath)
}
}
}
}

}

compileAjcJava {
sourceCompatibility = "1.6"
targetCompatibility = "1.6"

doLast {
ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajtools.asPath)
ant.iajc(source: "${sourceCompatibility}", target: "${targetCompatibility}",
destDir: "${sourceSets.ajc.output.classesDir.absolutePath}", maxmem: "512m", fork: "true", "showWeaveInfo": "true",
classpath: "${configurations.compile.asPath}")

{
sourceroots {
sourceSets.ajc.java.srcDirs.each {
pathelement(location: it.absolutePath)

}
}
}
}
}

task ajcTest(type: Test) {
testClassesDir = sourceSets.ajcTest.output.classesDir
classpath = sourceSets.ajcTest.runtimeClasspath
if (System.getProperty('DEBUG', 'false') == 'true') {
jvmArgs '-Xdebug',
'-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009'
}
}

check.dependsOn test, ajcTest


ext {
aspectjVersion = '1.7.4'
}


task ajcJar(type: Jar) {
archiveName = "${project.name}" + "-ctw-${version}.jar"
destinationDir = file("${buildDir}/libs")
from sourceSets.ajc.output
}

assemble.dependsOn(jar, ajcJar)

dependencies {
compile project(':hystrix-core')

ajtools "org.aspectj:aspectjtools:$aspectjVersion"
testRuntime "org.aspectj:aspectjrt:$aspectjVersion"
compile "org.aspectj:aspectjweaver:$aspectjVersion"
compile "org.aspectj:aspectjrt:$aspectjVersion"

compile 'com.google.guava:guava:15.0'
compile 'commons-collections:commons-collections:3.2.1'
compile 'org.apache.commons:commons-lang3:3.1'
compile 'com.google.code.findbugs:jsr305:2.0.0'
testCompile 'junit:junit-dep:4.10'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.netflix.hystrix.contrib.javanica.test.aspectj.cache;

import com.netflix.hystrix.contrib.javanica.test.common.cache.BasicCacheTest;
import org.junit.BeforeClass;

/**
* Created by dmgcodevil
*/
public class CacheTest extends BasicCacheTest {
@BeforeClass
public static void setUpEnv() {
System.setProperty("weavingMode", "compile");
}

@Override
protected UserService createUserService() {
UserService userService = new UserService();
userService.init();
return userService;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.netflix.hystrix.contrib.javanica.test.aspectj.collapser;

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

/**
* Created by dmgcodevil
*/
public class CollapserTest extends BasicCollapserTest {
@BeforeClass
public static void setUpEnv() {
System.setProperty("weavingMode", "compile");
}

@Override
protected UserService createUserService() {
return new UserService();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.netflix.hystrix.contrib.javanica.test.aspectj.command;

import com.netflix.hystrix.contrib.javanica.test.common.command.BasicCommandTest;
import org.junit.BeforeClass;


public class CommandTest extends BasicCommandTest {

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

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

@Override
protected AdvancedUserService createAdvancedUserServiceService() {
return new AdvancedUserService();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.netflix.hystrix.contrib.javanica.test.aspectj.configuration.command;

import com.netflix.hystrix.contrib.javanica.test.common.configuration.command.BasicCommandPropertiesTest;
import org.junit.BeforeClass;

/**
* Created by dmgcodevil
*/
public class CommandPropertiesTest extends BasicCommandPropertiesTest {

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

@Override
protected UserService createUserService() {
return new UserService();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.netflix.hystrix.contrib.javanica.test.aspectj.fallback;

import com.netflix.hystrix.contrib.javanica.test.common.fallback.BasicCommandFallbackTest;
import org.junit.BeforeClass;

/**
* Created by dmgcodevil
*/
public class CommandFallbackTest extends BasicCommandFallbackTest {

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

@Override
protected UserService createUserService() {
return new UserService();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.netflix.hystrix.contrib.javanica.test.aspectj.observable;

import com.netflix.hystrix.contrib.javanica.test.common.observable.BasicObservableTest;
import org.junit.BeforeClass;

/**
* Created by dmgcodevil
*/
public class ObservableTest extends BasicObservableTest {

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

@Override
protected UserService createUserService() {
return new UserService();
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Define the root logger with appender console
log4j.rootLogger = ERROR, CONSOLE

# Define the console appender
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.File=${log}/log.out

# Define the layout for console appender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.conversionPattern=%m%n
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.lang.reflect.Method;

import static com.netflix.hystrix.contrib.javanica.utils.AopUtils.getMethodFromTarget;
import static com.netflix.hystrix.contrib.javanica.utils.EnvUtils.isCompileWeaving;
import static com.netflix.hystrix.contrib.javanica.utils.ajc.AjcUtils.getAjcMethodAroundAdvice;

/**
* AspectJ aspect to process methods which annotated with annotations from
Expand All @@ -54,10 +56,13 @@ public Object methodsAnnotatedWithCacheRemove(final ProceedingJoinPoint joinPoin
MetaHolder metaHolder = MetaHolder.builder()
.args(args).method(method).obj(obj)
.executionType(ExecutionType.SYNCHRONOUS)
.ajcMethod(isCompileWeaving() ? getAjcMethodAroundAdvice(obj.getClass(), method) : null)
.build();
CacheInvocationContext<CacheRemove> context = CacheInvocationContextFactory
.createCacheRemoveInvocationContext(metaHolder);
HystrixRequestCacheManager.getInstance().clearCache(context);
return joinPoint.proceed();
}


}
Loading

0 comments on commit 4dec35d

Please sign in to comment.