use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonTest method testManyConnections.
@Test
public void testManyConnections() {
Assume.assumeFalse(RedissonRuntimeEnvironment.isTravis);
Config redisConfig = new Config();
redisConfig.useSingleServer().setConnectionMinimumIdleSize(10000).setConnectionPoolSize(10000).setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
RedissonClient r = Redisson.create(redisConfig);
r.shutdown();
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonTest method testSingleConfigJSON.
@Test
public void testSingleConfigJSON() throws IOException {
RedissonClient r = BaseTest.createInstance();
String t = r.getConfig().toJSON();
Config c = Config.fromJSON(t);
assertThat(c.toJSON()).isEqualTo(t);
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonTopicPatternTest method test.
@Test
public void test() throws InterruptedException {
final CountDownLatch messageRecieved = new CountDownLatch(5);
final CountDownLatch statusRecieved = new CountDownLatch(1);
RedissonClient redisson1 = BaseTest.createInstance();
RPatternTopic<Message> topic1 = redisson1.getPatternTopic("topic.*");
topic1.addListener(new BasePatternStatusListener() {
@Override
public void onPSubscribe(String pattern) {
Assert.assertEquals("topic.*", pattern);
statusRecieved.countDown();
}
});
topic1.addListener((pattern, channel, msg) -> {
Assert.assertEquals(new Message("123"), msg);
messageRecieved.countDown();
});
RedissonClient redisson2 = BaseTest.createInstance();
RTopic<Message> topic2 = redisson2.getTopic("topic.t1");
topic2.addListener((channel, msg) -> {
Assert.assertEquals(new Message("123"), msg);
messageRecieved.countDown();
});
topic2.publish(new Message("123"));
topic2.publish(new Message("123"));
RTopic<Message> topicz = redisson2.getTopic("topicz.t1");
// this message doesn't get
topicz.publish(new Message("789"));
// delivered, and would fail the
// assertion
RTopic<Message> topict2 = redisson2.getTopic("topic.t2");
topict2.publish(new Message("123"));
statusRecieved.await();
Assert.assertTrue(messageRecieved.await(5, TimeUnit.SECONDS));
redisson1.shutdown();
redisson2.shutdown();
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonTopicPatternTest method testLazyUnsubscribe.
@Test
public void testLazyUnsubscribe() throws InterruptedException {
final CountDownLatch messageRecieved = new CountDownLatch(1);
RedissonClient redisson1 = BaseTest.createInstance();
RPatternTopic<Message> topic1 = redisson1.getPatternTopic("topic.*");
int listenerId = topic1.addListener((pattern, channel, msg) -> {
Assert.fail();
});
Thread.sleep(1000);
topic1.removeListener(listenerId);
Thread.sleep(1000);
RedissonClient redisson2 = BaseTest.createInstance();
RPatternTopic<Message> topic2 = redisson2.getPatternTopic("topic.*");
topic2.addListener((pattern, channel, msg) -> {
Assert.assertEquals("topic.*", pattern);
Assert.assertEquals("topic.t1", channel);
Assert.assertEquals(new Message("123"), msg);
messageRecieved.countDown();
});
RTopic<Message> topic3 = redisson2.getTopic("topic.t1");
topic3.publish(new Message("123"));
messageRecieved.await();
redisson1.shutdown();
redisson2.shutdown();
}
use of org.redisson.api.RedissonClient 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();
}
Aggregations