|
| 1 | +package org.testcontainers.trino; |
| 2 | + |
| 3 | +import com.google.common.base.Strings; |
| 4 | +import org.jetbrains.annotations.NotNull; |
| 5 | +import org.jetbrains.annotations.VisibleForTesting; |
| 6 | +import org.testcontainers.containers.JdbcDatabaseContainer; |
| 7 | +import org.testcontainers.utility.DockerImageName; |
| 8 | + |
| 9 | +import java.sql.Connection; |
| 10 | +import java.sql.SQLException; |
| 11 | +import java.util.Set; |
| 12 | + |
| 13 | +/** |
| 14 | + * Testcontainers implementation for TrinoDB. |
| 15 | + * <p> |
| 16 | + * Supported image: {@code trinodb/trino} |
| 17 | + * <p> |
| 18 | + * Exposed ports: 8080 |
| 19 | + */ |
| 20 | +public class TrinoContainer extends JdbcDatabaseContainer<TrinoContainer> { |
| 21 | + |
| 22 | + static final String NAME = "trino"; |
| 23 | + |
| 24 | + private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("trinodb/trino"); |
| 25 | + |
| 26 | + static final String IMAGE = "trinodb/trino"; |
| 27 | + |
| 28 | + @VisibleForTesting |
| 29 | + static final String DEFAULT_TAG = "352"; |
| 30 | + |
| 31 | + private static final int TRINO_PORT = 8080; |
| 32 | + |
| 33 | + private String username = "test"; |
| 34 | + |
| 35 | + private String catalog = null; |
| 36 | + |
| 37 | + public TrinoContainer(final String dockerImageName) { |
| 38 | + this(DockerImageName.parse(dockerImageName)); |
| 39 | + } |
| 40 | + |
| 41 | + public TrinoContainer(final DockerImageName dockerImageName) { |
| 42 | + super(dockerImageName); |
| 43 | + dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); |
| 44 | + addExposedPort(TRINO_PORT); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @return the ports on which to check if the container is ready |
| 49 | + * @deprecated use {@link #getLivenessCheckPortNumbers()} instead |
| 50 | + */ |
| 51 | + @NotNull |
| 52 | + @Override |
| 53 | + @Deprecated |
| 54 | + protected Set<Integer> getLivenessCheckPorts() { |
| 55 | + return super.getLivenessCheckPorts(); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public String getDriverClassName() { |
| 60 | + return "io.trino.jdbc.TrinoDriver"; |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public String getJdbcUrl() { |
| 65 | + return String.format( |
| 66 | + "jdbc:trino://%s:%s/%s", |
| 67 | + getHost(), |
| 68 | + getMappedPort(TRINO_PORT), |
| 69 | + Strings.nullToEmpty(catalog) |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public String getUsername() { |
| 75 | + return username; |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public String getPassword() { |
| 80 | + return ""; |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public String getDatabaseName() { |
| 85 | + return catalog; |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public String getTestQueryString() { |
| 90 | + return "SELECT count(*) FROM tpch.tiny.nation"; |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public TrinoContainer withUsername(final String username) { |
| 95 | + this.username = username; |
| 96 | + return this; |
| 97 | + } |
| 98 | + |
| 99 | + @Override |
| 100 | + public TrinoContainer withDatabaseName(String dbName) { |
| 101 | + this.catalog = dbName; |
| 102 | + return this; |
| 103 | + } |
| 104 | + |
| 105 | + public Connection createConnection() throws SQLException, NoDriverFoundException { |
| 106 | + return createConnection(""); |
| 107 | + } |
| 108 | +} |
0 commit comments