Skip to content

Commit 1bbe122

Browse files
committed
Change the Docker Image used by the Presto module to prestodb/presto
1 parent 2e0ef57 commit 1bbe122

File tree

8 files changed

+92
-36
lines changed

8 files changed

+92
-36
lines changed

docs/modules/databases/presto.md

Lines changed: 4 additions & 7 deletions
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
@@ -50,13 +47,13 @@ public class SomeTest {
5047
"SELECT nationkey, element " +
5148
"FROM tpch.tiny.nation " +
5249
"JOIN memory.default.table_with_array twa ON nationkey = twa.id " +
53-
"LEFT JOIN UNNEST(my_array) a(element) ON true " +
54-
"ORDER BY element OFFSET 1 FETCH NEXT 3 ROWS WITH TIES ")) {
50+
"CROSS JOIN UNNEST(my_array) a(element) " +
51+
"ORDER BY element OFFSET 1 FETCH FIRST 3 ROWS ONLY ")) {
5552
List<Integer> actualElements = new ArrayList<>();
5653
while (resultSet.next()) {
5754
actualElements.add(resultSet.getInt("element"));
5855
}
59-
Assert.assertEquals(Arrays.asList(2, 4, 42, 42, 42), actualElements);
56+
Assert.assertEquals(Arrays.asList(2, 4, 42), actualElements);
6057
}
6158
}
6259
}
@@ -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

Lines changed: 1 addition & 1 deletion
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.292'
88
compileOnly 'org.jetbrains:annotations:24.1.0'
99
}

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,32 @@
33
import com.google.common.base.Strings;
44
import org.jetbrains.annotations.NotNull;
55
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
6+
import org.testcontainers.containers.wait.strategy.Wait;
7+
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
8+
import org.testcontainers.images.builder.Transferable;
69
import org.testcontainers.utility.DockerImageName;
10+
import org.testcontainers.utility.MountableFile;
711

812
import java.sql.Connection;
913
import java.sql.SQLException;
10-
import java.time.Duration;
11-
import java.time.temporal.ChronoUnit;
1214
import java.util.Set;
1315

1416
/**
15-
* @deprecated Use {@code TrinoContainer} instead.
17+
* Testcontainers implementation for Presto.
18+
* <p>
19+
* Supported image: {@code prestodb/presto}
20+
* <p>
21+
* Exposed ports: 8080
1622
*/
17-
@Deprecated
1823
public class PrestoContainer<SELF extends PrestoContainer<SELF>> extends JdbcDatabaseContainer<SELF> {
1924

2025
public static final String NAME = "presto";
2126

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

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

26-
public static final String DEFAULT_TAG = "344";
31+
public static final String DEFAULT_TAG = "0.292";
2732

2833
public static final Integer PRESTO_PORT = 8080;
2934

@@ -46,13 +51,16 @@ public PrestoContainer(final String dockerImageName) {
4651
public PrestoContainer(final DockerImageName dockerImageName) {
4752
super(dockerImageName);
4853
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
49-
50-
this.waitStrategy =
51-
new LogMessageWaitStrategy()
52-
.withRegEx(".*======== SERVER STARTED ========.*")
53-
.withStartupTimeout(Duration.of(60, ChronoUnit.SECONDS));
54-
54+
waitingFor(new WaitAllStrategy()
55+
.withStrategy(new LogMessageWaitStrategy().withRegEx(".*======== SERVER STARTED ========.*"))
56+
.withStrategy(Wait.forHttp("/v1/info/state").forPort(8080).forResponsePredicate("\"ACTIVE\""::equals))
57+
.withStrategy(new PrestoWaitStrategy(this))
58+
);
5559
addExposedPort(PRESTO_PORT);
60+
withCopyFileToContainer(
61+
MountableFile.forClasspathResource("default/config.properties", Transferable.DEFAULT_DIR_MODE),
62+
"/opt/presto-server/etc/config.properties"
63+
);
5664
}
5765

5866
/**
@@ -68,7 +76,7 @@ protected Set<Integer> getLivenessCheckPorts() {
6876

6977
@Override
7078
public String getDriverClassName() {
71-
return "io.prestosql.jdbc.PrestoDriver";
79+
return "com.facebook.presto.jdbc.PrestoDriver";
7280
}
7381

7482
@Override
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.testcontainers.containers;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.rnorth.ducttape.unreliables.Unreliables;
6+
import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;
7+
import org.testcontainers.containers.wait.strategy.WaitStrategyTarget;
8+
9+
import java.sql.Connection;
10+
import java.sql.SQLException;
11+
import java.sql.Statement;
12+
import java.util.concurrent.TimeUnit;
13+
14+
/**
15+
* Custom wait strategy for Presto.
16+
*/
17+
@RequiredArgsConstructor
18+
@Slf4j
19+
public final class PrestoWaitStrategy extends AbstractWaitStrategy {
20+
21+
private final WaitStrategyTarget target;
22+
23+
@SuppressWarnings("SqlNoDataSourceInspection")
24+
@Override
25+
public void waitUntilReady(WaitStrategyTarget target) {
26+
PrestoContainer<?> container = (PrestoContainer<?>) target;
27+
Unreliables.retryUntilSuccess(
28+
(int) startupTimeout.getSeconds(),
29+
TimeUnit.SECONDS,
30+
() -> {
31+
getRateLimiter().doWhenReady(() -> {
32+
try (Connection con = container.createConnection(); Statement stmt = con.createStatement()) {
33+
stmt.execute("SHOW SCHEMAS");
34+
} catch (SQLException e) {
35+
throw new RuntimeException(e);
36+
}
37+
});
38+
return true;
39+
}
40+
);
41+
}
42+
43+
@Override
44+
public void waitUntilReady() {
45+
waitUntilReady(target);
46+
}
47+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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
7+
cluster.required-workers-active=1

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

Lines changed: 2 additions & 2 deletions
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.292");
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.291");
99
}

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

Lines changed: 8 additions & 11 deletions
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

Lines changed: 1 addition & 1 deletion
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.292://hostname/", EnumSet.of(Options.PmdKnownBroken) },
1818
}
1919
);
2020
}

0 commit comments

Comments
 (0)