Skip to content

Commit 21ca081

Browse files
authored
Merge branch 'master' into FixedPort
2 parents 9f03423 + ba7955b commit 21ca081

File tree

4 files changed

+15
-27
lines changed

4 files changed

+15
-27
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test with a "real" Postgres without requiring end users to install and set up a
99

1010

1111
The release of 1.0 brings major changes to the innards of this library.
12-
Previous pre 1.x versions used an embedded tarball. This was extemely fast (a major plus), but we switched to a docker based version
12+
Previous pre 1.x versions used an embedded tarball. This was extremely fast (a major plus), but we switched to a docker based version
1313
for these reasons:
1414

1515
Advantages
@@ -20,7 +20,7 @@ Advantages
2020
* You need a tarball for every linux distribution as PG 10+ no longer ship a "universal binary" for linux. This means a lot of support and maintenance work.
2121
* Easy to switch docker image tag to upgrade versions - no need for a whole new pg-embedded version.
2222
* More maintainable and secure (you can pull docker images you trust, instead of trusting our tarballs running in your security context)
23-
* Trivial to do a build oneself based on the official Postgres image adding extensions, setup scripts etc - see https://github.com/docker-library/docs/blob/master/postgres/README.md for details.
23+
* Trivial to do a build oneself based on the official Postgres image adding extensions, setup scripts etc. - see https://github.com/docker-library/docs/blob/master/postgres/README.md for details.
2424

2525
Admittedly, a few disadvantages
2626
---
@@ -53,7 +53,7 @@ public SingleInstancePostgresRule pg = EmbeddedPostgresRules.singleInstance();
5353

5454
This simply has JUnit manage an instance of EmbeddedPostgres (start, stop). You can then use this to get a DataSource with: `pg.getEmbeddedPostgres().getPostgresDatabase();`
5555

56-
Additionally you may use the [`EmbeddedPostgres`](src/main/java/com/opentable/db/postgres/embedded/EmbeddedPostgres.java) class directly by manually starting and stopping the instance; see [`EmbeddedPostgresTest`](src/test/java/com/opentable/db/postgres/embedded/EmbeddedPostgresTest.java) for an example.
56+
Additionally, you may use the [`EmbeddedPostgres`](src/main/java/com/opentable/db/postgres/embedded/EmbeddedPostgres.java) class directly by manually starting and stopping the instance; see [`EmbeddedPostgresTest`](src/test/java/com/opentable/db/postgres/embedded/EmbeddedPostgresTest.java) for an example.
5757

5858
Default username/password is: postgres/postgres and the default database is 'postgres'
5959

@@ -97,7 +97,7 @@ independent databases gives you.
9797

9898
## Postgres version
9999

100-
The default is to use the docker hub registry and pull a tag, hardcoded in `EmbeddedPostgres`. Currently this is "13-latest",
100+
The default is to use the docker hub registry and pull a tag, hardcoded in `EmbeddedPostgres`. Currently, this is "13-latest",
101101
as this fits the needs of OpenTable, however you can change this easily. This is super useful, both to use a newer version
102102
of Postgres, or to build your own DockerFile with additional extensions.
103103

@@ -132,7 +132,7 @@ the network.
132132

133133
## Using JUnit5
134134

135-
JUnit5 does not have `@Rule`. So below is an example for how to create tests using JUnit5 and embedded postgress, it creates a Spring context and uses JDBI:
135+
JUnit5 does not have `@Rule`. So below is an example for how to create tests using JUnit5 and embedded postgres, it creates a Spring context and uses JDBI:
136136

