Skip to content

Commit 2fee4ad

Browse files
authored
Merge branch 'master' into dse/memoization
2 parents c943596 + 8d77e2d commit 2fee4ad

34 files changed

Lines changed: 1075 additions & 869 deletions

File tree

client-java/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<module>distance-heuristics</module>
2626
<module>test-utils-java</module>
2727
<module>test-old-libraries</module>
28+
<module>postgres-test-utils</module>
2829
</modules>
2930

3031
<licenses>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.evomaster</groupId>
7+
<artifactId>evomaster-client-java</artifactId>
8+
<version>6.1.2-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>evomaster-client-java-postgres-test-utils</artifactId>
12+
<packaging>jar</packaging>
13+
<name>${project.groupId}:${project.artifactId}</name>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.testcontainers</groupId>
18+
<artifactId>testcontainers</artifactId>
19+
<scope>compile</scope>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.junit.jupiter</groupId>
23+
<artifactId>junit-jupiter-engine</artifactId>
24+
</dependency>
25+
</dependencies>
26+
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>org.apache.maven.plugins</groupId>
31+
<artifactId>maven-compiler-plugin</artifactId>
32+
</plugin>
33+
</plugins>
34+
</build>
35+
36+
</project>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.evomaster.client.java.postgres.test.utils;
2+
3+
import org.testcontainers.containers.GenericContainer;
4+
import org.testcontainers.containers.wait.strategy.Wait;
5+
6+
import java.util.Collections;
7+
8+
/**
9+
* Shared utility for creating and configuring PostgreSQL Testcontainers instances.
10+
* Used across modules (client-java/sql, core, e2e tests) to avoid code duplication.
11+
*/
12+
public class PostgresContainerUtils {
13+
14+
/**
15+
* Default version of PostgreSQL used when none is explicitly specified.
16+
*/
17+
public static final String DEFAULT_POSTGRES_VERSION = "14";
18+
19+
/**
20+
* Creates a new PostgreSQL container using the default version ({@value DEFAULT_POSTGRES_VERSION}).
21+
*
22+
* @return A configured {@link GenericContainer} instance ready to be started.
23+
*/
24+
public static GenericContainer<?> newContainer() {
25+
return newContainer(DEFAULT_POSTGRES_VERSION);
26+
}
27+
28+
/**
29+
* Creates a new PostgreSQL container using the specified version.
30+
* The container is pre-configured with:
31+
* <ul>
32+
* <li>Port 5432 exposed</li>
33+
* <li>Temporary filesystem for the data directory (avoids disk I/O in tests)</li>
34+
* <li>{@code POSTGRES_HOST_AUTH_METHOD=trust} (no password required)</li>
35+
* <li>Readiness wait on the "database system is ready to accept connections" log message</li>
36+
* </ul>
37+
*
38+
* @param version The PostgreSQL Docker image version tag (e.g. {@code "14"}, {@code "17"}).
39+
* @return A configured {@link GenericContainer} instance ready to be started.
40+
*/
41+
public static GenericContainer<?> newContainer(String version) {
42+
return new GenericContainer<>("postgres:" + version)
43+
.withExposedPorts(5432)
44+
.withTmpFs(Collections.singletonMap("/var/lib/postgresql/data", "rw"))
45+
.withEnv("POSTGRES_HOST_AUTH_METHOD", "trust")
46+
/*
47+
* A call to getConnection() when the postgres container is still not ready
48+
* signals a PSQLException with message "FATAL: the database system is starting up".
49+
* See: https://github.com/testcontainers/testcontainers-java/issues/317
50+
*/
51+
.waitingFor(Wait.forLogMessage(".*database system is ready to accept connections.*\\s", 2));
52+
}
53+
54+
/**
55+
* Constructs a JDBC URL for a PostgreSQL database hosted in the given container.
56+
*
57+
* @param container A running PostgreSQL {@link GenericContainer} with port 5432 mapped.
58+
* @return JDBC URL of the form {@code jdbc:postgresql://<host>:<port>/postgres}.
59+
*/
60+
public static String getJdbcUrl(GenericContainer<?> container) {
61+
return "jdbc:postgresql://" + container.getHost() + ":" + container.getMappedPort(5432) + "/postgres";
62+
}
63+
}

client-java/sql/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<type>test-jar</type>
4141
<scope>test</scope>
4242
</dependency>
43+
<dependency>
44+
<groupId>org.evomaster</groupId>
45+
<artifactId>evomaster-client-java-postgres-test-utils</artifactId>
46+
<scope>test</scope>
47+
</dependency>
4348

