Example usage for org.springframework.integration.endpoint SourcePollingChannelAdapter setSource

List of usage examples for org.springframework.integration.endpoint SourcePollingChannelAdapter setSource

Introduction

In this page you can find the example usage for org.springframework.integration.endpoint SourcePollingChannelAdapter setSource.

Prototype

public void setSource(MessageSource<?> source) 

Source Link

Document

Specify the source to be polled for Messages.

Usage

From source file:org.springframework.integration.endpoint.PseudoTransactionalMessageSourceTests.java

@Test
public void testInt2777UnboundResourceAfterTransactionComplete() {
    SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();

    adapter.setSource(() -> null);

    TransactionSynchronizationManager.setActualTransactionActive(true);
    doPoll(adapter);/*from   w w  w.j  a  v a 2s. c  o m*/
    TransactionSynchronizationManager.setActualTransactionActive(false);

    // Before INT-2777 this test was failed here
    TransactionSynchronizationManager.setActualTransactionActive(true);
    doPoll(adapter);
    TransactionSynchronizationManager.setActualTransactionActive(false);
}

From source file:org.springframework.integration.endpoint.PseudoTransactionalMessageSourceTests.java

@Test
public void testInt2777CustomTransactionSynchronizationFactoryWithoutDealWithIntegrationResourceHolder() {
    SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();

    final AtomicInteger txSyncCounter = new AtomicInteger();

    TransactionSynchronizationFactory syncFactory = new TransactionSynchronizationFactory() {

        @Override/*from   w ww.  ja  v  a 2s .  com*/
        public TransactionSynchronization create(Object key) {
            return new TransactionSynchronizationAdapter() {
                @Override
                public void afterCompletion(int status) {
                    txSyncCounter.incrementAndGet();
                }
            };
        }
    };

    adapter.setTransactionSynchronizationFactory(syncFactory);
    adapter.setSource(() -> null);

    TransactionSynchronizationManager.initSynchronization();
    TransactionSynchronizationManager.setActualTransactionActive(true);
    doPoll(adapter);
    TransactionSynchronizationUtils.triggerAfterCompletion(TransactionSynchronization.STATUS_COMMITTED);
    TransactionSynchronizationManager.clearSynchronization();
    TransactionSynchronizationManager.setActualTransactionActive(false);
    assertEquals(1, txSyncCounter.get());

    TransactionSynchronizationManager.initSynchronization();
    TransactionSynchronizationManager.setActualTransactionActive(true);
    doPoll(adapter);
    TransactionSynchronizationUtils.triggerAfterCompletion(TransactionSynchronization.STATUS_COMMITTED);
    TransactionSynchronizationManager.clearSynchronization();
    TransactionSynchronizationManager.setActualTransactionActive(false);
    assertEquals(2, txSyncCounter.get());
}