use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class ZkLockRegistryTests method testTwoThreadsSecondFailsToGetLock.
@Test
public void testTwoThreadsSecondFailsToGetLock() throws Exception {
final ZookeeperLockRegistry registry = new ZookeeperLockRegistry(this.client);
final Lock lock1 = registry.obtain("foo");
lock1.lockInterruptibly();
final AtomicBoolean locked = new AtomicBoolean();
final CountDownLatch latch = new CountDownLatch(1);
Future<Object> result = Executors.newSingleThreadExecutor().submit(() -> {
Lock lock2 = registry.obtain("foo");
locked.set(lock2.tryLock(200, TimeUnit.MILLISECONDS));
latch.countDown();
try {
lock2.unlock();
} catch (MessagingException e) {
return e.getCause();
}
return null;
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertFalse(locked.get());
lock1.unlock();
Object ise = result.get(10, TimeUnit.SECONDS);
assertThat(ise, instanceOf(IllegalMonitorStateException.class));
assertThat(((Exception) ise).getMessage(), containsString("You do not own"));
registry.destroy();
}
use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class AbstractRemoteFileSynchronizerTests method testRollback.
@Test
public void testRollback() throws Exception {
final AtomicBoolean failWhenCopyingBar = new AtomicBoolean(true);
final AtomicInteger count = new AtomicInteger();
SessionFactory<String> sf = new StringSessionFactory();
AbstractInboundFileSynchronizer<String> sync = new AbstractInboundFileSynchronizer<String>(sf) {
@Override
protected boolean isFile(String file) {
return true;
}
@Override
protected String getFilename(String file) {
return file;
}
@Override
protected long getModified(String file) {
return 0;
}
@Override
protected boolean copyFileToLocalDirectory(String remoteDirectoryPath, String remoteFile, File localDirectory, Session<String> session) throws IOException {
if ("bar".equals(remoteFile) && failWhenCopyingBar.getAndSet(false)) {
throw new IOException("fail");
}
count.incrementAndGet();
return true;
}
};
sync.setFilter(new AcceptOnceFileListFilter<String>());
sync.setRemoteDirectory("foo");
try {
sync.synchronizeToLocalDirectory(mock(File.class));
assertEquals(1, count.get());
fail("Expected exception");
} catch (MessagingException e) {
assertThat(e.getCause(), instanceOf(MessagingException.class));
assertThat(e.getCause().getCause(), instanceOf(IOException.class));
assertEquals("fail", e.getCause().getCause().getMessage());
}
sync.synchronizeToLocalDirectory(mock(File.class));
assertEquals(3, count.get());
sync.close();
}
use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class FileOutboundChannelAdapterParserTests method adapterUsageWithFailMode.
@Test
public void adapterUsageWithFailMode() throws Exception {
File testFile = new File("test/fileToFail.txt");
if (testFile.exists()) {
testFile.delete();
}
usageChannelWithFailMode.send(new GenericMessage<String>("Initial File Content:"));
try {
usageChannelWithFailMode.send(new GenericMessage<String>("String content:"));
} catch (MessagingException e) {
assertTrue(e.getMessage().contains("The destination file already exists at"));
testFile.delete();
return;
}
Assert.fail("Was expecting an Exception to be thrown.");
}
use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class FtpRemoteFileTemplateTests method testFileCloseOnBadConnect.
@Test
public void testFileCloseOnBadConnect() throws Exception {
@SuppressWarnings("unchecked") SessionFactory<FTPFile> sessionFactory = mock(SessionFactory.class);
when(sessionFactory.getSession()).thenThrow(new RuntimeException("bar"));
FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(sessionFactory);
template.setRemoteDirectoryExpression(new LiteralExpression("foo"));
template.afterPropertiesSet();
File file = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write("foo".getBytes());
fileOutputStream.close();
try {
template.send(new GenericMessage<File>(file));
fail("exception expected");
} catch (MessagingException e) {
assertEquals("bar", e.getCause().getMessage());
}
File newFile = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
assertTrue(file.renameTo(newFile));
file.delete();
newFile.delete();
}
use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class AsyncGatewayTests method testWithTimeout.
@Test
public void testWithTimeout() throws Exception {
QueueChannel errors = new QueueChannel();
this.gateway2.setOutputChannel(errors);
this.gateway2.start();
this.gateway2.handleMessage(MessageBuilder.withPayload("foo").setErrorChannel(errors).build());
JmsTemplate template = new JmsTemplate(this.ccf);
template.setReceiveTimeout(10000);
final Message received = template.receive("asyncTest3");
assertNotNull(received);
org.springframework.messaging.Message<?> error = errors.receive(10000);
assertNotNull(error);
assertThat(error, instanceOf(ErrorMessage.class));
assertThat(error.getPayload(), instanceOf(MessagingException.class));
assertThat(((MessagingException) error.getPayload()).getCause(), instanceOf(JmsTimeoutException.class));
assertEquals("foo", ((MessagingException) error.getPayload()).getFailedMessage().getPayload());
this.gateway2.stop();
}
Aggregations