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

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

Introduction

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

Prototype

SourcePollingChannelAdapter

Source Link

Usage

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

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

    adapter.setSource(() -> null);//from   www  .j av a2 s .c  o  m

    TransactionSynchronizationManager.setActualTransactionActive(true);
    doPoll(adapter);
    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 w w .  j a  v a2s  . c om
        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());
}