You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/08/16 17:41:38 UTC
[GitHub] [camel-quarkus] tmdonalds opened a new issue, #4000: apache-camel-mock Routes are not getting cleaned up after test completes
tmdonalds opened a new issue, #4000:
URL: https://github.com/apache/camel-quarkus/issues/4000
The CamelContext is not cleaning up the routes across unit tests. I am running into an issue where the unit tests are failing because the routes were already created in another test.
`
@QuarkusTest
public class RouteTest {
@Inject
CamelContext camelContext;
private static boolean initialized = false;
@BeforeEach
public void init() throws Exception {
System.out.println("RouteTest : Initialized is : " + initialized);
if(initialized) {
return;
}
initialized = true;
this.camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:prepareItems")
.to("mock:result");
from("direct:writeItemst").to("mock:outputResult");
}
});
}
@Test
public void testRoutes(){
this.camelContext.start();
System.out.println("****** Routes ****** \n");
camelContext.getRoutes().forEach(route -> System.out.println(route.getRouteId()));
System.out.println("\n");
}
@Test
public void testRoutes2(){
this.camelContext.start();
System.out.println("****** Routes ****** \n");
camelContext.getRoutes().forEach(route -> System.out.println(route.getRouteId()));
System.out.println("\n");
}
}
`
`@QuarkusTest
public class RouteTwoTest {
@Inject
CamelContext camelContext;
private static boolean initialized = false;
@BeforeEach
public void init() throws Exception {
System.out.println("RouteTest : Initialized is : " + initialized);
if(initialized) {
return;
}
initialized = true;
this.camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:prepareItems")
.to("mock:result");
from("direct:writeItemst").to("mock:outputResult");
}
});
}
@Test
public void testRoutes(){
this.camelContext.start();
System.out.println("****** Routes ****** \n");
camelContext.getRoutes().forEach(route -> System.out.println(route.getRouteId()));
System.out.println("\n");
}
@Test
public void testRoutes2(){
this.camelContext.start();
System.out.println("****** Routes ****** \n");
camelContext.getRoutes().forEach(route -> System.out.println(route.getRouteId()));
System.out.println("\n");
}
}`
--
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: commits-unsubscribe@camel.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-quarkus] tmdonalds closed issue #4000: apache-camel-mock Routes are not getting cleaned up after test completes
Posted by GitBox <gi...@apache.org>.
tmdonalds closed issue #4000: apache-camel-mock Routes are not getting cleaned up after test completes
URL: https://github.com/apache/camel-quarkus/issues/4000
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-quarkus] tmdonalds commented on issue #4000: apache-camel-mock Routes are not getting cleaned up after test completes
Posted by GitBox <gi...@apache.org>.
tmdonalds commented on issue #4000:
URL: https://github.com/apache/camel-quarkus/issues/4000#issuecomment-1217833353
Thanks @jamesnetherton I will look forward to the 2.12.0 release. Thanks.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-quarkus] jamesnetherton commented on issue #4000: apache-camel-mock Routes are not getting cleaned up after test completes
Posted by GitBox <gi...@apache.org>.
jamesnetherton commented on issue #4000:
URL: https://github.com/apache/camel-quarkus/issues/4000#issuecomment-1217520768
It's a bit tricky to accomplish at the moment. There's some new functionality that'll be part of the upcoming 2.12.0 release which will mimic `CamelTestSupport`. It'll take take care of this scenario for you.
For now, you can either add the routes on a per test basis and remove them when testing is complete. E.g something like:
```java
@Test
public void testSomething() {
camelContext.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start").id("my-route").to("log:end");
}
});
try {
// Your test logic here
} finally {
// Could also be done in @AfterEach
camelContext.removeRoute("my-route");
}
}
```
The alternative is to use Quarkus [test profiles](https://quarkus.io/guides/getting-started-testing#testing_different_profiles). The application will get stopped / started for each profile, so you'll have a 'reset' `CamelContext`. But it comes at the cost of the time required to restart the application under test.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org