Skip to content

Commit f1aba97

Browse files
committed
Change the Docker Image used by the Presto module to prestodb/presto
1 parent 2707f31 commit f1aba97

File tree

11 files changed

+104
-34
lines changed

11 files changed

+104
-34
lines changed

docs/modules/databases/presto.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# Presto Module
22

3-
!!! note
4-
This module is deprecated, use Trino module.
5-
63
See [Database containers](./index.md) for documentation and usage that is common to all database container types.
74

85
## Usage example
@@ -84,6 +81,6 @@ Add the following dependency to your `pom.xml`/`build.gradle` file:
8481
!!! hint
8582
Adding this Testcontainers library JAR will not automatically add the Presto JDBC driver JAR to your project.
8683
You should ensure that your project has the Presto JDBC driver as a dependency, if you plan on using it.
87-
Refer to [Presto project download page](https://prestosql.io/download.html) for instructions.
84+
Refer to [Presto project download page](https://prestodb.io/getting-started/) for instructions.
8885

8986

modules/presto/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ dependencies {
44
api project(':jdbc')
55

66
testImplementation project(':jdbc-test')
7-
testRuntimeOnly 'io.prestosql:presto-jdbc:350'
7+
testRuntimeOnly 'com.facebook.presto:presto-jdbc:0.290'
88
compileOnly 'org.jetbrains:annotations:24.1.0'
99
}

modules/presto/src/main/java/org/testcontainers/containers/PrestoContainer.java

+16-15
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,30 @@
22

33
import com.google.common.base.Strings;
44
import org.jetbrains.annotations.NotNull;
5-
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
5+
import org.testcontainers.images.builder.Transferable;
66
import org.testcontainers.utility.DockerImageName;
7+
import org.testcontainers.utility.MountableFile;
78

89
import java.sql.Connection;
910
import java.sql.SQLException;
10-
import java.time.Duration;
11-
import java.time.temporal.ChronoUnit;
1211
import java.util.Set;
1312

1413
/**
15-
* @deprecated Use {@code TrinoContainer} instead.
14+
* Testcontainers implementation for Presto.
15+
* <p>
16+
* Supported image: {@code prestodb/presto}
17+
* <p>
18+
* Exposed ports: 8080
1619
*/
17-
@Deprecated
1820
public class PrestoContainer<SELF extends PrestoContainer<SELF>> extends JdbcDatabaseContainer<SELF> {
1921

2022
public static final String NAME = "presto";
2123

22-
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("ghcr.io/trinodb/presto");
24+
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("prestodb/presto");
2325

24-
public static final String IMAGE = "ghcr.io/trinodb/presto";
26+
public static final String IMAGE = "prestodb/presto";
2527

26-
public static final String DEFAULT_TAG = "344";
28+
public static final String DEFAULT_TAG = "0.290";
2729

2830
public static final Integer PRESTO_PORT = 8080;
2931

@@ -46,13 +48,12 @@ public PrestoContainer(final String dockerImageName) {
4648
public PrestoContainer(final DockerImageName dockerImageName) {
4749
super(dockerImageName);
4850
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
49-
50-
this.waitStrategy =
51-
new LogMessageWaitStrategy()
52-
.withRegEx(".*======== SERVER STARTED ========.*")
53-
.withStartupTimeout(Duration.of(60, ChronoUnit.SECONDS));
54-
51+
waitingFor(new PrestoWaitStrategy(this));
5552
addExposedPort(PRESTO_PORT);
53+
withCopyFileToContainer(
54+
MountableFile.forClasspathResource("default", Transferable.DEFAULT_DIR_MODE),
55+
"/opt/presto-server/etc"
56+
);
5657
}
5758

5859
/**
@@ -68,7 +69,7 @@ protected Set<Integer> getLivenessCheckPorts() {
6869

6970
@Override
7071
public String getDriverClassName() {
71-
return "io.prestosql.jdbc.PrestoDriver";
72+
return "com.facebook.presto.jdbc.PrestoDriver";
7273
}
7374

7475
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.testcontainers.containers;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;
6+
import org.testcontainers.containers.wait.strategy.WaitStrategyTarget;
7+
8+
import java.sql.Connection;
9+
import java.sql.ResultSet;
10+
import java.sql.SQLException;
11+
import java.sql.Statement;
12+
import java.util.concurrent.TimeUnit;
13+
14+
import static org.hamcrest.MatcherAssert.assertThat;
15+
import static org.hamcrest.Matchers.greaterThan;
16+
import static org.hamcrest.Matchers.is;
17+
import static org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess;
18+
19+
/**
20+
* Custom wait strategy for Presto.
21+
*/
22+
@RequiredArgsConstructor
23+
@Slf4j
24+
public final class PrestoWaitStrategy extends AbstractWaitStrategy {
25+
26+
private final WaitStrategyTarget target;
27+
28+
@SuppressWarnings("SqlNoDataSourceInspection")
29+
@Override
30+
public void waitUntilReady(WaitStrategyTarget target) {
31+
PrestoContainer<?> container = (PrestoContainer<?>) target;
32+
retryUntilSuccess(
33+
(int) startupTimeout.getSeconds(),
34+
TimeUnit.SECONDS,
35+
() -> {
36+
getRateLimiter().doWhenReady(() -> {
37+
try (Connection con = container.createConnection(); Statement stmt = con.createStatement()) {
38+
ResultSet firstResultSet = stmt.executeQuery("SELECT count(*) from system.runtime.nodes");
39+
firstResultSet.next();
40+
assertThat(firstResultSet.getInt(1), greaterThan(0));
41+
ResultSet secondResultSet = stmt.executeQuery("SELECT * from system.runtime.nodes");
42+
while (secondResultSet.next()) {
43+
assertThat(secondResultSet.getString("state"), is("active"));
44+
}
45+
} catch (SQLException e) {
46+
throw new RuntimeException(e);
47+
}
48+
});
49+
return true;
50+
}
51+
);
52+
}
53+
54+
@Override
55+
public void waitUntilReady() {
56+
waitUntilReady(target);
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
connector.name=memory
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
connector.name=tpch
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
coordinator=true
2+
node-scheduler.include-coordinator=true
3+
http-server.http.port=8080
4+
discovery-server.enabled=true
5+
discovery.uri=http://localhost:8080
6+
offset-clause-enabled=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-server
2+
-Xmx2G
3+
-XX:+UseG1GC
4+
-XX:G1HeapRegionSize=32M
5+
-XX:+UseGCOverheadLimit
6+
-XX:+ExplicitGCInvokesConcurrent
7+
-XX:+HeapDumpOnOutOfMemoryError
8+
-XX:+ExitOnOutOfMemoryError
9+
-Djdk.attach.allowAttachSelf=true

modules/presto/src/test/java/org/testcontainers/PrestoTestImages.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.testcontainers.utility.DockerImageName;
44

55
public interface PrestoTestImages {
6-
DockerImageName PRESTO_TEST_IMAGE = DockerImageName.parse("ghcr.io/trinodb/presto:344");
6+
DockerImageName PRESTO_TEST_IMAGE = DockerImageName.parse("prestodb/presto:0.290");
77

8-
DockerImageName PRESTO_PREVIOUS_VERSION_TEST_IMAGE = DockerImageName.parse("ghcr.io/trinodb/presto:343");
8+
DockerImageName PRESTO_PREVIOUS_VERSION_TEST_IMAGE = DockerImageName.parse("prestodb/presto:0.290");
99
}

modules/presto/src/test/java/org/testcontainers/containers/PrestoContainerTest.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void testSimple() throws Exception {
2828
assertThat(resultSet.next()).as("has result").isTrue();
2929
assertThat(resultSet.getString("node_version"))
3030
.as("Presto version")
31-
.isEqualTo(PrestoContainer.DEFAULT_TAG);
31+
.startsWith(PrestoContainer.DEFAULT_TAG);
3232
assertHasCorrectExposedAndLivenessCheckPorts(prestoSql);
3333
}
3434
}
@@ -48,7 +48,7 @@ public void testSpecificVersion() throws Exception {
4848
assertThat(resultSet.next()).as("has result").isTrue();
4949
assertThat(resultSet.getString("node_version"))
5050
.as("Presto version")
51-
.isEqualTo(PrestoTestImages.PRESTO_PREVIOUS_VERSION_TEST_IMAGE.getVersionPart());
51+
.startsWith(PrestoTestImages.PRESTO_PREVIOUS_VERSION_TEST_IMAGE.getVersionPart());
5252
}
5353
}
5454
}
@@ -73,15 +73,15 @@ public void testQueryMemoryAndTpch() throws SQLException {
7373
"SELECT nationkey, element " +
7474
"FROM tpch.tiny.nation " +
7575
"JOIN memory.default.table_with_array twa ON nationkey = twa.id " +
76-
"LEFT JOIN UNNEST(my_array) a(element) ON true " +
77-
"ORDER BY element OFFSET 1 FETCH NEXT 3 ROWS WITH TIES "
76+
"CROSS JOIN UNNEST(my_array) a(element) " +
77+
"ORDER BY element OFFSET 1 FETCH FIRST 3 ROWS ONLY "
7878
)
7979
) {
8080
List<Integer> actualElements = new ArrayList<>();
8181
while (resultSet.next()) {
8282
actualElements.add(resultSet.getInt("element"));
8383
}
84-
assertThat(actualElements).isEqualTo(Arrays.asList(2, 4, 42, 42, 42));
84+
assertThat(actualElements).isEqualTo(Arrays.asList(2, 4, 42));
8585
}
8686
}
8787
}
@@ -112,8 +112,7 @@ public void testTcJdbcUri() throws Exception {
112112
)
113113
) {
114114
// Verify metadata with tc: JDBC connection URI
115-
assertThat(Integer.parseInt(PrestoContainer.DEFAULT_TAG))
116-
.isEqualTo(connection.getMetaData().getDatabaseMajorVersion());
115+
assertThat(0).isEqualTo(connection.getMetaData().getDatabaseMajorVersion());
117116

118117
// Verify transactions with tc: JDBC connection URI
119118
assertThat(connection.getAutoCommit()).as("Is autocommit").isTrue();
@@ -128,12 +127,10 @@ public void testTcJdbcUri() throws Exception {
128127
.as("Update result")
129128
.isEqualTo(0);
130129
try (
131-
ResultSet resultSet = statement.executeQuery(
132-
"SELECT sum(cast(node_version AS bigint)) AS v FROM system.runtime.nodes"
133-
)
130+
ResultSet resultSet = statement.executeQuery("SELECT node_version AS v FROM system.runtime.nodes")
134131
) {
135132
assertThat(resultSet.next()).isTrue();
136-
assertThat(resultSet.getString("v")).isEqualTo(PrestoContainer.DEFAULT_TAG);
133+
assertThat(resultSet.getString("v")).startsWith(PrestoContainer.DEFAULT_TAG);
137134
assertThat(resultSet.next()).isFalse();
138135
}
139136
connection.commit();

modules/presto/src/test/java/org/testcontainers/jdbc/presto/PrestoJDBCDriverTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class PrestoJDBCDriverTest extends AbstractJDBCDriverTest {
1414
public static Iterable<Object[]> data() {
1515
return Arrays.asList(
1616
new Object[][] { //
17-
{ "jdbc:tc:presto:344://hostname/", EnumSet.of(Options.PmdKnownBroken) },
17+
{ "jdbc:tc:presto:0.290://hostname/", EnumSet.of(Options.PmdKnownBroken) },
1818
}
1919
);
2020
}

0 commit comments

Comments
 (0)