Search in sources :

Example 56 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.

the class RedisInboundChannelAdapterParserTests method testInboundChannelAdapterMessaging.

@Test
@RedisAvailable
public void testInboundChannelAdapterMessaging() throws Exception {
    RedisInboundChannelAdapter adapter = context.getBean("adapter", RedisInboundChannelAdapter.class);
    this.awaitContainerSubscribedWithPatterns(TestUtils.getPropertyValue(adapter, "container", RedisMessageListenerContainer.class));
    RedisConnectionFactory connectionFactory = this.getConnectionFactoryForTest();
    connectionFactory.getConnection().publish("foo".getBytes(), "Hello Redis from foo".getBytes());
    connectionFactory.getConnection().publish("bar".getBytes(), "Hello Redis from bar".getBytes());
    QueueChannel receiveChannel = context.getBean("receiveChannel", QueueChannel.class);
    for (int i = 0; i < 3; i++) {
        Message<?> receive = receiveChannel.receive(10000);
        assertNotNull(receive);
        assertThat(receive.getPayload(), Matchers.<Object>isOneOf("Hello Redis from foo", "Hello Redis from bar"));
    }
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) RedisMessageListenerContainer(org.springframework.data.redis.listener.RedisMessageListenerContainer) RedisInboundChannelAdapter(org.springframework.integration.redis.inbound.RedisInboundChannelAdapter) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 57 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.

the class PersistentAcceptOnceFileListFilterExternalStoreTests method testFileSystemWithRedisMetadataStore.

@Test
@RedisAvailable
public void testFileSystemWithRedisMetadataStore() throws Exception {
    RedisTemplate<String, ?> template = new RedisTemplate<String, Object>();
    template.setConnectionFactory(this.getConnectionFactoryForTest());
    template.setKeySerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    template.delete("persistentAcceptOnceFileListFilterRedisTests");
    try {
        this.testFileSystem(new RedisMetadataStore(this.getConnectionFactoryForTest(), "persistentAcceptOnceFileListFilterRedisTests"));
    } finally {
        template.delete("persistentAcceptOnceFileListFilterRedisTests");
    }
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) RedisMetadataStore(org.springframework.integration.redis.metadata.RedisMetadataStore) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 58 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.

the class RedisMetadataStoreTests method testGetNonExistingKeyValue.

@Test
@RedisAvailable
public void testGetNonExistingKeyValue() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMetadataStore metadataStore = new RedisMetadataStore(jcf);
    String retrievedValue = metadataStore.get("does-not-exist");
    assertNull(retrievedValue);
}
Also used : RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 59 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.

the class RedisMetadataStoreTests method testGetValueFromMetadataStore.

@Test
@RedisAvailable
public void testGetValueFromMetadataStore() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMetadataStore metadataStore = new RedisMetadataStore(jcf, "testMetadata");
    metadataStore.put("RedisMetadataStoreTests-GetValue", "Hello Redis");
    String retrievedValue = metadataStore.get("RedisMetadataStoreTests-GetValue");
    assertEquals("Hello Redis", retrievedValue);
}
Also used : RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 60 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.

the class RedisMetadataStoreTests method testGetValueWithNullKeyFromMetadataStore.

@Test
@RedisAvailable
public void testGetValueWithNullKeyFromMetadataStore() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMetadataStore metadataStore = new RedisMetadataStore(jcf, "testMetadata");
    try {
        metadataStore.get(null);
    } catch (IllegalArgumentException e) {
        assertEquals("'key' must not be null.", e.getMessage());
        return;
    }
    fail("Expected an IllegalArgumentException to be thrown.");
}
Also used : RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)99 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)99 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)62 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)28 GenericMessage (org.springframework.messaging.support.GenericMessage)24 BeanFactory (org.springframework.beans.factory.BeanFactory)23 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)16 MessageGroup (org.springframework.integration.store.MessageGroup)15 ArrayList (java.util.ArrayList)14 Lock (java.util.concurrent.locks.Lock)13 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)13 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)13 Message (org.springframework.messaging.Message)13 QueueChannel (org.springframework.integration.channel.QueueChannel)12 CountDownLatch (java.util.concurrent.CountDownLatch)11 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)9 JdkSerializationRedisSerializer (org.springframework.data.redis.serializer.JdkSerializationRedisSerializer)9 List (java.util.List)8 DefaultRedisList (org.springframework.data.redis.support.collections.DefaultRedisList)8 RedisList (org.springframework.data.redis.support.collections.RedisList)8