Search in sources :

Example 36 with RedisProcess

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();
}
Also used : CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) RedisProcess(org.redisson.RedisRunner.RedisProcess) MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) RedisRunner(org.redisson.RedisRunner) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) MutableConfiguration(javax.cache.configuration.MutableConfiguration) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 37 with RedisProcess

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();
}
Also used : RedisProcess(org.redisson.RedisRunner.RedisProcess) HashMap(java.util.HashMap) Config(org.redisson.config.Config) RedisRunner(org.redisson.RedisRunner) URL(java.net.URL) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 38 with RedisProcess

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();
}
Also used : LocalDateTime(java.time.LocalDateTime) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) RedisRunner(org.redisson.RedisRunner) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TypedJsonJacksonCodec(org.redisson.codec.TypedJsonJacksonCodec) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 39 with RedisProcess

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();
}
Also used : RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) RedisRunner(org.redisson.RedisRunner) URL(java.net.URL) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 40 with RedisProcess

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();
}
Also used : RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) Duration(javax.cache.expiry.Duration) RedisRunner(org.redisson.RedisRunner) URL(java.net.URL) MutableConfiguration(javax.cache.configuration.MutableConfiguration) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

RedisProcess (org.redisson.RedisRunner.RedisProcess)55 Test (org.junit.jupiter.api.Test)49 Config (org.redisson.config.Config)41 RedissonClient (org.redisson.api.RedissonClient)30 BaseTest (org.redisson.BaseTest)16 RedisRunner (org.redisson.RedisRunner)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 RLock (org.redisson.api.RLock)12 URL (java.net.URL)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 IOException (java.io.IOException)6 TimeoutException (java.util.concurrent.TimeoutException)6 MutableConfiguration (javax.cache.configuration.MutableConfiguration)6 URI (java.net.URI)5 ExecutionException (java.util.concurrent.ExecutionException)5 MutableCacheEntryListenerConfiguration (javax.cache.configuration.MutableCacheEntryListenerConfiguration)5 HashMap (java.util.HashMap)4 ExecutorService (java.util.concurrent.ExecutorService)4 ClusterProcesses (org.redisson.ClusterRunner.ClusterProcesses)4