Created
March 26, 2013 08:23
-
-
Save debop/5243870 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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