Search in sources :

Example 1 with RedisRunner

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

the class SpringNamespaceWikiTest method testMasterSlave.

@Test
public void testMasterSlave() throws Exception {
    RedisRunner.RedisProcess master = new RedisRunner().requirepass("do_not_use_if_it_is_not_set").nosave().randomDir().run();
    RedisRunner.RedisProcess slave1 = new RedisRunner().requirepass("do_not_use_if_it_is_not_set").masterauth("do_not_use_if_it_is_not_set").port(6380).nosave().randomDir().slaveof("127.0.0.1", 6379).run();
    RedisRunner.RedisProcess slave2 = new RedisRunner().requirepass("do_not_use_if_it_is_not_set").masterauth("do_not_use_if_it_is_not_set").port(6381).nosave().randomDir().slaveof("127.0.0.1", 6379).run();
    try {
        ((ConfigurableApplicationContext) new ClassPathXmlApplicationContext("classpath:org/redisson/spring/support/namespace_wiki_master_slave.xml")).close();
    } finally {
        master.stop();
        slave1.stop();
        slave2.stop();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RedisRunner(org.redisson.RedisRunner) Test(org.junit.Test)

Example 2 with RedisRunner

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

the class SpringNamespaceWikiTest method testSentinel.

@Test
public void testSentinel() throws Exception {
    RedisRunner.RedisProcess master = new RedisRunner().requirepass("do_not_use_if_it_is_not_set").nosave().randomDir().run();
    RedisRunner.RedisProcess slave1 = new RedisRunner().requirepass("do_not_use_if_it_is_not_set").masterauth("do_not_use_if_it_is_not_set").port(6380).nosave().randomDir().slaveof("127.0.0.1", 6379).run();
    RedisRunner.RedisProcess slave2 = new RedisRunner().requirepass("do_not_use_if_it_is_not_set").masterauth("do_not_use_if_it_is_not_set").port(6381).nosave().randomDir().slaveof("127.0.0.1", 6379).run();
    RedisRunner.RedisProcess sentinel1 = new RedisRunner().nosave().randomDir().port(26379).sentinel().sentinelMonitor("myMaster", "127.0.0.1", 6379, 2).sentinelAuthPass("myMaster", "do_not_use_if_it_is_not_set").run();
    RedisRunner.RedisProcess sentinel2 = new RedisRunner().nosave().randomDir().port(26380).sentinel().sentinelMonitor("myMaster", "127.0.0.1", 6379, 2).sentinelAuthPass("myMaster", "do_not_use_if_it_is_not_set").run();
    RedisRunner.RedisProcess sentinel3 = new RedisRunner().nosave().randomDir().port(26381).sentinel().sentinelMonitor("myMaster", "127.0.0.1", 6379, 2).sentinelAuthPass("myMaster", "do_not_use_if_it_is_not_set").run();
    try {
        ((ConfigurableApplicationContext) new ClassPathXmlApplicationContext("classpath:org/redisson/spring/support/namespace_wiki_sentinel.xml")).close();
    } finally {
        master.stop();
        slave1.stop();
        slave2.stop();
        sentinel1.stop();
        sentinel2.stop();
        sentinel3.stop();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RedisRunner(org.redisson.RedisRunner) Test(org.junit.Test)

Example 3 with RedisRunner

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

the class JCacheTest method testExpiration.

@Test
public void testExpiration() throws InterruptedException, IllegalArgumentException, URISyntaxException, FailedToStartRedisException, IOException {
    RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
    MutableConfiguration<String, String> config = new MutableConfiguration<>();
    config.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1)));
    config.setStoreByValue(true);
    URI configUri = getClass().getResource("redisson-jcache.json").toURI();
    Cache<String, String> cache = Caching.getCachingProvider().getCacheManager(configUri, null).createCache("test", config);
    CountDownLatch latch = new CountDownLatch(1);
    String key = "123";
    ExpiredListener clientListener = new ExpiredListener(latch, key, "90");
    MutableCacheEntryListenerConfiguration<String, String> listenerConfiguration = new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(clientListener), null, true, true);
    cache.registerCacheEntryListener(listenerConfiguration);
    cache.put(key, "90");
    Assert.assertNotNull(cache.get(key));
    latch.await();
    Assert.assertNull(cache.get(key));
    cache.close();
    runner.stop();
}
Also used : RedisProcess(org.redisson.RedisRunner.RedisProcess) CacheEntryExpiredListener(javax.cache.event.CacheEntryExpiredListener) MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) Duration(javax.cache.expiry.Duration) 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.Test)

Example 4 with RedisRunner

use of org.redisson.RedisRunner 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 5 with RedisRunner

use of org.redisson.RedisRunner 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

RedisRunner (org.redisson.RedisRunner)7 Test (org.junit.Test)6 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)5 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4 BaseTest (org.redisson.BaseTest)2 ClusterRunner (org.redisson.ClusterRunner)2 RedisProcess (org.redisson.RedisRunner.RedisProcess)2 URI (java.net.URI)1 URL (java.net.URL)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MutableCacheEntryListenerConfiguration (javax.cache.configuration.MutableCacheEntryListenerConfiguration)1 MutableConfiguration (javax.cache.configuration.MutableConfiguration)1 CacheEntryExpiredListener (javax.cache.event.CacheEntryExpiredListener)1 Duration (javax.cache.expiry.Duration)1 Config (org.redisson.config.Config)1