use of com.netflix.hystrix.contrib.javanica.test.common.domain.Profile 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());
}
Aggregations