-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial MongoDB support (sync and async)
- Loading branch information
1 parent
2dd6e6f
commit 22e1dc3
Showing
16 changed files
with
1,087 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<!-- | ||
Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved. | ||
This file is part of SeedStack, An enterprise-oriented full development stack. | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.seedstack.seed</groupId> | ||
<artifactId>seed-persistence-support</artifactId> | ||
<version>2.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>seed-persistence-support-mongodb</artifactId> | ||
|
||
<properties> | ||
<compatibility-check.skip>true</compatibility-check.skip> | ||
<mongodb.version>3.0.3</mongodb.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.seedstack.seed</groupId> | ||
<artifactId>seed-core-support-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mongodb</groupId> | ||
<artifactId>mongo-java-driver</artifactId> | ||
<version>${mongodb.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mongodb</groupId> | ||
<artifactId>mongodb-driver-async</artifactId> | ||
<version>${mongodb.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.seedstack.seed</groupId> | ||
<artifactId>seed-unittest-support</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.seedstack.seed</groupId> | ||
<artifactId>seed-integrationtest-support-core</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.syncleus.maven.plugins</groupId> | ||
<artifactId>maven-mongodb-plugin</artifactId> | ||
<version>1.1.1</version> | ||
<configuration> | ||
<!-- configure your proxy here if needed | ||
<proxyHost></proxyHost> | ||
<proxyPort></proxyPort> | ||
<proxyUser></proxyUser> | ||
<proxyPassword></proxyPassword> | ||
--> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>start-mongodb</id> | ||
<goals> | ||
<goal>start</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>stop-mongodb</id> | ||
<goals> | ||
<goal>stop</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
80 changes: 80 additions & 0 deletions
80
...ence-support/mongodb/src/it/java/org/seedstack/seed/persistence/mongodb/MongoAsyncIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved. | ||
* | ||
* This file is part of SeedStack, An enterprise-oriented full development stack. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package org.seedstack.seed.persistence.mongodb; | ||
|
||
import com.mongodb.async.SingleResultCallback; | ||
import com.mongodb.async.client.MongoClient; | ||
import com.mongodb.async.client.MongoDatabase; | ||
import org.bson.Document; | ||
import org.junit.Test; | ||
import org.seedstack.seed.it.AbstractSeedIT; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class MongoAsyncIT extends AbstractSeedIT { | ||
@Inject | ||
@Named("client2") | ||
MongoClient client2; | ||
|
||
@Inject | ||
@Named("db2") | ||
MongoDatabase db2; | ||
|
||
@Inject | ||
@Named("client3") | ||
MongoClient client3; | ||
|
||
@Inject | ||
@Named("db3") | ||
MongoDatabase db3; | ||
|
||
@Test | ||
public void mongo_clients_are_injectable() { | ||
assertThat(client2).isNotNull(); | ||
assertThat(client3).isNotNull(); | ||
} | ||
|
||
@Test | ||
public void mongo_databases_are_injectable() { | ||
assertThat(db2).isNotNull(); | ||
assertThat(db3).isNotNull(); | ||
} | ||
|
||
@Test | ||
public void test_insert_into_collection() throws InterruptedException { | ||
Document doc = new Document("name", "MongoDB") | ||
.append("type", "database") | ||
.append("count", 1) | ||
.append("info", new Document("x", 203).append("y", 102)); | ||
|
||
final Object mon = new Object(); | ||
final AtomicBoolean inserted = new AtomicBoolean(false); | ||
db2.getCollection("test1").insertOne(doc, new SingleResultCallback<Void>() { | ||
@Override | ||
public void onResult(Void result, Throwable t) { | ||
assertThat(t).isNull(); | ||
synchronized (mon) { | ||
inserted.set(true); | ||
mon.notify(); | ||
} | ||
} | ||
}); | ||
|
||
synchronized (mon) { | ||
mon.wait(5000); | ||
assertThat(inserted.get()).isTrue(); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
persistence-support/mongodb/src/it/java/org/seedstack/seed/persistence/mongodb/MongoIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved. | ||
* | ||
* This file is part of SeedStack, An enterprise-oriented full development stack. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package org.seedstack.seed.persistence.mongodb; | ||
|
||
import com.mongodb.MongoClient; | ||
import com.mongodb.client.MongoDatabase; | ||
import org.bson.Document; | ||
import org.junit.Test; | ||
import org.seedstack.seed.it.AbstractSeedIT; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class MongoIT extends AbstractSeedIT { | ||
@Inject | ||
@Named("client1") | ||
MongoClient client1; | ||
|
||
@Inject | ||
@Named("db1") | ||
MongoDatabase db1; | ||
|
||
@Inject | ||
MongoClient implicitClient; | ||
|
||
@Inject | ||
MongoDatabase implicitDatabase; | ||
|
||
@Test | ||
public void mongo_clients_are_injectable() { | ||
assertThat(client1).isNotNull(); | ||
assertThat(implicitClient).isNotNull(); | ||
} | ||
|
||
@Test | ||
public void mongo_databases_are_injectable() { | ||
assertThat(db1).isNotNull(); | ||
assertThat(implicitDatabase).isNotNull(); | ||
} | ||
|
||
@Test | ||
public void test_insert_into_collection() { | ||
Document doc = new Document("name", "MongoDB") | ||
.append("type", "database") | ||
.append("count", 1) | ||
.append("info", new Document("x", 203).append("y", 102)); | ||
|
||
db1.getCollection("test1").insertOne(doc); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ongodb/src/it/resources/META-INF/configuration/org.seedstack.seed.persistence.mongo.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# | ||
# Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved. | ||
# | ||
# This file is part of SeedStack, An enterprise-oriented full development stack. | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
|
||
[org.seedstack.seed.persistence.mongo] | ||
clients = client1, client2, client3 | ||
|
||
[org.seedstack.seed.persistence.mongo.client.client1] | ||
hosts = localhost | ||
option.connectionsPerHost = 50 | ||
databases = db1 | ||
|
||
[org.seedstack.seed.persistence.mongo.client.client2] | ||
async = true | ||
hosts = localhost | ||
setting.connectionPool.maxSize = 50 | ||
databases = db2 | ||
|
||
[org.seedstack.seed.persistence.mongo.client.client3] | ||
async = true | ||
hosts = localhost | ||
databases = db2 | ||
alias.db2 = db3 |
22 changes: 22 additions & 0 deletions
22
persistence-support/mongodb/src/it/resources/logback-test.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved. | ||
This file is part of SeedStack, An enterprise-oriented full development stack. | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
--> | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="INFO"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
24 changes: 24 additions & 0 deletions
24
...ort/mongodb/src/main/java/org/seedstack/seed/persistence/mongodb/api/MongoErrorCodes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved. | ||
* | ||
* This file is part of SeedStack, An enterprise-oriented full development stack. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package org.seedstack.seed.persistence.mongodb.api; | ||
|
||
import org.seedstack.seed.core.api.ErrorCode; | ||
|
||
public enum MongoErrorCodes implements ErrorCode { | ||
MISSING_URI, | ||
UNABLE_TO_PARSE_SERVER_ADDRESS, | ||
UNSUPPORTED_AUTHENTICATION_MECHANISM, | ||
UNKNOWN_CLIENT_SPECIFIED, | ||
DUPLICATE_DATABASE_NAME, | ||
UNABLE_TO_INSTANTIATE_CLASS, | ||
UNKNOWN_CLIENT_OPTION, | ||
UNKNOWN_CLIENT_SETTING, | ||
MISSING_HOSTS_CONFIGURATION | ||
} |
Oops, something went wrong.