use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class RedisStoreInboundChannelAdapterIntegrationTests method testListInboundConfigurationWithSynchronization.
@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public // synchronization commit renames the list
void testListInboundConfigurationWithSynchronization() throws Exception {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
StringRedisTemplate template = this.createStringRedisTemplate(jcf);
template.delete("bar");
this.prepareList(jcf);
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("list-inbound-adapter.xml", this.getClass());
SourcePollingChannelAdapter spca = context.getBean("listAdapterWithSynchronization", SourcePollingChannelAdapter.class);
spca.start();
QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class);
Message<Integer> message = (Message<Integer>) redisChannel.receive(10000);
assertNotNull(message);
assertEquals(Integer.valueOf(13), message.getPayload());
// poll again, should get nothing since the collection was removed during synchronization
message = (Message<Integer>) redisChannel.receive(100);
assertNull(message);
int n = 0;
while (n++ < 100 && template.keys("bar").size() == 0) {
Thread.sleep(100);
}
assertTrue("Rename didn't occur", n < 100);
assertEquals(Long.valueOf(13), template.boundListOps("bar").size());
template.delete("bar");
spca.stop();
context.close();
}
use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class TestReceivingMessageSourceParserTests method testReceivingAdapterConfigurationAutoStartup.
@Test
public void testReceivingAdapterConfigurationAutoStartup() {
ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("TestReceivingMessageSourceParser-context.xml", getClass());
SourcePollingChannelAdapter spca = ac.getBean("mentionAdapter", SourcePollingChannelAdapter.class);
MentionsReceivingMessageSource ms = TestUtils.getPropertyValue(spca, "source", MentionsReceivingMessageSource.class);
assertEquals(Integer.valueOf(23), TestUtils.getPropertyValue(ms, "pageSize", Integer.class));
assertNotNull(ms);
spca = ac.getBean("dmAdapter", SourcePollingChannelAdapter.class);
DirectMessageReceivingMessageSource dms = TestUtils.getPropertyValue(spca, "source", DirectMessageReceivingMessageSource.class);
assertNotNull(dms);
assertEquals(Integer.valueOf(45), TestUtils.getPropertyValue(dms, "pageSize", Integer.class));
spca = ac.getBean("updateAdapter", SourcePollingChannelAdapter.class);
TimelineReceivingMessageSource tms = TestUtils.getPropertyValue(spca, "source", TimelineReceivingMessageSource.class);
assertEquals(Integer.valueOf(67), TestUtils.getPropertyValue(tms, "pageSize", Integer.class));
assertNotNull(tms);
ac.close();
}
use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class TestSearchReceivingMessageSourceParserTests method testSearchReceivingDefaultTemplate.
@Test
public void testSearchReceivingDefaultTemplate() {
ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("TestSearchReceivingMessageSourceParser-context.xml", this.getClass());
SourcePollingChannelAdapter spca = ac.getBean("searchAdapterWithTemplate", SourcePollingChannelAdapter.class);
SearchReceivingMessageSource ms = (SearchReceivingMessageSource) TestUtils.getPropertyValue(spca, "source");
assertEquals(Integer.valueOf(23), TestUtils.getPropertyValue(ms, "pageSize", Integer.class));
Twitter template = (Twitter) TestUtils.getPropertyValue(ms, "twitter");
assertNotNull(template);
ac.close();
}
use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class JpaPollingChannelAdapterTests method testWithNamedQuery.
/**
* In this test, a Jpa Polling Channel Adapter will use Named query
* to retrieve a list of records from the database.
*
* @throws Exception
*/
@Test
public void testWithNamedQuery() throws Exception {
testTrigger.reset();
// ~~~~SETUP~~~~~
final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
jpaExecutor.setNamedQuery("selectStudent");
jpaExecutor.afterPropertiesSet();
final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter(jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader());
adapter.start();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final List<Message<Collection<?>>> received = new ArrayList<Message<Collection<?>>>();
final Consumer consumer = new Consumer();
received.add(consumer.poll(10000));
Message<Collection<?>> message = received.get(0);
adapter.stop();
assertNotNull(message);
assertNotNull(message.getPayload());
Collection<?> students = message.getPayload();
assertTrue(students.size() == 1);
}
use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class JpaPollingChannelAdapterTests method testWithJpaQueryOneResultOnly.
/**
* In this test, a Jpa Polling Channel Adapter will use JpQL query
* to retrieve a list of records from the database.
*
* @throws Exception
*/
@Test
public void testWithJpaQueryOneResultOnly() throws Exception {
testTrigger.reset();
// ~~~~SETUP~~~~~
final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
jpaExecutor.setJpaQuery("from Student s where s.firstName = 'First Two'");
jpaExecutor.afterPropertiesSet();
final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter(jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader());
adapter.start();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final List<Message<Collection<?>>> received = new ArrayList<Message<Collection<?>>>();
final Consumer consumer = new Consumer();
received.add(consumer.poll(10000));
Message<Collection<?>> message = received.get(0);
adapter.stop();
assertNotNull(message);
assertNotNull(message.getPayload());
Collection<?> students = message.getPayload();
assertTrue(students.size() == 1);
StudentDomain student = (StudentDomain) students.iterator().next();
assertEquals("Last Two", student.getLastName());
}
Aggregations