Skip to content

Commit

Permalink
Replaces flapdoodle with a docker based approach
Browse files Browse the repository at this point in the history
* MongoDbResource now starts and stops a mongo docker container instead of
  using flapdoodle

Signed-off-by: Yannic Klem <yannic.klem@bosch.io>
  • Loading branch information
Yannic92 committed Nov 25, 2020
1 parent 9ddab07 commit 94095ae
Show file tree
Hide file tree
Showing 24 changed files with 371 additions and 346 deletions.
16 changes: 10 additions & 6 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<jmh.version>1.21</jmh.version>

<scalatest.version>3.1.2</scalatest.version>
<flapdoodle.version>3.0.0</flapdoodle.version>
<docker-java.version>3.2.6</docker-java.version>
<system-rules.version>1.19.0</system-rules.version>
</properties>

Expand Down Expand Up @@ -996,14 +996,18 @@
<version>${akka-persistence-inmemory.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>${flapdoodle.version}</version>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-core</artifactId>
<version>${docker-java.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-transport-zerodep</artifactId>
<version>${docker-java.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions services/concierge/actors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-services-utils-test</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions services/connectivity/messaging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,6 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-services-utils-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

import javax.annotation.Nullable;

import org.apache.commons.compress.utils.Sets;
import org.awaitility.Awaitility;
import org.eclipse.ditto.json.JsonPointer;
import org.eclipse.ditto.json.JsonValue;
Expand Down Expand Up @@ -142,7 +141,7 @@
*/
public final class ConnectionPersistenceActorTest extends WithMockServers {

private static final Set<String> SUBJECTS = Sets.newHashSet(TestConstants.Authorization.SUBJECT_ID,
private static final Set<String> SUBJECTS = Set.of(TestConstants.Authorization.SUBJECT_ID,
TestConstants.Authorization.UNAUTHORIZED_SUBJECT_ID);
private static final Set<StreamingType> TWIN_AND_LIVE_EVENTS =
EnumSet.of(StreamingType.EVENTS, StreamingType.LIVE_EVENTS);
Expand Down
5 changes: 0 additions & 5 deletions services/connectivity/starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_${scala.version}</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions services/policies/persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-stream_${scala.version}</artifactId>
</dependency>

<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions services/policies/starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@
<artifactId>akka-testkit_${scala.version}</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-services-utils-test</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions services/things/persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,6 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions services/things/starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@
<artifactId>akka-testkit_${scala.version}</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-services-utils-test</artifactId>
Expand Down
9 changes: 7 additions & 2 deletions services/thingsearch/persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-transport-zerodep</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;

import com.mongodb.reactivestreams.client.MongoCollection;
import com.typesafe.config.Config;
Expand Down Expand Up @@ -67,7 +68,9 @@ public abstract class AbstractThingSearchPersistenceITBase {

protected static QueryBuilderFactory qbf;

private static MongoDbResource mongoResource;
@ClassRule
public static final MongoDbResource MONGO_RESOURCE = new MongoDbResource();

private static DittoMongoClient mongoClient;

private MongoCollection<Document> thingsCollection;
Expand All @@ -82,9 +85,6 @@ public static void startMongoResource() {
final Config rawTestConfig = ConfigFactory.load("test");
final DefaultLimitsConfig limitsConfig = DefaultLimitsConfig.of(rawTestConfig.getConfig("ditto"));
qbf = new MongoQueryBuilderFactory(limitsConfig);

mongoResource = new MongoDbResource("localhost");
mongoResource.start();
mongoClient = provideClientWrapper();
}

Expand Down Expand Up @@ -112,7 +112,7 @@ private TestSearchUpdaterStream provideWritePersistence() {
private static DittoMongoClient provideClientWrapper() {
return MongoClientWrapper.getBuilder()
.connectionString(
"mongodb://" + mongoResource.getBindIp() + ":" + mongoResource.getPort() + "/testSearchDB")
"mongodb://" + MONGO_RESOURCE.getBindIp() + ":" + MONGO_RESOURCE.getPort() + "/testSearchDB")
.connectionPoolMaxSize(100)
.connectionPoolMaxWaitQueueSize(500000)
.connectionPoolMaxWaitTime(Duration.ofSeconds(30))
Expand Down Expand Up @@ -159,9 +159,6 @@ public static void stopMongoResource() {
if (mongoClient != null) {
mongoClient.close();
}
if (mongoResource != null) {
mongoResource.stop();
}
} catch (final IllegalStateException e) {
System.err.println("IllegalStateException during shutdown of MongoDB: " + e.getMessage());
}
Expand Down
9 changes: 7 additions & 2 deletions services/thingsearch/starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-transport-zerodep</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;

import com.mongodb.reactivestreams.client.MongoCollection;
Expand All @@ -72,7 +73,8 @@ public final class SearchActorIT {
AuthorizationSubject.newInstance("ditto:ditto"));

private static QueryParser queryParser;
private static MongoDbResource mongoResource;
@ClassRule
public static final MongoDbResource MONGO_RESOURCE = new MongoDbResource();
private static DittoMongoClient mongoClient;

private MongoThingsSearchPersistence readPersistence;
Expand All @@ -84,8 +86,6 @@ public final class SearchActorIT {
@BeforeClass
public static void startMongoResource() {
queryParser = SearchRootActor.getQueryParser(DefaultLimitsConfig.of(ConfigFactory.empty()));
mongoResource = new MongoDbResource("localhost");
mongoResource.start();
mongoClient = provideClientWrapper();
}

Expand Down Expand Up @@ -115,7 +115,7 @@ private static TestSearchUpdaterStream provideWritePersistence() {
private static DittoMongoClient provideClientWrapper() {
return MongoClientWrapper.getBuilder()
.connectionString(
"mongodb://" + mongoResource.getBindIp() + ":" + mongoResource.getPort() + "/testSearchDB")
"mongodb://" + MONGO_RESOURCE.getBindIp() + ":" + MONGO_RESOURCE.getPort() + "/testSearchDB")
.build();
}

Expand All @@ -136,9 +136,6 @@ public static void stopMongoResource() {
if (mongoClient != null) {
mongoClient.close();
}
if (mongoResource != null) {
mongoResource.stop();
}
} catch (final IllegalStateException e) {
System.err.println("IllegalStateException during shutdown of MongoDB: " + e.getMessage());
}
Expand Down
9 changes: 4 additions & 5 deletions services/thingsearch/updater-actors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.ditto</groupId>
<artifactId>ditto-services-utils-test</artifactId>
<type>test-jar</type>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-transport-zerodep</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
9 changes: 7 additions & 2 deletions services/utils/persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,13 @@

<!-- test dependencies -->
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-transport-zerodep</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;

import javax.annotation.Nullable;

import org.eclipse.ditto.services.utils.persistence.mongo.DittoMongoClient;
import org.eclipse.ditto.services.utils.persistence.mongo.MongoClientWrapper;
import org.eclipse.ditto.services.utils.persistence.mongo.assertions.MongoIndexAssertions;
import org.eclipse.ditto.services.utils.test.mongo.MongoDbResource;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;

import com.mongodb.MongoCommandException;
Expand All @@ -52,6 +49,9 @@
*/
public final class IndexInitializerIT {

@ClassRule
public static final MongoDbResource MONGO_RESOURCE = new MongoDbResource();

private static final int CONNECTION_POOL_MAX_SIZE = 5;
private static final int CONNECTION_POOL_MAX_WAIT_QUEUE_SIZE = 5;
private static final long CONNECTION_POOL_MAX_WAIT_TIME_SECS = 3L;
Expand Down Expand Up @@ -89,37 +89,22 @@ public final class IndexInitializerIT {
Arrays.asList(DefaultIndexKey.of(FOO_FIELD, IndexDirection.ASCENDING),
DefaultIndexKey.of(BAR_FIELD, IndexDirection.ASCENDING)), false);

@Nullable private static MongoDbResource mongoResource;

private ActorSystem system;
private Materializer materializer;
private DittoMongoClient mongoClient;
private IndexInitializer indexInitializerUnderTest;
private IndexOperations indexOperations;

@BeforeClass
public static void startMongoResource() {
mongoResource = new MongoDbResource("localhost");
mongoResource.start();
}

@AfterClass
public static void stopMongoResource() {
if (mongoResource != null) {
mongoResource.stop();
}
}

@Before
public void before() {
system = ActorSystem.create("AkkaTestSystem");
materializer = SystemMaterializer.get(system).materializer();

requireNonNull(mongoResource);
requireNonNull(MONGO_RESOURCE);
requireNonNull(materializer);

mongoClient = MongoClientWrapper.getBuilder()
.hostnameAndPort(mongoResource.getBindIp(), mongoResource.getPort())
.hostnameAndPort(MONGO_RESOURCE.getBindIp(), MONGO_RESOURCE.getPort())
.defaultDatabaseName(getClass().getSimpleName() + "-" + UUID.randomUUID().toString())
.connectionPoolMaxSize(CONNECTION_POOL_MAX_SIZE)
.connectionPoolMaxWaitQueueSize(CONNECTION_POOL_MAX_WAIT_QUEUE_SIZE)
Expand Down
Loading

0 comments on commit 94095ae

Please sign in to comment.