use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.
the class BasicCommandFallbackTest method testGetUserAsyncFallbackAsyncCommand.
@Test
public void testGetUserAsyncFallbackAsyncCommand() throws ExecutionException, InterruptedException {
Future<User> f1 = userService.getUserAsyncFallbackAsyncCommand(" ", "name: ");
assertEquals("def", f1.get().getName());
assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixInvokableInfo<?> getUserAsyncFallbackAsyncCommand = getHystrixCommandByKey("getUserAsyncFallbackAsyncCommand");
com.netflix.hystrix.HystrixInvokableInfo firstAsyncFallbackCommand = getHystrixCommandByKey("firstAsyncFallbackCommand");
com.netflix.hystrix.HystrixInvokableInfo secondAsyncFallbackCommand = getHystrixCommandByKey("secondAsyncFallbackCommand");
com.netflix.hystrix.HystrixInvokableInfo thirdAsyncFallbackCommand = getHystrixCommandByKey("thirdAsyncFallbackCommand");
assertEquals("getUserAsyncFallbackAsyncCommand", getUserAsyncFallbackAsyncCommand.getCommandKey().name());
// confirm that command has failed
assertTrue(getUserAsyncFallbackAsyncCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
// confirm that first fallback has failed
assertTrue(firstAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
// and that second fallback was successful
assertTrue(secondAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
assertTrue(thirdAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
assertTrue(thirdAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
}
use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.
the class BasicDefaultFallbackTest method testClassScopeCommandDefaultFallback.
@Test
public void testClassScopeCommandDefaultFallback() {
String res = serviceWithDefaultCommandFallback.requestString("");
assertEquals(ServiceWithDefaultFallback.DEFAULT_RESPONSE, res);
assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixInvokableInfo<?> requestStringCommand = getHystrixCommandByKey("requestString");
com.netflix.hystrix.HystrixInvokableInfo fallback = getHystrixCommandByKey("classDefaultFallback");
assertEquals("requestString", 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));
}
use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.
the class BasicCollapserTest method testGetUserByIdWithFallbackWithThrowableParam.
@Test
public void testGetUserByIdWithFallbackWithThrowableParam() throws ExecutionException, InterruptedException {
Future<User> f1 = userService.getUserByIdWithFallbackWithThrowableParam("1");
Future<User> f2 = userService.getUserByIdWithFallbackWithThrowableParam("2");
Future<User> f3 = userService.getUserByIdWithFallbackWithThrowableParam("3");
Future<User> f4 = userService.getUserByIdWithFallbackWithThrowableParam("4");
Future<User> f5 = userService.getUserByIdWithFallbackWithThrowableParam("5");
assertEquals("name: 1", f1.get().getName());
assertEquals("name: 2", f2.get().getName());
assertEquals("name: 3", f3.get().getName());
assertEquals("name: 4", f4.get().getName());
assertEquals("name: 5", f5.get().getName());
// 4 commands should be executed
assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixInvokableInfo<?> batchCommand = getHystrixCommandByKey("getUserByIdsThrowsException");
com.netflix.hystrix.HystrixInvokableInfo fallback1 = getHystrixCommandByKey("getUserByIdsFallbackWithThrowableParam1");
com.netflix.hystrix.HystrixInvokableInfo fallback2 = getHystrixCommandByKey("getUserByIdsFallbackWithThrowableParam2");
com.netflix.hystrix.HystrixInvokableInfo fallback3 = getHystrixCommandByKey("getUserByIdsFallbackWithThrowableParam3");
// confirm that command has failed
assertTrue(batchCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
assertTrue(fallback1.getExecutionEvents().contains(HystrixEventType.FAILURE));
assertTrue(fallback2.getExecutionEvents().contains(HystrixEventType.FAILURE));
assertTrue(fallback2.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
// and that last fallback3 was successful
assertTrue(fallback3.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.
the class BasicCollapserTest method testGetUserByIdWithFallback.
@Test
public void testGetUserByIdWithFallback() throws ExecutionException, InterruptedException {
Future<User> f1 = userService.getUserByIdWithFallback("1");
Future<User> f2 = userService.getUserByIdWithFallback("2");
Future<User> f3 = userService.getUserByIdWithFallback("3");
Future<User> f4 = userService.getUserByIdWithFallback("4");
Future<User> f5 = userService.getUserByIdWithFallback("5");
assertEquals("name: 1", f1.get().getName());
assertEquals("name: 2", f2.get().getName());
assertEquals("name: 3", f3.get().getName());
assertEquals("name: 4", f4.get().getName());
assertEquals("name: 5", f5.get().getName());
// two command should be executed: "getUserByIdWithFallback" and "getUserByIdsWithFallback"
assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixInvokableInfo<?> getUserByIdsWithFallback = getHystrixCommandByKey("getUserByIdsWithFallback");
com.netflix.hystrix.HystrixInvokableInfo getUserByIdsFallback = getHystrixCommandByKey("getUserByIdsFallback");
// confirm that command has failed
assertTrue(getUserByIdsWithFallback.getExecutionEvents().contains(HystrixEventType.FAILURE));
assertTrue(getUserByIdsWithFallback.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
// and that fallback was successful
assertTrue(getUserByIdsFallback.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.
the class SerialHystrixRequestEventsTest method testTwoSuccessesSameKey.
@Test
public void testTwoSuccessesSameKey() throws IOException {
List<HystrixInvokableInfo<?>> executions = new ArrayList<HystrixInvokableInfo<?>>();
HystrixInvokableInfo<Integer> foo1 = new SimpleExecution(fooKey, 23, HystrixEventType.SUCCESS);
HystrixInvokableInfo<Integer> foo2 = new SimpleExecution(fooKey, 34, HystrixEventType.SUCCESS);
executions.add(foo1);
executions.add(foo2);
HystrixRequestEvents request = new HystrixRequestEvents(executions);
String actual = SerialHystrixRequestEvents.toJsonString(request);
assertEquals("[{\"name\":\"Foo\",\"events\":[\"SUCCESS\"],\"latencies\":[23,34]}]", actual);
}
Aggregations