Search in sources :

Example 46 with Config

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

the class RedissonTest method testMasterSlaveConnectionFail.

@Test(expected = RedisConnectionException.class)
public void testMasterSlaveConnectionFail() throws InterruptedException {
    Config config = new Config();
    config.useMasterSlaveServers().setMasterAddress("127.99.0.1:1111");
    Redisson.create(config);
    Thread.sleep(1500);
}
Also used : Config(org.redisson.config.Config) Test(org.junit.Test)

Example 47 with Config

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

the class RedissonTest method testSer.

@Test(expected = RedisException.class)
public void testSer() {
    Config config = new Config();
    config.useSingleServer().setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
    config.setCodec(new SerializationCodec());
    RedissonClient r = Redisson.create(config);
    r.getMap("test").put("1", new Dummy());
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) SerializationCodec(org.redisson.codec.SerializationCodec) Test(org.junit.Test)

Example 48 with Config

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

the class RedissonTest method testConnectionListener.

@Test
public void testConnectionListener() throws IOException, InterruptedException, TimeoutException {
    final RedisProcess p = redisTestConnection();
    final AtomicInteger connectCounter = new AtomicInteger();
    final AtomicInteger disconnectCounter = new AtomicInteger();
    Config config = new Config();
    config.useSingleServer().setAddress(p.getRedisServerAddressAndPort());
    RedissonClient r = Redisson.create(config);
    int id = r.getNodesGroup().addConnectionListener(new ConnectionListener() {

        @Override
        public void onDisconnect(InetSocketAddress addr) {
            assertThat(addr).isEqualTo(new InetSocketAddress(p.getRedisServerBindAddress(), p.getRedisServerPort()));
            disconnectCounter.incrementAndGet();
        }

        @Override
        public void onConnect(InetSocketAddress addr) {
            assertThat(addr).isEqualTo(new InetSocketAddress(p.getRedisServerBindAddress(), p.getRedisServerPort()));
            connectCounter.incrementAndGet();
        }
    });
    assertThat(id).isNotZero();
    r.getBucket("1").get();
    Assert.assertEquals(0, p.stop());
    try {
        r.getBucket("1").get();
    } catch (Exception e) {
    }
    RedisProcess pp = new RedisRunner().nosave().port(p.getRedisServerPort()).randomDir().run();
    r.getBucket("1").get();
    r.shutdown();
    Assert.assertEquals(0, pp.stop());
    await().atMost(1, TimeUnit.SECONDS).until(() -> assertThat(connectCounter.get()).isEqualTo(1));
    await().until(() -> assertThat(disconnectCounter.get()).isEqualTo(1));
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Config(org.redisson.config.Config) InetSocketAddress(java.net.InetSocketAddress) ConnectionListener(org.redisson.connection.ConnectionListener) RedisException(org.redisson.client.RedisException) TimeoutException(java.util.concurrent.TimeoutException) RedisConnectionException(org.redisson.client.RedisConnectionException) RedisOutOfMemoryException(org.redisson.client.RedisOutOfMemoryException) IOException(java.io.IOException) Test(org.junit.Test)

Example 49 with Config

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

the class CommandHandlersTest method testEncoder.

@Test(expected = RedisException.class)
public void testEncoder() throws InterruptedException {
    Config config = createConfig();
    config.setCodec(new ErrorsCodec());
    RedissonClient redisson = Redisson.create(config);
    redisson.getBucket("1234").set("1234");
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) Test(org.junit.Test)

Example 50 with Config

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

the class RedissonBlockingQueueTest method testPollAsyncReattach.

@Test
public void testPollAsyncReattach() 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);
    RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("queue:pollany");
    RFuture<Integer> f = queue1.pollAsync(10, TimeUnit.SECONDS);
    f.await(1, TimeUnit.SECONDS);
    runner.stop();
    runner = new RedisRunner().port(runner.getRedisServerPort()).nosave().randomDir().run();
    queue1.put(123);
    // check connection rotation
    for (int i = 0; i < 10; i++) {
        queue1.put(i);
    }
    assertThat(queue1.size()).isEqualTo(10);
    Integer result = f.get(1, TimeUnit.SECONDS);
    assertThat(result).isEqualTo(123);
    redisson.shutdown();
    runner.stop();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) Test(org.junit.Test)

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