Example usage for org.springframework.data.redis.connection.lettuce LettuceConnectionFactory destroy

List of usage examples for org.springframework.data.redis.connection.lettuce LettuceConnectionFactory destroy

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection.lettuce LettuceConnectionFactory destroy.

Prototype

public void destroy() 

Source Link

Usage

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@Test
public void testSelectDb() {

    LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(),
            SettingsUtils.getPort());//from w ww.  j a va 2 s. c om
    factory2.setClientResources(LettuceTestClientResources.getSharedClientResources());
    factory2.setShutdownTimeout(0);
    factory2.setDatabase(1);
    factory2.afterPropertiesSet();

    ConnectionFactoryTracker.add(factory2);

    StringRedisConnection connection2 = new DefaultStringRedisConnection(factory2.getConnection());
    connection2.flushDb();
    // put an item in database 0
    connection.set("sometestkey", "sometestvalue");
    try {
        // there should still be nothing in database 1
        assertEquals(Long.valueOf(0), connection2.dbSize());
    } finally {
        connection2.close();
        factory2.destroy();
    }
}

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@Test
public void testCreateFactoryWithPool() {
    DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();//www .  j av  a2 s  . c  o m
    LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
    factory2.setShutdownTimeout(0);
    factory2.afterPropertiesSet();

    ConnectionFactoryTracker.add(factory2);

    RedisConnection conn2 = factory2.getConnection();
    conn2.close();
    factory2.destroy();
    pool.destroy();
}

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@Test // DATAREDIS-667
public void factoryCreatesPooledConnections() {

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();

    LettuceClientConfiguration configuration = LettucePoolingClientConfiguration.builder()
            .poolConfig(poolConfig).clientResources(LettuceTestClientResources.getSharedClientResources())
            .shutdownTimeout(Duration.ZERO).build();

    LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration(),
            configuration);//from  www  . j  a  v a  2  s .  co m
    factory.setShareNativeConnection(false);
    factory.afterPropertiesSet();

    ConnectionFactoryTracker.add(factory);

    RedisConnection initial = factory.getConnection();
    Object initialNativeConnection = initial.getNativeConnection();

    initial.close();

    RedisConnection subsequent = factory.getConnection();
    Object subsequentNativeConnection = subsequent.getNativeConnection();

    subsequent.close();

    assertThat(initialNativeConnection, is(subsequentNativeConnection));

    factory.destroy();
}

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@Test // DATAREDIS-687
public void connectsThroughRedisSocket() {

    assumeTrue(EpollProvider.isAvailable() || KqueueProvider.isAvailable());
    assumeTrue(new File(SettingsUtils.getSocket()).exists());

    LettuceClientConfiguration configuration = LettuceTestClientConfiguration.create();

    LettuceConnectionFactory factory = new LettuceConnectionFactory(SettingsUtils.socketConfiguration(),
            configuration);//from   ww w  .j  a  va2  s .  co m
    factory.setShareNativeConnection(false);
    factory.afterPropertiesSet();

    RedisConnection connection = factory.getConnection();
    assertThat(connection.ping(), is(equalTo("PONG")));

    connection.close();
    factory.destroy();
}

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@Test // DATAREDIS-762, DATAREDIS-869
public void factoryUsesElastiCacheMasterReplicaConnections() {

    assumeThat(String.format("No slaves connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
            connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0, is(true));

    LettuceClientConfiguration configuration = LettuceTestClientConfiguration.builder().readFrom(ReadFrom.SLAVE)
            .build();//from w w w .j  a v  a  2  s .  c om

    RedisStaticMasterReplicaConfiguration elastiCache = new RedisStaticMasterReplicaConfiguration(
            SettingsUtils.getHost()).node(SettingsUtils.getHost(), SettingsUtils.getPort() + 1);

    LettuceConnectionFactory factory = new LettuceConnectionFactory(elastiCache, configuration);
    factory.afterPropertiesSet();

    RedisConnection connection = factory.getConnection();

    try {
        assertThat(connection.ping(), is(equalTo("PONG")));
        assertThat(connection.info().getProperty("role"), is(equalTo("slave")));
    } finally {
        connection.close();
    }

    factory.destroy();
}

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@Test // DATAREDIS-762, DATAREDIS-869
public void factoryUsesElastiCacheMasterWithoutMaster() {

    assumeThat(//ww w .ja v  a  2  s  . c  o  m
            String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
            connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0, is(true));

    LettuceClientConfiguration configuration = LettuceTestClientConfiguration.builder()
            .readFrom(ReadFrom.MASTER).build();

    RedisStaticMasterReplicaConfiguration elastiCache = new RedisStaticMasterReplicaConfiguration(
            SettingsUtils.getHost(), SettingsUtils.getPort() + 1);

    LettuceConnectionFactory factory = new LettuceConnectionFactory(elastiCache, configuration);
    factory.afterPropertiesSet();

    RedisConnection connection = factory.getConnection();

    try {
        connection.ping();
        fail("Expected RedisException: Master is currently unknown");
    } catch (RedisSystemException e) {

        assertThat(e.getCause(), is(instanceOf(RedisException.class)));
        assertThat(e.getCause().getMessage(), containsString("Master is currently unknown"));
    } finally {
        connection.close();
    }

    factory.destroy();
}

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@Test // DATAREDIS-580, DATAREDIS-869
public void factoryUsesMasterReplicaConnections() {

    assumeThat(//  w  w  w .  j a v  a 2  s.  co  m
            String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
            connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0, is(true));

    LettuceClientConfiguration configuration = LettuceTestClientConfiguration.builder().readFrom(ReadFrom.SLAVE)
            .build();

    LettuceConnectionFactory factory = new LettuceConnectionFactory(SettingsUtils.standaloneConfiguration(),
            configuration);
    factory.afterPropertiesSet();

    RedisConnection connection = factory.getConnection();

    try {
        assertThat(connection.ping(), is(equalTo("PONG")));
        assertThat(connection.info().getProperty("role"), is(equalTo("slave")));
    } finally {
        connection.close();
    }

    factory.destroy();
}

From source file:org.springframework.xd.test.redis.RedisAvailableRule.java

@Override
public Statement apply(Statement base, Description description) {
    LettuceConnectionFactory connectionFactory = null;
    try {/*from   w  w w  . java2  s . c  o  m*/
        connectionFactory = new LettuceConnectionFactory();
        connectionFactory.afterPropertiesSet();
        connectionFactory.getConnection().close();
    } catch (Exception e) {
        logger.error("REDIS IS NOT AVAILABLE", e);
        fail("REDIS IS NOT AVAILABLE");
    } finally {
        if (connectionFactory != null) {
            connectionFactory.destroy();
        }
    }
    return super.apply(base, description);
}