use of com.netflix.hystrix.contrib.javanica.test.common.domain.User in project Hystrix by Netflix.
the class BasicCacheTest method testGetSetGetUserCache_givenOneCommandAndOneMethodAnnotatedWithCacheRemove.
@Test
public void testGetSetGetUserCache_givenOneCommandAndOneMethodAnnotatedWithCacheRemove() {
// given
User user = userService.getUserById("1");
HystrixInvokableInfo<?> getUserByIdCommand = getLastExecutedCommand();
// this is the first time we've executed this command with
// the value of "1" so it should not be from cache
assertFalse(getUserByIdCommand.isResponseFromCache());
assertEquals("1", user.getId());
// initial name value
assertEquals("name", user.getName());
user = userService.getUserById("1");
assertEquals("1", user.getId());
getUserByIdCommand = getLastExecutedCommand();
// this is the second time we've executed this command with
// the same value so it should return from cache
assertTrue(getUserByIdCommand.isResponseFromCache());
// same name
assertEquals("name", user.getName());
// when
// update the user name
userService.updateName("1", "new_name");
// then
user = userService.getUserById("1");
getUserByIdCommand = getLastExecutedCommand();
// this is the first time we've executed this command after "update"
// method was invoked and a cache for "getUserById" command was flushed
// so the response should not be from cache
assertFalse(getUserByIdCommand.isResponseFromCache());
assertEquals("1", user.getId());
assertEquals("new_name", user.getName());
// start a new request context
resetContext();
user = userService.getUserById("1");
getUserByIdCommand = getLastExecutedCommand();
assertEquals("1", user.getId());
// this is a new request context so this
// should not come from cache
assertFalse(getUserByIdCommand.isResponseFromCache());
}
use of com.netflix.hystrix.contrib.javanica.test.common.domain.User in project Hystrix by Netflix.
the class BasicCommandTest method should_work_with_genericClass_fallback.
@Test
public void should_work_with_genericClass_fallback() {
User user = genericUserService.getByKeyForceFail("1", 2L);
assertEquals("name: 2", user.getName());
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator().next();
assertEquals("getByKeyForceFail", 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 BasicCollapserPropertiesTest method testCollapser.
@Test
public void testCollapser() throws ExecutionException, InterruptedException {
User u1 = userService.getUser("1");
User u2 = userService.getUser("2");
User u3 = userService.getUser("3");
User u4 = userService.getUser("4");
assertEquals("name: 1", u1.getName());
assertEquals("name: 2", u2.getName());
assertEquals("name: 3", u3.getName());
assertEquals("name: 4", u4.getName());
assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator().next();
assertEquals("getUsers", 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 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.contrib.javanica.test.common.domain.User 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));
}
Aggregations