Skip to content

Commit

Permalink
Merge pull request #723 from vitalatron/fix_getDeclaredMethod_to_trav…
Browse files Browse the repository at this point in the history
…erse_superclasses

fixed AopUtils#getDeclaredMethod to look for method also in superclasses
  • Loading branch information
mattrjacobs committed Mar 25, 2015
2 parents d8b66b8 + c1e6144 commit 6bf605e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public static Method getDeclaredMethod(Class<?> type, String methodName, Class<?
try {
method = type.getDeclaredMethod(methodName, parameterTypes);
} catch (NoSuchMethodException e) {
// do nothing
Class<?> superclass = type.getSuperclass();
if (superclass != null) {
method = getDeclaredMethod(superclass, methodName, parameterTypes);
}
}
return method;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class CommandTest {

@Autowired
private UserService userService;
@Autowired
private AdvancedUserService advancedUserService;
private HystrixRequestContext context;

@Before
Expand Down Expand Up @@ -83,13 +85,13 @@ public void testGetUserAsync() throws ExecutionException, InterruptedException {
@Test
public void testGetUserSync() {
User u1 = userService.getUserSync("1", "name: ");
assertEquals("name: 1", u1.getName());
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
com.netflix.hystrix.HystrixInvokableInfo<?> command = getCommand();
assertEquals("getUserSync", command.getCommandKey().name());
assertEquals("UserGroup", command.getCommandGroup().name());
assertEquals("UserGroup", command.getThreadPoolKey().name());
assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS));
assertGetUserSnycCommandExecuted(u1);
}

@Test
public void shouldWorkWithInheritedMethod() {
User u1 = advancedUserService.getUserSync("1", "name: ");
assertGetUserSnycCommandExecuted(u1);
}

@Test
Expand All @@ -100,6 +102,16 @@ public void should_work_with_parameterized_method() throws Exception {
assertTrue(getCommand().getExecutionEvents().contains(HystrixEventType.SUCCESS));
}

private void assertGetUserSnycCommandExecuted(User u1) {
assertEquals("name: 1", u1.getName());
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
com.netflix.hystrix.HystrixInvokableInfo<?> command = getCommand();
assertEquals("getUserSync", command.getCommandKey().name());
assertEquals("UserGroup", command.getCommandGroup().name());
assertEquals("UserGroup", command.getThreadPoolKey().name());
assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}

private com.netflix.hystrix.HystrixInvokableInfo<?> getCommand() {
return HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator().next();
}
Expand Down Expand Up @@ -128,13 +140,22 @@ public <T> T echo(T value) {

}

public static class AdvancedUserService extends UserService {

}

@Configurable
public static class CommandTestConfig {

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

@Bean
public AdvancedUserService advancedUserService() {
return new AdvancedUserService();
}
}

}

0 comments on commit 6bf605e

Please sign in to comment.