polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [19/35] polygene-java git commit: POLYGENE-172 - Also fix inconsistent naming in the extension. All classes has "MongoDB" instead of "Mongo" in the name.
Date Sun, 28 May 2017 16:10:39 GMT
POLYGENE-172 - Also fix inconsistent naming in the extension. All classes has "MongoDB" instead of "Mongo" in the name.

Signed-off-by: niclas <niclas@hedhman.org>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/09b92801
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/09b92801
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/09b92801

Branch: refs/heads/develop
Commit: 09b9280102065597909889d1cef823833917d600
Parents: f510c1e
Author: niclas <niclas@hedhman.org>
Authored: Thu May 25 12:38:12 2017 +0800
Committer: niclas <niclas@hedhman.org>
Committed: Thu May 25 12:38:12 2017 +0800

----------------------------------------------------------------------
 .../entitystore/mongodb/MongoAccessors.java     |  32 --
 .../entitystore/mongodb/MongoDBAccessors.java   |  32 ++
 .../MongoDBEntityStoreConfiguration.java        |  92 ++++++
 .../mongodb/MongoDBMapEntityStoreMixin.java     | 322 +++++++++++++++++++
 .../mongodb/MongoDBMapEntityStoreService.java   |  49 +++
 .../mongodb/MongoEntityStoreConfiguration.java  |  92 ------
 .../mongodb/MongoMapEntityStoreMixin.java       | 322 -------------------
 .../mongodb/MongoMapEntityStoreService.java     |  49 ---
 .../assembly/MongoDBEntityStoreAssembler.java   |   8 +-
 .../mongodb/EmbedMongoDBMapEntityStoreTest.java |  88 +++++
 .../mongodb/EmbedMongoMapEntityStoreTest.java   |  88 -----
 .../mongodb/MongoDBMapEntityStoreTest.java      |  88 +++++
 .../MongoDBMapEntityStoreWithCacheTest.java     |  84 +++++
 .../mongodb/MongoMapEntityStoreTest.java        |  88 -----
 .../MongoMapEntityStoreWithCacheTest.java       |  84 -----
 15 files changed, 759 insertions(+), 759 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoAccessors.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoAccessors.java b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoAccessors.java
