Search in sources :

Example 36 with MessagingException

use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.

the class SimpleMessageStore method setLastReleasedSequenceNumberForGroup.

@Override
public void setLastReleasedSequenceNumberForGroup(Object groupId, int sequenceNumber) {
    Lock lock = this.lockRegistry.obtain(groupId);
    try {
        lock.lockInterruptibly();
        try {
            MessageGroup group = this.groupIdToMessageGroup.get(groupId);
            Assert.notNull(group, "MessageGroup for groupId '" + groupId + "' " + "can not be located while attempting to set 'lastReleasedSequenceNumber'");
            group.setLastReleasedMessageSequenceNumber(sequenceNumber);
            group.setLastModified(System.currentTimeMillis());
        } finally {
            lock.unlock();
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new MessagingException("Interrupted while obtaining lock", e);
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) Lock(java.util.concurrent.locks.Lock)

Example 37 with MessagingException

use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.

the class SimpleMessageStore method completeGroup.

@Override
public void completeGroup(Object groupId) {
    Lock lock = this.lockRegistry.obtain(groupId);
    try {
        lock.lockInterruptibly();
        try {
            MessageGroup group = this.groupIdToMessageGroup.get(groupId);
            Assert.notNull(group, "MessageGroup for groupId '" + groupId + "' " + "can not be located while attempting to complete the MessageGroup");
            group.complete();
            group.setLastModified(System.currentTimeMillis());
        } finally {
            lock.unlock();
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new MessagingException("Interrupted while obtaining lock", e);
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) Lock(java.util.concurrent.locks.Lock)

Example 38 with MessagingException

use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.

the class ResequencerTests method testResequencingWithCapacity.

@Test
public void testResequencingWithCapacity() throws InterruptedException {
    this.resequencer.setReleaseStrategy(new SequenceSizeReleaseStrategy(true));
    // INT-3846
    this.resequencer.setMessageStore(new SimpleMessageStore(3, 2));
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message1 = createMessage("123", "ABC", 4, 4, replyChannel);
    Message<?> message2 = createMessage("456", "ABC", 4, 2, replyChannel);
    Message<?> message3 = createMessage("789", "ABC", 4, 1, replyChannel);
    this.resequencer.handleMessage(message1);
    this.resequencer.handleMessage(message2);
    try {
        this.resequencer.handleMessage(message3);
        fail("Expected exception");
    } catch (MessagingException e) {
        assertThat(e.getMessage(), containsString("out of capacity (2) for group 'ABC'"));
    }
}
Also used : SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) QueueChannel(org.springframework.integration.channel.QueueChannel) MessagingException(org.springframework.messaging.MessagingException) Test(org.junit.Test)

Example 39 with MessagingException

use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.

the class FluxMessageChannelTests method testFluxMessageChannel.

@Test
public void testFluxMessageChannel() throws InterruptedException {
    QueueChannel replyChannel = new QueueChannel();
    for (int i = 0; i < 10; i++) {
        this.fluxMessageChannel.send(MessageBuilder.withPayload(i).setReplyChannel(replyChannel).build());
    }
    for (int i = 0; i < 9; i++) {
        Message<?> receive = replyChannel.receive(10000);
        assertNotNull(receive);
        assertThat(receive.getPayload(), isOneOf("0", "1", "2", "3", "4", "6", "7", "8", "9"));
    }
    assertNull(replyChannel.receive(0));
    Message<?> error = this.errorChannel.receive(0);
    assertNotNull(error);
    assertEquals(5, ((MessagingException) error.getPayload()).getFailedMessage().getPayload());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) MessagingException(org.springframework.messaging.MessagingException) Test(org.junit.Test)

Example 40 with MessagingException

use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.

the class SimplePoolTests method testOverCommitAndResize.

@Test
public void testOverCommitAndResize() {
    final Set<String> strings = new HashSet<String>();
    final AtomicBoolean stale = new AtomicBoolean();
    SimplePool<String> pool = stringPool(2, strings, stale);
    String s1 = pool.getItem();
    assertEquals(0, pool.getIdleCount());
    assertEquals(1, pool.getActiveCount());
    assertEquals(1, pool.getAllocatedCount());
    pool.releaseItem(s1);
    assertEquals(1, pool.getIdleCount());
    assertEquals(0, pool.getActiveCount());
    assertEquals(1, pool.getAllocatedCount());
    s1 = pool.getItem();
    assertEquals(0, pool.getIdleCount());
    assertEquals(1, pool.getActiveCount());
    assertEquals(1, pool.getAllocatedCount());
    String s2 = pool.getItem();
    assertNotSame(s1, s2);
    pool.setWaitTimeout(1);
    assertEquals(0, pool.getIdleCount());
    assertEquals(2, pool.getActiveCount());
    assertEquals(2, pool.getAllocatedCount());
    try {
        pool.getItem();
        fail("Expected exception");
    } catch (MessagingException e) {
    }
    // resize up
    pool.setPoolSize(4);
    assertEquals(0, pool.getIdleCount());
    assertEquals(2, pool.getActiveCount());
    assertEquals(2, pool.getAllocatedCount());
    String s3 = pool.getItem();
    String s4 = pool.getItem();
    assertEquals(0, pool.getIdleCount());
    assertEquals(4, pool.getActiveCount());
    assertEquals(4, pool.getAllocatedCount());
    pool.releaseItem(s4);
    assertEquals(1, pool.getIdleCount());
    assertEquals(3, pool.getActiveCount());
    assertEquals(4, pool.getAllocatedCount());
    // resize down
    pool.setPoolSize(2);
    assertEquals(0, pool.getIdleCount());
    assertEquals(3, pool.getActiveCount());
    assertEquals(3, pool.getPoolSize());
    assertEquals(3, pool.getAllocatedCount());
    pool.releaseItem(s3);
    assertEquals(0, pool.getIdleCount());
    assertEquals(2, pool.getActiveCount());
    assertEquals(2, pool.getPoolSize());
    assertEquals(2, pool.getAllocatedCount());
    assertEquals(2, strings.size());
    pool.releaseItem(s2);
    pool.releaseItem(s1);
    assertEquals(2, pool.getIdleCount());
    assertEquals(0, pool.getActiveCount());
    assertEquals(2, pool.getPoolSize());
    assertEquals(2, strings.size());
    assertEquals(2, pool.getAllocatedCount());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MessagingException(org.springframework.messaging.MessagingException) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

MessagingException (org.springframework.messaging.MessagingException)145 Test (org.junit.Test)61 IOException (java.io.IOException)25 Message (org.springframework.messaging.Message)23 QueueChannel (org.springframework.integration.channel.QueueChannel)22 ErrorMessage (org.springframework.messaging.support.ErrorMessage)21 CountDownLatch (java.util.concurrent.CountDownLatch)17 MessageHandlingException (org.springframework.messaging.MessageHandlingException)16 BeanFactory (org.springframework.beans.factory.BeanFactory)15 MessageChannel (org.springframework.messaging.MessageChannel)15 GenericMessage (org.springframework.messaging.support.GenericMessage)15 MessageHandler (org.springframework.messaging.MessageHandler)14 File (java.io.File)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 DirectChannel (org.springframework.integration.channel.DirectChannel)12 ArrayList (java.util.ArrayList)11 PollableChannel (org.springframework.messaging.PollableChannel)11 Lock (java.util.concurrent.locks.Lock)8 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)8