use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.
the class RedisMessageGroupStoreTests method testRemoveNonExistingMessageFromTheGroup.
@Test
@RedisAvailable
public void testRemoveNonExistingMessageFromTheGroup() {
RedisConnectionFactory jcf = getConnectionFactoryForTest();
RedisMessageStore store = new RedisMessageStore(jcf);
MessageGroup messageGroup = store.getMessageGroup(this.groupId);
store.addMessagesToGroup(messageGroup.getGroupId(), new GenericMessage<>("1"));
store.removeMessagesFromGroup(this.groupId, new GenericMessage<>("2"));
}
use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.
the class RedisLockRegistryTests method testEquals.
@Test
@RedisAvailable
public void testEquals() throws Exception {
RedisConnectionFactory connectionFactory = this.getConnectionFactoryForTest();
RedisLockRegistry registry1 = new RedisLockRegistry(connectionFactory, this.registryKey);
RedisLockRegistry registry2 = new RedisLockRegistry(connectionFactory, this.registryKey);
RedisLockRegistry registry3 = new RedisLockRegistry(connectionFactory, this.registryKey2);
Lock lock1 = registry1.obtain("foo");
Lock lock2 = registry1.obtain("foo");
assertEquals(lock1, lock2);
lock1.lock();
lock2.lock();
assertEquals(lock1, lock2);
lock1.unlock();
lock2.unlock();
assertEquals(lock1, lock2);
lock1 = registry1.obtain("foo");
lock2 = registry2.obtain("foo");
assertNotEquals(lock1, lock2);
lock1.lock();
assertFalse(lock2.tryLock());
lock1.unlock();
lock1 = registry1.obtain("foo");
lock2 = registry3.obtain("foo");
assertNotEquals(lock1, lock2);
lock1.lock();
lock2.lock();
lock1.unlock();
lock2.unlock();
}
use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.
the class SubscribableRedisChannelTests method dispatcherHasNoSubscribersTest.
@Test
@RedisAvailable
public void dispatcherHasNoSubscribersTest() throws Exception {
RedisConnectionFactory connectionFactory = this.getConnectionFactoryForTest();
SubscribableRedisChannel channel = new SubscribableRedisChannel(connectionFactory, "si.test.channel.no.subs");
channel.setBeanName("dhnsChannel");
channel.setBeanFactory(mock(BeanFactory.class));
channel.afterPropertiesSet();
RedisMessageListenerContainer container = TestUtils.getPropertyValue(channel, "container", RedisMessageListenerContainer.class);
@SuppressWarnings("unchecked") Map<?, Set<MessageListenerAdapter>> channelMapping = (Map<?, Set<MessageListenerAdapter>>) TestUtils.getPropertyValue(container, "channelMapping");
MessageListenerAdapter listener = channelMapping.entrySet().iterator().next().getValue().iterator().next();
Object delegate = TestUtils.getPropertyValue(listener, "delegate");
try {
ReflectionUtils.findMethod(delegate.getClass(), "handleMessage", Object.class).invoke(delegate, "Hello, world!");
fail("Exception expected");
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
assertNotNull(cause);
assertThat(cause.getMessage(), containsString("Dispatcher has no subscribers for redis-channel 'si.test.channel.no.subs' (dhnsChannel)."));
}
}
use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.
the class SubscribableRedisChannelTests method pubSubChannelTest.
@Test
@RedisAvailable
public void pubSubChannelTest() throws Exception {
RedisConnectionFactory connectionFactory = this.getConnectionFactoryForTest();
SubscribableRedisChannel channel = new SubscribableRedisChannel(connectionFactory, "si.test.channel");
channel.setBeanFactory(mock(BeanFactory.class));
channel.afterPropertiesSet();
channel.start();
this.awaitContainerSubscribed(TestUtils.getPropertyValue(channel, "container", RedisMessageListenerContainer.class));
final CountDownLatch latch = new CountDownLatch(3);
MessageHandler handler = message -> latch.countDown();
channel.subscribe(handler);
channel.send(new GenericMessage<String>("1"));
channel.send(new GenericMessage<String>("2"));
channel.send(new GenericMessage<String>("3"));
assertTrue(latch.await(20, TimeUnit.SECONDS));
}
use of org.springframework.data.redis.connection.RedisConnectionFactory 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"));
}
}
Aggregations