Search in sources :

Example 16 with ClusterProcesses

use of org.redisson.ClusterRunner.ClusterProcesses in project redisson by redisson.

the class RedissonBucketsTest method testGetInCluster.

@Test
public void testGetInCluster() 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().setLoadBalancer(new RandomLoadBalancer()).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    RedissonClient redisson = Redisson.create(config);
    int size = 10000;
    Map<String, Integer> map = new HashMap<>();
    for (int i = 0; i < 10; i++) {
        map.put("test" + i, i);
    }
    for (int i = 10; i < size; i++) {
        map.put("test" + i + "{" + (i % 100) + "}", i);
    }
    redisson.getBuckets().set(map);
    Set<String> queryKeys = new HashSet<>(map.keySet());
    queryKeys.add("test_invalid");
    Map<String, Integer> buckets = redisson.getBuckets().get(queryKeys.toArray(new String[map.size()]));
    assertThat(buckets).isEqualTo(map);
    redisson.shutdown();
    process.shutdown();
}
Also used : HashMap(java.util.HashMap) Config(org.redisson.config.Config) RedissonClient(org.redisson.api.RedissonClient) ClusterProcesses(org.redisson.ClusterRunner.ClusterProcesses) RandomLoadBalancer(org.redisson.connection.balancer.RandomLoadBalancer) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 17 with ClusterProcesses

use of org.redisson.ClusterRunner.ClusterProcesses in project redisson by redisson.

the class RedissonBatchTest 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());
    RedissonClient redisson = Redisson.create(config);
    batchOptions.syncSlaves(1, 1, TimeUnit.SECONDS);
    RBatch batch = redisson.createBatch(batchOptions);
    for (int i = 0; i < 100; i++) {
        RMapAsync<String, String> map = batch.getMap("test");
        map.putAsync("" + i, "" + i);
    }
    BatchResult<?> result = 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) RandomString(net.bytebuddy.utility.RandomString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 18 with ClusterProcesses

use of org.redisson.ClusterRunner.ClusterProcesses in project redisson by redisson.

the class RedissonKeysTest method testDeleteInCluster.

@Test
public void testDeleteInCluster() 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().setLoadBalancer(new RandomLoadBalancer()).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    RedissonClient redisson = Redisson.create(config);
    int size = 10000;
    List<String> list = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        list.add("test" + i);
        redisson.getBucket("test" + i).set(i);
    }
    long deletedSize = redisson.getKeys().delete(list.toArray(new String[list.size()]));
    assertThat(deletedSize).isEqualTo(size);
    redisson.shutdown();
    process.shutdown();
}
Also used : ClusterProcesses(org.redisson.ClusterRunner.ClusterProcesses) Config(org.redisson.config.Config) RandomLoadBalancer(org.redisson.connection.balancer.RandomLoadBalancer) Test(org.junit.jupiter.api.Test)

Example 19 with ClusterProcesses

use of org.redisson.ClusterRunner.ClusterProcesses in project redisson by redisson.

the class RedissonTopicTest method testClusterSharding.

@Test
public void testClusterSharding() throws 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().setLoadBalancer(new RandomLoadBalancer()).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    RedissonClient redisson = Redisson.create(config);
    AtomicInteger counter = new AtomicInteger();
    for (int i = 0; i < 10; i++) {
        int j = i;
        RTopic topic = redisson.getTopic("test" + i);
        topic.addListener(Integer.class, (c, v) -> {
            assertThat(v).isEqualTo(j);
            counter.incrementAndGet();
        });
    }
    for (int i = 0; i < 10; i++) {
        RTopic topic = redisson.getTopic("test" + i);
        topic.publish(i);
    }
    Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> counter.get() == 10);
    redisson.shutdown();
    process.shutdown();
}
Also used : ClusterProcesses(org.redisson.ClusterRunner.ClusterProcesses) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Config(org.redisson.config.Config) RedisClientConfig(org.redisson.client.RedisClientConfig) RandomLoadBalancer(org.redisson.connection.balancer.RandomLoadBalancer)

Example 20 with ClusterProcesses

