Example usage for org.springframework.data.redis.connection.jedis JedisConnectionFactory destroy

List of usage examples for org.springframework.data.redis.connection.jedis JedisConnectionFactory destroy

Introduction

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

Prototype

public void destroy() 

Source Link

Usage

From source file:org.springframework.data.redis.connection.jedis.JedisConnectionFactoryUnitTests.java

/**
 * @throws IOException//from   ww w .j a va 2  s. c  om
 * @see DATAREDIS-315
 */
@Test
public void shouldClostClusterCorrectlyOnFactoryDestruction() throws IOException {

    JedisCluster clusterMock = mock(JedisCluster.class);
    JedisConnectionFactory factory = new JedisConnectionFactory();
    ReflectionTestUtils.setField(factory, "cluster", clusterMock);

    factory.destroy();

    verify(clusterMock, times(1)).close();
}

From source file:org.springframework.integration.redis.inbound.RedisInboundChannelAdapterTests.java

private void testRedisInboundChannelAdapterGuts(int iteration) throws Exception {
    int numToTest = 10;
    String redisChannelName = "testRedisInboundChannelAdapterChannel";
    QueueChannel channel = new QueueChannel();

    JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
    connectionFactory.setPort(7379);/*w ww.  j  av a 2 s . co  m*/
    connectionFactory.afterPropertiesSet();

    RedisInboundChannelAdapter adapter = new RedisInboundChannelAdapter(connectionFactory);
    adapter.setTopics("testRedisInboundChannelAdapterChannel");
    adapter.setOutputChannel(channel);
    adapter.afterPropertiesSet();
    adapter.start();

    RedisMessageListenerContainer container = waitUntilSubscribed(adapter);

    StringRedisTemplate redisTemplate = new StringRedisTemplate(connectionFactory);
    redisTemplate.afterPropertiesSet();
    for (int i = 0; i < numToTest; i++) {
        String message = "test-" + i + " iteration " + iteration;
        redisTemplate.convertAndSend(redisChannelName, message);
        logger.debug("Sent " + message);
    }
    int counter = 0;
    for (int i = 0; i < numToTest; i++) {
        Message<?> message = channel.receive(5000);
        if (message == null) {
            throw new RuntimeException("Failed to receive message # " + i + " iteration " + iteration);
        }
        assertNotNull(message);
        assertTrue(message.getPayload().toString().startsWith("test-"));
        counter++;
    }
    assertEquals(numToTest, counter);
    adapter.stop();
    container.stop();
    connectionFactory.destroy();
}