use of org.summerb.users.api.dto.User in project summerb by skarpushin.
the class UserCachedTest method testGetUserByEmail_expectReferencesEqualityForReturnedDtos.
@Test
public void testGetUserByEmail_expectReferencesEqualityForReturnedDtos() throws Exception {
User userToCreate = UserFactory.createNewUserTemplate();
userToCreate = userService.createUser(userToCreate);
User foundUser = userService.getUserByEmail(userToCreate.getEmail());
User foundUserCached = userService.getUserByEmail(userToCreate.getEmail());
assertTrue(foundUser == foundUserCached);
}
use of org.summerb.users.api.dto.User in project summerb by skarpushin.
the class UserCachedTest method testUpdateUser_expectReferencesNonEqualityForReturnedDtos.
@Test
public void testUpdateUser_expectReferencesNonEqualityForReturnedDtos() throws Exception {
User userToCreate = UserFactory.createNewUserTemplate();
userToCreate.setDisplayName("Display name");
userToCreate = userService.createUser(userToCreate);
User foundUser = userService.getUserByUuid(userToCreate.getUuid());
userToCreate.setDisplayName("Another display name");
userService.updateUser(userToCreate);
User foundUserAgain = userService.getUserByUuid(userToCreate.getUuid());
assertTrue(foundUser != foundUserAgain);
assertTrue(foundUserAgain.getDisplayName().equals("Another display name"));
}
use of org.summerb.users.api.dto.User in project summerb by skarpushin.
the class UserCachedTest method testDeleteUser_expectUserNotFoundException.
// (expected=UserNotFoundException.class)
@Test
public void testDeleteUser_expectUserNotFoundException() throws Exception {
User userToCreate = UserFactory.createNewUserTemplate();
userToCreate = userService.createUser(userToCreate);
userService.getUserByUuid(userToCreate.getUuid());
userService.deleteUserByUuid(userToCreate.getUuid());
try {
userService.getUserByUuid(userToCreate.getUuid());
fail();
} catch (UserNotFoundException e) {
}
}
use of org.summerb.users.api.dto.User in project summerb by skarpushin.
the class UserCachedTest method testPerformance_expectCacheFaster.
@Test
public void testPerformance_expectCacheFaster() throws Exception {
User userToCreate = UserFactory.createNewUserTemplate();
userToCreate = userService.createUser(userToCreate);
int cycles = 1000;
long before = new Date().getTime();
for (int i = 0; i < cycles; i++) {
userService.getUserByUuid(userToCreate.getUuid());
}
long after = new Date().getTime() - before;
long beforeNonCached = new Date().getTime();
for (int i = 0; i < cycles; i++) {
userServiceNoncached.getUserByUuid(userToCreate.getUuid());
}
long afterNonCached = new Date().getTime() - beforeNonCached;
System.out.println("Cached: " + after + "ms");
System.out.println("Noncached: " + afterNonCached + "ms");
assertTrue(afterNonCached / 5 > after);
}
use of org.summerb.users.api.dto.User in project summerb by skarpushin.
the class UserServiceCachedImpl method afterPropertiesSet.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void afterPropertiesSet() throws Exception {
CacheBuilder cacheBuilder = (CacheBuilder) CacheBuilder.newBuilder().maximumSize(1000).recordStats();
cacheByEmail = new TransactionBoundCache<String, User>("UserCacheByEmail", cacheBuilder, loaderByEmail);
cacheByUuid = new TransactionBoundCache<String, User>("UserCacheByUuid", cacheBuilder, loaderByUuid);
eventBus.register(this);
}
Aggregations