polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [6/7] polygene-java git commit: POLYGENE-221 integration test PostgreSQL ES using Docker
Date Mon, 09 Jan 2017 17:57:24 GMT
POLYGENE-221 integration test PostgreSQL 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/aed16885
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/aed16885
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/aed16885

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

----------------------------------------------------------------------
 .../sql/PostgreSQLEntityStoreTest.java           | 19 +++++++++++--------
 .../resources/postgresql-datasource.properties   |  1 -
 internals/docker-postgres/build.gradle           | 19 +++++++++++++++++++
 .../docker-postgres/src/main/docker/Dockerfile   |  2 ++
 .../src/main/docker/init-test-db.sh              | 14 ++++++++++++++
 internals/testsupport-internal/build.gradle      |  1 +
 settings.gradle                                  |  1 +
 7 files changed, 48 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/aed16885/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTest.java
b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTest.java
index 62c0cd0..49d5a13 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTest.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTest.java
@@ -22,7 +22,6 @@ package org.apache.polygene.entitystore.sql;
 import java.sql.Connection;
 import java.sql.Statement;
 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,14 +29,15 @@ import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler;
 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;
 
 /**
  * WARN This test run only if localhost:5432 is listening.
@@ -76,11 +76,8 @@ import static org.apache.polygene.test.util.Assume.assumeConnectivity;
 public class PostgreSQLEntityStoreTest
     extends AbstractEntityStoreTest
 {
-    @BeforeClass
-    public static void beforePostgreSQLEntityStoreTests()
-    {
-        assumeConnectivity( "localhost", 5432 );
-    }
+    @ClassRule
+    public static final DockerRule DOCKER = new DockerRule( "postgres", 5432 );
 
     @Override
     // START SNIPPET: assembly
@@ -114,6 +111,12 @@ public class PostgreSQLEntityStoreTest
             visibleIn( Visibility.application ).
             withConfig( config, Visibility.layer ).
             assemble( module );
+        // END SNIPPET: assembly
+        String host = DOCKER.getDockerHost();
+        int port = DOCKER.getExposedContainerPort( "5432/tcp" );
+        config.forMixin( DataSourceConfiguration.class ).declareDefaults()
+              .url().set( "jdbc:postgresql://" + host + ":" + port + "/jdbc_test_db" );
+        // START SNIPPET: assembly
     }
     // END SNIPPET: assembly
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/aed16885/extensions/entitystore-sql/src/test/resources/postgresql-datasource.properties
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/resources/postgresql-datasource.properties
b/extensions/entitystore-sql/src/test/resources/postgresql-datasource.properties
index ea16c45..bdda284 100644
--- a/extensions/entitystore-sql/src/test/resources/postgresql-datasource.properties
+++ b/extensions/entitystore-sql/src/test/resources/postgresql-datasource.properties
@@ -19,7 +19,6 @@
 #
 
 enabled=true
-url=jdbc:postgresql://localhost:5432/jdbc_test_db
 driver=org.postgresql.Driver
 username=jdbc_test_login
 password=password

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/aed16885/internals/docker-postgres/build.gradle
----------------------------------------------------------------------
diff --git a/internals/docker-postgres/build.gradle b/internals/docker-postgres/build.gradle
new file mode 100644
index 0000000..d6f59e0
--- /dev/null
+++ b/internals/docker-postgres/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/aed16885/internals/docker-postgres/src/main/docker/Dockerfile
----------------------------------------------------------------------
diff --git a/internals/docker-postgres/src/main/docker/Dockerfile b/internals/docker-postgres/src/main/docker/Dockerfile
new file mode 100644
index 0000000..e17d095
--- /dev/null
+++ b/internals/docker-postgres/src/main/docker/Dockerfile
@@ -0,0 +1,2 @@
+FROM postgres:alpine
+COPY init-test-db.sh /docker-entrypoint-initdb.d/init-test-db.sh

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/aed16885/internals/docker-postgres/src/main/docker/init-test-db.sh
----------------------------------------------------------------------
diff --git a/internals/docker-postgres/src/main/docker/init-test-db.sh b/internals/docker-postgres/src/main/docker/init-test-db.sh
new file mode 100755
index 0000000..2c0c759
--- /dev/null
+++ b/internals/docker-postgres/src/main/docker/init-test-db.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+set -e
+
+# Create test user and database
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
+    CREATE USER jdbc_test_login;
+    CREATE DATABASE jdbc_test_db;
+    GRANT ALL PRIVILEGES ON DATABASE jdbc_test_db TO jdbc_test_login;
+EOSQL
+
+# Enable ltree extension on test database
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" -d jdbc_test_db <<-EOSQL
+    CREATE EXTENSION ltree;
+EOSQL

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/aed16885/internals/testsupport-internal/build.gradle
----------------------------------------------------------------------
diff --git a/internals/testsupport-internal/build.gradle b/internals/testsupport-internal/build.gradle
index 432de86..cd67ed9 100644
--- a/internals/testsupport-internal/build.gradle
+++ b/internals/testsupport-internal/build.gradle
@@ -29,4 +29,5 @@ dependencies {
 // 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-postgres:docker'
 classes.dependsOn ':internals:docker-redis:docker'

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


Mime
View raw message