Skip to content

Instantly share code, notes, and snippets.

@debop
Created March 26, 2013 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debop/5243870 to your computer and use it in GitHub Desktop.
Save debop/5243870 to your computer and use it in GitHub Desktop.
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {RedisCacheConfiguration.class})
public class RedisCacheTest {
@Autowired
RedisCacheManager redisCacheManager;
@Autowired
UserRepository userRepository;
@Test
public void clearTest() {
Assert.assertNotNull(redisCacheManager);
Cache cache = redisCacheManager.getCache("user");
Assert.assertNotNull(cache);
cache.clear();
Assert.assertNotNull(cache);
}
@Test
public void getUserFromCache() {
Stopwatch sw = new Stopwatch("initial User");
sw.start();
User user1 = userRepository.getUser("debop", 100);
sw.stop();
sw = new Stopwatch("from Cache");
sw.start();
User user2 = userRepository.getUser("debop", 100);
sw.stop();
Assert.assertEquals(user1.getUsername(), user2.getUsername());
}
@Test
public void componentConfigurationTest() {
Assert.assertNotNull(redisCacheManager);
Cache cache = redisCacheManager.getCache("user");
Assert.assertNotNull(cache);
cache.evict("debop");
Assert.assertNotNull(userRepository);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment