Search in sources :

Example 16 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class ChannelAdapterParserTests method methodInvokingSourceStartedByApplicationContext.

@Test
public void methodInvokingSourceStartedByApplicationContext() {
    String beanName = "methodInvokingSource";
    PollableChannel channel = (PollableChannel) this.applicationContext.getBean("queueChannel");
    TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
    testBean.store("source test");
    Object adapter = this.applicationContext.getBean(beanName);
    assertNotNull(adapter);
    assertTrue(adapter instanceof SourcePollingChannelAdapter);
    this.applicationContext.start();
    Message<?> message = channel.receive(1000);
    assertNotNull(message);
    assertEquals("source test", testBean.getMessage());
    this.applicationContext.stop();
}
Also used : PollableChannel(org.springframework.messaging.PollableChannel) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 17 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class ResourceInboundChannelAdapterParserTests method testCustomPatternResolver.

@Test
public void testCustomPatternResolver() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ResourcePatternResolver-config-custom.xml", this.getClass());
    SourcePollingChannelAdapter resourceAdapter = context.getBean("resourceAdapterDefault", SourcePollingChannelAdapter.class);
    ResourceRetrievingMessageSource source = TestUtils.getPropertyValue(resourceAdapter, "source", ResourceRetrievingMessageSource.class);
    assertNotNull(source);
    assertEquals(context.getBean("customResolver"), TestUtils.getPropertyValue(source, "patternResolver"));
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 18 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class ResourceInboundChannelAdapterParserTests method testUsageWithEmptyFilter.

@Test
public void testUsageWithEmptyFilter() throws Exception {
    for (int i = 0; i < 10; i++) {
        File f = new File(workDir, "testUsageWithRf" + i);
        f.createNewFile();
    }
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ResourcePatternResolver-config-usage-emptyref.xml", this.getClass());
    SourcePollingChannelAdapter resourceAdapter = context.getBean("resourceAdapterDefault", SourcePollingChannelAdapter.class);
    ResourceRetrievingMessageSource source = TestUtils.getPropertyValue(resourceAdapter, "source", ResourceRetrievingMessageSource.class);
    assertNotNull(source);
    assertNull(TestUtils.getPropertyValue(source, "filter"));
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) File(java.io.File) Test(org.junit.Test)

Example 19 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class RedisStoreInboundChannelAdapterIntegrationTests method testZsetInboundAdapter.

@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public void testZsetInboundAdapter() throws InterruptedException {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.prepareZset(jcf);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("zset-inbound-adapter.xml", this.getClass());
    // No Score test
    SourcePollingChannelAdapter zsetAdapterNoScore = context.getBean("zsetAdapterNoScore", SourcePollingChannelAdapter.class);
    zsetAdapterNoScore.start();
    QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class);
    Message<RedisZSet<Object>> message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(13, message.getPayload().size());
    // poll again, should get the same stuff
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(13, message.getPayload().size());
    zsetAdapterNoScore.stop();
    // ScoreRange test
    SourcePollingChannelAdapter zsetAdapterWithScoreRange = context.getBean("zsetAdapterWithScoreRange", SourcePollingChannelAdapter.class);
    zsetAdapterWithScoreRange.start();
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(11, message.getPayload().rangeByScore(18, 20).size());
    // poll again, should get the same stuff
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(11, message.getPayload().rangeByScore(18, 20).size());
    zsetAdapterWithScoreRange.stop();
    // SingleScore test
    SourcePollingChannelAdapter zsetAdapterWithSingleScore = context.getBean("zsetAdapterWithSingleScore", SourcePollingChannelAdapter.class);
    zsetAdapterWithSingleScore.start();
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(2, message.getPayload().rangeByScore(18, 18).size());
    // poll again, should get the same stuff
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(2, message.getPayload().rangeByScore(18, 18).size());
    zsetAdapterWithSingleScore.stop();
    // SingleScoreAndSynchronization test
    SourcePollingChannelAdapter zsetAdapterWithSingleScoreAndSynchronization = context.getBean("zsetAdapterWithSingleScoreAndSynchronization", SourcePollingChannelAdapter.class);
    QueueChannel otherRedisChannel = context.getBean("otherRedisChannel", QueueChannel.class);
    // get all 13 presidents
    zsetAdapterNoScore.start();
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(13, message.getPayload().size());
    zsetAdapterNoScore.stop();
    // get only presidents for 18th century
    zsetAdapterWithSingleScoreAndSynchronization.start();
    Message<Integer> sizeMessage = (Message<Integer>) otherRedisChannel.receive(10000);
    assertNotNull(sizeMessage);
    assertEquals(Integer.valueOf(2), sizeMessage.getPayload());
    // ... however other elements are still available 13-2=11
    zsetAdapterNoScore.start();
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    int n = 0;
    while (n++ < 100 && message.getPayload().size() != 11) {
        Thread.sleep(100);
    }
    assertTrue(n < 100);
    zsetAdapterNoScore.stop();
    zsetAdapterWithSingleScoreAndSynchronization.stop();
    this.deletePresidents(jcf);
    context.close();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisZSet(org.springframework.data.redis.support.collections.RedisZSet) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 20 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class RedisStoreInboundChannelAdapterIntegrationTests method testListInboundConfigurationWithSynchronizationAndTemplate.

@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public // synchronization commit renames the list
void testListInboundConfigurationWithSynchronizationAndTemplate() 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("listAdapterWithSynchronizationAndRedisTemplate", 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();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Aggregations

SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)66 Test (org.junit.Test)58 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 Message (org.springframework.messaging.Message)15 PollableChannel (org.springframework.messaging.PollableChannel)13 Collection (java.util.Collection)10 ArrayList (java.util.ArrayList)9 QueueChannel (org.springframework.integration.channel.QueueChannel)9 JpaExecutor (org.springframework.integration.jpa.core.JpaExecutor)9 Consumer (org.springframework.integration.jpa.test.Consumer)9 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)8 PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)8 Trigger (org.springframework.scheduling.Trigger)7 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)6 Expression (org.springframework.expression.Expression)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 BeanFactory (org.springframework.beans.factory.BeanFactory)5 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)5 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)5 File (java.io.File)4