use of org.springframework.integration.redis.rules.RedisAvailable 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.integration.redis.rules.RedisAvailable 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.integration.redis.rules.RedisAvailable 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.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisQueueMessageDrivenEndpointTests method testInt3442ProperlyStop.
@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public void testInt3442ProperlyStop() throws Exception {
final String queueName = "si.test.testInt3442ProperlyStopTest";
final RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(this.connectionFactory);
redisTemplate.setEnableDefaultSerializer(false);
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
redisTemplate.afterPropertiesSet();
while (redisTemplate.boundListOps(queueName).rightPop() != null) {
// drain
}
RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint(queueName, this.connectionFactory);
BoundListOperations<String, byte[]> boundListOperations = TestUtils.getPropertyValue(endpoint, "boundListOperations", BoundListOperations.class);
boundListOperations = Mockito.spy(boundListOperations);
DirectFieldAccessor dfa = new DirectFieldAccessor(endpoint);
dfa.setPropertyValue("boundListOperations", boundListOperations);
endpoint.setBeanFactory(Mockito.mock(BeanFactory.class));
endpoint.setOutputChannel(new DirectChannel());
endpoint.setReceiveTimeout(10);
ExecutorService executorService = Executors.newCachedThreadPool();
endpoint.setTaskExecutor(executorService);
endpoint.afterPropertiesSet();
endpoint.start();
waitListening(endpoint);
dfa.setPropertyValue("listening", false);
redisTemplate.boundListOps(queueName).leftPush("foo");
final CountDownLatch stopLatch = new CountDownLatch(1);
endpoint.stop(() -> stopLatch.countDown());
executorService.shutdown();
assertTrue(executorService.awaitTermination(20, TimeUnit.SECONDS));
assertTrue(stopLatch.await(21, TimeUnit.SECONDS));
verify(boundListOperations, atLeastOnce()).rightPush(any(byte[].class));
}
use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisQueueMessageDrivenEndpointTests method testInt3014Default.
@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public void testInt3014Default() {
String queueName = "si.test.redisQueueInboundChannelAdapterTests";
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(this.connectionFactory);
redisTemplate.setEnableDefaultSerializer(false);
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
redisTemplate.afterPropertiesSet();
String payload = "testing";
redisTemplate.boundListOps(queueName).leftPush(payload);
Date payload2 = new Date();
redisTemplate.boundListOps(queueName).leftPush(payload2);
PollableChannel channel = new QueueChannel();
RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint(queueName, this.connectionFactory);
endpoint.setBeanFactory(Mockito.mock(BeanFactory.class));
endpoint.setOutputChannel(channel);
endpoint.setReceiveTimeout(10);
endpoint.afterPropertiesSet();
endpoint.start();
Message<Object> receive = (Message<Object>) channel.receive(10000);
assertNotNull(receive);
assertEquals(payload, receive.getPayload());
receive = (Message<Object>) channel.receive(10000);
assertNotNull(receive);
assertEquals(payload2, receive.getPayload());
endpoint.stop();
}
Aggregations