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();
}
}
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();
}
}
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();
}
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");
}
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();
}
}
}
Aggregations