mirror of https://github.com/apache/nifi.git
NIFI-2692
- Removing problematic timeout for SMTP Listen - Converting anonymous method to lambda - Adding debug and error logging Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes #1924.
This commit is contained in:
parent
490e1da5db
commit
2800df30d3
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue