Search in sources :

Example 1 with MetadataStore

use of org.springframework.integration.metadata.MetadataStore 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 MetadataStore

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

the class FeedInboundChannelAdapterParserTests method validateSuccessfulFileConfigurationWithCustomMetadataStore.

@Test
public void validateSuccessfulFileConfigurationWithCustomMetadataStore() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("FeedInboundChannelAdapterParserTests-file-context.xml", this.getClass());
    SourcePollingChannelAdapter adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class);
    FeedEntryMessageSource source = (FeedEntryMessageSource) TestUtils.getPropertyValue(adapter, "source");
    assertSame(context.getBean(MetadataStore.class), TestUtils.getPropertyValue(source, "metadataStore"));
    SyndFeedInput syndFeedInput = TestUtils.getPropertyValue(source, "syndFeedInput", SyndFeedInput.class);
    assertSame(context.getBean(SyndFeedInput.class), syndFeedInput);
    assertFalse(syndFeedInput.isPreserveWireFeed());
    context.close();
}
Also used : FeedEntryMessageSource(org.springframework.integration.feed.inbound.FeedEntryMessageSource) MetadataStore(org.springframework.integration.metadata.MetadataStore) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 MetadataStore (org.springframework.integration.metadata.MetadataStore)2 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)1 FeedEntryMessageSource (org.springframework.integration.feed.inbound.FeedEntryMessageSource)1 RedisMetadataStore (org.springframework.integration.redis.metadata.RedisMetadataStore)1 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)1 Tweet (org.springframework.social.twitter.api.Tweet)1