Search in sources :

Example 76 with Config

use of org.redisson.config.Config in project redisson by redisson.

the class RedissonTest method testNextResponseAfterDecoderError.

@Test
public void testNextResponseAfterDecoderError() throws Exception {
    Config config = new Config();
    config.useSingleServer().setConnectionMinimumIdleSize(1).setConnectionPoolSize(1).setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
    RedissonClient redisson = Redisson.create(config);
    setJSONValue(redisson, "test1", "test1");
    setStringValue(redisson, "test2", "test2");
    setJSONValue(redisson, "test3", "test3");
    try {
        RBuckets buckets = redisson.getBuckets(new JsonJacksonCodec());
        buckets.get("test2", "test1");
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertThat(getStringValue(redisson, "test3")).isEqualTo("\"test3\"");
    redisson.shutdown();
}
Also used : JsonJacksonCodec(org.redisson.codec.JsonJacksonCodec) Config(org.redisson.config.Config) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 77 with Config

use of org.redisson.config.Config in project redisson by redisson.

the class RedissonTwoLockedThread method testCountDown.

@ParameterizedTest
@MethodSource("data")
public void testCountDown(Codec codec) throws InterruptedException {
    Config config = BaseTest.createConfig();
    config.setCodec(codec);
    RedissonClient redisson = Redisson.create(config);
    Assertions.assertTimeout(Duration.ofSeconds(3), () -> {
        final String countDownName = getClass().getName() + ":countDown#1";
        final CountDownLatch startSignal = new CountDownLatch(1);
        final CountDownLatch testSignal = new CountDownLatch(1);
        final CountDownLatch completeSignal = new CountDownLatch(2);
        System.out.println("configure");
        final long millis = System.currentTimeMillis();
        new Thread() {

            @Override
            public void run() {
                try {
                    startSignal.await();
                    RCountDownLatch countDownLatch = redisson.getCountDownLatch(countDownName);
                    System.out.println("1. getCountDownLatch " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
                    countDownLatch.trySetCount(1);
                    System.out.println("1. trySetCount " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
                    Thread.sleep(500);
                    testSignal.countDown();
                    Thread.sleep(500);
                    System.out.println("1. sleep " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
                    countDownLatch.countDown();
                    System.out.println("1. countDown " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                completeSignal.countDown();
            }
        }.start();
        new Thread() {

            @Override
            public void run() {
                try {
                    testSignal.await();
                    RCountDownLatch countDownLatch = redisson.getCountDownLatch(countDownName);
                    System.out.println("2. getCountDownLatch " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
                    countDownLatch.await();
                    System.out.println("2. await " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
                    long current = System.currentTimeMillis();
                    Assertions.assertTrue((current - millis) >= 1000, "current=" + current + ", millis=" + millis);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                completeSignal.countDown();
            }
        }.start();
        System.out.println("start");
        startSignal.countDown();
        completeSignal.await();
        System.out.println("complete");
    });
}
Also used : RCountDownLatch(org.redisson.api.RCountDownLatch) RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) RCountDownLatch(org.redisson.api.RCountDownLatch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 78 with Config

use of org.redisson.config.Config in project redisson by redisson.

the class JCacheTest method testGetAll.

@Test
public void testGetAll() 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);
    cache.put("1", "2");
    cache.put("3", "4");
    Map<String, String> entries = cache.getAll(new HashSet<String>(Arrays.asList("1", "3", "7")));
    Map<String, String> expected = new HashMap<String, String>();
    expected.put("1", "2");
    expected.put("3", "4");
    assertThat(entries).isEqualTo(expected);
    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 79 with Config

use of org.redisson.config.Config in project redisson by redisson.

the class JCacheTest method testReactive.

@Test
public void testReactive() 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);
    CacheReactive<String, String> reactive = cache.unwrap(CacheReactive.class);
    reactive.put("1", "2").block();
    assertThat(reactive.get("1").block()).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 80 with Config

use of org.redisson.config.Config in project redisson by redisson.

the class JCacheTest method testGetAllHighVolume.

@Test
public void testGetAllHighVolume() 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> m = new HashMap<>();
    for (int i = 0; i < 10000; i++) {
        m.put("" + i, "" + i);
    }
    cache.putAll(m);
    Map<String, String> entries = cache.getAll(m.keySet());
    assertThat(entries).isEqualTo(m);
    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)

Aggregations

Config (org.redisson.config.Config)182 Test (org.junit.jupiter.api.Test)109 RedissonClient (org.redisson.api.RedissonClient)69 RedisProcess (org.redisson.RedisRunner.RedisProcess)52 RandomLoadBalancer (org.redisson.connection.balancer.RandomLoadBalancer)33 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)30 ClusterProcesses (org.redisson.ClusterRunner.ClusterProcesses)23 IOException (java.io.IOException)22 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17 RedisRunner (org.redisson.RedisRunner)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)15 BaseTest (org.redisson.BaseTest)15 RandomString (net.bytebuddy.utility.RandomString)14 URL (java.net.URL)12 RedisClientConfig (org.redisson.client.RedisClientConfig)12 Test (org.junit.Test)11 RLock (org.redisson.api.RLock)10 RedissonNodeConfig (org.redisson.config.RedissonNodeConfig)10 CountDownLatch (java.util.concurrent.CountDownLatch)9