use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.
the class CommonUtils method getHystrixCommandByKey.
public static HystrixInvokableInfo getHystrixCommandByKey(String key) {
HystrixInvokableInfo hystrixCommand = null;
Collection<HystrixInvokableInfo<?>> executedCommands = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands();
for (HystrixInvokableInfo command : executedCommands) {
if (command.getCommandKey().name().equals(key)) {
hystrixCommand = command;
break;
}
}
return hystrixCommand;
}
use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.
the class BasicCommandFallbackTest method testAsyncCommandWithAsyncFallbackCommand.
@Test
public void testAsyncCommandWithAsyncFallbackCommand() throws ExecutionException, InterruptedException {
Future<User> userFuture = userService.asyncCommandWithAsyncFallbackCommand("", "");
User user = userFuture.get();
assertEquals("def", user.getId());
assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixInvokableInfo<?> asyncCommandWithAsyncFallbackCommand = getHystrixCommandByKey("asyncCommandWithAsyncFallbackCommand");
com.netflix.hystrix.HystrixInvokableInfo asyncFallbackCommand = getHystrixCommandByKey("asyncFallbackCommand");
// confirm that command has failed
assertTrue(asyncCommandWithAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
assertTrue(asyncCommandWithAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
// and that second fallback was successful
assertTrue(asyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.
the class BasicCommandFallbackTest method testGetUserAsyncWithFallbackCommand.
/**
* * **************************** *
* * * TEST FALLBACK COMMANDS * *
* * **************************** *
*/
@Test
public void testGetUserAsyncWithFallbackCommand() throws ExecutionException, InterruptedException {
Future<User> f1 = userService.getUserAsyncFallbackCommand(" ", "name: ");
assertEquals("def", f1.get().getName());
assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixInvokableInfo<?> getUserAsyncFallbackCommand = getHystrixCommandByKey("getUserAsyncFallbackCommand");
com.netflix.hystrix.HystrixInvokableInfo firstFallbackCommand = getHystrixCommandByKey("firstFallbackCommand");
com.netflix.hystrix.HystrixInvokableInfo secondFallbackCommand = getHystrixCommandByKey("secondFallbackCommand");
assertEquals("getUserAsyncFallbackCommand", getUserAsyncFallbackCommand.getCommandKey().name());
// confirm that command has failed
assertTrue(getUserAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
// confirm that first fallback has failed
assertTrue(firstFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
// and that second fallback was successful
assertTrue(secondFallbackCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
}
use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.
the class BasicCommandFallbackTest method testGetUserSyncWithFallbackCommand.
@Test
public void testGetUserSyncWithFallbackCommand() {
User u1 = userService.getUserSyncFallbackCommand(" ", "name: ");
assertEquals("def", u1.getName());
assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixInvokableInfo<?> getUserSyncFallbackCommand = getHystrixCommandByKey("getUserSyncFallbackCommand");
com.netflix.hystrix.HystrixInvokableInfo firstFallbackCommand = getHystrixCommandByKey("firstFallbackCommand");
com.netflix.hystrix.HystrixInvokableInfo secondFallbackCommand = getHystrixCommandByKey("secondFallbackCommand");
assertEquals("getUserSyncFallbackCommand", getUserSyncFallbackCommand.getCommandKey().name());
// confirm that command has failed
assertTrue(getUserSyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
// confirm that first fallback has failed
assertTrue(firstFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
// and that second fallback was successful
assertTrue(secondFallbackCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
}
use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.
the class BasicDefaultFallbackTest method testCommandScopeCommandDefaultFallback.
@Test
public void testCommandScopeCommandDefaultFallback() {
Long res = serviceWithDefaultCommandFallback.commandWithDefaultFallback(1L);
assertEquals(Long.valueOf(0L), res);
assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixInvokableInfo<?> requestStringCommand = getHystrixCommandByKey("commandWithDefaultFallback");
com.netflix.hystrix.HystrixInvokableInfo fallback = getHystrixCommandByKey("defaultCommandFallback");
assertEquals("commandWithDefaultFallback", requestStringCommand.getCommandKey().name());
// confirm that command has failed
assertTrue(requestStringCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
assertTrue(requestStringCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
// confirm that fallback was successful
assertTrue(fallback.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
Aggregations