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);
}
}
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);
}
}
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'"));
}
}
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());
}
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());
}
Aggregations