Loading .gitlab-ci.yml +22 −1 Original line number Diff line number Diff line stages: - build - test build: script: "cd TASMAN-bom; mvn clean install; cd ../TASMAN-core; mvn clean install -P Test -Dmysql_host=localhost -Dmysql_port=3306 -Dmysql_user=tasman_tester -D mysql_password=tasman_tester -Dpostgres_host=localhost -Dpostgres_port=5432 -Dpostgres_user=tasman_tester -Dpostgres_password=tasman_tester -Dpostgres_database=tasman_test" stage: build tags: - docker image: maven:3.6.3-openjdk-14 script: - cp config.properties.example config.properties - ./build.sh embedded test_backend: stage: test tags: - docker image: git.ia2.inaf.it:5050/ia2/ia2-devops/maven-otj-pg-embedded script: - cd TASMAN-bom - mvn clean install - cd ../TASMAN-core - mvn clean install README.md +1 −3 Original line number Diff line number Diff line Loading @@ -14,9 +14,7 @@ See also the [CHANGELOG](CHANGELOG.md). 2. `chmod +x build.sh` 3. `./build.sh <command>`, commands are: * **core** build only TASMAN core * **test**: run tests; you need to create a `test.properties` file containing a configuration for connecting to a MySQL and a Postgres test database * MySQL testing database needs to have `default-storage-engine = innodb` configured into `/etc/my.cnf` * Postgres 9.3+ is required * **test**: run tests * **glassfish**: build GlassFish war package * **tomcat**: build Tomcat war package (using config.properties file) * **embedded**: build embedded package (to be run _locally!_) Loading TASMAN-bom/pom.xml +0 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,6 @@ <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <netbeans.hint.license>inaf-license-netbeans</netbeans.hint.license> <maven.test.skip>true</maven.test.skip> </properties> <dependencyManagement> Loading TASMAN-core/pom.xml +75 −12 Original line number Diff line number Diff line Loading @@ -11,6 +11,10 @@ <artifactId>tasman-core</artifactId> <packaging>jar</packaging> <properties> <zonky.postgres-binaries.version>12.5.0</zonky.postgres-binaries.version> </properties> <dependencies> <dependency> <groupId>org.apache.tomcat</groupId> Loading @@ -34,6 +38,19 @@ <version>9.3-1104-jdbc41</version> <scope>runtime</scope> </dependency> <!-- Embedded testing databases --> <dependency> <groupId>ch.vorburger.mariaDB4j</groupId> <artifactId>mariaDB4j</artifactId> <version>2.4.0</version> <scope>test</scope> </dependency> <dependency> <groupId>com.opentable.components</groupId> <artifactId>otj-pg-embedded</artifactId> <version>0.13.3</version> <scope>test</scope> </dependency> </dependencies> <profiles> Loading @@ -57,18 +74,64 @@ </dependencies> </profile> <profile> <id>test</id> <properties> <maven.test.skip>false</maven.test.skip> </properties> <build> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> </testResource> </testResources> </build> <id>platform-linux</id> <activation> <os> <family>unix</family> </os> </activation> <dependencies> <dependency> <groupId>io.zonky.test.postgres</groupId> <artifactId>embedded-postgres-binaries-linux-amd64</artifactId> <version>${zonky.postgres-binaries.version}</version> <scope>test</scope> </dependency> </dependencies> </profile> <profile> <id>platform-windows</id> <activation> <os> <family>windows</family> </os> </activation> <dependencies> <dependency> <groupId>io.zonky.test.postgres</groupId> <artifactId>embedded-postgres-binaries-windows-amd64</artifactId> <version>${zonky.postgres-binaries.version}</version> <scope>test</scope> </dependency> </dependencies> </profile> </profiles> <build> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> </plugin> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.6</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> No newline at end of file TASMAN-core/src/test/java/it/inaf/ia2/tsm/EmbeddedDatabases.java 0 → 100644 +59 −0 Original line number Diff line number Diff line package it.inaf.ia2.tsm; import ch.vorburger.mariadb4j.DB; import ch.vorburger.mariadb4j.DBConfigurationBuilder; import com.opentable.db.postgres.embedded.UncompressBundleDirectoryResolver; import com.opentable.db.postgres.embedded.EmbeddedPostgres; import com.opentable.db.postgres.embedded.PgBinaryResolver; import it.inaf.ia2.tsm.datalayer.Credentials; import it.inaf.ia2.tsm.datalayer.DatabaseType; import java.io.IOException; import java.io.InputStream; import org.springframework.core.io.ClassPathResource; public class EmbeddedDatabases { public static Credentials mariadbCredentials() throws Exception { DBConfigurationBuilder configBuilder = DBConfigurationBuilder.newBuilder(); DB db = DB.newEmbeddedDB(configBuilder.build()); db.start(); Credentials mysqlCredentials = new Credentials(DatabaseType.MYSQL); mysqlCredentials.setHostname("127.0.0.1"); mysqlCredentials.setPort(configBuilder.getPort()); mysqlCredentials.setUsername("root"); mysqlCredentials.setPassword(""); return mysqlCredentials; } public static Credentials postgresCredentials() throws Exception { EmbeddedPostgres embeddedPg = EmbeddedPostgres.builder() .setPgDirectoryResolver(new UncompressBundleDirectoryResolver(new CustomPostgresBinaryResolver())) .start(); Credentials postgresCredentials = new Credentials(DatabaseType.POSTGRES); postgresCredentials.setHostname("127.0.0.1"); postgresCredentials.setPort(embeddedPg.getPort()); postgresCredentials.setUsername("postgres"); postgresCredentials.setPassword(""); postgresCredentials.setDatabase("postgres"); return postgresCredentials; } private static class CustomPostgresBinaryResolver implements PgBinaryResolver { /** * Loads specific embedded Postgres version. */ @Override public InputStream getPgBinary(String system, String architecture) throws IOException { ClassPathResource resource = new ClassPathResource(String.format("postgres-%s-%s.txz", system.toLowerCase(), architecture)); return resource.getInputStream(); } } } Loading
.gitlab-ci.yml +22 −1 Original line number Diff line number Diff line stages: - build - test build: script: "cd TASMAN-bom; mvn clean install; cd ../TASMAN-core; mvn clean install -P Test -Dmysql_host=localhost -Dmysql_port=3306 -Dmysql_user=tasman_tester -D mysql_password=tasman_tester -Dpostgres_host=localhost -Dpostgres_port=5432 -Dpostgres_user=tasman_tester -Dpostgres_password=tasman_tester -Dpostgres_database=tasman_test" stage: build tags: - docker image: maven:3.6.3-openjdk-14 script: - cp config.properties.example config.properties - ./build.sh embedded test_backend: stage: test tags: - docker image: git.ia2.inaf.it:5050/ia2/ia2-devops/maven-otj-pg-embedded script: - cd TASMAN-bom - mvn clean install - cd ../TASMAN-core - mvn clean install
README.md +1 −3 Original line number Diff line number Diff line Loading @@ -14,9 +14,7 @@ See also the [CHANGELOG](CHANGELOG.md). 2. `chmod +x build.sh` 3. `./build.sh <command>`, commands are: * **core** build only TASMAN core * **test**: run tests; you need to create a `test.properties` file containing a configuration for connecting to a MySQL and a Postgres test database * MySQL testing database needs to have `default-storage-engine = innodb` configured into `/etc/my.cnf` * Postgres 9.3+ is required * **test**: run tests * **glassfish**: build GlassFish war package * **tomcat**: build Tomcat war package (using config.properties file) * **embedded**: build embedded package (to be run _locally!_) Loading
TASMAN-bom/pom.xml +0 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,6 @@ <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <netbeans.hint.license>inaf-license-netbeans</netbeans.hint.license> <maven.test.skip>true</maven.test.skip> </properties> <dependencyManagement> Loading
TASMAN-core/pom.xml +75 −12 Original line number Diff line number Diff line Loading @@ -11,6 +11,10 @@ <artifactId>tasman-core</artifactId> <packaging>jar</packaging> <properties> <zonky.postgres-binaries.version>12.5.0</zonky.postgres-binaries.version> </properties> <dependencies> <dependency> <groupId>org.apache.tomcat</groupId> Loading @@ -34,6 +38,19 @@ <version>9.3-1104-jdbc41</version> <scope>runtime</scope> </dependency> <!-- Embedded testing databases --> <dependency> <groupId>ch.vorburger.mariaDB4j</groupId> <artifactId>mariaDB4j</artifactId> <version>2.4.0</version> <scope>test</scope> </dependency> <dependency> <groupId>com.opentable.components</groupId> <artifactId>otj-pg-embedded</artifactId> <version>0.13.3</version> <scope>test</scope> </dependency> </dependencies> <profiles> Loading @@ -57,18 +74,64 @@ </dependencies> </profile> <profile> <id>test</id> <properties> <maven.test.skip>false</maven.test.skip> </properties> <build> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> </testResource> </testResources> </build> <id>platform-linux</id> <activation> <os> <family>unix</family> </os> </activation> <dependencies> <dependency> <groupId>io.zonky.test.postgres</groupId> <artifactId>embedded-postgres-binaries-linux-amd64</artifactId> <version>${zonky.postgres-binaries.version}</version> <scope>test</scope> </dependency> </dependencies> </profile> <profile> <id>platform-windows</id> <activation> <os> <family>windows</family> </os> </activation> <dependencies> <dependency> <groupId>io.zonky.test.postgres</groupId> <artifactId>embedded-postgres-binaries-windows-amd64</artifactId> <version>${zonky.postgres-binaries.version}</version> <scope>test</scope> </dependency> </dependencies> </profile> </profiles> <build> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> </plugin> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.6</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> No newline at end of file
TASMAN-core/src/test/java/it/inaf/ia2/tsm/EmbeddedDatabases.java 0 → 100644 +59 −0 Original line number Diff line number Diff line package it.inaf.ia2.tsm; import ch.vorburger.mariadb4j.DB; import ch.vorburger.mariadb4j.DBConfigurationBuilder; import com.opentable.db.postgres.embedded.UncompressBundleDirectoryResolver; import com.opentable.db.postgres.embedded.EmbeddedPostgres; import com.opentable.db.postgres.embedded.PgBinaryResolver; import it.inaf.ia2.tsm.datalayer.Credentials; import it.inaf.ia2.tsm.datalayer.DatabaseType; import java.io.IOException; import java.io.InputStream; import org.springframework.core.io.ClassPathResource; public class EmbeddedDatabases { public static Credentials mariadbCredentials() throws Exception { DBConfigurationBuilder configBuilder = DBConfigurationBuilder.newBuilder(); DB db = DB.newEmbeddedDB(configBuilder.build()); db.start(); Credentials mysqlCredentials = new Credentials(DatabaseType.MYSQL); mysqlCredentials.setHostname("127.0.0.1"); mysqlCredentials.setPort(configBuilder.getPort()); mysqlCredentials.setUsername("root"); mysqlCredentials.setPassword(""); return mysqlCredentials; } public static Credentials postgresCredentials() throws Exception { EmbeddedPostgres embeddedPg = EmbeddedPostgres.builder() .setPgDirectoryResolver(new UncompressBundleDirectoryResolver(new CustomPostgresBinaryResolver())) .start(); Credentials postgresCredentials = new Credentials(DatabaseType.POSTGRES); postgresCredentials.setHostname("127.0.0.1"); postgresCredentials.setPort(embeddedPg.getPort()); postgresCredentials.setUsername("postgres"); postgresCredentials.setPassword(""); postgresCredentials.setDatabase("postgres"); return postgresCredentials; } private static class CustomPostgresBinaryResolver implements PgBinaryResolver { /** * Loads specific embedded Postgres version. */ @Override public InputStream getPgBinary(String system, String architecture) throws IOException { ClassPathResource resource = new ClassPathResource(String.format("postgres-%s-%s.txz", system.toLowerCase(), architecture)); return resource.getInputStream(); } } }