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);
}
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();
}
Aggregations