11package io .vertx .pgclient ;
22
33
4- import io .vertx .core .*;
4+ import io .vertx .core .CompositeFuture ;
5+ import io .vertx .core .Future ;
6+ import io .vertx .core .Vertx ;
57import io .vertx .ext .unit .junit .VertxUnitRunner ;
68import io .vertx .sqlclient .Cursor ;
79import io .vertx .sqlclient .Tuple ;
10+ import org .apache .commons .compress .utils .IOUtils ;
811import org .junit .After ;
912import org .junit .Before ;
1013import org .junit .Test ;
1114import org .junit .runner .RunWith ;
1215import org .testcontainers .Testcontainers ;
1316import org .testcontainers .containers .FixedHostPortGenericContainer ;
1417import org .testcontainers .containers .GenericContainer ;
15- import org .testcontainers .utility .DockerImageName ;
16-
17- import java .util .*;
18+ import org .testcontainers .images .builder .ImageFromDockerfile ;
19+ import org .testcontainers .images .builder .Transferable ;
20+
21+ import java .io .IOException ;
22+ import java .io .InputStream ;
23+ import java .util .ArrayList ;
24+ import java .util .Arrays ;
25+ import java .util .List ;
1826import java .util .concurrent .TimeUnit ;
1927import java .util .stream .Collectors ;
2028
2129import static org .junit .Assert .assertEquals ;
30+ import static org .testcontainers .containers .BindMode .READ_ONLY ;
2231
2332@ RunWith (VertxUnitRunner .class )
2433public class PgBouncerTest {
@@ -39,21 +48,15 @@ public void setUp() {
3948 pgContainer .withNetworkAliases ("foo" );
4049 pgContainer .start ();
4150 Integer pgPort = pgContainer .getFirstMappedPort ();
42- String pgHost = pgContainer .getHost ();
4351
4452 Testcontainers .exposeHostPorts (pgPort );
4553
46-
47- pgBouncerContainer = new GenericContainer (DockerImageName .parse ("bitnamilegacy/pgbouncer:1.20.1-debian-11-r30" ));
48- pgBouncerContainer .withEnv ("POSTGRESQL_USERNAME" , "postgres" );
49- pgBouncerContainer .withEnv ("POSTGRESQL_PASSWORD" , "postgres" );
50- pgBouncerContainer .withEnv ("POSTGRESQL_DATABASE" , "postgres" );
51- pgBouncerContainer .withEnv ("POSTGRESQL_HOST" , "host.testcontainers.internal" );
52- pgBouncerContainer .withEnv ("POSTGRESQL_PORT" , "" + pgPort );
53- pgBouncerContainer .withEnv ("PGBOUNCER_IGNORE_STARTUP_PARAMETERS" , "extra_float_digits" );
54- pgBouncerContainer .withEnv ("PGBOUNCER_POOL_MODE" , "transaction" );
55- pgBouncerContainer .withEnv ("PGBOUNCER_MAX_DB_CONNECTIONS" , "2" );
56- pgBouncerContainer .withExposedPorts (6432 );
54+ pgBouncerContainer = new GenericContainer <>(
55+ new ImageFromDockerfile ()
56+ .withFileFromTransferable ("Dockerfile" , resourceTransferable ("pgBouncer/Dockerfile" )))
57+ .withClasspathResourceMapping ("pgBouncer/pgbouncer.ini" , "/etc/pgbouncer/pgbouncer.ini" , READ_ONLY )
58+ .withClasspathResourceMapping ("pgBouncer/userlist.txt" , "/etc/pgbouncer/userlist.txt" , READ_ONLY )
59+ .withExposedPorts (6432 );
5760 pgBouncerContainer .start ();
5861 Integer bouncerPort = pgBouncerContainer .getFirstMappedPort ();
5962 String bouncerHost = pgBouncerContainer .getHost ();
@@ -70,6 +73,15 @@ public void setUp() {
7073 vertx = Vertx .vertx ();
7174 }
7275
76+ private static Transferable resourceTransferable (String resourceName ) {
77+ try (InputStream stream = PgBouncerTest .class .getClassLoader ().getResourceAsStream (resourceName )) {
78+ assert stream != null ;
79+ return Transferable .of (IOUtils .toByteArray (stream ));
80+ } catch (IOException e ) {
81+ throw new RuntimeException (e );
82+ }
83+ }
84+
7385 @ After
7486 public void tearDown () throws Exception {
7587 Testcontainers .exposeHostPorts ();
0 commit comments