Search in sources :

Example 71 with Config

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

the class RedissonTest method testClusterConnectionFail.

@Test
public void testClusterConnectionFail() {
    Assertions.assertThrows(RedisConnectionException.class, () -> {
        Config config = new Config();
        config.useClusterServers().addNodeAddress("redis://127.99.0.1:1111");
        Redisson.create(config);
        Thread.sleep(1500);
    });
}
Also used : Config(org.redisson.config.Config) Test(org.junit.jupiter.api.Test)

Example 72 with Config

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

the class RedissonTest method testConfigValidation.

@Test
public void testConfigValidation() {
    Assertions.assertThrows(IllegalArgumentException.class, () -> {
        Config redissonConfig = new Config();
        redissonConfig.useSingleServer().setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort()).setConnectionPoolSize(2);
        Redisson.create(redissonConfig);
    });
}
Also used : Config(org.redisson.config.Config) Test(org.junit.jupiter.api.Test)

Example 73 with Config

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

the class RedissonBatchRxTest method testSyncSlaves.

@ParameterizedTest
@MethodSource("data")
public void testSyncSlaves(BatchOptions batchOptions) throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();
    ClusterRunner clusterRunner = new ClusterRunner().addNode(master1, slave1).addNode(master2, slave2).addNode(master3, slave3);
    ClusterProcesses process = clusterRunner.run();
    Config config = new Config();
    config.useClusterServers().setTimeout(1000000).setRetryInterval(1000000).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    RedissonRxClient redisson = Redisson.create(config).rxJava();
    batchOptions.syncSlaves(1, 1, TimeUnit.SECONDS);
    RBatchRx batch = redisson.createBatch(batchOptions);
    for (int i = 0; i < 100; i++) {
        RMapRx<String, String> map = batch.getMap("test");
        map.put("" + i, "" + i);
    }
    BatchResult<?> result = sync(batch.execute());
    assertThat(result.getResponses()).hasSize(100);
    assertThat(result.getSyncedSlaves()).isEqualTo(1);
    process.shutdown();
    redisson.shutdown();
}
Also used : ClusterProcesses(org.redisson.ClusterRunner.ClusterProcesses) Config(org.redisson.config.Config) RedisRunner(org.redisson.RedisRunner) ClusterRunner(org.redisson.ClusterRunner) RBatchRx(org.redisson.api.RBatchRx) RedissonRxClient(org.redisson.api.RedissonRxClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 74 with Config

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

the class RedissonBatchRxTest method testAtomicSyncSlaves.

@ParameterizedTest
@MethodSource("data")
public void testAtomicSyncSlaves(BatchOptions batchOptions) throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();
    ClusterRunner clusterRunner = new ClusterRunner().addNode(master1, slave1).addNode(master2, slave2).addNode(master3, slave3);
    ClusterProcesses process = clusterRunner.run();
    Config config = new Config();
    config.useClusterServers().setTimeout(123000).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    RedissonRxClient redisson = Redisson.create(config).rxJava();
    batchOptions.executionMode(ExecutionMode.IN_MEMORY_ATOMIC).syncSlaves(1, 1, TimeUnit.SECONDS);
    RBatchRx batch = redisson.createBatch(batchOptions);
    for (int i = 0; i < 10; i++) {
        batch.getAtomicLong("{test}" + i).addAndGet(i);
    }
    BatchResult<?> result = sync(batch.execute());
    assertThat(result.getSyncedSlaves()).isEqualTo(1);
    int i = 0;
    for (Object res : result.getResponses()) {
        assertThat((Long) res).isEqualTo(i++);
    }
    process.shutdown();
    redisson.shutdown();
}
Also used : ClusterProcesses(org.redisson.ClusterRunner.ClusterProcesses) Config(org.redisson.config.Config) AtomicLong(java.util.concurrent.atomic.AtomicLong) RedisRunner(org.redisson.RedisRunner) ClusterRunner(org.redisson.ClusterRunner) RBatchRx(org.redisson.api.RBatchRx) RedissonRxClient(org.redisson.api.RedissonRxClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 75 with Config

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

the class RedissonBatchRxTest method testWriteTimeout.

@ParameterizedTest
@MethodSource("data")
public void testWriteTimeout(BatchOptions batchOptions) throws InterruptedException {
    Config config = BaseTest.createConfig();
    config.useSingleServer().setRetryInterval(700).setTimeout(1500);
    RedissonRxClient redisson = Redisson.create(config).rxJava();
    RBatchRx batch = redisson.createBatch(batchOptions);
    RMapCacheRx<String, String> map = batch.getMapCache("test");
    int total = 10000;
    for (int i = 0; i < total; i++) {
        map.put("" + i, "" + i, 5, TimeUnit.MINUTES);
        if (batchOptions.getExecutionMode() == ExecutionMode.REDIS_WRITE_ATOMIC) {
            if (i % 100 == 0) {
                Thread.sleep(10);
            }
        }
    }
    long s = System.currentTimeMillis();
    sync(batch.execute());
    long executionTime = System.currentTimeMillis() - s;
    if (batchOptions.getExecutionMode() == ExecutionMode.IN_MEMORY) {
        assertThat(executionTime).isLessThan(1000);
    } else {
        assertThat(executionTime).isLessThan(300);
    }
    assertThat(sync(redisson.getMapCache("test").size())).isEqualTo(total);
    redisson.shutdown();
}
Also used : Config(org.redisson.config.Config) RBatchRx(org.redisson.api.RBatchRx) RedissonRxClient(org.redisson.api.RedissonRxClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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