use of com.netflix.hystrix.contrib.javanica.test.common.domain.User in project Hystrix by Netflix.
the class BasicCollapserTest method testReactive.
@Test
public void testReactive() throws Exception {
final Observable<User> u1 = userService.getUserByIdReactive("1");
final Observable<User> u2 = userService.getUserByIdReactive("2");
final Observable<User> u3 = userService.getUserByIdReactive("3");
final Observable<User> u4 = userService.getUserByIdReactive("4");
final Observable<User> u5 = userService.getUserByIdReactive("5");
final Iterable<User> users = Observable.merge(u1, u2, u3, u4, u5).toBlocking().toIterable();
Set<String> expectedIds = Sets.newHashSet("1", "2", "3", "4", "5");
for (User cUser : users) {
assertEquals(expectedIds.remove(cUser.getId()), true);
}
assertEquals(expectedIds.isEmpty(), true);
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator().next();
// assert the command is the one we're expecting
assertEquals("getUserByIds", command.getCommandKey().name());
// confirm that it was a COLLAPSED command execution
assertTrue(command.getExecutionEvents().contains(HystrixEventType.COLLAPSED));
// and that it was successful
assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
use of com.netflix.hystrix.contrib.javanica.test.common.domain.User in project Hystrix by Netflix.
the class BasicCommandFallbackTest method testCommandWithFallbackWithAdditionalParameter.
@Test
public void testCommandWithFallbackWithAdditionalParameter() {
User user = userService.commandWithFallbackWithAdditionalParameter("", "");
assertEquals("def", user.getName());
}
use of com.netflix.hystrix.contrib.javanica.test.common.domain.User in project Hystrix by Netflix.
the class BasicCommandFallbackTest method testGetUserSyncWithFallback.
@Test
public void testGetUserSyncWithFallback() {
User u1 = userService.getUserSync(" ", "name: ");
assertEquals("def", u1.getName());
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator().next();
assertEquals("getUserSync", command.getCommandKey().name());
// confirm that command has failed
assertTrue(command.getExecutionEvents().contains(HystrixEventType.FAILURE));
// and that fallback was successful
assertTrue(command.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
}
use of com.netflix.hystrix.contrib.javanica.test.common.domain.User 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.contrib.javanica.test.common.domain.User in project Hystrix by Netflix.
the class BasicCommandFallbackTest method testCommandWithFallbackReturnSubType.
@Test
public void testCommandWithFallbackReturnSubType() {
User user = (User) userService.commandWithFallbackReturnSubType("", "");
assertEquals("def", user.getName());
}
Aggregations