Search in sources :

Example 66 with RedisAvailable

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

the class RedisMessageStoreTests method testAddStringMessage.

@Test
@RedisAvailable
public void testAddStringMessage() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    Message<String> stringMessage = new GenericMessage<String>("Hello Redis");
    Message<String> storedMessage = store.addMessage(stringMessage);
    assertNotSame(stringMessage, storedMessage);
    assertEquals("Hello Redis", storedMessage.getPayload());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 67 with RedisAvailable

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

the class RedisMessageStoreTests method testAddAndGetWithPrefix.

@SuppressWarnings("unchecked")
@Test
@RedisAvailable
public void testAddAndGetWithPrefix() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf, "foo");
    Message<String> stringMessage = new GenericMessage<String>("Hello Redis");
    store.addMessage(stringMessage);
    Message<String> retrievedMessage = (Message<String>) store.getMessage(stringMessage.getHeaders().getId());
    assertNotNull(retrievedMessage);
    assertEquals("Hello Redis", retrievedMessage.getPayload());
    StringRedisTemplate template = createStringRedisTemplate(getConnectionFactoryForTest());
    BoundValueOperations<String, String> ops = template.boundValueOps("foo" + "MESSAGE_" + stringMessage.getHeaders().getId());
    assertNotNull(ops.get());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 68 with RedisAvailable

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

the class RedisMessageStoreTests method testAddSerializableObjectMessage.

@Test
@RedisAvailable
public void testAddSerializableObjectMessage() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    Address address = new Address();
    address.setAddress("1600 Pennsylvania Av, Washington, DC");
    Person person = new Person(address, "Barak Obama");
    Message<Person> objectMessage = new GenericMessage<Person>(person);
    Message<Person> storedMessage = store.addMessage(objectMessage);
    assertNotSame(objectMessage, storedMessage);
    assertEquals("Barak Obama", storedMessage.getPayload().getName());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 69 with RedisAvailable

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

the class RedisOutboundChannelAdapterParserTests method validateConfiguration.

@Test
@RedisAvailable
public void validateConfiguration() {
    EventDrivenConsumer adapter = context.getBean("outboundAdapter", EventDrivenConsumer.class);
    Object handler = context.getBean("outboundAdapter.handler");
    assertEquals("outboundAdapter", adapter.getComponentName());
    DirectFieldAccessor accessor = new DirectFieldAccessor(handler);
    Object topicExpression = accessor.getPropertyValue("topicExpression");
    assertNotNull(topicExpression);
    assertEquals("headers['topic'] ?: 'foo'", ((Expression) topicExpression).getExpressionString());
    Object converterBean = context.getBean("testConverter");
    assertEquals(converterBean, accessor.getPropertyValue("messageConverter"));
    assertEquals(context.getBean("serializer"), accessor.getPropertyValue("serializer"));
    Object endpointHandler = TestUtils.getPropertyValue(adapter, "handler");
    assertTrue(AopUtils.isAopProxy(endpointHandler));
    assertThat(TestUtils.getPropertyValue(endpointHandler, "h.advised.advisors.first.item.advice"), Matchers.instanceOf(RequestHandlerRetryAdvice.class));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) RequestHandlerRetryAdvice(org.springframework.integration.handler.advice.RequestHandlerRetryAdvice) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 70 with RedisAvailable

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

the class RedisStoreInboundChannelAdapterIntegrationTests method testListInboundConfiguration.

@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public void testListInboundConfiguration() throws Exception {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.prepareList(jcf);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("list-inbound-adapter.xml", this.getClass());
    SourcePollingChannelAdapter spca = context.getBean("listAdapter", SourcePollingChannelAdapter.class);
    spca.start();
    QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class);
    Message<Integer> message = (Message<Integer>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(Integer.valueOf(13), message.getPayload());
    // poll again, should get the same stuff
    message = (Message<Integer>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(Integer.valueOf(13), message.getPayload());
    this.deletePresidents(jcf);
    context.close();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) 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