From 56c7572dde766fc717a6abd673841febc3cf4986 Mon Sep 17 00:00:00 2001 From: Alessandro Costa Date: Fri, 9 Oct 2020 18:12:03 +0200 Subject: [PATCH] KOGITO-3208: fixes to integration-tests-trusty-service --- .../pom.xml | 5 ++ ...AbstractTrustyExplainabilityEnd2EndIT.java | 89 +++++++++++-------- ...plainabilityServiceMessagingContainer.java | 2 +- .../testcontainers/InfinispanContainer.java | 2 +- .../KogitoServiceContainer.java | 2 +- .../TrustyServiceContainer.java | 2 +- .../pom.xml | 3 +- .../src/main/resources/application.properties | 8 +- 8 files changed, 70 insertions(+), 43 deletions(-) diff --git a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/pom.xml b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/pom.xml index 34a28dd1ce..a6843457ac 100644 --- a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/pom.xml +++ b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/pom.xml @@ -45,6 +45,11 @@ rest-assured compile + + org.awaitility + awaitility + compile + diff --git a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/it/trusty/AbstractTrustyExplainabilityEnd2EndIT.java b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/it/trusty/AbstractTrustyExplainabilityEnd2EndIT.java index d8289ba88f..7e214522be 100644 --- a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/it/trusty/AbstractTrustyExplainabilityEnd2EndIT.java +++ b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/it/trusty/AbstractTrustyExplainabilityEnd2EndIT.java @@ -28,12 +28,13 @@ import org.kie.kogito.trusty.service.responses.SalienciesResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.Testcontainers; import org.testcontainers.containers.KafkaContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.output.Slf4jLogConsumer; import static io.restassured.RestAssured.given; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; @@ -43,6 +44,20 @@ public abstract class AbstractTrustyExplainabilityEnd2EndIT { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTrustyExplainabilityEnd2EndIT.class); + private static final String EXPL_SERVICE_ALIAS = "expl-service"; + private static final int EXPL_SERVICE_SAMPLES = 10; + + private static final String INFINISPAN_ALIAS = "infinispan"; + private static final String INFINISPAN_SERVER_LIST = INFINISPAN_ALIAS + ":11222"; + + private static final String KAFKA_ALIAS = "kafka"; + private static final String KAFKA_BOOTSTRAP_SERVERS = KAFKA_ALIAS + ":9092"; + + private static final String KOGITO_SERVICE_ALIAS = "kogito-service"; + private static final String KOGITO_SERVICE_URL = "http://" + KOGITO_SERVICE_ALIAS + ":8080"; + + private static final String TRUSTY_SERVICE_ALIAS = "trusty-service"; + private final BiFunction kogitoServiceContainerProducer; protected AbstractTrustyExplainabilityEnd2EndIT(BiFunction kogitoServiceContainerProducer) { @@ -56,26 +71,26 @@ public void doTest() throws Exception { final InfinispanContainer infinispan = new InfinispanContainer() .withNetwork(network) - .withNetworkAliases("infinispan"); + .withNetworkAliases(INFINISPAN_ALIAS); final KafkaContainer kafka = new KafkaContainer() .withNetwork(network) - .withNetworkAliases("kafka"); + .withNetworkAliases(KAFKA_ALIAS); - final ExplainabilityServiceMessagingContainer explService = new ExplainabilityServiceMessagingContainer("kafka:9092", 10) + final ExplainabilityServiceMessagingContainer explService = new ExplainabilityServiceMessagingContainer(KAFKA_BOOTSTRAP_SERVERS, EXPL_SERVICE_SAMPLES) .withLogConsumer(new Slf4jLogConsumer(LOGGER)) .withNetwork(network) - .withNetworkAliases("expl-service"); + .withNetworkAliases(EXPL_SERVICE_ALIAS); - final TrustyServiceContainer trustyService = new TrustyServiceContainer("infinispan:11222", "kafka:9092", true) + final TrustyServiceContainer trustyService = new TrustyServiceContainer(INFINISPAN_SERVER_LIST, KAFKA_BOOTSTRAP_SERVERS, true) .withLogConsumer(new Slf4jLogConsumer(LOGGER)) .withNetwork(network) - .withNetworkAliases("trusty-service"); + .withNetworkAliases(TRUSTY_SERVICE_ALIAS); - final KogitoServiceContainer kogitoService = kogitoServiceContainerProducer.apply("kafka:9092", "http://kogito-service:8080") + final KogitoServiceContainer kogitoService = kogitoServiceContainerProducer.apply(KAFKA_BOOTSTRAP_SERVERS, KOGITO_SERVICE_URL) .withLogConsumer(new Slf4jLogConsumer(LOGGER)) .withNetwork(network) - .withNetworkAliases("kogito-service") + .withNetworkAliases(KOGITO_SERVICE_ALIAS) ) { infinispan.start(); assertTrue(infinispan.isRunning()); @@ -83,8 +98,6 @@ public void doTest() throws Exception { kafka.start(); assertTrue(kafka.isRunning()); - Testcontainers.exposeHostPorts(18080); - explService.start(); assertTrue(explService.isRunning()); @@ -103,32 +116,34 @@ public void doTest() throws Exception { .when().post("/Traffic Violation") .then().statusCode(200); - // wait a reasonable amount of time for the loop to complete - Thread.sleep(5000); - - ExecutionsResponse executionsResponse = given() - .port(trustyService.getFirstMappedPort()) - .when().get("/executions?limit=1") - .then().statusCode(200) - .extract().as(ExecutionsResponse.class); - - assertSame(1, executionsResponse.getHeaders().size()); - - String executionId = executionsResponse.getHeaders().stream() - .findFirst() - .map(ExecutionHeaderResponse::getExecutionId) - .orElseThrow(IllegalStateException::new); - - assertNotNull(executionId); - - SalienciesResponse salienciesResponse = given() - .port(trustyService.getFirstMappedPort()) - .when().get("/executions/decisions/" + executionId + "/explanations/saliencies") - .then().statusCode(200) - .extract().as(SalienciesResponse.class); - - assertEquals("SUCCEEDED", salienciesResponse.getStatus()); + await() + .atLeast(5, SECONDS) + .atMost(30, SECONDS) + .with().pollInterval(5, SECONDS) + .untilAsserted(() -> { + ExecutionsResponse executionsResponse = given() + .port(trustyService.getFirstMappedPort()) + .when().get("/executions?limit=1") + .then().statusCode(200) + .extract().as(ExecutionsResponse.class); + + assertSame(1, executionsResponse.getHeaders().size()); + + String executionId = executionsResponse.getHeaders().stream() + .findFirst() + .map(ExecutionHeaderResponse::getExecutionId) + .orElseThrow(IllegalStateException::new); + + assertNotNull(executionId); + + SalienciesResponse salienciesResponse = given() + .port(trustyService.getFirstMappedPort()) + .when().get("/executions/decisions/" + executionId + "/explanations/saliencies") + .then().statusCode(200) + .extract().as(SalienciesResponse.class); + + assertEquals("SUCCEEDED", salienciesResponse.getStatus()); + }); } } - } diff --git a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/ExplainabilityServiceMessagingContainer.java b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/ExplainabilityServiceMessagingContainer.java index 5619aa9734..47b5822094 100644 --- a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/ExplainabilityServiceMessagingContainer.java +++ b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/ExplainabilityServiceMessagingContainer.java @@ -24,7 +24,7 @@ public class ExplainabilityServiceMessagingContainer extends GenericContainer { public ExplainabilityServiceMessagingContainer(String kafkaBootstrapServers, int numberOfSamples) { - super(getImageName("explainability-service-messaging")); // "org.kie.kogito/explainability-service-messaging:1.0.0-SNAPSHOT" + super(getImageName("explainability-service-messaging")); addEnv("KAFKA_BOOTSTRAP_SERVERS", kafkaBootstrapServers); addEnv("TRUSTY_EXPLAINABILITY_NUMBEROFSAMPLES", String.valueOf(numberOfSamples)); addExposedPort(8080); diff --git a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/InfinispanContainer.java b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/InfinispanContainer.java index 7b8fc509b6..4a3b6c5242 100644 --- a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/InfinispanContainer.java +++ b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/InfinispanContainer.java @@ -24,7 +24,7 @@ public class InfinispanContainer extends GenericContainer { public InfinispanContainer() { - super(getImageName("infinispan")); // "quay.io/infinispan/server:10.1.5.Final" + super(getImageName("infinispan")); addEnv("USER", "admin"); addEnv("PASS", "admin"); addExposedPort(11222); diff --git a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/KogitoServiceContainer.java b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/KogitoServiceContainer.java index f22697170b..bb37016b09 100644 --- a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/KogitoServiceContainer.java +++ b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/KogitoServiceContainer.java @@ -23,7 +23,7 @@ public class KogitoServiceContainer extends GenericContainer { public KogitoServiceContainer(String kogitoServiceUrl) { - super(getImageName("kogito-service")); // "org.kie.kogito/integration-tests-trusty-service-quarkus:1.0.0-SNAPSHOT" + super(getImageName("kogito-service")); addEnv("KOGITO_SERVICE_URL", kogitoServiceUrl); addExposedPort(8080); } diff --git a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/TrustyServiceContainer.java b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/TrustyServiceContainer.java index fb9ff66207..925926c8ae 100644 --- a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/TrustyServiceContainer.java +++ b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/testcontainers/TrustyServiceContainer.java @@ -24,7 +24,7 @@ public class TrustyServiceContainer extends GenericContainer { public TrustyServiceContainer(String infinispanServerList, String kafkaBootstrapServer, boolean explainabilityEnabled) { - super(getImageName("trusty-service")); // "org.kie.kogito/trusty-service:1.0.0-SNAPSHOT" + super(getImageName("trusty-service")); addEnv("INFINISPAN_SERVER_LIST", infinispanServerList); addEnv("KAFKA_BOOTSTRAP_SERVERS", kafkaBootstrapServer); addEnv("TRUSTY_EXPLAINABILITY_ENABLED", String.valueOf(explainabilityEnabled)); diff --git a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-springboot/pom.xml b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-springboot/pom.xml index d3910837e3..a956f077c4 100644 --- a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-springboot/pom.xml +++ b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-springboot/pom.xml @@ -13,6 +13,7 @@ org.kie.kogito/integration-tests-trusty-service-springboot:${project.version} **/KogitoApplication.java + 2.5.2 @@ -83,7 +84,7 @@ com.google.cloud.tools jib-maven-plugin - 2.5.2 + ${version.jib-maven-plugin} ${container.image.kogito-service} diff --git a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-springboot/src/main/resources/application.properties b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-springboot/src/main/resources/application.properties index 392408d9ed..6f51ccae27 100644 --- a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-springboot/src/main/resources/application.properties +++ b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-springboot/src/main/resources/application.properties @@ -15,4 +15,10 @@ # server.address=0.0.0.0 -resteasy.jaxrs.scan-packages=org.kie.kogito.**,http* + +#static content generated by swagger-maven-plugin +spring.mvc.servlet.path=/docs + +resteasy.jaxrs.scan-packages=org.kie.**,org.kie.kogito,http* + +kogito.service.url=http://localhost:8080