You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by pv...@apache.org on 2017/06/17 13:22:44 UTC
nifi git commit: NIFI-2692
Repository: nifi
Updated Branches:
refs/heads/master 490e1da5d -> 2800df30d
NIFI-2692
- Removing problematic timeout for SMTP Listen
- Converting anonymous method to lambda
- Adding debug and error logging
Signed-off-by: Pierre Villard <pi...@gmail.com>
This closes #1924.
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/2800df30
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/2800df30
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/2800df30
Branch: refs/heads/master
Commit: 2800df30d383030a02c4e1547a9eab1fb88cc59e
Parents: 490e1da
Author: Chris Herrera <ch...@hashmapinc.com>
Authored: Fri Jun 16 17:24:35 2017 -0500
Committer: Pierre Villard <pi...@gmail.com>
Committed: Sat Jun 17 15:22:33 2017 +0200
----------------------------------------------------------------------
.../nifi/processors/email/ListenSMTP.java | 6 +-
.../nifi/processors/email/TestListenSMTP.java | 118 +++++++++----------
2 files changed, 58 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/2800df30/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/main/java/org/apache/nifi/processors/email/ListenSMTP.java
----------------------------------------------------------------------
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 9e422ca..32c9649 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;
}
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/2800df30/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/test/java/org/apache/nifi/processors/email/TestListenSMTP.java
----------------------------------------------------------------------
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 f17978f..93b3a4e 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");
-
- // 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();
- }
+ 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();
}
}
}, 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);