Skip to content

Commit

Permalink
KOGITO-3208: fixes to integration-tests-trusty-service
Browse files Browse the repository at this point in the history
  • Loading branch information
kostola committed Oct 9, 2020
1 parent 2f94569 commit 56c7572
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<artifactId>rest-assured</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String, KogitoServiceContainer> kogitoServiceContainerProducer;

protected AbstractTrustyExplainabilityEnd2EndIT(BiFunction<String, String, KogitoServiceContainer> kogitoServiceContainerProducer) {
Expand All @@ -56,35 +71,33 @@ 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());

kafka.start();
assertTrue(kafka.isRunning());

Testcontainers.exposeHostPorts(18080);

explService.start();
assertTrue(explService.isRunning());

Expand All @@ -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());
});
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class ExplainabilityServiceMessagingContainer extends GenericContainer<ExplainabilityServiceMessagingContainer> {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class InfinispanContainer extends GenericContainer<InfinispanContainer> {

public InfinispanContainer() {
super(getImageName("infinispan")); // "quay.io/infinispan/server:10.1.5.Final"
super(getImageName("infinispan"));
addEnv("USER", "admin");
addEnv("PASS", "admin");
addExposedPort(11222);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class KogitoServiceContainer extends GenericContainer<KogitoServiceContainer> {

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class TrustyServiceContainer extends GenericContainer<TrustyServiceContainer> {

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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<properties>
<container.image.kogito-service>org.kie.kogito/integration-tests-trusty-service-springboot:${project.version}</container.image.kogito-service>
<sonar.exclusions>**/KogitoApplication.java</sonar.exclusions>
<version.jib-maven-plugin>2.5.2</version.jib-maven-plugin>
</properties>

<dependencies>
Expand Down Expand Up @@ -83,7 +84,7 @@
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>2.5.2</version>
<version>${version.jib-maven-plugin}</version>
<configuration>
<to>
<image>${container.image.kogito-service}</image>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 56c7572

Please sign in to comment.