deleted file mode 100644
index 2d3ddd8..0000000
--- a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoAccessors.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- *
- */
-package org.apache.polygene.entitystore.mongodb;
-
-import com.mongodb.MongoClient;
-import com.mongodb.client.MongoDatabase;
-
-public interface MongoAccessors
-{
-    MongoClient mongoInstanceUsed();
-
-    MongoDatabase dbInstanceUsed();
-
-    String collectionUsed();
-}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBAccessors.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBAccessors.java b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBAccessors.java
new file mode 100644
index 0000000..d6b5723
--- /dev/null
+++ b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBAccessors.java
@@ -0,0 +1,32 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.polygene.entitystore.mongodb;
+
+import com.mongodb.MongoClient;
+import com.mongodb.client.MongoDatabase;
+
+public interface MongoDBAccessors
+{
+    MongoClient mongoInstanceUsed();
+
+    MongoDatabase dbInstanceUsed();
+
+    String collectionUsed();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBEntityStoreConfiguration.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBEntityStoreConfiguration.java b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBEntityStoreConfiguration.java
new file mode 100644
index 0000000..2e8146e
--- /dev/null
+++ b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBEntityStoreConfiguration.java
@@ -0,0 +1,92 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.polygene.entitystore.mongodb;
+
+import java.util.List;
+import org.apache.polygene.api.common.Optional;
+import org.apache.polygene.api.common.UseDefaults;
+import org.apache.polygene.api.property.Property;
+
+// START SNIPPET: config
+public interface MongoDBEntityStoreConfiguration
+{
+
+    @Optional
+    Property<String> hostname();
+
+    @Optional
+    Property<Integer> port();
+
+    @UseDefaults
+    Property<List<String>> nodes();
+
+    @UseDefaults
+    Property<String> username();
+
+    @UseDefaults
+    Property<String> password();
+
+    @Optional
+    Property<String> database();
+
+    @Optional
+    Property<String> collection();
+
+    @UseDefaults
+    Property<WriteConcern> writeConcern();
+
+    enum WriteConcern
+    {
+        /**
+         *  Write operations that use this write concern will wait for acknowledgement,
+         *  using the default write concern configured on the server.
+         *  This is the default value.
+         */
+        ACKNOWLEDGED,
+        /**
+         * Write operations that use this write concern will wait for acknowledgement from a single member.
+         */
+        W1,
+        /**
+         * Write operations that use this write concern will wait for acknowledgement from two members.
+         */
+        W2,
+        /**
+         * Write operations that use this write concern will wait for acknowledgement from three members.
+         */
+        W3,
+        /**
+         * Write operations that use this write concern will return as soon as the message is written to the socket.
+         * Exceptions are raised for network issues, but not server errors.
+         */
+        UNACKNOWLEDGED,
+        /**
+         * Write operations wait for the server to group commit to the journal file on disk.
+         */
+        JOURNALED,
+        /**
+         * Exceptions are raised for network issues, and server errors;
+         * waits on a majority of servers for the write operation.
+         */
+        MAJORITY
+
+    }
+}
+// END SNIPPET: config
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreMixin.java b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreMixin.java
new file mode 100644
index 0000000..3294910
--- /dev/null
+++ b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreMixin.java
@@ -0,0 +1,322 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.polygene.entitystore.mongodb;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.MongoClient;
+import com.mongodb.MongoClientOptions;
+import com.mongodb.MongoCredential;
+import com.mongodb.ServerAddress;
+import com.mongodb.WriteConcern;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoCursor;
+import com.mongodb.client.MongoDatabase;
+import com.mongodb.util.JSON;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+import org.apache.polygene.api.configuration.Configuration;
+import org.apache.polygene.api.entity.EntityDescriptor;
+import org.apache.polygene.api.entity.EntityReference;
+import org.apache.polygene.api.injection.scope.This;
+import org.apache.polygene.api.service.ServiceActivation;
+import org.apache.polygene.spi.entitystore.EntityNotFoundException;
+import org.apache.polygene.spi.entitystore.EntityStoreException;
+import org.apache.polygene.spi.entitystore.helpers.MapEntityStore;
+import org.bson.Document;
+import org.bson.conversions.Bson;
+
+import static com.mongodb.client.model.Filters.eq;
+import static java.util.stream.Collectors.toList;
+
+/**
+ * MongoDB implementation of MapEntityStore.
+ */
+public class MongoDBMapEntityStoreMixin
+    implements ServiceActivation, MapEntityStore, MongoDBAccessors
+{
+    private static final String DEFAULT_DATABASE_NAME = "polygene:entitystore";
+    private static final String DEFAULT_COLLECTION_NAME = "polygene:entitystore:entities";
+    public static final String IDENTITY_COLUMN = "_id";
+    public static final String STATE_COLUMN = "state";
+    @This
+    private Configuration<MongoDBEntityStoreConfiguration> configuration;
+    private List<ServerAddress> serverAddresses;
+    private String databaseName;
+    private String collectionName;
+    private WriteConcern writeConcern;
+    private String username;
+    private char[] password;
+    private MongoClient mongo;
+    private MongoDatabase db;
+
+    @Override
+    public void activateService()
+        throws Exception
+    {
+        loadConfiguration();
+
+        // Create Mongo driver and open the database
+        MongoClientOptions options = MongoClientOptions.builder().writeConcern( writeConcern ).build();
+        if( username.isEmpty() )
+        {
+            mongo = new MongoClient( serverAddresses, options );
+        }
+        else
+        {
+            MongoCredential credential = MongoCredential.createMongoCRCredential( username, databaseName, password );
+            mongo = new MongoClient( serverAddresses, Collections.singletonList( credential ), options );
+        }
+        db = mongo.getDatabase( databaseName );
+
+        // Create index if needed
+        MongoCollection<Document> entities = db.getCollection( collectionName );
+        if( !entities.listIndexes().iterator().hasNext() )
+        {
+            entities.createIndex( new BasicDBObject( IDENTITY_COLUMN, 1 ) );
+        }
+    }
+
+    private void loadConfiguration()
+        throws UnknownHostException
+    {
+        configuration.refresh();
+        MongoDBEntityStoreConfiguration config = configuration.get();
+
+        // Combine hostname, port and nodes configuration properties
+        // If no configuration, use 127.0.0.1:27017
+        serverAddresses = new ArrayList<>();
+        int port = config.port().get() == null ? 27017 : config.port().get();
+        List<String> nodes = config.nodes().get();
+        if( nodes.isEmpty() )
+        {
+            String hostname = config.hostname().get() == null ? "127.0.0.1" : config.hostname().get();
+            serverAddresses.add( new ServerAddress( hostname, port ) );
+        }
+        else
+        {
+            if( config.hostname().get() != null && !config.hostname().get().isEmpty() )
+            {
+                serverAddresses.add( new ServerAddress( config.hostname().get(), port ) );
+            }
+            serverAddresses.addAll( nodes.stream()
+                                         .map( this::parseNode )
+                                         .collect( toList() )
+                                  );
+        }
+
+        // If database name not configured, set it to polygene:entitystore
+        databaseName = config.database().get();
+        if( databaseName == null )
+        {
+            databaseName = DEFAULT_DATABASE_NAME;
+        }
+
+        // If collection name not configured, set it to polygene:entitystore:entities
+        collectionName = config.collection().get();
+        if( collectionName == null )
+        {
+            collectionName = DEFAULT_COLLECTION_NAME;
+        }
+
+        // If write concern not configured, set it to normal
+        switch( config.writeConcern().get() )
+        {
+        case W1:
+            writeConcern = WriteConcern.W1;
+            break;
+        case W2:
+            writeConcern = WriteConcern.W2;
+            break;
+        case W3:
+            writeConcern = WriteConcern.W3;
+            break;
+        case UNACKNOWLEDGED:
+            writeConcern = WriteConcern.UNACKNOWLEDGED;
+            break;
+        case JOURNALED:
+            writeConcern = WriteConcern.JOURNALED;
+            break;
+        case MAJORITY:
+            writeConcern = WriteConcern.MAJORITY;
+            break;
+        case ACKNOWLEDGED:
+        default:
+            writeConcern = WriteConcern.ACKNOWLEDGED;
+        }
+
+        // Username and password are defaulted to empty strings
+        username = config.username().get();
+        password = config.password().get().toCharArray();
+    }
+
+    private <R> ServerAddress parseNode( String nodeString )
+    {
+        String[] parts = nodeString.split( ":" );
+        String host = parts[ 0 ];
+        if( parts.length == 2 )
+        {
+            int port = Integer.parseInt( parts[ 1 ] );
+            return new ServerAddress( host, port );
+        }
+        return new ServerAddress( host );
+    }
+
+    @Override
+    public void passivateService()
+        throws Exception
+    {
+        mongo.close();
+        mongo = null;
+        databaseName = null;
+        collectionName = null;
+        writeConcern = null;
+        username = null;
+        Arrays.fill( password, ' ' );
+        password = null;
+        db = null;
+    }
+
+    @Override
+    public MongoClient mongoInstanceUsed()
+    {
+        return mongo;
+    }
+
+    @Override
+    public MongoDatabase dbInstanceUsed()
+    {
+        return db;
+    }
+
+    @Override
+    public String collectionUsed()
+    {
+        return collectionName;
+    }
+
+    @Override
+    public Reader get( EntityReference entityReference )
+        throws EntityStoreException
+    {
+        MongoCursor<Document> cursor = db.getCollection( collectionName )
+                                         .find( byIdentity( entityReference ) )
+                                         .limit( 1 ).iterator();
+        if( !cursor.hasNext() )
+        {
+            throw new EntityNotFoundException( entityReference );
+        }
+        Document bsonState = (Document) cursor.next().get( STATE_COLUMN );
+        String jsonState = JSON.serialize( bsonState );
+        return new StringReader( jsonState );
+    }
+
+    @Override
+    public void applyChanges( MapChanges changes )
+        throws Exception
+    {
+        final MongoCollection<Document> entities = db.getCollection( collectionName );
+
+        changes.visitMap( new MapChanger()
+        {
+            @Override
+            public Writer newEntity( EntityReference ref, EntityDescriptor entityDescriptor )
+                throws IOException
+            {
+                return new StringWriter( 1000 )
+                {
+                    @Override
+                    public void close()
+                        throws IOException
+                    {
+                        super.close();
+                        Document bsonState = Document.parse( toString() );
+                        Document entity = new Document();
+                        entity.put( IDENTITY_COLUMN, ref.identity().toString() );
+                        entity.put( STATE_COLUMN, bsonState );
+                        entities.insertOne( entity );
+                    }
+                };
+            }
+
+            @Override
+            public Writer updateEntity( MapChange mapChange )
+                throws IOException
+            {
+                return new StringWriter( 1000 )
+                {
+                    @Override
+                    public void close()
+                        throws IOException
+                    {
+                        super.close();
+                        Document bsonState = Document.parse( toString() );
+                        Document entity = new Document();
+                        entity.put( IDENTITY_COLUMN, mapChange.reference().identity().toString() );
+                        entity.put( STATE_COLUMN, bsonState );
+                        entities.replaceOne( byIdentity( mapChange.reference() ), entity );
+                    }
+                };
+            }
+
+            @Override
+            public void removeEntity( EntityReference ref, EntityDescriptor entityDescriptor )
+                throws EntityNotFoundException
+            {
+                Bson byIdFilter = byIdentity( ref );
+                MongoCursor<Document> cursor = db.getCollection( collectionName )
+                                                 .find( byIdFilter )
+                                                 .limit( 1 ).iterator();
+                if( !cursor.hasNext() )
+                {
+                    throw new EntityNotFoundException( ref );
+                }
+                entities.deleteOne( byIdFilter );
+            }
+        } );
+    }
+
+    @Override
+    public Stream<Reader> entityStates()
+    {
+        return StreamSupport
+            .stream( db.getCollection( collectionName ).find().spliterator(), false )
+            .map( eachEntity ->
+                  {
+                      Document bsonState = (Document) eachEntity.get( STATE_COLUMN );
+                      String jsonState = JSON.serialize( bsonState );
+                      return new StringReader( jsonState );
+                  } );
+    }
+
+    private Bson byIdentity( EntityReference entityReference )
+    {
+        return eq( IDENTITY_COLUMN, entityReference.identity().toString() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreService.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreService.java b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreService.java
new file mode 100644
index 0000000..4f34214
--- /dev/null
+++ b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreService.java
@@ -0,0 +1,49 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.polygene.entitystore.mongodb;
+
+import org.apache.polygene.api.concern.Concerns;
+import org.apache.polygene.api.configuration.Configuration;
+import org.apache.polygene.api.mixin.Mixins;
+import org.apache.polygene.api.service.ServiceActivation;
+import org.apache.polygene.library.locking.LockingAbstractComposite;
+import org.apache.polygene.spi.entitystore.ConcurrentModificationCheckConcern;
+import org.apache.polygene.spi.entitystore.EntityStateVersions;
+import org.apache.polygene.spi.entitystore.EntityStore;
+import org.apache.polygene.spi.entitystore.StateChangeNotificationConcern;
+import org.apache.polygene.spi.entitystore.helpers.JSONMapEntityStoreActivation;
+import org.apache.polygene.spi.entitystore.helpers.JSONMapEntityStoreMixin;
+
+/**
+ * MongoDB EntityStore service.
+ * <p>Based on @{@link JSONMapEntityStoreMixin}.</p>
+ */
+@Concerns( { StateChangeNotificationConcern.class, ConcurrentModificationCheckConcern.class } )
+@Mixins( { JSONMapEntityStoreMixin.class, MongoDBMapEntityStoreMixin.class } )
+public interface MongoDBMapEntityStoreService
+    extends EntityStore,
+            EntityStateVersions,
+            ServiceActivation,
+            JSONMapEntityStoreActivation,
+            LockingAbstractComposite,
+            Configuration,
+            MongoDBAccessors
+{
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoEntityStoreConfiguration.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoEntityStoreConfiguration.java b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoEntityStoreConfiguration.java
deleted file mode 100644
index 75c95ac..0000000
--- a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoEntityStoreConfiguration.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- *
- */
-package org.apache.polygene.entitystore.mongodb;
-
-import java.util.List;
-import org.apache.polygene.api.common.Optional;
-import org.apache.polygene.api.common.UseDefaults;
-import org.apache.polygene.api.property.Property;
-
-// START SNIPPET: config
-public interface MongoEntityStoreConfiguration
-{
-
-    @Optional
-    Property<String> hostname();
-
-    @Optional
-    Property<Integer> port();
-
-    @UseDefaults
-    Property<List<String>> nodes();
-
-    @UseDefaults
-    Property<String> username();
-
-    @UseDefaults
-    Property<String> password();
-
-    @Optional
-    Property<String> database();
-
-    @Optional
-    Property<String> collection();
-
-    @UseDefaults
-    Property<WriteConcern> writeConcern();
-
-    enum WriteConcern
-    {
-        /**
-         *  Write operations that use this write concern will wait for acknowledgement,
-         *  using the default write concern configured on the server.
-         *  This is the default value.
-         */
-        ACKNOWLEDGED,
-        /**
-         * Write operations that use this write concern will wait for acknowledgement from a single member.
-         */
-        W1,
-        /**
-         * Write operations that use this write concern will wait for acknowledgement from two members.
-         */
-        W2,
-        /**
-         * Write operations that use this write concern will wait for acknowledgement from three members.
-         */
-        W3,
-        /**
-         * Write operations that use this write concern will return as soon as the message is written to the socket.
-         * Exceptions are raised for network issues, but not server errors.
-         */
-        UNACKNOWLEDGED,
-        /**
-         * Write operations wait for the server to group commit to the journal file on disk.
-         */
-        JOURNALED,
-        /**
-         * Exceptions are raised for network issues, and server errors;
-         * waits on a majority of servers for the write operation.
-         */
-        MAJORITY
-
-    }
-}
-// END SNIPPET: config
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreMixin.java b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreMixin.java
deleted file mode 100644
index 3766b82..0000000
--- a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreMixin.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- *
- */
-package org.apache.polygene.entitystore.mongodb;
-
-import com.mongodb.BasicDBObject;
-import com.mongodb.MongoClient;
-import com.mongodb.MongoClientOptions;
-import com.mongodb.MongoCredential;
-import com.mongodb.ServerAddress;
-import com.mongodb.WriteConcern;
-import com.mongodb.client.MongoCollection;
-import com.mongodb.client.MongoCursor;
-import com.mongodb.client.MongoDatabase;
-import com.mongodb.util.JSON;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Stream;
-import java.util.stream.StreamSupport;
-import org.apache.polygene.api.configuration.Configuration;
-import org.apache.polygene.api.entity.EntityDescriptor;
-import org.apache.polygene.api.entity.EntityReference;
-import org.apache.polygene.api.injection.scope.This;
-import org.apache.polygene.api.service.ServiceActivation;
-import org.apache.polygene.spi.entitystore.EntityNotFoundException;
-import org.apache.polygene.spi.entitystore.EntityStoreException;
-import org.apache.polygene.spi.entitystore.helpers.MapEntityStore;
-import org.bson.Document;
-import org.bson.conversions.Bson;
-
-import static com.mongodb.client.model.Filters.eq;
-import static java.util.stream.Collectors.toList;
-
-/**
- * MongoDB implementation of MapEntityStore.
- */
-public class MongoMapEntityStoreMixin
-    implements ServiceActivation, MapEntityStore, MongoAccessors
-{
-    private static final String DEFAULT_DATABASE_NAME = "polygene:entitystore";
-    private static final String DEFAULT_COLLECTION_NAME = "polygene:entitystore:entities";
-    public static final String IDENTITY_COLUMN = "_id";
-    public static final String STATE_COLUMN = "state";
-    @This
-    private Configuration<MongoEntityStoreConfiguration> configuration;
-    private List<ServerAddress> serverAddresses;
-    private String databaseName;
-    private String collectionName;
-    private WriteConcern writeConcern;
-    private String username;
-    private char[] password;
-    private MongoClient mongo;
-    private MongoDatabase db;
-
-    @Override
-    public void activateService()
-        throws Exception
-    {
-        loadConfiguration();
-
-        // Create Mongo driver and open the database
-        MongoClientOptions options = MongoClientOptions.builder().writeConcern( writeConcern ).build();
-        if( username.isEmpty() )
-        {
-            mongo = new MongoClient( serverAddresses, options );
-        }
-        else
-        {
-            MongoCredential credential = MongoCredential.createMongoCRCredential( username, databaseName, password );
-            mongo = new MongoClient( serverAddresses, Collections.singletonList( credential ), options );
-        }
-        db = mongo.getDatabase( databaseName );
-
-        // Create index if needed
-        MongoCollection<Document> entities = db.getCollection( collectionName );
-        if( !entities.listIndexes().iterator().hasNext() )
-        {
-            entities.createIndex( new BasicDBObject( IDENTITY_COLUMN, 1 ) );
-        }
-    }
-
-    private void loadConfiguration()
-        throws UnknownHostException
-    {
-        configuration.refresh();
-        MongoEntityStoreConfiguration config = configuration.get();
-
-        // Combine hostname, port and nodes configuration properties
-        // If no configuration, use 127.0.0.1:27017
-        serverAddresses = new ArrayList<>();
-        int port = config.port().get() == null ? 27017 : config.port().get();
-        List<String> nodes = config.nodes().get();
-        if( nodes.isEmpty() )
-        {
-            String hostname = config.hostname().get() == null ? "127.0.0.1" : config.hostname().get();
-            serverAddresses.add( new ServerAddress( hostname, port ) );
-        }
-        else
-        {
-            if( config.hostname().get() != null && !config.hostname().get().isEmpty() )
-            {
-                serverAddresses.add( new ServerAddress( config.hostname().get(), port ) );
-            }
-            serverAddresses.addAll( nodes.stream()
-                                         .map( this::parseNode )
-                                         .collect( toList() )
-                                  );
-        }
-
-        // If database name not configured, set it to polygene:entitystore
-        databaseName = config.database().get();
-        if( databaseName == null )
-        {
-            databaseName = DEFAULT_DATABASE_NAME;
-        }
-
-        // If collection name not configured, set it to polygene:entitystore:entities
-        collectionName = config.collection().get();
-        if( collectionName == null )
-        {
-            collectionName = DEFAULT_COLLECTION_NAME;
-        }
-
-        // If write concern not configured, set it to normal
-        switch( config.writeConcern().get() )
-        {
-        case W1:
-            writeConcern = WriteConcern.W1;
-            break;
-        case W2:
-            writeConcern = WriteConcern.W2;
-            break;
-        case W3:
-            writeConcern = WriteConcern.W3;
-            break;
-        case UNACKNOWLEDGED:
-            writeConcern = WriteConcern.UNACKNOWLEDGED;
-            break;
-        case JOURNALED:
-            writeConcern = WriteConcern.JOURNALED;
-            break;
-        case MAJORITY:
-            writeConcern = WriteConcern.MAJORITY;
-            break;
-        case ACKNOWLEDGED:
-        default:
-            writeConcern = WriteConcern.ACKNOWLEDGED;
-        }
-
-        // Username and password are defaulted to empty strings
-        username = config.username().get();
-        password = config.password().get().toCharArray();
-    }
-
-    private <R> ServerAddress parseNode( String nodeString )
-    {
-        String[] parts = nodeString.split( ":" );
-        String host = parts[ 0 ];
-        if( parts.length == 2 )
-        {
-            int port = Integer.parseInt( parts[ 1 ] );
-            return new ServerAddress( host, port );
-        }
-        return new ServerAddress( host );
-    }
-
-    @Override
-    public void passivateService()
-        throws Exception
-    {
-        mongo.close();
-        mongo = null;
-        databaseName = null;
-        collectionName = null;
-        writeConcern = null;
-        username = null;
-        Arrays.fill( password, ' ' );
-        password = null;
-        db = null;
-    }
-
-    @Override
-    public MongoClient mongoInstanceUsed()
-    {
-        return mongo;
-    }
-
-    @Override
-    public MongoDatabase dbInstanceUsed()
-    {
-        return db;
-    }
-
-    @Override
-    public String collectionUsed()
-    {
-        return collectionName;
-    }
-
-    @Override
-    public Reader get( EntityReference entityReference )
-        throws EntityStoreException
-    {
-        MongoCursor<Document> cursor = db.getCollection( collectionName )
-                                         .find( byIdentity( entityReference ) )
-                                         .limit( 1 ).iterator();
-        if( !cursor.hasNext() )
-        {
-            throw new EntityNotFoundException( entityReference );
-        }
-        Document bsonState = (Document) cursor.next().get( STATE_COLUMN );
-        String jsonState = JSON.serialize( bsonState );
-        return new StringReader( jsonState );
-    }
-
-    @Override
-    public void applyChanges( MapChanges changes )
-        throws Exception
-    {
-        final MongoCollection<Document> entities = db.getCollection( collectionName );
-
-        changes.visitMap( new MapChanger()
-        {
-            @Override
-            public Writer newEntity( EntityReference ref, EntityDescriptor entityDescriptor )
-                throws IOException
-            {
-                return new StringWriter( 1000 )
-                {
-                    @Override
-                    public void close()
-                        throws IOException
-                    {
-                        super.close();
-                        Document bsonState = Document.parse( toString() );
-                        Document entity = new Document();
-                        entity.put( IDENTITY_COLUMN, ref.identity().toString() );
-                        entity.put( STATE_COLUMN, bsonState );
-                        entities.insertOne( entity );
-                    }
-                };
-            }
-
-            @Override
-            public Writer updateEntity( MapChange mapChange )
-                throws IOException
-            {
-                return new StringWriter( 1000 )
-                {
-                    @Override
-                    public void close()
-                        throws IOException
-                    {
-                        super.close();
-                        Document bsonState = Document.parse( toString() );
-                        Document entity = new Document();
-                        entity.put( IDENTITY_COLUMN, mapChange.reference().identity().toString() );
-                        entity.put( STATE_COLUMN, bsonState );
-                        entities.replaceOne( byIdentity( mapChange.reference() ), entity );
-                    }
-                };
-            }
-
-            @Override
-            public void removeEntity( EntityReference ref, EntityDescriptor entityDescriptor )
-                throws EntityNotFoundException
-            {
-                Bson byIdFilter = byIdentity( ref );
-                MongoCursor<Document> cursor = db.getCollection( collectionName )
-                                                 .find( byIdFilter )
-                                                 .limit( 1 ).iterator();
-                if( !cursor.hasNext() )
-                {
-                    throw new EntityNotFoundException( ref );
-                }
-                entities.deleteOne( byIdFilter );
-            }
-        } );
-    }
-
-    @Override
-    public Stream<Reader> entityStates()
-    {
-        return StreamSupport
-            .stream( db.getCollection( collectionName ).find().spliterator(), false )
-            .map( eachEntity ->
-                  {
-                      Document bsonState = (Document) eachEntity.get( STATE_COLUMN );
-                      String jsonState = JSON.serialize( bsonState );
-                      return new StringReader( jsonState );
-                  } );
-    }
-
-    private Bson byIdentity( EntityReference entityReference )
-    {
-        return eq( IDENTITY_COLUMN, entityReference.identity().toString() );
-    }
-}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreService.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreService.java b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreService.java
deleted file mode 100644
index 2145544..0000000
--- a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreService.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- *
- */
-package org.apache.polygene.entitystore.mongodb;
-
-import org.apache.polygene.api.concern.Concerns;
-import org.apache.polygene.api.configuration.Configuration;
-import org.apache.polygene.api.mixin.Mixins;
-import org.apache.polygene.api.service.ServiceActivation;
-import org.apache.polygene.library.locking.LockingAbstractComposite;
-import org.apache.polygene.spi.entitystore.ConcurrentModificationCheckConcern;
-import org.apache.polygene.spi.entitystore.EntityStateVersions;
-import org.apache.polygene.spi.entitystore.EntityStore;
-import org.apache.polygene.spi.entitystore.StateChangeNotificationConcern;
-import org.apache.polygene.spi.entitystore.helpers.JSONMapEntityStoreActivation;
-import org.apache.polygene.spi.entitystore.helpers.JSONMapEntityStoreMixin;
-
-/**
- * MongoDB EntityStore service.
- * <p>Based on @{@link JSONMapEntityStoreMixin}.</p>
- */
-@Concerns( { StateChangeNotificationConcern.class, ConcurrentModificationCheckConcern.class } )
-@Mixins( { JSONMapEntityStoreMixin.class, MongoMapEntityStoreMixin.class } )
-public interface MongoMapEntityStoreService
-    extends EntityStore,
-            EntityStateVersions,
-            ServiceActivation,
-            JSONMapEntityStoreActivation,
-            LockingAbstractComposite,
-            Configuration,
-            MongoAccessors
-{
-}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/assembly/MongoDBEntityStoreAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/assembly/MongoDBEntityStoreAssembler.java b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/assembly/MongoDBEntityStoreAssembler.java
index a270305..eff0463 100644
--- a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/assembly/MongoDBEntityStoreAssembler.java
+++ b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/assembly/MongoDBEntityStoreAssembler.java
@@ -23,8 +23,8 @@ import org.apache.polygene.bootstrap.Assemblers;
 import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.bootstrap.ServiceDeclaration;
-import org.apache.polygene.entitystore.mongodb.MongoEntityStoreConfiguration;
-import org.apache.polygene.entitystore.mongodb.MongoMapEntityStoreService;
+import org.apache.polygene.entitystore.mongodb.MongoDBEntityStoreConfiguration;
+import org.apache.polygene.entitystore.mongodb.MongoDBMapEntityStoreService;
 
 public class MongoDBEntityStoreAssembler
     extends Assemblers.VisibilityIdentityConfig<MongoDBEntityStoreAssembler>
@@ -33,14 +33,14 @@ public class MongoDBEntityStoreAssembler
     public void assemble( ModuleAssembly module )
         throws AssemblyException
     {
-        ServiceDeclaration service = module.services( MongoMapEntityStoreService.class ).visibleIn( visibility() );
+        ServiceDeclaration service = module.services( MongoDBMapEntityStoreService.class ).visibleIn( visibility() );
         if( hasIdentity() )
         {
             service.identifiedBy( identity() );
         }
         if( hasConfig() )
         {
-            configModule().entities( MongoEntityStoreConfiguration.class ).visibleIn( configVisibility() );
+            configModule().entities( MongoDBEntityStoreConfiguration.class ).visibleIn( configVisibility() );
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoDBMapEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoDBMapEntityStoreTest.java b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoDBMapEntityStoreTest.java
new file mode 100644
index 0000000..9f285aa
--- /dev/null
+++ b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoDBMapEntityStoreTest.java
@@ -0,0 +1,88 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.polygene.entitystore.mongodb;
+
+import de.flapdoodle.embed.mongo.MongodExecutable;
+import de.flapdoodle.embed.mongo.MongodStarter;
+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 java.io.IOException;
+import java.util.Collections;
+import org.apache.polygene.api.common.Visibility;
+import org.apache.polygene.bootstrap.AssemblyException;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.entitystore.mongodb.assembly.MongoDBEntityStoreAssembler;
+import org.apache.polygene.test.EntityTestAssembler;
+import org.apache.polygene.test.entity.AbstractEntityStoreTest;
+import org.apache.polygene.test.util.FreePortFinder;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+
+public class EmbedMongoDBMapEntityStoreTest extends AbstractEntityStoreTest
+{
+    private static final MongodStarter MONGO_STARTER = MongodStarter.getDefaultInstance();
+
+    @Rule
+    public TestName testName = new TestName();
+    private static int port;
+    private static MongodExecutable mongod;
+
+    @BeforeClass
+    public static void startEmbedMongo()
+        throws IOException
+    {
+        port = FreePortFinder.findFreePortOnLoopback();
+        mongod = MONGO_STARTER.prepare( new MongodConfigBuilder()
+                                            .version( Version.Main.PRODUCTION )
+                                            .net( new Net( "localhost", port, Network.localhostIsIPv6() ) )
+                                            .build() );
+        mongod.start();
+    }
+
+    @AfterClass
+    public static void stopEmbedMongo()
+    {
+        if( mongod != null )
+        {
+            mongod.stop();
+        }
+    }
+
+    @Override
+    public void assemble( ModuleAssembly module )
+        throws AssemblyException
+    {
+        super.assemble( module );
+
+        ModuleAssembly config = module.layer().module( "config" );
+        new EntityTestAssembler().assemble( config );
+
+        new MongoDBEntityStoreAssembler().withConfig( config, Visibility.layer ).assemble( module );
+
+        MongoDBEntityStoreConfiguration mongoConfig = config.forMixin( MongoDBEntityStoreConfiguration.class )
+                                                            .declareDefaults();
+        mongoConfig.writeConcern().set( MongoDBEntityStoreConfiguration.WriteConcern.MAJORITY );
+        mongoConfig.database().set( "polygene-test" );
+        mongoConfig.collection().set( testName.getMethodName() );
+        mongoConfig.nodes().set( Collections.singletonList( "localhost:" + port ) );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java
deleted file mode 100644
index 5a65389..0000000
--- a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package org.apache.polygene.entitystore.mongodb;
-
-import de.flapdoodle.embed.mongo.MongodExecutable;
-import de.flapdoodle.embed.mongo.MongodStarter;
-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 java.io.IOException;
-import java.util.Collections;
-import org.apache.polygene.api.common.Visibility;
-import org.apache.polygene.bootstrap.AssemblyException;
-import org.apache.polygene.bootstrap.ModuleAssembly;
-import org.apache.polygene.entitystore.mongodb.assembly.MongoDBEntityStoreAssembler;
-import org.apache.polygene.test.EntityTestAssembler;
-import org.apache.polygene.test.entity.AbstractEntityStoreTest;
-import org.apache.polygene.test.util.FreePortFinder;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-
-public class EmbedMongoMapEntityStoreTest extends AbstractEntityStoreTest
-{
-    private static final MongodStarter MONGO_STARTER = MongodStarter.getDefaultInstance();
-
-    @Rule
-    public TestName testName = new TestName();
-    private static int port;
-    private static MongodExecutable mongod;
-
-    @BeforeClass
-    public static void startEmbedMongo()
-        throws IOException
-    {
-        port = FreePortFinder.findFreePortOnLoopback();
-        mongod = MONGO_STARTER.prepare( new MongodConfigBuilder()
-                                            .version( Version.Main.PRODUCTION )
-                                            .net( new Net( "localhost", port, Network.localhostIsIPv6() ) )
-                                            .build() );
-        mongod.start();
-    }
-
-    @AfterClass
-    public static void stopEmbedMongo()
-    {
-        if( mongod != null )
-        {
-            mongod.stop();
-        }
-    }
-
-    @Override
-    public void assemble( ModuleAssembly module )
-        throws AssemblyException
-    {
-        super.assemble( module );
-
-        ModuleAssembly config = module.layer().module( "config" );
-        new EntityTestAssembler().assemble( config );
-
-        new MongoDBEntityStoreAssembler().withConfig( config, Visibility.layer ).assemble( module );
-
-        MongoEntityStoreConfiguration mongoConfig = config.forMixin( MongoEntityStoreConfiguration.class )
-                                                          .declareDefaults();
-        mongoConfig.writeConcern().set( MongoEntityStoreConfiguration.WriteConcern.MAJORITY );
-        mongoConfig.database().set( "polygene-test" );
-        mongoConfig.collection().set( testName.getMethodName() );
-        mongoConfig.nodes().set( Collections.singletonList( "localhost:" + port ) );
-    }
-}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreTest.java b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreTest.java
new file mode 100644
index 0000000..f98fdc3
--- /dev/null
+++ b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreTest.java
@@ -0,0 +1,88 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.polygene.entitystore.mongodb;
+
+import com.mongodb.Mongo;
+import org.apache.polygene.api.common.Visibility;
+import org.apache.polygene.bootstrap.AssemblyException;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.entitystore.mongodb.assembly.MongoDBEntityStoreAssembler;
+import org.apache.polygene.test.EntityTestAssembler;
+import org.apache.polygene.test.entity.AbstractEntityStoreTest;
+import org.junit.BeforeClass;
+
+import static org.apache.polygene.test.util.Assume.assumeConnectivity;
+
+/**
+ * Test the MongoDBMapEntityStoreService.
+ * <p>Installing mongodb and starting it should suffice as the test use mongodb defaults: 127.0.0.1:27017</p>
+ */
+public class MongoDBMapEntityStoreTest extends AbstractEntityStoreTest
+{
+    @BeforeClass
+    public static void beforeRedisMapEntityStoreTests()
+    {
+        assumeConnectivity( "localhost", 27017 );
+    }
+
+    @Override
+    // START SNIPPET: assembly
+    public void assemble( ModuleAssembly module )
+        throws AssemblyException
+    {
+        // END SNIPPET: assembly
+        super.assemble( module );
+
+        ModuleAssembly config = module.layer().module( "config" );
+        new EntityTestAssembler().assemble( config );
+
+        // START SNIPPET: assembly
+        new MongoDBEntityStoreAssembler().withConfig( config, Visibility.layer ).assemble( module );
+        // END SNIPPET: assembly
+
+        MongoDBEntityStoreConfiguration mongoConfig = config.forMixin( MongoDBEntityStoreConfiguration.class ).declareDefaults();
+        mongoConfig.writeConcern().set( MongoDBEntityStoreConfiguration.WriteConcern.MAJORITY );
+        mongoConfig.database().set( "polygene:test" );
+        mongoConfig.collection().set( "polygene:test:entities" );
+        // START SNIPPET: assembly
+    }
+
+    // END SNIPPET: assembly
+    private Mongo mongo;
+    private String dbName;
+
+    @Override
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+        MongoDBMapEntityStoreService es = serviceFinder.findService( MongoDBMapEntityStoreService.class ).get();
+        mongo = es.mongoInstanceUsed();
+        dbName = es.dbInstanceUsed().getName();
+    }
+
+    @Override
+    public void tearDown()
+        throws Exception
+    {
+        mongo.dropDatabase( dbName );
+        super.tearDown();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreWithCacheTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreWithCacheTest.java b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreWithCacheTest.java
new file mode 100644
index 0000000..65e9a13
--- /dev/null
+++ b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoDBMapEntityStoreWithCacheTest.java
@@ -0,0 +1,84 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.polygene.entitystore.mongodb;
+
+import com.mongodb.Mongo;
+import org.apache.polygene.api.common.Visibility;
+import org.apache.polygene.bootstrap.AssemblyException;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.entitystore.mongodb.assembly.MongoDBEntityStoreAssembler;
+import org.apache.polygene.test.EntityTestAssembler;
+import org.apache.polygene.test.cache.AbstractEntityStoreWithCacheTest;
+import org.junit.BeforeClass;
+
+import static org.apache.polygene.test.util.Assume.assumeConnectivity;
+
+/**
+ * Test the MongoDBMapEntityStoreService usage with a CachePool.
+ * <p>Installing mongodb and starting it should suffice as the test use mongodb defaults: 127.0.0.1:27017</p>
+ */
+public class MongoDBMapEntityStoreWithCacheTest
+    extends AbstractEntityStoreWithCacheTest
+{
+    @BeforeClass
+    public static void beforeRedisMapEntityStoreTests()
+    {
+        assumeConnectivity( "localhost", 27017 );
+    }
+
+    @Override
+    public void assemble( ModuleAssembly module )
+        throws AssemblyException
+    {
+        super.assemble( module );
+
+        ModuleAssembly config = module.layer().module( "config" );
+        new EntityTestAssembler().assemble( config );
+
+        new MongoDBEntityStoreAssembler().withConfig( config, Visibility.layer ).assemble( module );
+
+        MongoDBEntityStoreConfiguration mongoConfig = config.forMixin( MongoDBEntityStoreConfiguration.class ).declareDefaults();
+        mongoConfig.writeConcern().set( MongoDBEntityStoreConfiguration.WriteConcern.MAJORITY );
+        mongoConfig.database().set( "polygene:test" );
+        mongoConfig.collection().set( "polygene:test:entities" );
+    }
+
+    private Mongo mongo;
+    private String dbName;
+
+    @Override
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+        MongoDBMapEntityStoreService es = serviceFinder.findService( MongoDBMapEntityStoreService.class ).get();
+        mongo = es.mongoInstanceUsed();
+        dbName = es.dbInstanceUsed().getName();
+
+    }
+
+    @Override
+    public void tearDown()
+        throws Exception
+    {
+        mongo.dropDatabase( dbName );
+        super.tearDown();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreTest.java b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreTest.java
deleted file mode 100644
index 9c48fe5..0000000
--- a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- *
- */
-package org.apache.polygene.entitystore.mongodb;
-
-import com.mongodb.Mongo;
-import org.apache.polygene.api.common.Visibility;
-import org.apache.polygene.bootstrap.AssemblyException;
-import org.apache.polygene.bootstrap.ModuleAssembly;
-import org.apache.polygene.entitystore.mongodb.assembly.MongoDBEntityStoreAssembler;
-import org.apache.polygene.test.EntityTestAssembler;
-import org.apache.polygene.test.entity.AbstractEntityStoreTest;
-import org.junit.BeforeClass;
-
-import static org.apache.polygene.test.util.Assume.assumeConnectivity;
-
-/**
- * Test the MongoMapEntityStoreService.
- * <p>Installing mongodb and starting it should suffice as the test use mongodb defaults: 127.0.0.1:27017</p>
- */
-public class MongoMapEntityStoreTest extends AbstractEntityStoreTest
-{
-    @BeforeClass
-    public static void beforeRedisMapEntityStoreTests()
-    {
-        assumeConnectivity( "localhost", 27017 );
-    }
-
-    @Override
-    // START SNIPPET: assembly
-    public void assemble( ModuleAssembly module )
-        throws AssemblyException
-    {
-        // END SNIPPET: assembly
-        super.assemble( module );
-
-        ModuleAssembly config = module.layer().module( "config" );
-        new EntityTestAssembler().assemble( config );
-
-        // START SNIPPET: assembly
-        new MongoDBEntityStoreAssembler().withConfig( config, Visibility.layer ).assemble( module );
-        // END SNIPPET: assembly
-
-        MongoEntityStoreConfiguration mongoConfig = config.forMixin( MongoEntityStoreConfiguration.class ).declareDefaults();
-        mongoConfig.writeConcern().set( MongoEntityStoreConfiguration.WriteConcern.MAJORITY );
-        mongoConfig.database().set( "polygene:test" );
-        mongoConfig.collection().set( "polygene:test:entities" );
-        // START SNIPPET: assembly
-    }
-
-    // END SNIPPET: assembly
-    private Mongo mongo;
-    private String dbName;
-
-    @Override
-    public void setUp()
-        throws Exception
-    {
-        super.setUp();
-        MongoMapEntityStoreService es = serviceFinder.findService( MongoMapEntityStoreService.class ).get();
-        mongo = es.mongoInstanceUsed();
-        dbName = es.dbInstanceUsed().getName();
-    }
-
-    @Override
-    public void tearDown()
-        throws Exception
-    {
-        mongo.dropDatabase( dbName );
-        super.tearDown();
-    }
-}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/09b92801/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreWithCacheTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreWithCacheTest.java b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreWithCacheTest.java
deleted file mode 100644
index cad95ea..0000000
--- a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreWithCacheTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- *
- */
-package org.apache.polygene.entitystore.mongodb;
-
-import com.mongodb.Mongo;
-import org.apache.polygene.api.common.Visibility;
-import org.apache.polygene.bootstrap.AssemblyException;
-import org.apache.polygene.bootstrap.ModuleAssembly;
-import org.apache.polygene.entitystore.mongodb.assembly.MongoDBEntityStoreAssembler;
-import org.apache.polygene.test.EntityTestAssembler;
-import org.apache.polygene.test.cache.AbstractEntityStoreWithCacheTest;
-import org.junit.BeforeClass;
-
-import static org.apache.polygene.test.util.Assume.assumeConnectivity;
-
-/**
- * Test the MongoMapEntityStoreService usage with a CachePool.
- * <p>Installing mongodb and starting it should suffice as the test use mongodb defaults: 127.0.0.1:27017</p>
- */
-public class MongoMapEntityStoreWithCacheTest
-    extends AbstractEntityStoreWithCacheTest
-{
-    @BeforeClass
-    public static void beforeRedisMapEntityStoreTests()
-    {
-        assumeConnectivity( "localhost", 27017 );
-    }
-
-    @Override
-    public void assemble( ModuleAssembly module )
-        throws AssemblyException
-    {
-        super.assemble( module );
-
-        ModuleAssembly config = module.layer().module( "config" );
-        new EntityTestAssembler().assemble( config );
-
-        new MongoDBEntityStoreAssembler().withConfig( config, Visibility.layer ).assemble( module );
-
-        MongoEntityStoreConfiguration mongoConfig = config.forMixin( MongoEntityStoreConfiguration.class ).declareDefaults();
-        mongoConfig.writeConcern().set( MongoEntityStoreConfiguration.WriteConcern.MAJORITY );
-        mongoConfig.database().set( "polygene:test" );
-        mongoConfig.collection().set( "polygene:test:entities" );
-    }
-
-    private Mongo mongo;
-    private String dbName;
-
-    @Override
-    public void setUp()
-        throws Exception
-    {
-        super.setUp();
-        MongoMapEntityStoreService es = serviceFinder.findService( MongoMapEntityStoreService.class ).get();
-        mongo = es.mongoInstanceUsed();
-        dbName = es.dbInstanceUsed().getName();
-
-    }
-
-    @Override
-    public void tearDown()
-        throws Exception
-    {
-        mongo.dropDatabase( dbName );
-        super.tearDown();
-    }
-}


Mime
View raw message