diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 00000000..c9b2105b
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,10 @@
+version: 2
+updates:
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ schedule:
+ interval: "weekly"
+ - package-ecosystem: "maven"
+ directory: "/"
+ schedule:
+ interval: "weekly"
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 41d21ab6..096409a0 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
@@ -17,7 +17,7 @@ jobs:
git config user.name "Zonky Bot"
git config user.email "bot@zonky.com"
- name: Set up JDK
- uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 8
@@ -32,4 +32,4 @@ jobs:
MAVEN_USER: ${{ secrets.MAVEN_USER }}
MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
SIGNING_PASS: ${{ secrets.SIGNING_PASS }}
- run: mvn -B release:prepare release:perform -DreleaseVersion=$RELEASE_VERSION
\ No newline at end of file
+ run: mvn -B release:prepare release:perform -DreleaseVersion=$RELEASE_VERSION
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index e0faa4f9..84b53f3a 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -6,12 +6,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- java: [8, 11, 13, 15, 17, 18, 19]
+ java: [8, 11, 17, 21, 22] # LTS and newer versions
steps:
- name: Checkout project
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
- name: Set up JDK
- uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}
diff --git a/README.md b/README.md
index 72f5c3a2..54d91e0a 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,9 @@
## Introduction
-This project is a fork of [OpenTable Embedded PostgreSQL Component](https://github.com/opentable/otj-pg-embedded) created due to inactivity of maintainers.
+This project is a fork of [OpenTable Embedded PostgreSQL Component](https://github.com/opentable/otj-pg-embedded) created back in 2018. The original
+project continues, but with a very different philosophy - wrapping the postgres instance in a docker container.
+Whereas this project follows the original approach of using native postgres binaries running directly on the target platform without the overhead of virtualization.
The library allows embedding PostgreSQL into Java application code with no external dependencies.
Excellent for allowing you to unit test with a "real" Postgres without requiring end users to install and set up a database cluster.
@@ -24,12 +26,12 @@ Add the following Maven dependency:
io.zonky.test
embedded-postgres
- 2.0.6
+ 2.1.0
test
```
-The default version of the embedded postgres is `PostgreSQL 14.10`, but you can change it by following the instructions described in [Postgres version](#postgres-version).
+The default version of the embedded postgres is `PostgreSQL 14.15`, but you can change it by following the instructions described in [Postgres version](#postgres-version).
## Basic Usage
@@ -71,7 +73,7 @@ independent databases gives you.
## Postgres version
-The default version of the embedded postgres is `PostgreSQL 14.10`, but it can be changed by importing `embedded-postgres-binaries-bom` in a required version into your dependency management section.
+The default version of the embedded postgres is `PostgreSQL 14.15`, but it can be changed by importing `embedded-postgres-binaries-bom` in a required version into your dependency management section.
```xml
@@ -79,7 +81,7 @@ The default version of the embedded postgres is `PostgreSQL 14.10`, but it can b
io.zonky.test.postgres
embedded-postgres-binaries-bom
- 16.1.0
+ 17.2.0
pom
import
@@ -97,7 +99,7 @@ The default version of the embedded postgres is `PostgreSQL 14.10`, but it can b
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'io.zonky.test.postgres') {
- details.useVersion '16.1.0'
+ details.useVersion '17.2.0'
}
}
}
@@ -105,7 +107,7 @@ The default version of the embedded postgres is `PostgreSQL 14.10`, but it can b
2. If you use Gradle 5+, [Maven BOMs are supported out of the box](https://docs.gradle.org/5.0/userguide/managing_transitive_dependencies.html#sec:bom_import), so you can import the bom:
dependencies {
- testImplementation enforcedPlatform('io.zonky.test.postgres:embedded-postgres-binaries-bom:16.1.0')
+ testImplementation enforcedPlatform('io.zonky.test.postgres:embedded-postgres-binaries-bom:17.2.0')
}
3. Or, you can use [Spring's dependency management plugin](https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/#dependency-management-configuration-bom-import) that provides Maven-like dependency management to Gradle:
@@ -116,7 +118,7 @@ The default version of the embedded postgres is `PostgreSQL 14.10`, but it can b
dependencyManagement {
imports {
- mavenBom 'io.zonky.test.postgres:embedded-postgres-binaries-bom:16.1.0'
+ mavenBom 'io.zonky.test.postgres:embedded-postgres-binaries-bom:17.2.0'
}
}
@@ -210,5 +212,8 @@ Below are some examples of how to prepare a docker image running with a non-root
+
+If the above do not resolve your error, verify that the correct locales are available in your container. For example, many variants of AlmaLinux:9 do not come with `glibc-langpack-en`. This will lead to misleading errors during `initdb`. Additionally, you can optionally set your locale with `setLocaleConfig()` when building your EmbeddedPostgres instance.
+
## License
The project is released under version 2.0 of the [Apache License](http://www.apache.org/licenses/LICENSE-2.0.html).
diff --git a/pom.xml b/pom.xml
index 0f05991a..9e4b59ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,7 +18,7 @@
io.zonky.test
embedded-postgres
- 2.0.6
+ 2.1.1-SNAPSHOT
embedded-postgres
Embedded PostgreSQL Server
@@ -30,7 +30,27 @@
UTF-8
UTF-8
- 14.10.1
+ 14.15.0
+ 1.17.1
+ 1.26.2
+ 2.16.1
+ 3.15.0
+ 9.22.3
+ 5.10.5
+ 4.13.2
+ 4.30.0
+ 4.11.0
+ 7.4.0
+ 42.7.4
+ 1.7.36
+ 1.10
+ 3.5.0
+ 1.6
+ 3.8.0
+ 3.24.0
+ 3.1.1
+ 3.3.1
+ 3.3.1
https://github.com/zonkyio/embedded-postgres
@@ -39,7 +59,7 @@
scm:git:https://github.com/zonkyio/embedded-postgres.git
scm:git:https://github.com/zonkyio/embedded-postgres.git
https://github.com/zonkyio/embedded-postgres
- v2.0.6
+ HEAD
@@ -71,6 +91,37 @@
+
+
+
+ commons-io
+ commons-io
+ ${commons-io.version}
+
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
+
+ org.apache.commons
+ commons-compress
+ ${commons-compress.version}
+
+
+ commons-codec
+ commons-codec
+ ${commons-codec.version}
+
+
+ org.junit
+ junit-bom
+ ${junit5.version}
+ pom
+ import
+
+
+
io.zonky.test.postgres
@@ -100,100 +151,117 @@
org.slf4j
slf4j-api
- 1.7.36
+ ${slf4j.version}
org.apache.commons
commons-lang3
- 3.12.0
org.apache.commons
commons-compress
- 1.21
org.tukaani
xz
- 1.9
+ ${xz.version}
commons-io
commons-io
- 2.11.0
commons-codec
commons-codec
- 1.15
org.flywaydb
flyway-core
- 7.15.0
+ ${flyway.version}
true
org.liquibase
liquibase-core
- 4.10.0
+ ${liquibase.version}
true
org.postgresql
postgresql
- 42.3.5
+ ${postgresql.version}
junit
junit
- 4.13.2
+ ${junit4.version}
provided
true
org.junit.jupiter
junit-jupiter-api
- 5.8.2
provided
true
org.junit.vintage
junit-vintage-engine
- 5.8.2
test
org.junit.jupiter
junit-jupiter-engine
- 5.8.2
test
org.slf4j
slf4j-simple
- 1.7.36
+ ${slf4j.version}
test
org.mockito
mockito-core
- 3.12.4
+ ${mockito.version}
test
+
+ org.apache.maven.plugins
+ maven-enforcer-plugin
+ ${maven-enforcer-plugin.version}
+
+
+ enforce-versions
+ validate
+
+ enforce
+
+
+
+
+
+
+
+
+
maven-surefire-plugin
- 2.22.2
+ ${maven-surefire-plugin.version}
+
+
+ ${env.LC_ALL}
+
+
maven-pmd-plugin
- 3.13.0
+ ${maven-pmd-plugin.version}
verify
@@ -206,13 +274,13 @@
net.sourceforge.pmd
pmd-core
- 6.55.0
+ ${pmd.version}
compile
net.sourceforge.pmd
pmd-java
- 6.55.0
+ ${pmd.version}
compile
@@ -220,7 +288,7 @@
false
true
1.8
- UTF-8
+ UTF-8
100
4
@@ -228,7 +296,7 @@
org.apache.maven.plugins
maven-source-plugin
- 3.2.1
+ ${maven-source-plugin.version}
attach-sources
@@ -241,7 +309,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 3.2.0
+ ${maven-javadoc-plugin.version}
attach-javadocs
@@ -257,7 +325,7 @@
org.apache.maven.plugins
maven-release-plugin
- 2.5.3
+ ${maven-release-plugin.version}
false
release
@@ -268,6 +336,21 @@
+
+
+ default-lc-all
+
+
+ !env.LC_ALL
+
+
+ Unix
+
+
+
+ en_US.UTF-8
+
+
release
@@ -275,7 +358,7 @@
org.apache.maven.plugins
maven-gpg-plugin
- 1.6
+ ${maven-gpg-plugin.version}
sign-artifacts
diff --git a/src/main/java/io/zonky/test/db/postgres/embedded/EmbeddedPostgres.java b/src/main/java/io/zonky/test/db/postgres/embedded/EmbeddedPostgres.java
index ed67769e..9e6b0c0d 100644
--- a/src/main/java/io/zonky/test/db/postgres/embedded/EmbeddedPostgres.java
+++ b/src/main/java/io/zonky/test/db/postgres/embedded/EmbeddedPostgres.java
@@ -108,6 +108,7 @@ public class EmbeddedPostgres implements Closeable
private final ProcessBuilder.Redirect errorRedirector;
private final ProcessBuilder.Redirect outputRedirector;
+ private final Process process;
EmbeddedPostgres(File parentDirectory, File dataDirectory, boolean cleanDataDirectory,
Map postgresConfig, Map localeConfig, int port, Map connectConfig,
@@ -158,7 +159,11 @@ public class EmbeddedPostgres implements Closeable
}
lock();
- startPostmaster();
+ this.process = startPostmaster();
+ }
+
+ public Process getProcess() {
+ return this.process;
}
public DataSource getTemplateDatabase()
@@ -220,7 +225,7 @@ Map getConnectConfig()
private static int detectPort() throws IOException
{
try (ServerSocket socket = new ServerSocket(0)) {
- while(!socket.isBound()) {
+ while (!socket.isBound()) {
Thread.sleep(50);
}
return socket.getLocalPort();
@@ -251,7 +256,7 @@ private void initdb()
LOG.info("{} initdb completed in {}", instanceId, watch);
}
- private void startPostmaster() throws IOException
+ private Process startPostmaster() throws IOException
{
final StopWatch watch = new StopWatch();
watch.start();
@@ -283,6 +288,7 @@ private void startPostmaster() throws IOException
Runtime.getRuntime().addShutdownHook(newCloserThread());
waitForServerStartup(watch);
+ return postmaster;
}
private List createInitOptions()
@@ -803,23 +809,19 @@ private static File prepareBinaries(PgBinaryResolver pgBinaryResolver, File over
mkdirs(pgDir);
workingDirectory.setWritable(true, false);
- final File unpackLockFile = new File(pgDir, LOCK_FILE_NAME);
final File pgDirExists = new File(pgDir, ".exists");
if (!isPgBinReady(pgDirExists)) {
+ File unpackLockFile = new File(pgDir, LOCK_FILE_NAME);
try (FileOutputStream lockStream = new FileOutputStream(unpackLockFile);
FileLock unpackLock = lockStream.getChannel().tryLock()) {
if (unpackLock != null) {
- try {
- LOG.info("Extracting Postgres...");
- try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) {
- extractTxz(bais, pgDir);
- }
- if (!pgDirExists.createNewFile()) {
- pgDirExists.setLastModified(System.currentTimeMillis());
- }
- } catch (Exception e) {
- LOG.error("while unpacking Postgres", e);
+ LOG.info("Extracting Postgres...");
+ try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) {
+ extractTxz(bais, pgDir);
+ }
+ if (!pgDirExists.createNewFile()) {
+ pgDirExists.setLastModified(System.currentTimeMillis());
}
} else {
// the other guy is unpacking for us.
@@ -838,6 +840,7 @@ private static File prepareBinaries(PgBinaryResolver pgBinaryResolver, File over
}
}
} catch (final IOException | NoSuchAlgorithmException e) {
+ LOG.error("Got error while unpacking Postgres", e);
throw new ExceptionInInitializerError(e);
} catch (final InterruptedException ie) {
Thread.currentThread().interrupt();
diff --git a/src/main/resources/sh/detect_linux_distribution.sh b/src/main/resources/sh/detect_linux_distribution.sh
index 2ef4f015..8304880a 100644
--- a/src/main/resources/sh/detect_linux_distribution.sh
+++ b/src/main/resources/sh/detect_linux_distribution.sh
@@ -12,7 +12,7 @@ detect_linux_distribution() {
else
DISTRO=''
fi
- echo $DISTRO
+ echo "$DISTRO"
}
-echo $(detect_linux_distribution)
\ No newline at end of file
+detect_linux_distribution