use of org.springframework.integration.redis.rules.RedisAvailable 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.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisLockRegistryTests method testThreadLocalListLeaks.
@Test
@RedisAvailable
public void testThreadLocalListLeaks() {
RedisLockRegistry registry = new RedisLockRegistry(this.getConnectionFactoryForTest(), this.registryKey, 100);
for (int i = 0; i < 10; i++) {
registry.obtain("foo" + i);
}
assertEquals(10, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
for (int i = 0; i < 10; i++) {
Lock lock = registry.obtain("foo" + i);
lock.lock();
}
assertEquals(10, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
for (int i = 0; i < 10; i++) {
Lock lock = registry.obtain("foo" + i);
lock.unlock();
}
assertEquals(10, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
}
use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class SearchReceivingMessageSourceWithRedisTests method testPollForTweetsThreeResultsWithRedisMetadataStore.
@Test
@RedisAvailable
public void testPollForTweetsThreeResultsWithRedisMetadataStore() throws Exception {
String metadataKey = TestUtils.getPropertyValue(twitterSearchAdapter, "source.metadataKey", String.class);
// There is need to set a value, not 'remove' and re-init 'twitterMessageSource'
this.metadataStore.put(metadataKey, "-1");
this.twitterMessageSource.afterPropertiesSet();
MetadataStore metadataStore = TestUtils.getPropertyValue(this.twitterSearchAdapter, "source.metadataStore", MetadataStore.class);
assertTrue("Expected metadataStore to be an instance of RedisMetadataStore", metadataStore instanceof RedisMetadataStore);
assertSame(this.metadataStore, metadataStore);
assertEquals("twitterSearchAdapter.74", metadataKey);
this.twitterSearchAdapter.start();
Message<?> receive = this.tweets.receive(10000);
assertNotNull(receive);
receive = this.tweets.receive(10000);
assertNotNull(receive);
receive = this.tweets.receive(10000);
assertNotNull(receive);
/* We received 3 messages so far. When invoking receive() again the search
* will return again the 3 test Tweets but as we already processed them
* no message (null) is returned. */
assertNull(this.tweets.receive(0));
String persistedMetadataStoreValue = this.metadataStore.get(metadataKey);
assertNotNull(persistedMetadataStoreValue);
assertEquals("3", persistedMetadataStoreValue);
this.twitterSearchAdapter.stop();
this.metadataStore.put(metadataKey, "1");
this.twitterMessageSource.afterPropertiesSet();
this.twitterSearchAdapter.start();
receive = this.tweets.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(Tweet.class));
assertEquals(((Tweet) receive.getPayload()).getId(), 2L);
receive = this.tweets.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(Tweet.class));
assertEquals(((Tweet) receive.getPayload()).getId(), 3L);
assertNull(this.tweets.receive(0));
persistedMetadataStoreValue = this.metadataStore.get(metadataKey);
assertNotNull(persistedMetadataStoreValue);
assertEquals("3", persistedMetadataStoreValue);
}
use of org.springframework.integration.redis.rules.RedisAvailable 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.integration.redis.rules.RedisAvailable 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));
}
Aggregations