You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "nandorsoma (via GitHub)" <gi...@apache.org> on 2023/02/07 01:52:29 UTC
[GitHub] [nifi] nandorsoma opened a new pull request, #6930: NIFI-11144 Fix failing tests for ConsumeJMS/PublishJMS
nandorsoma opened a new pull request, #6930:
URL: https://github.com/apache/nifi/pull/6930
<!-- Licensed to the Apache Software Foundation (ASF) under one or more -->
<!-- contributor license agreements. See the NOTICE file distributed with -->
<!-- this work for additional information regarding copyright ownership. -->
<!-- The ASF licenses this file to You under the Apache License, Version 2.0 -->
<!-- (the "License"); you may not use this file except in compliance with -->
<!-- the License. You may obtain a copy of the License at -->
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
<!-- Unless required by applicable law or agreed to in writing, software -->
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
<!-- 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. -->
# Summary
[NIFI-11144](https://issues.apache.org/jira/browse/NIFI-11144)
As the title says, this PR intends to fix currently failing tests without changing the behavior of the processors. There are two things worth mentioning. There was an exception propagation in ConsumeJMS. The comment next to it doesn't really make sense. In 2020 a commit was added, which even caught all exceptions in the Abstract class. I tried to figure out what the expectation would be. Propagate it according to the original behavior, or go forward and remove the rethrow part. I decided to do the latter because propagating the exception doesn't make sense in this case. There is no upstream connection, and when "consume" fails, there won't be a flowfile in the output relationship, so rollback is unnecessary, which could be triggered by the exception.
The other thing is testMultiplethreads(). It failed with timeout because we reached a limit after publishing a thousand messages. It is probably related to [this](https://activemq.apache.org/how-to-deal-with-large-number-of-threads-in-clients). I tried multiple different configurations without luck. It is a hint, but maybe not all of them work with the test broker implementation. Ultimately I decided to set the total messages to that threshold. This way, we can spare the additional configuration, and one thousand messages should be enough for the purpose of the test.
# Tracking
Please complete the following tracking steps prior to pull request creation.
### Issue Tracking
- [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
### Pull Request Tracking
- [x] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
- [x] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
### Pull Request Formatting
- [x] Pull Request based on current revision of the `main` branch
- [x] Pull Request refers to a feature branch with one commit containing changes
# Verification
Please indicate the verification steps performed prior to pull request creation.
### Build
- [x] Build completed using `mvn clean install -P contrib-check`
- [x] JDK 8
- [ ] JDK 11
- [ ] JDK 17
### Licensing
- [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
- [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
### Documentation
- [ ] Documentation formatting appears as expected in rendered files
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] tpalfy commented on a diff in pull request #6930: NIFI-11144 Fix failing tests for ConsumeJMS/PublishJMS
Posted by "tpalfy (via GitHub)" <gi...@apache.org>.
tpalfy commented on code in PR #6930:
URL: https://github.com/apache/nifi/pull/6930#discussion_r1106136128
##########
nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/helpers/AssertionUtils.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.jms.processors.helpers;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class AssertionUtils {
+
+ public static <T extends Throwable> void assertCausedBy(Class<T> expectedType, Runnable runnable) {
+ assertCausedBy(expectedType, null, runnable);
+ }
+
+ public static <T extends Throwable> void assertCausedBy(Class<T> expectedType, String expectedMessage, Runnable runnable) {
+ try {
+ runnable.run();
+ fail(String.format("Expected an exception to be thrown with a cause of %s, but nothing was thrown.", expectedType.getCanonicalName()));
+ } catch (Throwable throwable) {
+ final List<Throwable> causes = ExceptionUtils.getThrowableList(throwable);
+ for (Throwable cause : causes) {
+ if (expectedType.isInstance(cause)) {
+ if (expectedMessage != null) {
+ if (cause.getMessage() != null && cause.getMessage().startsWith(expectedMessage)) {
+ return;
+ }
+ } else {
+ return;
+ }
+ }
+ }
+ fail(String.format("Exception is thrown but not found %s as a cause. Received exception is: %s", expectedType.getCanonicalName(), throwable), throwable);
+ }
+ }
+
+ public static void assertCausedBy(Throwable expectedException, Runnable runnable) {
Review Comment:
This is only used in `ConsumeJMSIT.whenExceptionIsRaisedInAcceptTheProcessorShouldYieldAndRollback` like this:
```java
assertCausedBy(expectedException, () -> runner.run(1, false));
```
We could remove this method altogether and change the call to this:
```java
assertCausedBy(expectedException.getClass(), () -> runner.run(1, false));
```
I think checking an `equals` on an `Exception` is a questionable practice in general to put it in a util class.
##########
nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/ConsumeJMSIT.java:
##########
@@ -409,29 +418,75 @@ public void whenExceptionIsRaisedTheProcessorShouldBeYielded() throws Exception
runner.setProperty(ConsumeJMS.DESTINATION, "foo");
runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.TOPIC);
- assertThrows(AssertionError.class, () -> runner.run());
- assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled(), "In case of an exception, the processor should be yielded.");
+ assertCausedBy(UnknownHostException.class, runner::run);
+
+ assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled(), "In case of an exception, the processor should be yielded.");
}
@Test
public void whenExceptionIsRaisedDuringConnectionFactoryInitializationTheProcessorShouldBeYielded() throws Exception {
+ final String nonExistentClassName = "DummyJMSConnectionFactoryClass";
+
TestRunner runner = TestRunners.newTestRunner(ConsumeJMS.class);
// using (non-JNDI) JMS Connection Factory via controller service
JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
runner.addControllerService("cfProvider", cfProvider);
- runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, "DummyJMSConnectionFactoryClass");
+ runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, nonExistentClassName);
runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, "DummyBrokerUri");
runner.enableControllerService(cfProvider);
runner.setProperty(ConsumeJMS.CF_SERVICE, "cfProvider");
runner.setProperty(ConsumeJMS.DESTINATION, "myTopic");
runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.TOPIC);
- assertThrows(AssertionError.class, () -> runner.run());
+ assertCausedBy(ClassNotFoundException.class, nonExistentClassName, runner::run);
+
assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled(), "In case of an exception, the processor should be yielded.");
}
+ @Test
+ @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
+ public void whenExceptionIsRaisedInAcceptTheProcessorShouldYieldAndRollback() throws Exception {
+ final String destination = "testQueue";
+ final RuntimeException expectedException = new RuntimeException();
+
+ final ConsumeJMS processor = new ConsumeJMS() {
+ @Override
+ protected void rendezvousWithJms(ProcessContext context, ProcessSession processSession, JMSConsumer consumer) throws ProcessException {
+ ProcessSession spiedSession = spy(processSession);
+ doThrow(expectedException).when(spiedSession).write(any(FlowFile.class), any(OutputStreamCallback.class));
+ super.rendezvousWithJms(context, spiedSession, consumer);
+ }
+ };
+
+ JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);
+ try {
+ JMSPublisher sender = new JMSPublisher((CachingConnectionFactory) jmsTemplate.getConnectionFactory(), jmsTemplate, mock(ComponentLog.class));
+
+ sender.jmsTemplate.send(destination, session -> session.createTextMessage("msg"));
+
+ TestRunner runner = TestRunners.newTestRunner(processor);
+ JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
+ when(cs.getIdentifier()).thenReturn("cfProvider");
+ when(cs.getConnectionFactory()).thenReturn(jmsTemplate.getConnectionFactory());
+ runner.addControllerService("cfProvider", cs);
+ runner.enableControllerService(cs);
+
+ runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
+ runner.setProperty(ConsumeJMS.DESTINATION, destination);
+ runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.QUEUE);
+
+ ((MockSessionFactory) runner.getProcessSessionFactory()).getCreatedSessions();
Review Comment:
Do we need this?
##########
nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/JMSPublisherConsumerIT.java:
##########
@@ -332,14 +332,21 @@ public void accept(JMSResponse response) {
@Test
@Timeout(value = 20000, unit = TimeUnit.MILLISECONDS)
public void testMultipleThreads() throws Exception {
+ final int threadCount = 4;
+ final int totalMessageCount = 1000;
+ final int messagesPerThreadCount = totalMessageCount / threadCount;
+
String destinationName = "testMultipleThreads";
JmsTemplate publishTemplate = CommonTest.buildJmsTemplateForDestination(false);
- final CountDownLatch consumerTemplateCloseCount = new CountDownLatch(4);
+ final CountDownLatch consumerTemplateCloseCount = new CountDownLatch(threadCount);
+
+ final AtomicInteger test = new AtomicInteger(0);
Review Comment:
Do we need this?
##########
nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/ConsumeJMSIT.java:
##########
@@ -409,29 +418,75 @@ public void whenExceptionIsRaisedTheProcessorShouldBeYielded() throws Exception
runner.setProperty(ConsumeJMS.DESTINATION, "foo");
runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.TOPIC);
- assertThrows(AssertionError.class, () -> runner.run());
- assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled(), "In case of an exception, the processor should be yielded.");
+ assertCausedBy(UnknownHostException.class, runner::run);
+
+ assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled(), "In case of an exception, the processor should be yielded.");
}
@Test
public void whenExceptionIsRaisedDuringConnectionFactoryInitializationTheProcessorShouldBeYielded() throws Exception {
+ final String nonExistentClassName = "DummyJMSConnectionFactoryClass";
+
TestRunner runner = TestRunners.newTestRunner(ConsumeJMS.class);
// using (non-JNDI) JMS Connection Factory via controller service
JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
runner.addControllerService("cfProvider", cfProvider);
- runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, "DummyJMSConnectionFactoryClass");
+ runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, nonExistentClassName);
runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, "DummyBrokerUri");
runner.enableControllerService(cfProvider);
runner.setProperty(ConsumeJMS.CF_SERVICE, "cfProvider");
runner.setProperty(ConsumeJMS.DESTINATION, "myTopic");
runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.TOPIC);
- assertThrows(AssertionError.class, () -> runner.run());
+ assertCausedBy(ClassNotFoundException.class, nonExistentClassName, runner::run);
+
assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled(), "In case of an exception, the processor should be yielded.");
}
+ @Test
+ @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
+ public void whenExceptionIsRaisedInAcceptTheProcessorShouldYieldAndRollback() throws Exception {
+ final String destination = "testQueue";
+ final RuntimeException expectedException = new RuntimeException();
+
+ final ConsumeJMS processor = new ConsumeJMS() {
+ @Override
+ protected void rendezvousWithJms(ProcessContext context, ProcessSession processSession, JMSConsumer consumer) throws ProcessException {
+ ProcessSession spiedSession = spy(processSession);
+ doThrow(expectedException).when(spiedSession).write(any(FlowFile.class), any(OutputStreamCallback.class));
+ super.rendezvousWithJms(context, spiedSession, consumer);
+ }
+ };
+
+ JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);
+ try {
+ JMSPublisher sender = new JMSPublisher((CachingConnectionFactory) jmsTemplate.getConnectionFactory(), jmsTemplate, mock(ComponentLog.class));
+
+ sender.jmsTemplate.send(destination, session -> session.createTextMessage("msg"));
Review Comment:
```suggestion
jmsTemplate.send(destination, session -> session.createTextMessage("msg"));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] nandorsoma commented on a diff in pull request #6930: NIFI-11144 Fix failing tests for ConsumeJMS/PublishJMS
Posted by "nandorsoma (via GitHub)" <gi...@apache.org>.
nandorsoma commented on code in PR #6930:
URL: https://github.com/apache/nifi/pull/6930#discussion_r1106833048
##########
nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/ConsumeJMSIT.java:
##########
@@ -409,29 +418,75 @@ public void whenExceptionIsRaisedTheProcessorShouldBeYielded() throws Exception
runner.setProperty(ConsumeJMS.DESTINATION, "foo");
runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.TOPIC);
- assertThrows(AssertionError.class, () -> runner.run());
- assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled(), "In case of an exception, the processor should be yielded.");
+ assertCausedBy(UnknownHostException.class, runner::run);
+
+ assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled(), "In case of an exception, the processor should be yielded.");
}
@Test
public void whenExceptionIsRaisedDuringConnectionFactoryInitializationTheProcessorShouldBeYielded() throws Exception {
+ final String nonExistentClassName = "DummyJMSConnectionFactoryClass";
+
TestRunner runner = TestRunners.newTestRunner(ConsumeJMS.class);
// using (non-JNDI) JMS Connection Factory via controller service
JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
runner.addControllerService("cfProvider", cfProvider);
- runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, "DummyJMSConnectionFactoryClass");
+ runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, nonExistentClassName);
runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, "DummyBrokerUri");
runner.enableControllerService(cfProvider);
runner.setProperty(ConsumeJMS.CF_SERVICE, "cfProvider");
runner.setProperty(ConsumeJMS.DESTINATION, "myTopic");
runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.TOPIC);
- assertThrows(AssertionError.class, () -> runner.run());
+ assertCausedBy(ClassNotFoundException.class, nonExistentClassName, runner::run);
+
assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled(), "In case of an exception, the processor should be yielded.");
}
+ @Test
+ @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
+ public void whenExceptionIsRaisedInAcceptTheProcessorShouldYieldAndRollback() throws Exception {
+ final String destination = "testQueue";
+ final RuntimeException expectedException = new RuntimeException();
+
+ final ConsumeJMS processor = new ConsumeJMS() {
+ @Override
+ protected void rendezvousWithJms(ProcessContext context, ProcessSession processSession, JMSConsumer consumer) throws ProcessException {
+ ProcessSession spiedSession = spy(processSession);
+ doThrow(expectedException).when(spiedSession).write(any(FlowFile.class), any(OutputStreamCallback.class));
+ super.rendezvousWithJms(context, spiedSession, consumer);
+ }
+ };
+
+ JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);
+ try {
+ JMSPublisher sender = new JMSPublisher((CachingConnectionFactory) jmsTemplate.getConnectionFactory(), jmsTemplate, mock(ComponentLog.class));
+
+ sender.jmsTemplate.send(destination, session -> session.createTextMessage("msg"));
+
+ TestRunner runner = TestRunners.newTestRunner(processor);
+ JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
+ when(cs.getIdentifier()).thenReturn("cfProvider");
+ when(cs.getConnectionFactory()).thenReturn(jmsTemplate.getConnectionFactory());
+ runner.addControllerService("cfProvider", cs);
+ runner.enableControllerService(cs);
+
+ runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
+ runner.setProperty(ConsumeJMS.DESTINATION, destination);
+ runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.QUEUE);
+
+ ((MockSessionFactory) runner.getProcessSessionFactory()).getCreatedSessions();
Review Comment:
No, it is a leftover from debug. 😕
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] asfgit closed pull request #6930: NIFI-11144 Fix failing tests for ConsumeJMS/PublishJMS
Posted by "asfgit (via GitHub)" <gi...@apache.org>.
asfgit closed pull request #6930: NIFI-11144 Fix failing tests for ConsumeJMS/PublishJMS
URL: https://github.com/apache/nifi/pull/6930
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] nandorsoma commented on a diff in pull request #6930: NIFI-11144 Fix failing tests for ConsumeJMS/PublishJMS
Posted by "nandorsoma (via GitHub)" <gi...@apache.org>.
nandorsoma commented on code in PR #6930:
URL: https://github.com/apache/nifi/pull/6930#discussion_r1107001349
##########
nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/helpers/AssertionUtils.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.jms.processors.helpers;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class AssertionUtils {
+
+ public static <T extends Throwable> void assertCausedBy(Class<T> expectedType, Runnable runnable) {
+ assertCausedBy(expectedType, null, runnable);
+ }
+
+ public static <T extends Throwable> void assertCausedBy(Class<T> expectedType, String expectedMessage, Runnable runnable) {
+ try {
+ runnable.run();
+ fail(String.format("Expected an exception to be thrown with a cause of %s, but nothing was thrown.", expectedType.getCanonicalName()));
+ } catch (Throwable throwable) {
+ final List<Throwable> causes = ExceptionUtils.getThrowableList(throwable);
+ for (Throwable cause : causes) {
+ if (expectedType.isInstance(cause)) {
+ if (expectedMessage != null) {
+ if (cause.getMessage() != null && cause.getMessage().startsWith(expectedMessage)) {
+ return;
+ }
+ } else {
+ return;
+ }
+ }
+ }
+ fail(String.format("Exception is thrown but not found %s as a cause. Received exception is: %s", expectedType.getCanonicalName(), throwable), throwable);
+ }
+ }
+
+ public static void assertCausedBy(Throwable expectedException, Runnable runnable) {
Review Comment:
I provided this overload because checking the exact exception is much safer. When I mock the exception, why should I check if it is "similar" to what I expect when I can check if it is precisely the mocked exception?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] tpalfy commented on pull request #6930: NIFI-11144 Fix failing tests for ConsumeJMS/PublishJMS
Posted by "tpalfy (via GitHub)" <gi...@apache.org>.
tpalfy commented on PR #6930:
URL: https://github.com/apache/nifi/pull/6930#issuecomment-1433208805
LGTM
Thank you for your work @nandorsoma !
Merged into main.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] tpalfy commented on a diff in pull request #6930: NIFI-11144 Fix failing tests for ConsumeJMS/PublishJMS
Posted by "tpalfy (via GitHub)" <gi...@apache.org>.
tpalfy commented on code in PR #6930:
URL: https://github.com/apache/nifi/pull/6930#discussion_r1106155851
##########
nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/ConsumeJMSIT.java:
##########
@@ -409,29 +418,75 @@ public void whenExceptionIsRaisedTheProcessorShouldBeYielded() throws Exception
runner.setProperty(ConsumeJMS.DESTINATION, "foo");
runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.TOPIC);
- assertThrows(AssertionError.class, () -> runner.run());
- assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled(), "In case of an exception, the processor should be yielded.");
+ assertCausedBy(UnknownHostException.class, runner::run);
+
+ assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled(), "In case of an exception, the processor should be yielded.");
}
@Test
public void whenExceptionIsRaisedDuringConnectionFactoryInitializationTheProcessorShouldBeYielded() throws Exception {
+ final String nonExistentClassName = "DummyJMSConnectionFactoryClass";
+
TestRunner runner = TestRunners.newTestRunner(ConsumeJMS.class);
// using (non-JNDI) JMS Connection Factory via controller service
JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
runner.addControllerService("cfProvider", cfProvider);
- runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, "DummyJMSConnectionFactoryClass");
+ runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, nonExistentClassName);
runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, "DummyBrokerUri");
runner.enableControllerService(cfProvider);
runner.setProperty(ConsumeJMS.CF_SERVICE, "cfProvider");
runner.setProperty(ConsumeJMS.DESTINATION, "myTopic");
runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.TOPIC);
- assertThrows(AssertionError.class, () -> runner.run());
+ assertCausedBy(ClassNotFoundException.class, nonExistentClassName, runner::run);
+
assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled(), "In case of an exception, the processor should be yielded.");
}
+ @Test
+ @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
+ public void whenExceptionIsRaisedInAcceptTheProcessorShouldYieldAndRollback() throws Exception {
+ final String destination = "testQueue";
+ final RuntimeException expectedException = new RuntimeException();
+
+ final ConsumeJMS processor = new ConsumeJMS() {
+ @Override
+ protected void rendezvousWithJms(ProcessContext context, ProcessSession processSession, JMSConsumer consumer) throws ProcessException {
+ ProcessSession spiedSession = spy(processSession);
+ doThrow(expectedException).when(spiedSession).write(any(FlowFile.class), any(OutputStreamCallback.class));
+ super.rendezvousWithJms(context, spiedSession, consumer);
+ }
+ };
+
+ JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);
+ try {
+ JMSPublisher sender = new JMSPublisher((CachingConnectionFactory) jmsTemplate.getConnectionFactory(), jmsTemplate, mock(ComponentLog.class));
+
+ sender.jmsTemplate.send(destination, session -> session.createTextMessage("msg"));
Review Comment:
I think this is my fault (this has been copy-paster from my code). We can still improve it, if only a little bit. :)
```suggestion
jmsTemplate.send(destination, session -> session.createTextMessage("msg"));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] nandorsoma commented on pull request #6930: NIFI-11144 Fix failing tests for ConsumeJMS/PublishJMS
Posted by "nandorsoma (via GitHub)" <gi...@apache.org>.
nandorsoma commented on PR #6930:
URL: https://github.com/apache/nifi/pull/6930#issuecomment-1431213499
Thank you @tpalfy for your review! I've updated the pr based on your comments, except in the "assertCausedBy" topic. Please see my comment inline.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] tpalfy commented on a diff in pull request #6930: NIFI-11144 Fix failing tests for ConsumeJMS/PublishJMS
Posted by "tpalfy (via GitHub)" <gi...@apache.org>.
tpalfy commented on code in PR #6930:
URL: https://github.com/apache/nifi/pull/6930#discussion_r1106136128
##########
nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/helpers/AssertionUtils.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.jms.processors.helpers;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class AssertionUtils {
+
+ public static <T extends Throwable> void assertCausedBy(Class<T> expectedType, Runnable runnable) {
+ assertCausedBy(expectedType, null, runnable);
+ }
+
+ public static <T extends Throwable> void assertCausedBy(Class<T> expectedType, String expectedMessage, Runnable runnable) {
+ try {
+ runnable.run();
+ fail(String.format("Expected an exception to be thrown with a cause of %s, but nothing was thrown.", expectedType.getCanonicalName()));
+ } catch (Throwable throwable) {
+ final List<Throwable> causes = ExceptionUtils.getThrowableList(throwable);
+ for (Throwable cause : causes) {
+ if (expectedType.isInstance(cause)) {
+ if (expectedMessage != null) {
+ if (cause.getMessage() != null && cause.getMessage().startsWith(expectedMessage)) {
+ return;
+ }
+ } else {
+ return;
+ }
+ }
+ }
+ fail(String.format("Exception is thrown but not found %s as a cause. Received exception is: %s", expectedType.getCanonicalName(), throwable), throwable);
+ }
+ }
+
+ public static void assertCausedBy(Throwable expectedException, Runnable runnable) {
Review Comment:
This is only used in `ConsumeJMSIT.whenExceptionIsRaisedInAcceptTheProcessorShouldYieldAndRollback` like this:
```java
assertCausedBy(expectedException, () -> runner.run(1, false));
```
We could remove this method altogether and change the call to this:
```java
assertCausedBy(expectedException.getClass(), () -> runner.run(1, false));
```
or if want to be extra careful, then like this:
```java
final String expectedErrorMessage = "Expected error message";
final RuntimeException expectedException = new RuntimeException(expectedErrorMessage);
...
assertCausedBy(expectedException.getClass(), expectedErrorMessage, () -> runner.run(1, false));
```
I think checking an `equals` on an `Exception` is a questionable practice in general to put it in a util class.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org