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