Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions deps/rabbit/test/amqp_jms_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -122,32 +122,24 @@ jms_temporary_queue(Config) ->

%% Send different message types from JMS client to JMS client.
message_types_jms_to_jms(Config) ->
TestName = QName = atom_to_binary(?FUNCTION_NAME),
ok = declare_queue(QName, <<"quorum">>, Config),
ok = run_jms_test(TestName, [{"-Dqueue=~ts", [rabbitmq_amqp_address:queue(QName)]}], Config),
ok = delete_queue(QName, Config).
ok = run_jms_test(?FUNCTION_NAME, Config).

%% Send different message types from JMS client to Erlang AMQP 1.0 client.
message_types_jms_to_amqp(Config) ->
TestName = atom_to_binary(?FUNCTION_NAME),
ok = run_jms_test(TestName, [], Config).
ok = run_jms_test(?FUNCTION_NAME, Config).

temporary_queue_rpc(Config) ->
TestName = QName = atom_to_binary(?FUNCTION_NAME),
ok = declare_queue(QName, <<"classic">>, Config),
ok = run_jms_test(TestName, [{"-Dqueue=~ts", [rabbitmq_amqp_address:queue(QName)]}], Config),
ok = delete_queue(QName, Config).
ok = run_jms_test(?FUNCTION_NAME, Config).

temporary_queue_delete(Config) ->
TestName = atom_to_binary(?FUNCTION_NAME),
ok = run_jms_test(TestName, [], Config).
ok = run_jms_test(?FUNCTION_NAME, Config).

%% -------------------------------------------------------------------
%% Helpers
%% -------------------------------------------------------------------

run_jms_test(TestName, JavaProps, Config) ->
run(TestName, [{"-Dtest=JmsTest#~ts", [TestName]} | JavaProps], Config).
run_jms_test(TestName, Config) ->
run(TestName, [{"-Dtest=JmsTest#~ts", [TestName]}], Config).

run(TestName, JavaProps, Config) ->
TestProjectDir = ?config(data_dir, Config),
Expand Down
27 changes: 27 additions & 0 deletions deps/rabbit/test/amqp_jms_SUITE_data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<!-- add explicitly to update automatically with dependabot -->
<dependency>
<groupId>com.google.googlejavaformat</groupId>
<artifactId>google-java-format</artifactId>
<version>${google-java-format.version}</version>
<scope>test</scope>
</dependency>

</dependencies>
<build>
Expand Down Expand Up @@ -89,6 +96,26 @@
<style>GOOGLE</style>
</googleJavaFormat>
</java>
<ratchetFrom>origin/main</ratchetFrom>
<licenseHeader>
<content>// The contents of this file are subject to the Mozilla Public 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 https://www.mozilla.org/en-US/MPL/2.0/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
// the License for the specific language governing rights and
// limitations under the License.
//
// The Original Code is RabbitMQ.
//
// The Initial Developer of the Original Code is Pivotal Software, Inc.
// Copyright (c) $YEAR Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
// and/or its subsidiaries. All rights reserved.
//
</content>
</licenseHeader>
</configuration>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
// The Original Code is RabbitMQ.
//
// The Initial Developer of the Original Code is Pivotal Software, Inc.
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
// and/or its subsidiaries. All rights reserved.
//
package com.rabbitmq.amqp.tests.jms;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
// and/or its subsidiaries. All rights reserved.
//

package com.rabbitmq.amqp.tests.jms;

import static com.rabbitmq.amqp.tests.jms.Cli.startBroker;
import static com.rabbitmq.amqp.tests.jms.Cli.stopBroker;
import static com.rabbitmq.amqp.tests.jms.TestUtils.*;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.assertj.core.api.Assertions.*;

import jakarta.jms.*;
import java.util.concurrent.CountDownLatch;
Expand All @@ -41,34 +37,32 @@
@JmsTestInfrastructure
public class JmsConnectionTest {

String destination;
ConnectionFactory factory;

@Test
@Timeout(30)
public void testCreateConnection() throws Exception {
try (Connection connection = connection()) {
assertNotNull(connection);
try (Connection connection = factory.createConnection()) {
assertThat(connection).isNotNull();
}
}

@Test
@Timeout(30)
public void testCreateConnectionAndStart() throws Exception {
try (Connection connection = connection()) {
assertNotNull(connection);
try (Connection connection = factory.createConnection()) {
assertThat(connection).isNotNull();
connection.start();
}
}

@Test
@Timeout(30)
// Currently not supported by RabbitMQ.
@Disabled
@Disabled("Client ID conflict detection is not supported by RabbitMQ")
public void testCreateWithDuplicateClientIdFails() throws Exception {
JmsConnectionFactory factory = (JmsConnectionFactory) connectionFactory();
JmsConnection connection1 = (JmsConnection) factory.createConnection();
connection1.setClientID("Test");
assertNotNull(connection1);
assertThat(connection1).isNotNull();
connection1.start();
JmsConnection connection2 = (JmsConnection) factory.createConnection();
try {
Expand All @@ -86,75 +80,74 @@ public void testCreateWithDuplicateClientIdFails() throws Exception {

@Test
public void testSetClientIdAfterStartedFails() {
assertThrows(
JMSException.class,
() -> {
try (Connection connection = connection()) {
connection.setClientID("Test");
connection.start();
connection.setClientID("NewTest");
}
});
assertThatThrownBy(
() -> {
try (Connection connection = factory.createConnection()) {
connection.setClientID("Test");
connection.start();
connection.setClientID("NewTest");
}
})
.isInstanceOf(JMSException.class);
}

@Test
@Timeout(30)
public void testCreateConnectionAsSystemAdmin() throws Exception {
JmsConnectionFactory factory = (JmsConnectionFactory) connectionFactory();
factory.setUsername(adminUsername());
factory.setPassword(adminPassword());
JmsConnectionFactory f = (JmsConnectionFactory) factory;

f.setUsername(adminUsername());
f.setPassword(adminPassword());
try (Connection connection = factory.createConnection()) {
assertNotNull(connection);
assertThat(connection).isNotNull();
connection.start();
}
}

@Test
@Timeout(30)
public void testCreateConnectionCallSystemAdmin() throws Exception {
try (Connection connection =
connectionFactory().createConnection(adminUsername(), adminPassword())) {
assertNotNull(connection);
try (Connection connection = factory.createConnection(adminUsername(), adminPassword())) {
assertThat(connection).isNotNull();
connection.start();
}
}

@Test
@Timeout(30)
public void testCreateConnectionAsUnknwonUser() {
assertThrows(
JMSSecurityException.class,
() -> {
JmsConnectionFactory factory = (JmsConnectionFactory) connectionFactory();
factory.setUsername("unknown");
factory.setPassword("unknown");
try (Connection connection = factory.createConnection()) {
assertNotNull(connection);
connection.start();
}
});
public void testCreateConnectionAsUnknownUser() {
assertThatThrownBy(
() -> {
JmsConnectionFactory f = (JmsConnectionFactory) factory;
f.setUsername("unknown");
f.setPassword("unknown");
try (Connection connection = factory.createConnection()) {
assertThat(connection).isNotNull();
connection.start();
}
})
.isInstanceOf(JMSSecurityException.class);
}

@Test
@Timeout(30)
public void testCreateConnectionCallUnknwonUser() {
assertThrows(
JMSSecurityException.class,
() -> {
try (Connection connection = connectionFactory().createConnection("unknown", "unknown")) {
assertNotNull(connection);
connection.start();
}
});
public void testCreateConnectionCallUnknownUser() {
assertThatThrownBy(
() -> {
try (Connection connection = factory.createConnection("unknown", "unknown")) {
assertThat(connection).isNotNull();
connection.start();
}
})
.isInstanceOf(JMSSecurityException.class);
}

@Test
@Timeout(30)
public void testBrokerStopWontHangConnectionClose() throws Exception {
Connection connection = connection();
public void testBrokerStopWontHangConnectionClose(Queue queue) throws Exception {
Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

Queue queue = queue(destination);
connection.start();

MessageProducer producer = session.createProducer(queue);
Expand All @@ -179,15 +172,15 @@ public void testBrokerStopWontHangConnectionClose() throws Exception {
@Timeout(60)
public void testConnectionExceptionBrokerStop() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
try (Connection connection = connection()) {
try (Connection connection = factory.createConnection()) {
connection.setExceptionListener(exception -> latch.countDown());
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session);
assertThat(session).isNotNull();

try {
stopBroker();
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
} finally {
startBroker();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
// and/or its subsidiaries. All rights reserved.
//

package com.rabbitmq.amqp.tests.jms;

import static com.rabbitmq.amqp.tests.jms.TestUtils.brokerUri;
import static com.rabbitmq.amqp.tests.jms.TestUtils.connection;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.fail;
import static org.assertj.core.api.Assertions.*;

import jakarta.jms.*;
import jakarta.jms.IllegalStateException;
Expand All @@ -35,13 +32,16 @@
* Based on
* https://github.com/apache/qpid-jms/tree/main/qpid-jms-interop-tests/qpid-jms-activemq-tests.
*/
@JmsTestInfrastructure
public class JmsTemporaryQueueTest {

ConnectionFactory factory;

Connection connection;

@BeforeEach
void init() throws JMSException {
connection = connection();
connection = factory.createConnection();
}

@AfterEach
Expand All @@ -55,14 +55,14 @@ public void testCreatePublishConsumeTemporaryQueue() throws Exception {
connection.start();

Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session);
assertThat(session).isNotNull();
TemporaryQueue queue = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(queue);

MessageProducer producer = session.createProducer(queue);
String body = UUID.randomUUID().toString();
producer.send(session.createTextMessage(body));
assertEquals(body, consumer.receive(60_000).getBody(String.class));
assertThat(consumer.receive(60_000).getBody(String.class)).isEqualTo(body);
}

@Test
Expand Down
Loading
Loading