Search in sources :

Example 1 with RedisMetadataStore

use of org.springframework.integration.redis.metadata.RedisMetadataStore 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);
}
Also used : MetadataStore(org.springframework.integration.metadata.MetadataStore) RedisMetadataStore(org.springframework.integration.redis.metadata.RedisMetadataStore) Tweet(org.springframework.social.twitter.api.Tweet) RedisMetadataStore(org.springframework.integration.redis.metadata.RedisMetadataStore) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 2 with RedisMetadataStore

use of org.springframework.integration.redis.metadata.RedisMetadataStore in project spring-integration by spring-projects.

the class PersistentAcceptOnceFileListFilterExternalStoreTests method testFileSystemWithRedisMetadataStore.

@Test
@RedisAvailable
public void testFileSystemWithRedisMetadataStore() throws Exception {
    RedisTemplate<String, ?> template = new RedisTemplate<String, Object>();
    template.setConnectionFactory(this.getConnectionFactoryForTest());
    template.setKeySerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    template.delete("persistentAcceptOnceFileListFilterRedisTests");
    try {
        this.testFileSystem(new RedisMetadataStore(this.getConnectionFactoryForTest(), "persistentAcceptOnceFileListFilterRedisTests"));
    } finally {
        template.delete("persistentAcceptOnceFileListFilterRedisTests");
    }
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) RedisMetadataStore(org.springframework.integration.redis.metadata.RedisMetadataStore) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 RedisMetadataStore (org.springframework.integration.redis.metadata.RedisMetadataStore)2 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)2 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)1 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)1 MetadataStore (org.springframework.integration.metadata.MetadataStore)1 Tweet (org.springframework.social.twitter.api.Tweet)1