Skip to content

Commit

Permalink
Fix ports in service test and add to action
Browse files Browse the repository at this point in the history
  • Loading branch information
SandroNeumann committed Sep 8, 2023
1 parent 515ce31 commit b988658
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build-gradle-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ jobs:
build-gradle-project:
runs-on: ubuntu-latest
services:
postgis:
postgis-first:
image: mdillon/postgis:9.6
ports:
- 49153:5432
postgis-second:
image: mdillon/postgis:9.6
ports:
- 49154:5432
steps:
- name: Checkout project sources
uses: actions/checkout@v3
Expand Down
12 changes: 12 additions & 0 deletions pub-service-test-postgis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '2'

services:
postgis-test-first:
image: mdillon/postgis:9.6
ports:
- "127.0.0.1:49153:5432"

postgis-test-second:
image: mdillon/postgis:9.6
ports:
- "127.0.0.1:49154:5432"
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ public void onReceive(Object msg) throws Exception {

@BeforeClass
public static void testServers() throws Exception {
h = new GeoServerTestHelper();
String dbPort = "49154";
h = new GeoServerTestHelper(dbPort);
h.start();

Connection connection = DriverManager.getConnection("jdbc:postgresql://" + h.getDbHost() + ":" + h.getDbPort() + "/test", "postgres", "postgres");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ public class GeoServerTestHelper {

private static final String DB_HOST = "localhost";

private static final String DB_PORT = "49153";
private String dbPort;

private Server jettyServer;

private DocumentBuilder documentBuilder;

private XPath xpath;

public GeoServerTestHelper() throws Exception {
public GeoServerTestHelper(String dbPort) throws Exception {
this.dbPort = dbPort;

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
documentBuilder = dbf.newDocumentBuilder();
Expand Down Expand Up @@ -98,7 +100,7 @@ public void start() throws Exception {
for(int i = 60; i >= 0; i--) {
Thread.sleep(1000);

try(Connection c = DriverManager.getConnection("jdbc:postgresql://" + DB_HOST + ":" + DB_PORT + "/postgres", "postgres", "postgres");
try(Connection c = DriverManager.getConnection("jdbc:postgresql://" + DB_HOST + ":" + dbPort + "/postgres", "postgres", "postgres");
Statement stmt = c.createStatement()) {
stmt.execute("create database \"test\"");
break;
Expand All @@ -109,7 +111,7 @@ public void start() throws Exception {
}
}

try(Connection c = DriverManager.getConnection("jdbc:postgresql://" + DB_HOST + ":" + DB_PORT + "/test", "postgres", "postgres");
try(Connection c = DriverManager.getConnection("jdbc:postgresql://" + DB_HOST + ":" + dbPort + "/test", "postgres", "postgres");
Statement stmt = c.createStatement()) {
stmt.execute("create extension postgis");
} catch(Exception e) {
Expand Down Expand Up @@ -169,7 +171,7 @@ public void start() throws Exception {

BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("org.postgresql.Driver");
ds.setUrl("jdbc:postgresql://" + DB_HOST + ":" + DB_PORT + "/test");
ds.setUrl("jdbc:postgresql://" + DB_HOST + ":" + dbPort + "/test");
ds.setUsername("postgres");
ds.setPassword("postgres");

Expand Down Expand Up @@ -285,7 +287,7 @@ public void clean(FutureUtils f, LoggingAdapter log) throws Exception {
}

public String getDbPort() {
return DB_PORT;
return dbPort;
}

public String getDbHost() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public void cleanDb() throws Exception {

@BeforeClass
public static void startServers() throws Exception {
h = new GeoServerTestHelper();
String dbPort = "49153";
h = new GeoServerTestHelper(dbPort);
h.start();

Config akkaConfig = ConfigFactory.empty()
Expand Down

0 comments on commit b988658

Please sign in to comment.