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();
}
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));
}
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);
}
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();
}
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");
}
Aggregations