Skip to content

Commit

Permalink
#1: PSQL tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jenetics committed Sep 11, 2019
1 parent 2c3be65 commit 85c2725
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 19 deletions.
1 change: 1 addition & 0 deletions jpx.jdbc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies {
testImplementation 'com.h2database:h2:1.4.193'
testImplementation 'mysql:mysql-connector-java:6.0.5'
testImplementation 'org.mariadb.jdbc:mariadb-java-client:2.4.3'
testImplementation 'org.postgresql:postgresql:42.2.7.jre7'
}

lombok {
Expand Down
38 changes: 19 additions & 19 deletions jpx.jdbc/src/test/java/io/jenetics/jpx/jdbc/GPXAccessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public class GPXAccessTest {
private final Random random = new Random(1231321);
private final GPX gpx = GPXTest.nextGPX(random);

//@BeforeClass
@BeforeClass
public void setup() throws IOException, SQLException {
final String[] queries = IO.
toSQLText(getClass().getResourceAsStream("/model-mysql.sql"))
.split(";");

MariaDB.INSTANCE.transaction(conn -> {
PSQLDB.INSTANCE.transaction(conn -> {
for (String query : queries) {
if (!query.trim().isEmpty()) {
try (Statement stmt = conn.createStatement()) {
Expand Down Expand Up @@ -103,7 +103,7 @@ public FileVisitResult visitFile(
});
}

//@Test
@Test
public void insert() throws SQLException, IOException {
final String dir = "/home/fwilhelm/Workspace/Documents/GPS";

Expand All @@ -121,25 +121,25 @@ public FileVisitResult visitFile(
{
final GPX gpx = fix(GPX.reader(Version.V10, Mode.LENIENT).read(file));

final Path export = Paths.get(
"/home/fwilhelm/Downloads/gpx/",
gpx.getMetadata().flatMap(Metadata::getName).orElse("null") + ".gpx"
);

GPX.writer(" ").write(gpx, export);
// final Path export = Paths.get(
// "/home/fwilhelm/Downloads/gpx/",
// gpx.getMetadata().flatMap(Metadata::getName).orElse("null") + ".gpx"
// );
//
// GPX.writer(" ").write(gpx, export);

System.out.println("Inserting: " + file);

// long start = System.currentTimeMillis();
// try {
// MariaDB.INSTANCE.transaction(conn -> {
// final Long id = GPXAccess.insert(gpx, conn);
// });
// } catch (SQLException e) {
// throw new IOException(e);
// }
// long stop = System.currentTimeMillis();
// System.out.println(format("%s: %s s", file, (stop - start)/1000.0));
long start = System.currentTimeMillis();
try {
PSQLDB.INSTANCE.transaction(conn -> {
final Long id = GPXAccess.insert(gpx, conn);
});
} catch (SQLException e) {
throw new IOException(e);
}
long stop = System.currentTimeMillis();
System.out.println(format("%s: %s s", file, (stop - start)/1000.0));
}
return FileVisitResult.CONTINUE;
}
Expand Down
43 changes: 43 additions & 0 deletions jpx.jdbc/src/test/java/io/jenetics/jpx/jdbc/PSQLDB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Java Genetic Algorithm Library (@__identifier__@).
* Copyright (c) @__year__@ Franz Wilhelmstötter
*
* Licensed 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.
*
* Author:
* Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
*/
package io.jenetics.jpx.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
* @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
* @version !__version__!
* @since !__version__!
*/
public class PSQLDB extends DB {

public final static DB INSTANCE = new PSQLDB();

private static final String TEST_DB =
"jdbc:postgresql://localhost/gpx_db?user=gpx_usr&password=gpx_pwd";

@Override
public Connection getConnection() throws SQLException {
return DriverManager.getConnection(TEST_DB);
}

}

0 comments on commit 85c2725

Please sign in to comment.