use of com.netflix.hystrix.contrib.javanica.test.common.domain.User 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.contrib.javanica.test.common.domain.User in project Hystrix by Netflix.
the class BasicObservableTest method testGetUserWithRegularFallback.
@Test
public void testGetUserWithRegularFallback() {
final User exUser = new User("def", "def");
Observable<User> userObservable = userService.getUserRegularFallback(" ", "");
// blocking
assertEquals(exUser, userObservable.toBlocking().single());
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
com.netflix.hystrix.HystrixInvokableInfo getUserCommand = getHystrixCommandByKey("getUserRegularFallback");
// confirm that command has failed
assertTrue(getUserCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
// and that fallback was successful
assertTrue(getUserCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
}
use of com.netflix.hystrix.contrib.javanica.test.common.domain.User in project Hystrix by Netflix.
the class BasicObservableTest method testGetUserWithRxFallback.
@Test
public void testGetUserWithRxFallback() {
final User exUser = new User("def", "def");
// blocking
assertEquals(exUser, userService.getUserRxFallback(" ", "").toBlocking().single());
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
com.netflix.hystrix.HystrixInvokableInfo getUserCommand = getHystrixCommandByKey("getUserRxFallback");
// confirm that command has failed
assertTrue(getUserCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
// and that fallback was successful
assertTrue(getUserCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
}
use of com.netflix.hystrix.contrib.javanica.test.common.domain.User in project Hystrix by Netflix.
the class BasicCacheTest method testGetSetGetUserCache_givenGetUserByEmailAndUpdateProfile.
@Test
public void testGetSetGetUserCache_givenGetUserByEmailAndUpdateProfile() {
User user = userService.getUserByEmail("email");
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());
assertEquals("name", user.getName());
// initial email value
assertEquals("email", user.getProfile().getEmail());
user = userService.getUserByEmail("email");
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 email
assertEquals("email", user.getProfile().getEmail());
// create new user with same id but with new email
Profile profile = new Profile();
profile.setEmail("new_email");
user.setProfile(profile);
// update the user profile
userService.updateProfile(user);
user = userService.getUserByEmail("new_email");
getUserByIdCommand = getLastExecutedCommand();
// this is the first time we've executed this command after "updateProfile"
// method was invoked and a cache for "getUserByEmail" command was flushed
// so the response should not be from cache
assertFalse(getUserByIdCommand.isResponseFromCache());
assertEquals("1", user.getId());
assertEquals("name", user.getName());
assertEquals("new_email", user.getProfile().getEmail());
// start a new request context
resetContext();
user = userService.getUserByEmail("new_email");
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 BasicCacheTest method testGetSetGetUserCache_givenTwoCommands.
/**
* Get-Set-Get with Request Cache Invalidation Test.
* <p/>
* given:
* command to get user by id, see {@link UserService#getUserById(String)}
* command to update user, see {@link UserService#update(com.netflix.hystrix.contrib.javanica.test.common.domain.User)}
* <p/>
* when:
* 1. call {@link UserService#getUserById(String)}
* 2. call {@link UserService#getUserById(String)}
* 3. call {@link UserService#update(com.netflix.hystrix.contrib.javanica.test.common.domain.User)}
* 4. call {@link UserService#getUserById(String)}
* <p/>
* then:
* at the first time "getUserById" command shouldn't retrieve value from cache
* at the second time "getUserById" command should retrieve value from cache
* "update" method should update an user and flush cache related to "getUserById" command
* after "update" method execution "getUserById" command shouldn't retrieve value from cache
*/
@Test
public void testGetSetGetUserCache_givenTwoCommands() {
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());
// create new user with same id but with new name
user = new User("1", "new_name");
// update the user
userService.update(user);
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());
}
Aggregations