I test sending messages using JavaMailSender , which is launched from ExecutorService using submit , everything works fine, but in GreenMail tests GreenMail does not receive messages, because it finishes work too quickly. Before that I used execute+awaitTermination - everything went off with a bang. setServerStartUpTimeout, setServerConnectionTimeout for GreenMail does not help at any time. How can this be solved? Or are there other libraries to simulate an SMTP server ? Here's the code, what's in the sender
notifications.forEach(notification -> { Supplier<Boolean> sendingTask = () -> sendNotification(notification); CompletableFuture<Boolean> future = CompletableFuture.supplyAsync(sendingTask, executorService); future.whenComplete((result, ex) -> { if (result) { log.info("Successfull"); } if (ex != null) { log.error("Error by sending", ex); } }); }); It's in test
def setup() { ServerSetup serverSetup = ServerSetupTest.SMTP serverSetup.setServerStartupTimeout(50000) serverSetup.setWriteTimeout(50000) serverSetup.setReadTimeout(50000) serverSetup.setConnectionTimeout(50000) testSmtp = new GreenMail(serverSetup) testSmtp.start() javaMailSender = new JavaMailSenderImpl() javaMailSender.setHost("127.0.0.1") javaMailSender.setPort(3025) } and in the test method itself def messages = testSmtp.getReceivedMessages() - shows an empty sheet (