diff --git a/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/main/java/org/apache/nifi/processors/email/ListenSMTP.java b/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/main/java/org/apache/nifi/processors/email/ListenSMTP.java index 9e422ca5ce..32c9649eb1 100644 --- a/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/main/java/org/apache/nifi/processors/email/ListenSMTP.java +++ b/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/main/java/org/apache/nifi/processors/email/ListenSMTP.java @@ -177,6 +177,7 @@ public class ListenSMTP extends AbstractSessionFactoryProcessor { try { final SMTPServer server = prepareServer(context, sessionFactory); server.start(); + getLogger().debug("Started SMTP Server on port " + server.getPort()); smtp = server; } catch (final Exception ex) {//have to catch exception due to awkward exception handling in subethasmtp smtp = null; @@ -190,7 +191,10 @@ public class ListenSMTP extends AbstractSessionFactoryProcessor { public void stop() { try { smtp.stop(); - } finally { + getLogger().debug("Stopped SMTP server on port " + smtp.getPort()); + }catch (Exception ex){ + getLogger().error("Error stopping SMTP server: " + ex.getMessage()); + }finally { smtp = null; } } diff --git a/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/test/java/org/apache/nifi/processors/email/TestListenSMTP.java b/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/test/java/org/apache/nifi/processors/email/TestListenSMTP.java index f17978fc08..93b3a4ec13 100644 --- a/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/test/java/org/apache/nifi/processors/email/TestListenSMTP.java +++ b/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/test/java/org/apache/nifi/processors/email/TestListenSMTP.java @@ -56,32 +56,28 @@ public class TestListenSMTP { TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class); runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port)); runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3"); - runner.setProperty(ListenSMTP.SMTP_TIMEOUT, "10 seconds"); runner.assertValid(); runner.run(5, false); final int numMessages = 5; CountDownLatch latch = new CountDownLatch(numMessages); - this.executor.schedule(new Runnable() { - @Override - public void run() { - for (int i = 0; i < numMessages; i++) { - try { - Email email = new SimpleEmail(); - email.setHostName("localhost"); - email.setSmtpPort(port); - email.setFrom("alice@nifi.apache.org"); - email.setSubject("This is a test"); - email.setMsg("MSG-" + i); - email.addTo("bob@nifi.apache.org"); - email.send(); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } finally { - latch.countDown(); - } + this.executor.schedule(() -> { + for (int i = 0; i < numMessages; i++) { + try { + Email email = new SimpleEmail(); + email.setHostName("localhost"); + email.setSmtpPort(port); + email.setFrom("alice@nifi.apache.org"); + email.setSubject("This is a test"); + email.setMsg("MSG-" + i); + email.addTo("bob@nifi.apache.org"); + email.send(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } finally { + latch.countDown(); } } }, 1500, TimeUnit.MILLISECONDS); @@ -102,7 +98,6 @@ public class TestListenSMTP { TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class); runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port)); runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3"); - runner.setProperty(ListenSMTP.SMTP_TIMEOUT, "10 seconds"); // Setup the SSL Context SSLContextService sslContextService = new StandardSSLContextService(); @@ -124,30 +119,27 @@ public class TestListenSMTP { CountDownLatch latch = new CountDownLatch(messageCount); runner.run(messageCount, false); - this.executor.schedule(new Runnable() { - @Override - public void run() { - for (int i = 0; i < messageCount; i++) { - try { - Email email = new SimpleEmail(); - email.setHostName("localhost"); - email.setSmtpPort(port); - email.setFrom("alice@nifi.apache.org"); - email.setSubject("This is a test"); - email.setMsg("MSG-" + i); - email.addTo("bob@nifi.apache.org"); + this.executor.schedule(() -> { + for (int i = 0; i < messageCount; i++) { + try { + Email email = new SimpleEmail(); + email.setHostName("localhost"); + email.setSmtpPort(port); + email.setFrom("alice@nifi.apache.org"); + email.setSubject("This is a test"); + email.setMsg("MSG-" + i); + email.addTo("bob@nifi.apache.org"); - // Enable STARTTLS but ignore the cert - email.setStartTLSEnabled(true); - email.setStartTLSRequired(true); - email.setSSLCheckServerIdentity(false); - email.send(); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } finally { - latch.countDown(); - } + // Enable STARTTLS but ignore the cert + email.setStartTLSEnabled(true); + email.setStartTLSRequired(true); + email.setSSLCheckServerIdentity(false); + email.send(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } finally { + latch.countDown(); } } }, 1500, TimeUnit.MILLISECONDS); @@ -165,7 +157,6 @@ public class TestListenSMTP { TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class); runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port)); runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3"); - runner.setProperty(ListenSMTP.SMTP_TIMEOUT, "10 seconds"); runner.setProperty(ListenSMTP.SMTP_MAXIMUM_MSG_SIZE, "10 B"); runner.assertValid(); @@ -175,25 +166,22 @@ public class TestListenSMTP { runner.run(messageCount, false); - this.executor.schedule(new Runnable() { - @Override - public void run() { - for (int i = 0; i < messageCount; i++) { - try { - Email email = new SimpleEmail(); - email.setHostName("localhost"); - email.setSmtpPort(port); - email.setFrom("alice@nifi.apache.org"); - email.setSubject("This is a test"); - email.setMsg("MSG-" + i); - email.addTo("bob@nifi.apache.org"); - email.send(); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } finally { - latch.countDown(); - } + this.executor.schedule(() -> { + for (int i = 0; i < messageCount; i++) { + try { + Email email = new SimpleEmail(); + email.setHostName("localhost"); + email.setSmtpPort(port); + email.setFrom("alice@nifi.apache.org"); + email.setSubject("This is a test"); + email.setMsg("MSG-" + i); + email.addTo("bob@nifi.apache.org"); + email.send(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } finally { + latch.countDown(); } } }, 1000, TimeUnit.MILLISECONDS);