The code that triggers the OptimisticLockingFailureException:
@Test
public void shouldIncrementUserTotalLikesByOne() throws IllegalArgumentException, UserNotFoundException {
databuilderService.createAll();
User user = userService.findByEmail("abc@gmail.com");
long numberOfLikeCount = user.getLikeCount();
userService.incrementUserTotalLikesByOne(user.getId());
userService.save(user);
long numberOfUpdatedUpdatedCount = user.getLikeCount();
Assert.assertNotNull(numberOfUpdatedUpdatedCount);
Assert.assertEquals(numberOfUpdatedUpdatedCount, numberOfLikeCount+1);
}
The exception occurs when UserService.save()
is called:
org.springframework.dao.OptimisticLockingFailureException: Optimistic lock exception on saving entity: