Search in sources :

Example 76 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisStoreInboundChannelAdapterIntegrationTests method testListInboundConfigurationWithSynchronizationAndRollback.

@SuppressWarnings("resource")
@Test
@RedisAvailable
public // synchronization rollback renames the list
void testListInboundConfigurationWithSynchronizationAndRollback() throws Exception {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    StringRedisTemplate template = this.createStringRedisTemplate(jcf);
    template.delete("baz");
    this.prepareList(jcf);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("list-inbound-adapter.xml", this.getClass());
    SubscribableChannel fail = context.getBean("redisFailChannel", SubscribableChannel.class);
    final CountDownLatch latch = new CountDownLatch(1);
    fail.subscribe(message -> {
        latch.countDown();
        throw new RuntimeException("Test Rollback");
    });
    SourcePollingChannelAdapter spca = context.getBean("listAdapterWithSynchronizationAndRollback", SourcePollingChannelAdapter.class);
    spca.start();
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    int n = 0;
    while (n++ < 100 && template.keys("baz").size() == 0) {
        Thread.sleep(100);
    }
    assertTrue("Rename didn't occur", n < 100);
    assertEquals(Long.valueOf(13), template.boundListOps("baz").size());
    template.delete("baz");
    spca.stop();
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) SubscribableChannel(org.springframework.messaging.SubscribableChannel) 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 77 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMetadataStoreTests method testRemoveFromMetadataStore.

@Test
@RedisAvailable
public void testRemoveFromMetadataStore() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMetadataStore metadataStore = new RedisMetadataStore(jcf, "testMetadata");
    String testKey = "RedisMetadataStoreTests-Remove";
    String testValue = "Integration";
    metadataStore.put(testKey, testValue);
    assertEquals(testValue, metadataStore.remove(testKey));
    assertNull(metadataStore.remove(testKey));
}
Also used : RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 78 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMetadataStoreTests method testPersistWithEmptyKeyToMetadataStore.

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

Example 79 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisStoreWritingMessageHandlerTests method testListWithMapKeyExpression.

@Test(expected = IllegalStateException.class)
@RedisAvailable
public void testListWithMapKeyExpression() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    String key = "foo";
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
    handler.setKey(key);
    handler.setMapKeyExpression(new LiteralExpression(key));
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
}
Also used : LiteralExpression(org.springframework.expression.common.LiteralExpression) BeanFactory(org.springframework.beans.factory.BeanFactory) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 80 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisStoreWritingMessageHandlerTests method testZsetWithListPayloadParsedAndProvidedKeyDefault.

@Test
@RedisAvailable
public void testZsetWithListPayloadParsedAndProvidedKeyDefault() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.deleteKey(jcf, "foo");
    String key = "foo";
    RedisZSet<String> redisZset = new DefaultRedisZSet<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
    assertEquals(0, redisZset.size());
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
    handler.setKey(key);
    handler.setCollectionType(CollectionType.ZSET);
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    List<String> list = new ArrayList<String>();
    list.add("Manny");
    list.add("Moe");
    list.add("Jack");
    Message<List<String>> message = MessageBuilder.withPayload(list).setHeader(RedisHeaders.ZSET_INCREMENT_SCORE, true).build();
    handler.handleMessage(message);
    assertEquals(3, redisZset.size());
    Set<TypedTuple<String>> pepboys = redisZset.rangeByScoreWithScores(1, 1);
    for (TypedTuple<String> pepboy : pepboys) {
        assertTrue(pepboy.getScore() == 1);
    }
    handler.handleMessage(message);
    assertEquals(3, redisZset.size());
    pepboys = redisZset.rangeByScoreWithScores(1, 2);
    // should have incremented by 1
    for (TypedTuple<String> pepboy : pepboys) {
        assertEquals(Double.valueOf(2), pepboy.getScore());
    }
    this.deleteKey(jcf, "foo");
}
Also used : DefaultRedisZSet(org.springframework.data.redis.support.collections.DefaultRedisZSet) ArrayList(java.util.ArrayList) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) BeanFactory(org.springframework.beans.factory.BeanFactory) ArrayList(java.util.ArrayList) DefaultRedisList(org.springframework.data.redis.support.collections.DefaultRedisList) List(java.util.List) RedisList(org.springframework.data.redis.support.collections.RedisList) TypedTuple(org.springframework.data.redis.core.ZSetOperations.TypedTuple) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Aggregations

RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)95 Test (org.junit.Test)83 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)62 GenericMessage (org.springframework.messaging.support.GenericMessage)22 BeanFactory (org.springframework.beans.factory.BeanFactory)19 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)17 MessageGroup (org.springframework.integration.store.MessageGroup)14 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)13 ArrayList (java.util.ArrayList)12 Message (org.springframework.messaging.Message)10 Properties (java.util.Properties)9 ApplicationContext (org.springframework.context.ApplicationContext)9 List (java.util.List)8 DefaultRedisList (org.springframework.data.redis.support.collections.DefaultRedisList)8 RedisList (org.springframework.data.redis.support.collections.RedisList)8 RedisConnection (org.springframework.data.redis.connection.RedisConnection)7 DefaultRedisZSet (org.springframework.data.redis.support.collections.DefaultRedisZSet)7 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)6 TypedTuple (org.springframework.data.redis.core.ZSetOperations.TypedTuple)6 LiteralExpression (org.springframework.expression.common.LiteralExpression)6