137137
```java
138138
@ExtendWith(SpringExtension.class)
@@ -158,7 +158,7 @@ class DaoTestUsingJunit5 {
158158
}
159159

160160
/**
161-
* This class is here as inner class for brevity
161+
* This class is here as inner class for brevity,
162162
* but it's better to have only one for all tests.
163163
*/
164164
@Configuration
@@ -232,14 +232,14 @@ But certainly there's no real reason you can't use TestContainers directly - the
232232

233233
* Why not _use a maven plugin approach like fabric8-docker-maven?
234234

235-
Honestly I suspect this is a better approach in that it doesn't try to maintain it's own version of the Docker API, and
236-
runs outside the tests, reducing issues like forking and threading conflicts. However it would have been too major an overhaul
235+
Honestly I suspect this is a better approach in that it doesn't try to maintain its own version of the Docker API, and
236+
runs outside the tests, reducing issues like forking and threading conflicts. However, it would have been too major an overhaul
237237
for our users.
238238

239239
* "I really prefer the old embedded postgres approach. It's faster."
240240
* We recommend those who prefer the embedded tarball use https://github.com/zonkyio/embedded-postgres which was forked a couple
241-
years ago from the embedded branch and is kept reasonably up to date.
242-
* Another alternative is flapdoodle's embedded postgres.
241+
of years ago from the embedded branch and is kept reasonably up to date.
242+
* Another alternative is Flapdoodle's embedded postgres, but that is deprecated in favor of testcontainers too.
243243

244244
Both libraries suffer from many of the cons that bedeviled upkeep of this library for years, but they are certainly viable options
245245
for many.

src/main/java/com/opentable/db/postgres/embedded/DatabaseConnectionPreparer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import javax.sql.DataSource;
2020

2121
/**
22-
* Provides a default implementation of the DatabasePreparer, and adds an additional
22+
* Provides a default implementation of the DatabasePreparer, and adds a
2323
* method
2424
*/
2525
public interface DatabaseConnectionPreparer extends DatabasePreparer {

src/main/java/com/opentable/db/postgres/embedded/EmbeddedPostgres.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class EmbeddedPostgres implements Closeable {
5959
// 1) If this is defined, then it's assumed this contains the full image and tag...
6060
static final String ENV_DOCKER_IMAGE="PG_FULL_IMAGE";
6161
// 2)Otherwise if this is defined, we'll use this as the prefix, and combine with the DOCKER_DEFAULT_TAG below
62-
// This is already used in TestContainers as a env var, so it's useful to reuse for consistency.
62+
// This is already used in TestContainers as an env var, so it's useful to reuse for consistency.
6363
static final String ENV_DOCKER_PREFIX = "TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX";
6464
// 3) Otherwise we'll just pull from docker hub with the DOCKER_DEFAULT_TAG
6565
static final DockerImageName DOCKER_DEFAULT_IMAGE_NAME = DockerImageName.parse(POSTGRES);
@@ -70,19 +70,6 @@ public class EmbeddedPostgres implements Closeable {
7070

7171
private final UUID instanceId = UUID.randomUUID();
7272

73-
74-
EmbeddedPostgres(Map<String, String> postgresConfig,
75-
Map<String, String> localeConfig,
76-
Map<String, BindMount> bindMounts,
77-
Optional<Network> network,
78-
Optional<String> networkAlias,
79-
OptionalInt fixedPort,
80-
DockerImageName image,
81-
String databaseName
82-
) {
83-
this(postgresConfig, localeConfig, bindMounts, network, networkAlias, fixedPort, image, DEFAULT_PG_STARTUP_WAIT, databaseName);
84-
}
85-
8673
EmbeddedPostgres(Map<String, String> postgresConfig,
8774
Map<String, String> localeConfig,
8875
Map<String, BindMount> bindMounts,
@@ -226,6 +213,7 @@ public String getPassword() {
226213
return postgreSQLContainer.getPassword();
227214
}
228215

216+
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
229217
public static class Builder {
230218
private final Map<String, String> config = new HashMap<>();
231219
private final Map<String, String> localeConfig = new HashMap<>();
@@ -315,7 +303,7 @@ public Builder setBindMount(BindMount bindMount) {
315303
}
316304

317305
/**
318-
* Set up a shared network and the alias. This is useful if you have multiple containers
306+
* Set up a shared network and the alias. This is useful if you have multiple containers,
319307
* and they need to communicate with each other.
320308
* @param network The Network. Usually Network.Shared.
321309
* @param networkAlias an alias by which other containers in the network can refer to this container

src/main/java/com/opentable/db/postgres/embedded/LiquibasePreparer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private LiquibasePreparer(String location, Contexts contexts) {
5151

5252
@Override
5353
public void prepare(DataSource ds) throws SQLException {
54-
try (Connection connection = ds.getConnection();){
54+
try (Connection connection = ds.getConnection()){
5555

5656
Database database = getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
5757
Liquibase liquibase = new Liquibase(location, new ClassLoaderResourceAccessor(), database); //NOPMD

0 commit comments

Comments
 (0)