Skip to content

Commit

Permalink
Add tests for supervised routes with MicroProfile health
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed May 20, 2024
1 parent 7aa1f6a commit f9eb2bd
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 0 deletions.
5 changes: 5 additions & 0 deletions integration-tests/microprofile-health/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.camel.quarkus.component.microprofile.it.health;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spi.SupervisingRouteController;

public class MicroProfileHealthRouteBuilder extends RouteBuilder {
@Override
Expand All @@ -26,5 +27,14 @@ public void configure() {

from("direct:disabled").routeId("disabledHealthRoute")
.log("This route will not show up in health checks as it is disabled in application.properties");

if (getContext().getRouteController() instanceof SupervisingRouteController) {
from("direct:supervising").routeId("supervisingRoute")
.to("log:end");

// Force a failure for SupervisingRouteController to try and recover (duplicate consumer on the same endpoint)
from("direct:supervising?timeout=100").routeId("brokenRoute")
.to("log:end");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.microprofile.it.health;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
class MicroProfileHealthSupervisedRouteIT extends MicroProfileHealthSupervisedRouteTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.microprofile.it.health;

import java.util.concurrent.TimeUnit;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test;

import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;

@QuarkusTest
@TestProfile(SupervisedRouteTestProfile.class)
class MicroProfileHealthSupervisedRouteTest {
@Test
void supervisedRouteTest() throws InterruptedException {
// Verify the initial health state
await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
RestAssured.when().get("/q/health").then()
.contentType(ContentType.JSON)
.header("Content-Type", containsString("charset=UTF-8"))
.body("status", is("DOWN"),
"checks.status.findAll().unique()", contains("UP", "DOWN"),
"checks.find { it.name == 'camel-routes' }.status", is("DOWN"),
"checks.find { it.name == 'camel-consumers' }.status", is("DOWN"));
});

// camel.routecontroller.unhealthy-on-exhausted is false so the heath status should be UP
await().pollDelay(1, TimeUnit.SECONDS).atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
RestAssured.when().get("/q/health").then()
.contentType(ContentType.JSON)
.header("Content-Type", containsString("charset=UTF-8"))
.body("status", is("UP"),
"checks.status.findAll().unique()", contains("UP"),
"checks.find { it.name == 'camel-routes' }.status", is("UP"),
"checks.find { it.name == 'camel-consumers' }.status", is("UP"));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.microprofile.it.health;

import java.util.Map;

import io.quarkus.test.junit.QuarkusTestProfile;

public class SupervisedRouteTestProfile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
"camel.routecontroller.enabled", "true",
"camel.routecontroller.initial-delay", "0",
"camel.routecontroller.backoff-delay", "250",
"camel.routecontroller.backoff-max-attempts", "4",
"camel.routecontroller.unhealthy-on-exhausted", "false");
}
}

0 comments on commit f9eb2bd

Please sign in to comment.