Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed AopUtils#getDeclaredMethod to look for method also in superclasses #723

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}

}