-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleJUnit5Test.java
More file actions
62 lines (55 loc) · 1.97 KB
/
SampleJUnit5Test.java
File metadata and controls
62 lines (55 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package nl.wouterh.pgpool.junit5.example;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import lombok.extern.slf4j.Slf4j;
import nl.wouterh.pgpool.PooledDatabase;
import nl.wouterh.pgpool.PgPoolConfig;
import nl.wouterh.pgpool.common.example.CommonTestContainers;
import nl.wouterh.pgpool.common.example.ExampleTableCreator;
import nl.wouterh.pgpool.common.example.ExampleTableFiller;
import nl.wouterh.pgpool.junit5.PgPoolExtension;
import nl.wouterh.pgpool.testcontainers.PostgreSQLContainerConnectionProvider;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.testcontainers.utility.TestcontainersConfiguration;
@Slf4j
public class SampleJUnit5Test {
static {
CommonTestContainers.postgres.start();
}
@RegisterExtension
public static final PgPoolExtension pgPoolExtension = new PgPoolExtension(
PgPoolConfig.builder()
.connectionProvider(new PostgreSQLContainerConnectionProvider(CommonTestContainers.postgres))
.waitForDropOnShutdown(
TestcontainersConfiguration.getInstance().environmentSupportsReuse())
.pooledDatabase(PooledDatabase.builder()
.name("db1")
.createThreads(2)
.spares(5)
.initializer(new ExampleTableCreator())
.initializer(new ExampleTableFiller())
.build())
.pooledDatabase(PooledDatabase.builder()
.name("db2")
.build())
.build());
private void test() throws Exception {
try (Connection connection = pgPoolExtension.createConnection("db1")) {
try (Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT current_database()")) {
rs.next();
log.info("{}", rs.getString(1));
}
}
}
@Test
public void test1() throws Exception {
test();
}
@Test
public void test2() throws Exception {
test();
}
}