[
https://issues.apache.org/jira/browse/NIFI-2519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15416445#comment-15416445
]
ASF GitHub Bot commented on NIFI-2519:
--------------------------------------
Github user trixpan commented on a diff in the pull request:
https://github.com/apache/nifi/pull/827#discussion_r74364045
--- Diff:
nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/test/java/org/apache/nifi/processors/email/TestListenSMTP.java
---
@@ -13,307 +13,174 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-*/
+ */
package org.apache.nifi.processors.email;
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
-import org.apache.nifi.processor.ProcessContext;
-import org.apache.nifi.processor.ProcessSessionFactory;
+import org.apache.nifi.remote.io.socket.NetworkUtils;
+import org.apache.nifi.ssl.SSLContextService;
import org.apache.nifi.ssl.StandardSSLContextService;
-import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-
-import org.apache.nifi.ssl.SSLContextService;
-
-import org.junit.Assert;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-
public class TestListenSMTP {
- @Test(timeout=15000)
- public void ValidEmailTls() throws Exception {
- boolean[] failed = {false};
- ListenSMTP listenSmtp = new ListenSMTP();
- final TestRunner runner = TestRunners.newTestRunner(listenSmtp);
-
- runner.setProperty(ListenSMTP.SMTP_PORT, "0");
- runner.setProperty(ListenSMTP.SMTP_HOSTNAME, "bermudatriangle");
- runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3");
- runner.setProperty(ListenSMTP.SMTP_TIMEOUT, "10 seconds");
-
- // Setup the SSL Context
- final SSLContextService sslContextService = new
StandardSSLContextService();
- runner.addControllerService("ssl-context", sslContextService);
- runner.setProperty(sslContextService,
StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
- runner.setProperty(sslContextService,
StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
- runner.setProperty(sslContextService,
StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
- runner.setProperty(sslContextService,
StandardSSLContextService.KEYSTORE, "src/test/resources/localhost-ks.jks");
- runner.setProperty(sslContextService,
StandardSSLContextService.KEYSTORE_PASSWORD, "localtest");
- runner.setProperty(sslContextService,
StandardSSLContextService.KEYSTORE_TYPE, "JKS");
- runner.enableControllerService(sslContextService);
-
- // and add the SSL context to the runner
- runner.setProperty(ListenSMTP.SSL_CONTEXT_SERVICE, "ssl-context");
- runner.setProperty(ListenSMTP.CLIENT_AUTH,
SSLContextService.ClientAuth.NONE.name());
-
+ private ScheduledExecutorService executor;
+ /**
+ *
+ */
+ @Before
+ public void before() {
+ this.executor = Executors.newScheduledThreadPool(2);
+ }
- final ProcessSessionFactory processSessionFactory =
runner.getProcessSessionFactory();
- final ProcessContext context = runner.getProcessContext();
-
- // NOTE: This test routine uses the same strategy used by
TestListenAndPutSyslog
- // where listenSmtp method calls are used to allow the processor
to be started using
- // port "0" without triggering a violation of PORT_VALIDATOR
-
- listenSmtp.onScheduled(context);
- listenSmtp.initializeSMTPServer(context);
-
- final int port = listenSmtp.getPort();
-
- try {
- final Thread clientThread = new Thread(new Runnable() {
- @Override
- public void run() {
- try {
-
-
- System.setProperty("mail.smtp.ssl.trust", "*");
- System.setProperty("javax.net.ssl.keyStore",
"src/test/resources/localhost-ks.jks");
-
System.setProperty("javax.net.ssl.keyStorePassword", "localtest");
-
- Email email = new SimpleEmail();
-
- email.setHostName("127.0.0.1");
- email.setSmtpPort(port);
-
- // Enable STARTTLS but ignore the cert
- email.setStartTLSEnabled(true);
- email.setStartTLSRequired(true);
- email.setSSLCheckServerIdentity(false);
-
- email.setFrom("[email protected]");
- email.setSubject("This is a test");
- email.setMsg("Test test test chocolate");
- email.addTo("[email protected]");
-
- email.send();
- } catch (final Throwable t) {
- failed[0] = true;
- }
- }
- });
- clientThread.start();
-
- while
(runner.getFlowFilesForRelationship(ListenSMTP.REL_SUCCESS).isEmpty()) {
- // process the request.
- listenSmtp.onTrigger(context, processSessionFactory);
- }
-
- // Checks if client experienced Exception
- Assert.assertFalse("Client experienced exception",
failed[0]);
-
- runner.assertTransferCount(ListenSMTP.REL_SUCCESS, 1);
- clientThread.stop();
-
- Assert.assertFalse("Sending email failed", failed[0]);
-
- runner.assertQueueEmpty();
- final List<MockFlowFile> splits =
runner.getFlowFilesForRelationship(ListenSMTP.REL_SUCCESS);
- splits.get(0).assertAttributeEquals("smtp.from",
"[email protected]");
- splits.get(0).assertAttributeEquals("smtp.to",
"[email protected]");
-
- Thread.sleep(100);
- } finally {
- // shut down the server
- listenSmtp.startShutdown();
- }
+ /**
+ *
+ */
+ @After
+ public void after() {
+ this.executor.shutdown();
}
- @Test(timeout=15000)
- public void ValidEmail() throws Exception, EmailException {
- final boolean[] failed = {false};
- ListenSMTP listenSmtp = new ListenSMTP();
- final TestRunner runner = TestRunners.newTestRunner(listenSmtp);
+ /**
+ *
+ */
+ @Test
+ public void validateSuccessfulInteraction() throws Exception,
EmailException {
+ int port = NetworkUtils.availablePort();
- runner.setProperty(ListenSMTP.SMTP_PORT, "0");
- runner.setProperty(ListenSMTP.SMTP_HOSTNAME, "bermudatriangle");
+ 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");
- final ProcessSessionFactory processSessionFactory =
runner.getProcessSessionFactory();
- final ProcessContext context = runner.getProcessContext();
+ runner.assertValid();
- // NOTE: This test routine uses the same strategy used by
TestListenAndPutSyslog
- // where listenSmtp method calls are used to allow the processor
to be started using
- // port "0" without triggering a violation of PORT_VALIDATOR
- listenSmtp.onScheduled(context);
- listenSmtp.initializeSMTPServer(context);
+ int messageCount = 5;
+ CountDownLatch latch = new CountDownLatch(messageCount);
- final int port = listenSmtp.getPort();
+ this.executor.scheduleAtFixedRate(new Runnable() {
+ @Override
+ public void run() {
+ runner.run(1, false);
+ }
+ }, 0, 500, TimeUnit.MILLISECONDS);
- try {
- final Thread clientThread = new Thread(new Runnable() {
- @Override
- public void run() {
+ this.executor.schedule(new Runnable() {
+ @Override
+ public void run() {
+ for (int i = 0; i < messageCount; i++) {
try {
Email email = new SimpleEmail();
- email.setHostName("127.0.0.1");
+ email.setHostName("localhost");
email.setSmtpPort(port);
- email.setStartTLSEnabled(false);
email.setFrom("[email protected]");
email.setSubject("This is a test");
- email.setMsg("Test test test chocolate");
+ email.setMsg("MSG-" + i);
--- End diff --
/joke on
NOOOOOOOOOO!!!! What have you done!??!! :-)
https://github.com/apache/nifi/search?utf8=%E2%9C%93&q=chocolate
/joke off
> TestListenSMTP ValidEmail fails during parallel build
> -----------------------------------------------------
>
> Key: NIFI-2519
> URL: https://issues.apache.org/jira/browse/NIFI-2519
> Project: Apache NiFi
> Issue Type: Bug
> Components: Extensions
> Reporter: Joseph Witt
> Assignee: Oleg Zhurakousky
> Fix For: 1.0.0
>
>
> While running a full NiFi parallel build received the following. So there is
> some test issue at least that is impacting build stability.
> [INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @
> nifi-email-processors ---
> [INFO] Changes detected - recompiling the module!
> [INFO] Compiling 4 source files to
> /home/travis/build/apache/nifi/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/target/test-classes
> [WARNING]
> /home/travis/build/apache/nifi/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/test/java/org/apache/nifi/processors/email/TestListenSMTP.java:[122,24]
> [deprecation] stop() in Thread has been deprecated
> [WARNING]
> /home/travis/build/apache/nifi/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/test/java/org/apache/nifi/processors/email/TestListenSMTP.java:[186,24]
> [deprecation] stop() in Thread has been deprecated
> [WARNING]
> /home/travis/build/apache/nifi/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/test/java/org/apache/nifi/processors/email/TestListenSMTP.java:[307,24]
> [deprecation] stop() in Thread has been deprecated
> [INFO]
> [INFO] --- maven-compiler-plugin:3.2:testCompile (groovy-tests) @
> nifi-email-processors ---
> [INFO] Changes detected - recompiling the module!
> [INFO] Nothing to compile - all classes are up to date
> [INFO]
> [INFO] --- maven-surefire-plugin:2.18:test (default-test) @
> nifi-email-processors ---
> [INFO] Surefire report directory:
> /home/travis/build/apache/nifi/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/target/surefire-reports
> [INFO] Using configured provider
> org.apache.maven.surefire.junit4.JUnit4Provider
> -------------------------------------------------------
> T E S T S
> -------------------------------------------------------
> Running org.apache.nifi.processors.email.TestListenSMTP
> Tests run: 4, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.473 sec <<<
> FAILURE! - in org.apache.nifi.processors.email.TestListenSMTP
> ValidEmail(org.apache.nifi.processors.email.TestListenSMTP) Time elapsed:
> 0.038 sec <<< FAILURE!
> java.lang.AssertionError: Sending email failed
> at org.junit.Assert.fail(Assert.java:88)
> at org.junit.Assert.assertTrue(Assert.java:41)
> at org.junit.Assert.assertFalse(Assert.java:64)
> at
> org.apache.nifi.processors.email.TestListenSMTP.ValidEmail(TestListenSMTP.java:188)
> Running org.apache.nifi.processors.email.TestExtractEmailAttachments
> Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.1 sec - in
> org.apache.nifi.processors.email.TestExtractEmailAttachments
> Running org.apache.nifi.processors.email.TestExtractEmailHeaders
> Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.029 sec -
> in org.apache.nifi.processors.email.TestExtractEmailHeaders
> Results :
> Failed tests:
> TestListenSMTP.ValidEmail:188 Sending email failed
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)