Search in sources :

Example 41 with Config

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

the class RedissonTopicPatternTest method testConcurrentTopic.

@Test
public void testConcurrentTopic() throws Exception {
    Config config = BaseTest.createConfig();
    RedissonClient redisson = Redisson.create(config);
    int threads = 30;
    int loops = 50000;
    ExecutorService executor = Executors.newFixedThreadPool(threads);
    List<Future<?>> futures = new ArrayList<>();
    for (int i = 0; i < threads; i++) {
        Runnable worker = new Runnable() {

            @Override
            public void run() {
                for (int j = 0; j < loops; j++) {
                    RPatternTopic<String> t = redisson.getPatternTopic("PUBSUB*");
                    int listenerId = t.addListener(new PatternStatusListener() {

                        @Override
                        public void onPUnsubscribe(String channel) {
                        }

                        @Override
                        public void onPSubscribe(String channel) {
                        }
                    });
                    redisson.getTopic("PUBSUB_" + j).publish("message");
                    t.removeListener(listenerId);
                }
            }
        };
        Future<?> s = executor.submit(worker);
        futures.add(s);
    }
    executor.shutdown();
    Assert.assertTrue(executor.awaitTermination(threads * loops * 1000, TimeUnit.SECONDS));
    for (Future<?> future : futures) {
        future.get();
    }
    redisson.shutdown();
}
Also used : Config(org.redisson.config.Config) ArrayList(java.util.ArrayList) RedissonClient(org.redisson.api.RedissonClient) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) BasePatternStatusListener(org.redisson.api.listener.BasePatternStatusListener) PatternStatusListener(org.redisson.api.listener.PatternStatusListener) Test(org.junit.Test)

Example 42 with Config

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

the class RedissonTopicPatternTest method testReattach.

@Test
public void testReattach() throws InterruptedException, IOException, ExecutionException, TimeoutException {
    RedisProcess runner = new RedisRunner().nosave().randomDir().randomPort().run();
    Config config = new Config();
    config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
    RedissonClient redisson = Redisson.create(config);
    final AtomicBoolean executed = new AtomicBoolean();
    RPatternTopic<Integer> topic = redisson.getPatternTopic("topic*");
    topic.addListener(new PatternMessageListener<Integer>() {

        @Override
        public void onMessage(String pattern, String channel, Integer msg) {
            if (msg == 1) {
                executed.set(true);
            }
        }
    });
    runner.stop();
    runner = new RedisRunner().port(runner.getRedisServerPort()).nosave().randomDir().run();
    Thread.sleep(1000);
    redisson.getTopic("topic1").publish(1);
    await().atMost(5, TimeUnit.SECONDS).untilTrue(executed);
    redisson.shutdown();
    runner.stop();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) Test(org.junit.Test)

Example 43 with Config

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

the class RedissonScheduledExecutorServiceTest method beforeClass.

@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
    if (!RedissonRuntimeEnvironment.isTravis) {
        BaseTest.beforeClass();
        Config config = createConfig();
        RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
        nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test", 1));
        node = RedissonNode.create(nodeConfig);
        node.start();
    }
}
Also used : Config(org.redisson.config.Config) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) BeforeClass(org.junit.BeforeClass)

Example 44 with Config

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

the class JCacheTest method testRedissonConfig.

@Test
public void testRedissonConfig() throws InterruptedException, IllegalArgumentException, URISyntaxException, IOException {
    RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
    URL configUrl = getClass().getResource("redisson-jcache.json");
    Config cfg = Config.fromJSON(configUrl);
    Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg);
    Cache<String, String> cache = Caching.getCachingProvider().getCacheManager().createCache("test", config);
    cache.put("1", "2");
    Assert.assertEquals("2", cache.get("1"));
    cache.close();
    runner.stop();
}
Also used : RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) RedisRunner(org.redisson.RedisRunner) URL(java.net.URL) BaseTest(org.redisson.BaseTest) Test(org.junit.Test)

Example 45 with Config

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

the class RedissonRedLockTest method createClient.

private RedissonClient createClient(NioEventLoopGroup group, String host) {
    Config config1 = new Config();
    config1.useSingleServer().setAddress(host);
    config1.setEventLoopGroup(group);
    RedissonClient client1 = Redisson.create(config1);
    client1.getKeys().flushdb();
    return client1;
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config)

Aggregations

Config (org.redisson.config.Config)68 Test (org.junit.Test)51 RedissonClient (org.redisson.api.RedissonClient)44 RedisProcess (org.redisson.RedisRunner.RedisProcess)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 IOException (java.io.IOException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 RedissonNodeConfig (org.redisson.config.RedissonNodeConfig)4 HashMap (java.util.HashMap)3 ExecutorService (java.util.concurrent.ExecutorService)3 Before (org.junit.Before)3 SerializationCodec (org.redisson.codec.SerializationCodec)3 File (java.io.File)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 LifecycleException (org.apache.catalina.LifecycleException)2 BeforeClass (org.junit.BeforeClass)2 BaseTest.createConfig (org.redisson.BaseTest.createConfig)2 RLock (org.redisson.api.RLock)2 JsonJacksonCodec (org.redisson.codec.JsonJacksonCodec)2