mirror of
https://github.com/apache/nifi.git
synced 2025-02-17 23:47:08 +00:00
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 {
|
try {
|
||||||
final SMTPServer server = prepareServer(context, sessionFactory);
|
final SMTPServer server = prepareServer(context, sessionFactory);
|
||||||
server.start();
|
server.start();
|
||||||
|
getLogger().debug("Started SMTP Server on port " + server.getPort());
|
||||||
smtp = server;
|
smtp = server;
|
||||||
} catch (final Exception ex) {//have to catch exception due to awkward exception handling in subethasmtp
|
} catch (final Exception ex) {//have to catch exception due to awkward exception handling in subethasmtp
|
||||||
smtp = null;
|
smtp = null;
|
||||||
@ -190,7 +191,10 @@ public class ListenSMTP extends AbstractSessionFactoryProcessor {
|
|||||||
public void stop() {
|
public void stop() {
|
||||||
try {
|
try {
|
||||||
smtp.stop();
|
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;
|
smtp = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,32 +56,28 @@ public class TestListenSMTP {
|
|||||||
TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class);
|
TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class);
|
||||||
runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port));
|
runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port));
|
||||||
runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3");
|
runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3");
|
||||||
runner.setProperty(ListenSMTP.SMTP_TIMEOUT, "10 seconds");
|
|
||||||
|
|
||||||
runner.assertValid();
|
runner.assertValid();
|
||||||
runner.run(5, false);
|
runner.run(5, false);
|
||||||
final int numMessages = 5;
|
final int numMessages = 5;
|
||||||
CountDownLatch latch = new CountDownLatch(numMessages);
|
CountDownLatch latch = new CountDownLatch(numMessages);
|
||||||
|
|
||||||
this.executor.schedule(new Runnable() {
|
this.executor.schedule(() -> {
|
||||||
@Override
|
for (int i = 0; i < numMessages; i++) {
|
||||||
public void run() {
|
try {
|
||||||
for (int i = 0; i < numMessages; i++) {
|
Email email = new SimpleEmail();
|
||||||
try {
|
email.setHostName("localhost");
|
||||||
Email email = new SimpleEmail();
|
email.setSmtpPort(port);
|
||||||
email.setHostName("localhost");
|
email.setFrom("alice@nifi.apache.org");
|
||||||
email.setSmtpPort(port);
|
email.setSubject("This is a test");
|
||||||
email.setFrom("alice@nifi.apache.org");
|
email.setMsg("MSG-" + i);
|
||||||
email.setSubject("This is a test");
|
email.addTo("bob@nifi.apache.org");
|
||||||
email.setMsg("MSG-" + i);
|
email.send();
|
||||||
email.addTo("bob@nifi.apache.org");
|
} catch (Exception e) {
|
||||||
email.send();
|
e.printStackTrace();
|
||||||
} catch (Exception e) {
|
throw new RuntimeException(e);
|
||||||
e.printStackTrace();
|
} finally {
|
||||||
throw new RuntimeException(e);
|
latch.countDown();
|
||||||
} finally {
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1500, TimeUnit.MILLISECONDS);
|
}, 1500, TimeUnit.MILLISECONDS);
|
||||||
@ -102,7 +98,6 @@ public class TestListenSMTP {
|
|||||||
TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class);
|
TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class);
|
||||||
runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port));
|
runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port));
|
||||||
runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3");
|
runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3");
|
||||||
runner.setProperty(ListenSMTP.SMTP_TIMEOUT, "10 seconds");
|
|
||||||
|
|
||||||
// Setup the SSL Context
|
// Setup the SSL Context
|
||||||
SSLContextService sslContextService = new StandardSSLContextService();
|
SSLContextService sslContextService = new StandardSSLContextService();
|
||||||
@ -124,30 +119,27 @@ public class TestListenSMTP {
|
|||||||
CountDownLatch latch = new CountDownLatch(messageCount);
|
CountDownLatch latch = new CountDownLatch(messageCount);
|
||||||
runner.run(messageCount, false);
|
runner.run(messageCount, false);
|
||||||
|
|
||||||
this.executor.schedule(new Runnable() {
|
this.executor.schedule(() -> {
|
||||||
@Override
|
for (int i = 0; i < messageCount; i++) {
|
||||||
public void run() {
|
try {
|
||||||
for (int i = 0; i < messageCount; i++) {
|
Email email = new SimpleEmail();
|
||||||
try {
|
email.setHostName("localhost");
|
||||||
Email email = new SimpleEmail();
|
email.setSmtpPort(port);
|
||||||
email.setHostName("localhost");
|
email.setFrom("alice@nifi.apache.org");
|
||||||
email.setSmtpPort(port);
|
email.setSubject("This is a test");
|
||||||
email.setFrom("alice@nifi.apache.org");
|
email.setMsg("MSG-" + i);
|
||||||
email.setSubject("This is a test");
|
email.addTo("bob@nifi.apache.org");
|
||||||
email.setMsg("MSG-" + i);
|
|
||||||
email.addTo("bob@nifi.apache.org");
|
|
||||||
|
|
||||||
// Enable STARTTLS but ignore the cert
|
// Enable STARTTLS but ignore the cert
|
||||||
email.setStartTLSEnabled(true);
|
email.setStartTLSEnabled(true);
|
||||||
email.setStartTLSRequired(true);
|
email.setStartTLSRequired(true);
|
||||||
email.setSSLCheckServerIdentity(false);
|
email.setSSLCheckServerIdentity(false);
|
||||||
email.send();
|
email.send();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1500, TimeUnit.MILLISECONDS);
|
}, 1500, TimeUnit.MILLISECONDS);
|
||||||
@ -165,7 +157,6 @@ public class TestListenSMTP {
|
|||||||
TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class);
|
TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class);
|
||||||
runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port));
|
runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port));
|
||||||
runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3");
|
runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3");
|
||||||
runner.setProperty(ListenSMTP.SMTP_TIMEOUT, "10 seconds");
|
|
||||||
runner.setProperty(ListenSMTP.SMTP_MAXIMUM_MSG_SIZE, "10 B");
|
runner.setProperty(ListenSMTP.SMTP_MAXIMUM_MSG_SIZE, "10 B");
|
||||||
|
|
||||||
runner.assertValid();
|
runner.assertValid();
|
||||||
@ -175,25 +166,22 @@ public class TestListenSMTP {
|
|||||||
|
|
||||||
runner.run(messageCount, false);
|
runner.run(messageCount, false);
|
||||||
|
|
||||||
this.executor.schedule(new Runnable() {
|
this.executor.schedule(() -> {
|
||||||
@Override
|
for (int i = 0; i < messageCount; i++) {
|
||||||
public void run() {
|
try {
|
||||||
for (int i = 0; i < messageCount; i++) {
|
Email email = new SimpleEmail();
|
||||||
try {
|
email.setHostName("localhost");
|
||||||
Email email = new SimpleEmail();
|
email.setSmtpPort(port);
|
||||||
email.setHostName("localhost");
|
email.setFrom("alice@nifi.apache.org");
|
||||||
email.setSmtpPort(port);
|
email.setSubject("This is a test");
|
||||||
email.setFrom("alice@nifi.apache.org");
|
email.setMsg("MSG-" + i);
|
||||||
email.setSubject("This is a test");
|
email.addTo("bob@nifi.apache.org");
|
||||||
email.setMsg("MSG-" + i);
|
email.send();
|
||||||
email.addTo("bob@nifi.apache.org");
|
} catch (Exception e) {
|
||||||
email.send();
|
e.printStackTrace();
|
||||||
} catch (Exception e) {
|
throw new RuntimeException(e);
|
||||||
e.printStackTrace();
|
} finally {
|
||||||
throw new RuntimeException(e);
|
latch.countDown();
|
||||||
} finally {
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1000, TimeUnit.MILLISECONDS);
|
}, 1000, TimeUnit.MILLISECONDS);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user