polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [2/7] polygene-java git commit: POLYGENE-221 integration test MySQL ES using Docker
Date Mon, 09 Jan 2017 17:57:20 GMT
POLYGENE-221 integration test MySQL ES using Docker


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

Branch: refs/heads/develop
Commit: 1cc1e44530696c8a2f6047328a465c5440e7ef61
Parents: 9ace50e
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Jan 9 18:54:04 2017 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Mon Jan 9 18:56:58 2017 +0100

----------------------------------------------------------------------
 extensions/entitystore-sql/build.gradle         |  2 +-
 .../internal/MySQLDatabaseSQLServiceMixin.java  |  2 +-
 .../entitystore/sql/MySQLEntityStoreTest.java   | 48 ++++++++++----------
 .../test/resources/mysql-datasource.properties  |  2 +-
 internals/docker-mysql/build.gradle             | 19 ++++++++
 .../docker-mysql/src/main/docker/Dockerfile     |  1 +
 internals/testsupport-internal/build.gradle     |  1 +
 settings.gradle                                 |  1 +
 8 files changed, 50 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/1cc1e445/extensions/entitystore-sql/build.gradle
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/build.gradle b/extensions/entitystore-sql/build.gradle
index 89f890d..c0c5c8d 100644
--- a/extensions/entitystore-sql/build.gradle
+++ b/extensions/entitystore-sql/build.gradle
@@ -34,7 +34,7 @@ dependencies {
 
   runtime polygene.core.runtime
 
-  testCompile polygene.core.testsupport
+  testCompile polygene.internals.testsupport
   testCompile polygene.library( 'sql-dbcp' )
   testCompile polygene.extension( 'valueserialization-orgjson' )
   testCompile libraries.derby // Needed at compile time for polite test shutdown

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/1cc1e445/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/MySQLDatabaseSQLServiceMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/MySQLDatabaseSQLServiceMixin.java
b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/MySQLDatabaseSQLServiceMixin.java
index 5317b47..da3479d 100644
--- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/MySQLDatabaseSQLServiceMixin.java
+++ b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/MySQLDatabaseSQLServiceMixin.java
@@ -45,7 +45,7 @@ public abstract class MySQLDatabaseSQLServiceMixin
         ResultSet rs = null;
         try
         {
-            String tableNameForQuery = SQLs.TABLE_NAME.toUpperCase();
+            String tableNameForQuery = SQLs.TABLE_NAME;
             rs = connection.getMetaData().getTables( null, null, tableNameForQuery, new String[]
             {
                 "TABLE"

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/1cc1e445/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTest.java
b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTest.java
index 1a0c095..9183801 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTest.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTest.java
@@ -21,8 +21,8 @@ package org.apache.polygene.entitystore.sql;
 
 import java.sql.Connection;
 import java.sql.Statement;
+import java.util.HashMap;
 import javax.sql.DataSource;
-import org.junit.BeforeClass;
 import org.apache.polygene.api.common.Visibility;
 import org.apache.polygene.api.unitofwork.UnitOfWork;
 import org.apache.polygene.api.usecase.UsecaseBuilder;
@@ -30,23 +30,30 @@ import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.entitystore.sql.assembly.MySQLEntityStoreAssembler;
 import org.apache.polygene.entitystore.sql.internal.SQLs;
+import org.apache.polygene.test.internal.DockerRule;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
-import org.apache.polygene.library.sql.common.SQLConfiguration;
+import org.apache.polygene.library.sql.datasource.DataSourceConfiguration;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.EntityTestAssembler;
 import org.apache.polygene.test.entity.AbstractEntityStoreTest;
 import org.apache.polygene.valueserialization.orgjson.OrgJsonValueSerializationAssembler;
-
-import static org.apache.polygene.test.util.Assume.assumeConnectivity;
+import org.junit.ClassRule;
 
 public class MySQLEntityStoreTest
     extends AbstractEntityStoreTest
 {
-    @BeforeClass
-    public static void beforeMySQLEntityStoreTests()
-    {
-        assumeConnectivity( "localhost", 3306 );
-    }
+    @ClassRule
+    public static final DockerRule DOCKER = new DockerRule(
+        "mysql",
+        new HashMap<String, String>()
+        {{
+            put( "MYSQL_ROOT_PASSWORD", "" );
+            put( "MYSQL_ALLOW_EMPTY_PASSWORD", "yes" );
+            put( "MYSQL_DATABASE", "jdbc_test_db" );
+            put( "MYSQL_ROOT_HOST", "172.17.0.1" );
+        }},
+        3306
+    );
 
     @Override
     // START SNIPPET: assembly
@@ -80,33 +87,29 @@ public class MySQLEntityStoreTest
             visibleIn( Visibility.application ).
             withConfig( config, Visibility.layer ).
             assemble( module );
+        // END SNIPPET: assembly
+        String mysqlHost = DOCKER.getDockerHost();
+        int mysqlPort = DOCKER.getExposedContainerPort( "3306/tcp" );
+        config.forMixin( DataSourceConfiguration.class ).declareDefaults()
+              .url().set( "jdbc:mysql://" + mysqlHost + ":" + mysqlPort
+                          + "/jdbc_test_db?profileSQL=true&useLegacyDatetimeCode=false&serverTimezone=UTC"
);
+        // START SNIPPET: assembly
     }
     // END SNIPPET: assembly
 
     @Override
-    public void tearDown()
-        throws Exception
+    public void tearDown() throws Exception
     {
-        if( true )
-        {
-            return;
-        }
         UnitOfWork uow = this.unitOfWorkFactory.newUnitOfWork(
             UsecaseBuilder.newUsecase( "Delete " + getClass().getSimpleName() + " test data"
)
         );
         try
         {
-            SQLConfiguration config = uow.get( SQLConfiguration.class, MySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY
);
             Connection connection = serviceFinder.findService( DataSource.class ).get().getConnection();
             connection.setAutoCommit( false );
-            String schemaName = config.schemaName().get();
-            if( schemaName == null )
-            {
-                schemaName = SQLs.DEFAULT_SCHEMA_NAME;
-            }
             try( Statement stmt = connection.createStatement() )
             {
-                stmt.execute( String.format( "DELETE FROM %s." + SQLs.TABLE_NAME, schemaName
) );
+                stmt.execute( String.format( "DELETE FROM %s", SQLs.TABLE_NAME ) );
                 connection.commit();
             }
         }
@@ -116,5 +119,4 @@ public class MySQLEntityStoreTest
             super.tearDown();
         }
     }
-
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/1cc1e445/extensions/entitystore-sql/src/test/resources/mysql-datasource.properties
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/resources/mysql-datasource.properties b/extensions/entitystore-sql/src/test/resources/mysql-datasource.properties
index b6c57cb..6ace8dc 100644
--- a/extensions/entitystore-sql/src/test/resources/mysql-datasource.properties
+++ b/extensions/entitystore-sql/src/test/resources/mysql-datasource.properties
@@ -19,7 +19,7 @@
 #
 
 enabled=true
-url=jdbc:mysql://localhost:3306/jdbc_test_db?profileSQL=true&useLegacyDatetimeCode=false&serverTimezone=UTC
+#url=jdbc:mysql://localhost:3306/jdbc_test_db?profileSQL=true&useLegacyDatetimeCode=false&serverTimezone=UTC
 driver=com.mysql.jdbc.Driver
 username=root
 password=

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/1cc1e445/internals/docker-mysql/build.gradle
----------------------------------------------------------------------
diff --git a/internals/docker-mysql/build.gradle b/internals/docker-mysql/build.gradle
new file mode 100644
index 0000000..d6f59e0
--- /dev/null
+++ b/internals/docker-mysql/build.gradle
@@ -0,0 +1,19 @@
+/*
+ *  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.
+ */
+
+apply plugin: 'polygene-internal-docker'

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/1cc1e445/internals/docker-mysql/src/main/docker/Dockerfile
----------------------------------------------------------------------
diff --git a/internals/docker-mysql/src/main/docker/Dockerfile b/internals/docker-mysql/src/main/docker/Dockerfile
new file mode 100644
index 0000000..f0169e9
--- /dev/null
+++ b/internals/docker-mysql/src/main/docker/Dockerfile
@@ -0,0 +1 @@
+FROM mariadb:latest
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/1cc1e445/internals/testsupport-internal/build.gradle
----------------------------------------------------------------------
diff --git a/internals/testsupport-internal/build.gradle b/internals/testsupport-internal/build.gradle
index 561035a..432de86 100644
--- a/internals/testsupport-internal/build.gradle
+++ b/internals/testsupport-internal/build.gradle
@@ -28,4 +28,5 @@ dependencies {
 // Ensure that all Docker images are built alongside this project
 // This is a bit of a stretch but works for now
 classes.dependsOn ':internals:docker-memcached:docker'
+classes.dependsOn ':internals:docker-mysql:docker'
 classes.dependsOn ':internals:docker-redis:docker'

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/1cc1e445/settings.gradle
----------------------------------------------------------------------
diff --git a/settings.gradle b/settings.gradle
index dacb684..11378a9 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -102,6 +102,7 @@ include 'core:api',
 
 include 'internals:testsupport-internal',
         'internals:docker-memcached',
+        'internals:docker-mysql',
         'internals:docker-redis'
 
 include 'manual', 'reports', 'distributions', 'release'


Mime
View raw message