The behavior you're seeing is expected at this point given the fix for
ARTEMIS-4234 [1]. The capabilities of the JUnit resources are very basic,
and it doesn't really make sense to make them support more complex
use-cases when the client API already does this. Therefore you just need to
create your own consumer, e.g.:

    @Test
    void testInputStream() throws Exception {
        File file = new
File(Objects.requireNonNull(getClass().getResource("/testFile.txt")).toURI());
        String content = Files.readString(file.toPath());

        InputStream inputStream = new FileInputStream(file);
        BufferedInputStream bufferedInputStream = new
BufferedInputStream(inputStream);

        jmsTemplate.send(LargeMessageTest.TOPIC_NAME, session -> {
            javax.jms.Message msg = session.createBytesMessage();

            msg.setObjectProperty("JMS_AMQ_InputStream",
bufferedInputStream);
            return msg;
        });

        ServerLocator serverLocator =
ActiveMQClient.createServerLocator(embeddedActiveMQResource.getVmURL());
        ClientSessionFactory clientSessionFactory =
serverLocator.createSessionFactory();
        ClientSession session = clientSessionFactory.createSession();
        ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
        BufferedOutputStream bufferedOutput = new
BufferedOutputStream(byteArrayOutputStream);

        try (ClientConsumer consumer = session.createConsumer(TOPIC_NAME)) {
            session.start();
            ClientMessage receivedMessage = consumer.receive();
            receivedMessage.saveToOutputStream(bufferedOutput);
        }

        String readContent = byteArrayOutputStream.toString();

        assertEquals(content, readContent);
    }


Justin

[1] https://issues.apache.org/jira/browse/ARTEMIS-4234

On Thu, Aug 17, 2023 at 12:13 PM Vojtěch Frič <vojtech.f...@manta.io.invalid>
wrote:

> Hi.
>
> After upgrading to Artemis 2.30 which contains changes from
> https://issues.apache.org/jira/browse/ARTEMIS-4234 one of our tests
> started failing. We were able to track it down to the previously
> mentioned issue.
>
> Fixing of the leaking ClientConsumer resources in the
> EmbeddedActiveMQResource causes the underlying data stream to be mark as
> closed as well. This means it is not possible to actually save the
> received message into a buffer. The result is AMQ219023:
>
>
> ActiveMQIllegalStateException[errorType=ILLEGAL_STATE message=AMQ219023:
> The large message lost connection with its session, either because of a
> rollback or a closed session
> ]
>      at
>
> org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl.saveBuffer(LargeMessageControllerImpl.java:265)
>      at
>
> org.apache.activemq.artemis.core.client.impl.ClientLargeMessageImpl.saveToOutputStream(ClientLargeMessageImpl.java:113)
>      at LargeMessageTest.testInputStream(LargeMessageTest.java:68)
>
>
> I have a working example showing this error available here
> https://github.com/sutr90/artemis-junit-large-message/tree/master
>
>
> Can you advise how to fix this test, or confirm that this is expected
> behavior of the EmbeddedActiveMQResource?
>
>
> Thank you.
>
> Vojtěch Frič
>
>
> --
> *This email is intended solely for the addressee(s) and all its contents,
> including all attachments and files transmitted with it, represent
> confidential information. Unauthorized distribution, modification or
> disclosure of its contents and unauthorized reliance on its contents are
> prohibited. If you have received this email in error, please notify the
> sender immediately by return email. Please then delete the email from your
> system and do not (i) copy or distribute it, (ii) rely on its contents, or
> (iii) disclose its contents to any person.*
>
>

Reply via email to