Skip to content

Commit

Permalink
Add integration test for Mongo Service Binding
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Aug 4, 2021
1 parent 3a09093 commit f5aa66b
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 0 deletions.
69 changes: 69 additions & 0 deletions integration-tests/mongodb-rest-data-panache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<!-- Service Binding - This isn't necessary to any Kafka functionality, but we want to test that Quarkus provides the proper config from a mock service binding -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-service-binding</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand Down Expand Up @@ -69,6 +74,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-service-binding-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand All @@ -84,6 +102,57 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<quarkus.kubernetes-service-binding.root>
${project.basedir}/src/test/resources/k8s-sb
</quarkus.kubernetes-service-binding.root>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>
${project.build.directory}/${project.build.finalName}-runner
</native.image.path>
<systemPropertyVariables>
<quarkus.kubernetes-service-binding.root>
${project.basedir}/src/test/resources/k8s-sb
</quarkus.kubernetes-service-binding.root>
</systemPropertyVariables>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;

@QuarkusTest
@DisabledOnOs(OS.WINDOWS)
@QuarkusTestResource(MongoTestResource.class)
class MongoDbRestDataPanacheTest {

private Author dostoevsky;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package io.quarkus.it.mongodb.rest.data.panache;

import java.util.Collections;
import java.util.Map;

import org.jboss.logging.Logger;

import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodStarter;
import de.flapdoodle.embed.mongo.config.IMongodConfig;
import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
import de.flapdoodle.embed.mongo.config.Net;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.process.runtime.Network;
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;

public class MongoTestResource implements QuarkusTestResourceLifecycleManager {

private static final Logger LOGGER = Logger.getLogger(MongoTestResource.class);
private static MongodExecutable MONGO;

@Override
public Map<String, String> start() {
try {
//JDK bug workaround
//https://github.com/quarkusio/quarkus/issues/14424
//force class init to prevent possible deadlock when done by mongo threads
Class.forName("sun.net.ext.ExtendedSocketOptions", true, ClassLoader.getSystemClassLoader());
} catch (ClassNotFoundException e) {
}
try {
Version.Main version = Version.Main.V4_0;
int port = 37017;
LOGGER.infof("Starting Mongo %s on port %s", version, port);
IMongodConfig config = new MongodConfigBuilder()
.version(version)
.net(new Net(port, Network.localhostIsIPv6()))
.build();
MONGO = getMongodExecutable(config);
try {
MONGO.start();
} catch (Exception e) {
//every so often mongo fails to start on CI runs
//see if this helps
Thread.sleep(1000);
MONGO.start();
}

// don't return any properties, since we want Service Binding to configure Quarkus
return Collections.emptyMap();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private MongodExecutable getMongodExecutable(IMongodConfig config) {
try {
return doGetExecutable(config);
} catch (Exception e) {
// sometimes the download process can timeout so just sleep and try again
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {

}
return doGetExecutable(config);
}
}

private MongodExecutable doGetExecutable(IMongodConfig config) {
return MongodStarter.getDefaultInstance().prepare(config);
}

private void initData() {

}

@Override
public void stop() {
if (MONGO != null) {
MONGO.stop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
37017
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mongodb

0 comments on commit f5aa66b

Please sign in to comment.