-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJava21TrimAndShutdownTest.java
More file actions
64 lines (54 loc) · 1.71 KB
/
Java21TrimAndShutdownTest.java
File metadata and controls
64 lines (54 loc) · 1.71 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
63
64
package org.example.tests;
import io.ebean.datasource.DataSourceBuilder;
import io.ebean.datasource.DataSourcePool;
import io.ebean.test.containers.PostgresContainer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
class Java21TrimAndShutdownTest {
private static Logger log = LoggerFactory.getLogger(Java21TrimAndShutdownTest.class);
@BeforeAll
static void before() {
PostgresContainer.builder("15")
.port(9999)
.containerName("pool_test")
.dbName("app")
.user("db_owner")
.build()
.startWithDropCreate();
}
@Test
void test() throws InterruptedException, SQLException {
Properties clientInfo = new Properties();
clientInfo.setProperty("ApplicationName", "my-test");
DataSourcePool pool = DataSourceBuilder.create()
.url("jdbc:postgresql://127.0.0.1:9999/app")
.username("db_owner")
.password("test")
.clientInfo(clientInfo)
.maxInactiveTimeSecs(2)
.heartbeatFreqSecs(1)
.trimPoolFreqSecs(1)
.build();
List<Connection> connectionList = new ArrayList<>();
for (int i = 0; i < 50; i++) {
connectionList.add(pool.getConnection());
}
// close them slowly to allow multiple trims
for (Connection connection : connectionList) {
connection.rollback();
connection.close();
Thread.sleep(200);
}
log.info("----------- Sleep allowing trim -------------");
Thread.sleep(9_000);
log.info("----------- Shutdown pool -------------");
pool.shutdown();
}
}