use of org.redisson.ClusterRunner.ClusterProcesses in project redisson by redisson.

the class RedissonTopicTest method testReattachInClusterMaster.

@Test
public void testReattachInClusterMaster() throws Exception {
    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().setSubscriptionMode(SubscriptionMode.MASTER).setLoadBalancer(new RandomLoadBalancer()).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    RedissonClient redisson = Redisson.create(config);
    final AtomicBoolean executed = new AtomicBoolean();
    final AtomicInteger subscriptions = new AtomicInteger();
    RTopic topic = redisson.getTopic("3");
    topic.addListener(new StatusListener() {

        @Override
        public void onUnsubscribe(String channel) {
        }

        @Override
        public void onSubscribe(String channel) {
            subscriptions.incrementAndGet();
        }
    });
    topic.addListener(Integer.class, new MessageListener<Integer>() {

        @Override
        public void onMessage(CharSequence channel, Integer msg) {
            executed.set(true);
        }
    });
    sendCommands(redisson, "3");
    process.getNodes().stream().filter(x -> master1.getPort() == x.getRedisServerPort()).forEach(x -> {
        try {
            x.stop();
            Thread.sleep(18000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    });
    Thread.sleep(25000);
    redisson.getTopic("3").publish(1);
    await().atMost(75, TimeUnit.SECONDS).until(() -> subscriptions.get() == 2);
    assertThat(executed.get()).isTrue();
    redisson.shutdown();
    process.shutdown();
}
Also used : java.util(java.util) RedisConnection(org.redisson.client.RedisConnection) StringCodec(org.redisson.client.codec.StringCodec) org.redisson.api.listener(org.redisson.api.listener) Config(org.redisson.config.Config) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RedisClient(org.redisson.client.RedisClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClusterProcesses(org.redisson.ClusterRunner.ClusterProcesses) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) org.redisson.api(org.redisson.api) ClusterNodeInfo(org.redisson.cluster.ClusterNodeInfo) RedisClientConfig(org.redisson.client.RedisClientConfig) LongCodec(org.redisson.client.codec.LongCodec) Awaitility.await(org.awaitility.Awaitility.await) java.util.concurrent(java.util.concurrent) SubscriptionMode(org.redisson.config.SubscriptionMode) IOException(java.io.IOException) RedisTimeoutException(org.redisson.client.RedisTimeoutException) Collectors(java.util.stream.Collectors) RedisCommands(org.redisson.client.protocol.RedisCommands) Serializable(java.io.Serializable) KEYSPACE_EVENTS_OPTIONS(org.redisson.RedisRunner.KEYSPACE_EVENTS_OPTIONS) AtomicLong(java.util.concurrent.atomic.AtomicLong) org.junit.jupiter.api(org.junit.jupiter.api) RedisStrictCommand(org.redisson.client.protocol.RedisStrictCommand) RandomLoadBalancer(org.redisson.connection.balancer.RandomLoadBalancer) Awaitility(org.awaitility.Awaitility) Config(org.redisson.config.Config) RedisClientConfig(org.redisson.client.RedisClientConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterProcesses(org.redisson.ClusterRunner.ClusterProcesses) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RandomLoadBalancer(org.redisson.connection.balancer.RandomLoadBalancer)

Aggregations

ClusterProcesses (org.redisson.ClusterRunner.ClusterProcesses)20 Config (org.redisson.config.Config)20 RandomLoadBalancer (org.redisson.connection.balancer.RandomLoadBalancer)13 Test (org.junit.jupiter.api.Test)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 RedisProcess (org.redisson.RedisRunner.RedisProcess)6 ClusterNodeInfo (org.redisson.cluster.ClusterNodeInfo)6 IOException (java.io.IOException)5 RedissonClient (org.redisson.api.RedissonClient)5 RedisClientConfig (org.redisson.client.RedisClientConfig)5 java.util (java.util)4 java.util.concurrent (java.util.concurrent)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 Collectors (java.util.stream.Collectors)4 RandomString (net.bytebuddy.utility.RandomString)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Awaitility.await (org.awaitility.Awaitility.await)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4