Search in sources :

Example 1 with ClusterRunner

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

the class SpringNamespaceTest method startContext.

public static void startContext() throws Exception {
    System.setProperty("redisAddress", RedisRunner.getDefaultRedisServerBindAddressAndPort());
    //Needs a instance running on the default port, launch it if there isn't one already
    if (RedisRunner.isFreePort(6379)) {
        new RedisRunner().nosave().randomDir().run();
    }
    RedisRunner.RedisProcess slave1 = new RedisRunner().nosave().randomDir().randomPort().slaveof(RedisRunner.getDefaultRedisServerInstance().getRedisServerBindAddress(), RedisRunner.getDefaultRedisServerInstance().getRedisServerPort()).run();
    System.setProperty("slave1Address", slave1.getRedisServerAddressAndPort());
    RedisRunner.RedisProcess slave2 = new RedisRunner().nosave().randomDir().randomPort().slaveof(RedisRunner.getDefaultRedisServerInstance().getRedisServerBindAddress(), RedisRunner.getDefaultRedisServerInstance().getRedisServerPort()).run();
    System.setProperty("slave2Address", slave2.getRedisServerAddressAndPort());
    RedisRunner.RedisProcess sentinel1 = new RedisRunner().nosave().randomDir().randomPort().sentinel().sentinelMonitor("myMaster", RedisRunner.getDefaultRedisServerInstance().getRedisServerBindAddress(), RedisRunner.getDefaultRedisServerInstance().getRedisServerPort(), 2).run();
    System.setProperty("sentinel1Address", sentinel1.getRedisServerAddressAndPort());
    RedisRunner.RedisProcess sentinel2 = new RedisRunner().nosave().randomDir().randomPort().sentinel().sentinelMonitor("myMaster", RedisRunner.getDefaultRedisServerInstance().getRedisServerBindAddress(), RedisRunner.getDefaultRedisServerInstance().getRedisServerPort(), 2).run();
    System.setProperty("sentinel2Address", sentinel2.getRedisServerAddressAndPort());
    RedisRunner.RedisProcess sentinel3 = new RedisRunner().nosave().randomDir().randomPort().sentinel().sentinelMonitor("myMaster", RedisRunner.getDefaultRedisServerInstance().getRedisServerBindAddress(), RedisRunner.getDefaultRedisServerInstance().getRedisServerPort(), 2).run();
    System.setProperty("sentinel3Address", sentinel3.getRedisServerAddressAndPort());
    ClusterRunner clusterRunner = new ClusterRunner().addNode(new RedisRunner().randomPort().randomDir().nosave()).addNode(new RedisRunner().randomPort().randomDir().nosave()).addNode(new RedisRunner().randomPort().randomDir().nosave());
    List<RedisRunner.RedisProcess> nodes = clusterRunner.run();
    nodes.stream().forEach((node) -> {
        System.setProperty("node" + (nodes.indexOf(node) + 1) + "Address", node.getRedisServerAddressAndPort());
    });
    context = new ClassPathXmlApplicationContext("classpath:org/redisson/spring/support/namespace.xml");
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RedisRunner(org.redisson.RedisRunner) ClusterRunner(org.redisson.ClusterRunner)

Example 2 with ClusterRunner

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

the class SpringNamespaceWikiTest method testCluster.

@Test
public void testCluster() throws Exception {
    ClusterRunner clusterRunner = new ClusterRunner().addNode(new RedisRunner().requirepass("do_not_use_if_it_is_not_set").port(6379).randomDir().nosave()).addNode(new RedisRunner().requirepass("do_not_use_if_it_is_not_set").port(6380).randomDir().nosave()).addNode(new RedisRunner().requirepass("do_not_use_if_it_is_not_set").port(6381).randomDir().nosave());
    List<RedisRunner.RedisProcess> nodes = clusterRunner.run();
    try {
        ((ConfigurableApplicationContext) new ClassPathXmlApplicationContext("classpath:org/redisson/spring/support/namespace_wiki_cluster.xml")).close();
    } finally {
        for (RedisRunner.RedisProcess node : nodes) {
            node.stop();
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClusterRunner(org.redisson.ClusterRunner) RedisRunner(org.redisson.RedisRunner) Test(org.junit.Test)

Aggregations

ClusterRunner (org.redisson.ClusterRunner)2 RedisRunner (org.redisson.RedisRunner)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 Test (org.junit.Test)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1