4449
<dependency>
4550
<groupId>com.github.jsqlparser</groupId>

client-java/sql/src/main/java/org/evomaster/client/java/sql/internal/SqlColumnId.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* No case sensitive is considered when comparing column ids within
1111
* this class.
1212
*/
13-
public class SqlColumnId {
13+
public class SqlColumnId implements Comparable<SqlColumnId> {
1414

1515
private final String columnId;
1616

@@ -27,6 +27,11 @@ public String toString() {
2727
return columnId;
2828
}
2929

30+
@Override
31+
public int compareTo(SqlColumnId o) {
32+
return columnId.compareTo(o.columnId);
33+
}
34+
3035
public boolean equals(Object obj) {
3136
if (this == obj) {
3237
return true;

client-java/sql/src/test/java/org/evomaster/client/java/sql/DbInfoExtractorPostgresTest.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
11
package org.evomaster.client.java.sql;
22

33
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
4+
import org.evomaster.client.java.postgres.test.utils.PostgresContainerUtils;
45
import org.junit.jupiter.api.AfterAll;
56
import org.junit.jupiter.api.BeforeAll;
67
import org.junit.jupiter.api.BeforeEach;
78
import org.testcontainers.containers.GenericContainer;
89

910
import java.sql.Connection;
1011
import java.sql.DriverManager;
11-
import java.util.Collections;
1212

1313
public class DbInfoExtractorPostgresTest extends DbInfoExtractorTestBase {
1414

15-
private static final String POSTGRES_VERSION = "14";
16-
17-
private static final GenericContainer<?> postgres = new GenericContainer("postgres:" + POSTGRES_VERSION)
18-
.withExposedPorts(5432)
19-
.withTmpFs(Collections.singletonMap("/var/lib/postgresql/data", "rw"))
20-
.withEnv("POSTGRES_HOST_AUTH_METHOD","trust");
15+
private static final GenericContainer<?> postgres = PostgresContainerUtils.newContainer();
2116

2217
private static Connection connection;
2318

2419
@BeforeAll
2520
public static void initClass() throws Exception{
2621
postgres.start();
27-
String host = postgres.getHost();
28-
int port = postgres.getMappedPort(5432);
29-
String url = "jdbc:postgresql://"+host+":"+port+"/postgres";
30-
31-
connection = DriverManager.getConnection(url, "postgres", "");
22+
final String jdbcUrl = PostgresContainerUtils.getJdbcUrl(postgres);
23+
connection = DriverManager.getConnection(jdbcUrl, "postgres", "");
3224
}
3325

3426
@AfterAll

client-java/sql/src/test/java/org/evomaster/client/java/sql/QueryResultPostgresTest.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.evomaster.client.java.sql;
22

33
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
4+
import org.evomaster.client.java.postgres.test.utils.PostgresContainerUtils;
45
import org.junit.jupiter.api.AfterAll;
56
import org.junit.jupiter.api.BeforeAll;
67
import org.junit.jupiter.api.BeforeEach;
@@ -9,30 +10,21 @@
910

1011
import java.sql.Connection;
1112
import java.sql.DriverManager;
12-
import java.util.Collections;
1313

1414
import static org.junit.jupiter.api.Assertions.assertEquals;
1515
import static org.junit.jupiter.api.Assertions.assertTrue;
1616

1717
public class QueryResultPostgresTest extends QueryResultTestBase {
1818

19-
private static final String POSTGRES_VERSION = "14";
20-
21-
private static final GenericContainer<?> postgres = new GenericContainer("postgres:" + POSTGRES_VERSION)
22-
.withExposedPorts(5432)
23-
.withTmpFs(Collections.singletonMap("/var/lib/postgresql/data", "rw"))
24-
.withEnv("POSTGRES_HOST_AUTH_METHOD","trust");
19+
private static final GenericContainer<?> postgres = PostgresContainerUtils.newContainer();
2520

2621
private static Connection connection;
2722

2823
@BeforeAll
2924
public static void initClass() throws Exception{
3025
postgres.start();
31-
String host = postgres.getHost();
32-
int port = postgres.getMappedPort(5432);
33-
String url = "jdbc:postgresql://"+host+":"+port+"/postgres";
34-
35-
connection = DriverManager.getConnection(url, "postgres", "");
26+
final String jdbcUrl = PostgresContainerUtils.getJdbcUrl(postgres);
27+
connection = DriverManager.getConnection(jdbcUrl, "postgres", "");
3628
}
3729

3830
@AfterAll

client-java/sql/src/test/java/org/evomaster/client/java/sql/cleaner/DbCleanerPostgresTest.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
44
import org.evomaster.client.java.sql.DbCleaner;
5+
import org.evomaster.client.java.postgres.test.utils.PostgresContainerUtils;
56
import org.evomaster.client.java.sql.SqlScriptRunner;
67
import org.junit.jupiter.api.AfterAll;
78
import org.junit.jupiter.api.BeforeAll;
@@ -10,31 +11,22 @@
1011

1112
import java.sql.Connection;
1213
import java.sql.DriverManager;
13-
import java.util.Collections;
1414
import java.util.List;
1515

1616
/**
1717
* Created by arcuri82 on 08-Apr-19.
1818
*/
1919
public class DbCleanerPostgresTest extends DbCleanerTestBase{
2020

21-
private static final String POSTGRES_VERSION = "14";
22-
23-
private static final GenericContainer postgres = new GenericContainer("postgres:" + POSTGRES_VERSION)
24-
.withExposedPorts(5432)
25-
.withTmpFs(Collections.singletonMap("/var/lib/postgresql/data", "rw"))
26-
.withEnv("POSTGRES_HOST_AUTH_METHOD","trust");
21+
private static final GenericContainer<?> postgres = PostgresContainerUtils.newContainer();
2722

2823
private static Connection connection;
2924

3025
@BeforeAll
3126
public static void initClass() throws Exception{
3227
postgres.start();
33-
String host = postgres.getContainerIpAddress();
34-
int port = postgres.getMappedPort(5432);
35-
String url = "jdbc:postgresql://"+host+":"+port+"/postgres";
36-
37-
connection = DriverManager.getConnection(url, "postgres", "");
28+
final String jdbcUrl = PostgresContainerUtils.getJdbcUrl(postgres);
29+
connection = DriverManager.getConnection(jdbcUrl, "postgres", "");
3830
}
3931

4032
@AfterAll

client-java/sql/src/test/java/org/evomaster/client/java/sql/h2/SqlHandlerGetDistanceH2Test.java renamed to client-java/sql/src/test/java/org/evomaster/client/java/sql/h2/SqlHandlerGetDistanceCompleteHeuristicH2Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
44
import org.evomaster.client.java.sql.SqlScriptRunner;
5-
import org.evomaster.client.java.sql.heuristic.SqlHandlerGetDistanceTestBase;
5+
import org.evomaster.client.java.sql.heuristic.SqlHandlerGetDistanceCompleteHeuristicTestBase;
66
import org.junit.jupiter.api.AfterAll;
77
import org.junit.jupiter.api.BeforeAll;
88

@@ -11,7 +11,7 @@
1111
import java.sql.DriverManager;
1212
import java.sql.SQLException;
1313

14-
public class SqlHandlerGetDistanceH2Test extends SqlHandlerGetDistanceTestBase {
14+
public class SqlHandlerGetDistanceCompleteHeuristicH2Test extends SqlHandlerGetDistanceCompleteHeuristicTestBase {
1515

1616
private static Connection connection;
1717

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.evomaster.client.java.sql.h2;
2+
3+
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
4+
import org.evomaster.client.java.sql.SqlScriptRunner;
5+
import org.evomaster.client.java.sql.heuristic.SqlHandlerGetDistancePartialHeuristicTestBase;
6+
import org.junit.jupiter.api.AfterAll;
7+
import org.junit.jupiter.api.BeforeAll;
8+
9+
import java.sql.Connection;
10+
import java.sql.DriverManager;
11+
import java.sql.SQLException;
12+
13+
public class SqlHandlerGetDistancePartialHeuristicH2Test extends SqlHandlerGetDistancePartialHeuristicTestBase {
14+
15+
private static Connection connection;
16+
17+
@Override
18+
protected Connection getConnection() {
19+
return connection;
20+
}
21+
22+
@Override
23+
protected DatabaseType getDbType() {
24+
return DatabaseType.H2;
25+
}
26+
27+
@BeforeAll
28+
public static void initClass() throws Exception {
29+
connection = DriverManager.getConnection("jdbc:h2:mem:db_test_partial", "sa", "");
30+
}
31+
32+
@AfterAll
33+
public static void afterClass() throws Exception {
34+
connection.close();
35+
}
36+
37+
@Override
38+
protected void clearDatabase() throws SQLException {
39+
SqlScriptRunner.execCommand(getConnection(), "DROP ALL OBJECTS;");
40+
}
41+
}

0 commit comments

Comments
 (0)