use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class JCacheTest method testUpdateAsync.
@Test
public void testUpdateAsync() throws IOException, InterruptedException, URISyntaxException {
RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
MutableConfiguration<String, String> config = new MutableConfiguration<>();
config.setStoreByValue(true);
URI configUri = getClass().getResource("redisson-jcache.yaml").toURI();
Cache<String, String> cache = Caching.getCachingProvider().getCacheManager(configUri, null).createCache("test", config);
CountDownLatch latch = new CountDownLatch(2);
String key = "123";
UpdatedListener clientListener = new UpdatedListener(latch, key, "80", "90");
MutableCacheEntryListenerConfiguration<String, String> listenerConfiguration = new MutableCacheEntryListenerConfiguration<>(FactoryBuilder.factoryOf(clientListener), null, true, false);
cache.registerCacheEntryListener(listenerConfiguration);
UpdatedListener secondClientListener = new UpdatedListener(latch, key, "80", "90");
MutableCacheEntryListenerConfiguration<String, String> secondListenerConfiguration = new MutableCacheEntryListenerConfiguration<>(FactoryBuilder.factoryOf(secondClientListener), null, false, false);
cache.registerCacheEntryListener(secondListenerConfiguration);
cache.put(key, "80");
assertThat(cache.get(key)).isNotNull();
cache.put(key, "90");
latch.await();
assertThat(cache.get(key)).isNotNull();
cache.close();
runner.stop();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class JCacheTest method testPutAll.
@Test
public void testPutAll() throws Exception {
RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
URL configUrl = getClass().getResource("redisson-jcache.yaml");
Config cfg = Config.fromYAML(configUrl);
Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg);
Cache<String, String> cache = Caching.getCachingProvider().getCacheManager().createCache("test", config);
Map<String, String> map = new HashMap<>();
for (int i = 0; i < 10000; i++) {
map.put("" + i, "" + i);
}
long start = System.currentTimeMillis();
cache.putAll(map);
System.out.println(System.currentTimeMillis() - start);
for (int i = 0; i < 10000; i++) {
assertThat(cache.containsKey("" + i)).isTrue();
}
cache.close();
runner.stop();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class JCacheTest method testJson.
@Test
public void testJson() throws InterruptedException, IllegalArgumentException, URISyntaxException, IOException {
RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
URL configUrl = getClass().getResource("redisson-jcache.yaml");
Config cfg = Config.fromYAML(configUrl);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
cfg.setCodec(new TypedJsonJacksonCodec(String.class, LocalDateTime.class, objectMapper));
Configuration<String, LocalDateTime> config = RedissonConfiguration.fromConfig(cfg);
Cache<String, LocalDateTime> cache = Caching.getCachingProvider().getCacheManager().createCache("test", config);
LocalDateTime t = LocalDateTime.now();
cache.put("1", t);
Assertions.assertEquals(t, cache.get("1"));
cache.close();
runner.stop();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class JCacheTest method testRx.
@Test
public void testRx() throws Exception {
RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
URL configUrl = getClass().getResource("redisson-jcache.yaml");
Config cfg = Config.fromYAML(configUrl);
Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg);
Cache<String, String> cache = Caching.getCachingProvider().getCacheManager().createCache("test", config);
CacheRx<String, String> rx = cache.unwrap(CacheRx.class);
rx.put("1", "2").blockingAwait();
assertThat(rx.get("1").blockingGet()).isEqualTo("2");
cache.close();
runner.stop();
}
use of org.redisson.RedisRunner.RedisProcess in project redisson by redisson.
the class JCacheTest method testCreatedExpiryPolicy.
@Test
public void testCreatedExpiryPolicy() throws Exception {
RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
URL configUrl = getClass().getResource("redisson-jcache.yaml");
Config cfg = Config.fromYAML(configUrl);
MutableConfiguration c = new MutableConfiguration();
c.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(MILLISECONDS, 500)));
Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg, c);
Cache<String, String> cache = Caching.getCachingProvider().getCacheManager().createCache("test", config);
cache.put("1", "2");
Thread.sleep(500);
assertThat(cache.get("1")).isNull();
cache.put("1", "3");
assertThat(cache.get("1")).isEqualTo("3");
Thread.sleep(500);
assertThat(cache.get("1")).isNull();
cache.put("1", "4");
assertThat(cache.get("1")).isEqualTo("4");
Thread.sleep(100);
cache.put("1", "5");
assertThat(cache.get("1")).isEqualTo("5");
cache.close();
runner.stop();
}
Aggregations