Skip to content

Accept and test TextMessage with null payload#1505

Merged
thjaeckle merged 2 commits into
eclipse-ditto:masterfrom
tobias-zeptio:1503_acceptTextMessageWithNullPayload
Oct 12, 2022
Merged

Accept and test TextMessage with null payload#1505
thjaeckle merged 2 commits into
eclipse-ditto:masterfrom
tobias-zeptio:1503_acceptTextMessageWithNullPayload

Conversation

@tobias-zeptio
Copy link
Copy Markdown
Contributor

Adds the ability to handle TextMessage with null payload, from issue #1503

Signed-off-by: Tobias Månsson tobias@zept.io

Signed-off-by: Tobias Månsson <tobias@zept.io>
@tobias-zeptio
Copy link
Copy Markdown
Contributor Author

tobias-zeptio commented Oct 7, 2022

I tried testing with a BytesMessage, but couldn't figure it out. I gave up when I got the error The method getJmsBytesMessage(ByteBuffer, String) is undefined for the type new TestKit().

Reading through the code in AmqpJmsBytesMessageFacade BytesMessage seems to handle a null body already.

Copy link
Copy Markdown
Member

@thjaeckle thjaeckle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks almost good to me - just 2 smaller things to adjust in the test.
The byte null payload I could also not understand in the JMS / Qpid facade API ..
I think it is sufficient to support null textMessage.

@tobias-zeptio
Copy link
Copy Markdown
Contributor Author

I tried to add a BytesMessage test as well, but can't get it. Creating a empty BytesMessage makes it write-only for some reason, and setting up the body creation using byteStream is beyond me. This is my attempt:

    @SafeVarargs // varargs array is not modified or passed around
    private JmsMessage getEmptyJmsByteMessage(final String correlationId, final Map.Entry<String, ?>... headers) {
        try {
            final AmqpJmsBytesMessageFacade messageFacade = new AmqpJmsBytesMessageFacade();
            // give it a connection returning null for all methods to set any AMQP
            // properties at all
            messageFacade.initialize(mock(AmqpConnection.class));
            messageFacade.setCorrelationId(correlationId);

            final JmsMessage message = messageFacade.asJmsMessage();
            JMSPropertyMapper.setPropertiesAndApplicationProperties(messageFacade.asJmsMessage(),
                    Arrays.stream(headers)
                            .collect(Collectors.toMap(Map.Entry::getKey,
                                    e -> e.getValue().toString())),
                    mock(ThreadSafeDittoLoggingAdapter.class));
            message.setAcknowledgeCallback(mockJmsAcknowledgeCallback());
            return message;
        } catch (final JMSException e) {
            throw new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e.getCause());
        }
    }

@thjaeckle
Copy link
Copy Markdown
Member

@tobias-zeptio I also tried to add a test with a null ByteMessage and failed to create it - the byte message does not seem to support this in the used AMQP client.

If you find out that you still require this also for byte messages, I suggest to create a follow-up PR.

@thjaeckle thjaeckle merged commit d46d0d0 into eclipse-ditto:master Oct 12, 2022
@thjaeckle thjaeckle added this to the 3.0.1 milestone Oct 12, 2022
@thjaeckle
Copy link
Copy Markdown
Member

Cherry-picked to release-3.0 branch to have it included in an upcoming 3.0.1 version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants