Skip to content

Commit dded836

Browse files
Test Artemis ConnectoryFactory URL with parameters
1 parent 37aa3bb commit dded836

File tree

7 files changed

+68
-15
lines changed

7 files changed

+68
-15
lines changed

integration-tests/jms-artemis-client/src/main/java/org/apache/camel/quarkus/component/jms/artemis/it/CustomConnectionFactory.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@
1616
*/
1717
package org.apache.camel.quarkus.component.jms.artemis.it;
1818

19-
import io.quarkus.arc.properties.UnlessBuildProperty;
19+
import io.quarkus.arc.properties.IfBuildProperty;
20+
import io.smallrye.common.annotation.Identifier;
21+
import jakarta.enterprise.context.ApplicationScoped;
2022
import jakarta.enterprise.context.Dependent;
2123
import jakarta.enterprise.inject.Produces;
24+
import jakarta.enterprise.inject.Typed;
2225
import jakarta.jms.ConnectionFactory;
2326
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
2427
import org.eclipse.microprofile.config.ConfigProvider;
2528

2629
@Dependent
2730
public class CustomConnectionFactory {
31+
static final int RECONNECT_ATTEMPTS = 50;
32+
2833
@Produces
29-
@UnlessBuildProperty(name = "quarkus.artemis.enabled", stringValue = "true")
34+
@IfBuildProperty(name = "artemis.custom.connection-factory.enabled", stringValue = "true")
35+
@Typed({ ConnectionFactory.class })
36+
@ApplicationScoped
37+
@Identifier("camel-quarkus-custom-connection-factory")
3038
ConnectionFactory createConnectionFactory() {
3139
String url = ConfigProvider.getConfig().getValue("quarkus.artemis.url", String.class);
32-
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(url);
33-
return cf;
40+
String options = "?reconnectAttempts=" + RECONNECT_ATTEMPTS;
41+
return new ActiveMQConnectionFactory(url + options);
3442
}
3543
}

integration-tests/jms-artemis-client/src/main/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisResource.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.camel.quarkus.component.jms.artemis.it;
1818

19+
import io.quarkus.arc.ClientProxy;
1920
import jakarta.enterprise.context.ApplicationScoped;
2021
import jakarta.inject.Inject;
2122
import jakarta.jms.ConnectionFactory;
@@ -24,11 +25,13 @@
2425
import jakarta.ws.rs.Path;
2526
import jakarta.ws.rs.Produces;
2627
import jakarta.ws.rs.core.MediaType;
28+
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
2729
import org.apache.camel.CamelContext;
2830
import org.apache.camel.CamelExecutionException;
2931
import org.apache.camel.Produce;
3032
import org.apache.camel.ProducerTemplate;
3133
import org.apache.camel.component.mock.MockEndpoint;
34+
import org.apache.camel.support.CamelContextHelper;
3235

3336
@ApplicationScoped
3437
@Path("/messaging/jms/artemis")
@@ -50,7 +53,16 @@ public class JmsArtemisResource {
5053
@Path("/connection/factory")
5154
@Produces(MediaType.TEXT_PLAIN)
5255
public String connectionFactoryImplementation() {
53-
return connectionFactory.getClass().getName();
56+
return ClientProxy.unwrap(connectionFactory).getClass().getName();
57+
}
58+
59+
@GET
60+
@Path("/connection/factory/reconnectAttempts")
61+
@Produces(MediaType.TEXT_PLAIN)
62+
public int connectionFactoryReconnectAttempts() {
63+
ConnectionFactory customConnectionFactory = CamelContextHelper.mandatoryLookup(context,
64+
"camel-quarkus-custom-connection-factory", ConnectionFactory.class);
65+
return ((ActiveMQConnectionFactory) ClientProxy.unwrap(customConnectionFactory)).getReconnectAttempts();
5466
}
5567

5668
@POST

integration-tests/jms-artemis-client/src/main/resources/application.properties

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818

1919
quarkus.artemis.devservices.extra-args=--no-autotune --mapped --no-fsync --java-options=-Dbrokerconfig.maxDiskUsage=-1
2020

21-
# Overridden to false via @TestProfile(JmsArtemisDisable.class) for some tests
22-
# When false, we produce a custom ConnectionFactory via CustomConnectionFactory producer bean
23-
quarkus.artemis.enabled=true
21+
# Overridden to true via @TestProfile(JmsArtemisDisable.class) for some tests
22+
# When true, we produce a custom ConnectionFactory via CustomConnectionFactory producer bean
23+
artemis.custom.connection-factory.enabled=false
2424

25-
#
2625
# Only enabled with JmsArtemisPoolingTest
2726
quarkus.pooled-jms.pooling.enabled=false

integration-tests/jms-artemis-client/src/test/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisDisable.java renamed to integration-tests/jms-artemis-client/src/test/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisCustomConnectionFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222

2323
import io.quarkus.test.junit.QuarkusTestProfile;
2424

25-
public class JmsArtemisDisable implements QuarkusTestProfile {
25+
public class JmsArtemisCustomConnectionFactory implements QuarkusTestProfile {
2626
@Override
2727
public Map<String, String> getConfigOverrides() {
2828
Map<String, String> props = new HashMap<>();
29-
props.put("quarkus.artemis.enabled", "false");
29+
props.put("artemis.custom.connection-factory.enabled", "true");
30+
props.put("camel.component.jms.connection-factory", "#camel-quarkus-custom-connection-factory");
3031
return props;
3132
}
3233

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.quarkus.component.jms.artemis.it;
18+
19+
import io.quarkus.test.junit.QuarkusIntegrationTest;
20+
21+
@QuarkusIntegrationTest
22+
class JmsArtemisCustomConnectionFactoryIT extends JmsArtemisCustomConnectionFactory {
23+
}

integration-tests/jms-artemis-client/src/test/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisCustomTest.java renamed to integration-tests/jms-artemis-client/src/test/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisCustomConnectionFactoryTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,30 @@
2626
import org.apache.camel.quarkus.test.support.activemq.ActiveMQTestResource;
2727
import org.junit.jupiter.api.Test;
2828

29+
import static org.apache.camel.quarkus.component.jms.artemis.it.CustomConnectionFactory.RECONNECT_ATTEMPTS;
2930
import static org.hamcrest.Matchers.is;
3031

3132
@QuarkusTest
32-
@TestProfile(JmsArtemisDisable.class)
33+
@TestProfile(JmsArtemisCustomConnectionFactory.class)
3334
@QuarkusTestResource(initArgs = {
3435
@ResourceArg(name = "modules", value = "quarkus.artemis"),
3536
@ResourceArg(name = "java-args", value = "-Dbrokerconfig.securityEnabled=false")
3637
}, value = ActiveMQTestResource.class)
37-
public class JmsArtemisCustomTest extends AbstractJmsMessagingTest {
38+
public class JmsArtemisCustomConnectionFactoryTest extends AbstractJmsMessagingTest {
3839
@Test
3940
public void connectionFactoryImplementation() {
4041
RestAssured.get("/messaging/jms/artemis/connection/factory")
4142
.then()
4243
.statusCode(200)
4344
.body(is(ActiveMQConnectionFactory.class.getName()));
4445
}
46+
47+
@Test
48+
public void connectionFactoryReconnectAttemptsConfigured() {
49+
RestAssured.get("/messaging/jms/artemis/connection/factory/reconnectAttempts")
50+
.then()
51+
.statusCode(200)
52+
.body(is(String.valueOf(RECONNECT_ATTEMPTS)));
53+
}
54+
4555
}

integration-tests/jms-artemis-client/src/test/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919
import io.quarkus.test.junit.QuarkusTest;
2020
import io.restassured.RestAssured;
21+
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
2122
import org.apache.camel.quarkus.messaging.jms.AbstractJmsMessagingTest;
2223
import org.junit.jupiter.api.Test;
2324

2425
import static org.hamcrest.Matchers.is;
25-
import static org.hamcrest.Matchers.startsWith;
2626

2727
@QuarkusTest
2828
class JmsArtemisTest extends AbstractJmsMessagingTest {
@@ -32,7 +32,7 @@ public void connectionFactoryImplementation() {
3232
RestAssured.get("/messaging/jms/artemis/connection/factory")
3333
.then()
3434
.statusCode(200)
35-
.body(startsWith("jakarta.jms.ConnectionFactory"));
35+
.body(is(ActiveMQConnectionFactory.class.getName()));
3636
}
3737

3838
@Test

0 commit comments

Comments
 (0)