-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
TrinoContainer.java
100 lines (78 loc) · 2.44 KB
/
TrinoContainer.java
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package org.testcontainers.containers;
import com.google.common.base.Strings;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.VisibleForTesting;
import org.testcontainers.utility.DockerImageName;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Set;
public class TrinoContainer extends JdbcDatabaseContainer<TrinoContainer> {
static final String NAME = "trino";
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("trinodb/trino");
static final String IMAGE = "trinodb/trino";
@VisibleForTesting
static final String DEFAULT_TAG = "352";
private static final int TRINO_PORT = 8080;
private String username = "test";
private String catalog = null;
public TrinoContainer(final String dockerImageName) {
this(DockerImageName.parse(dockerImageName));
}
public TrinoContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
addExposedPort(TRINO_PORT);
}
/**
* @return the ports on which to check if the container is ready
* @deprecated use {@link #getLivenessCheckPortNumbers()} instead
*/
@NotNull
@Override
@Deprecated
protected Set<Integer> getLivenessCheckPorts() {
return super.getLivenessCheckPorts();
}
@Override
public String getDriverClassName() {
return "io.trino.jdbc.TrinoDriver";
}
@Override
public String getJdbcUrl() {
return String.format(
"jdbc:trino://%s:%s/%s",
getHost(),
getMappedPort(TRINO_PORT),
Strings.nullToEmpty(catalog)
);
}
@Override
public String getUsername() {
return username;
}
@Override
public String getPassword() {
return "";
}
@Override
public String getDatabaseName() {
return catalog;
}
@Override
public String getTestQueryString() {
return "SELECT count(*) FROM tpch.tiny.nation";
}
@Override
public TrinoContainer withUsername(final String username) {
this.username = username;
return this;
}
@Override
public TrinoContainer withDatabaseName(String dbName) {
this.catalog = dbName;
return this;
}
public Connection createConnection() throws SQLException, NoDriverFoundException {
return createConnection("");
}
}