Skip to content

Missing an HTTP endpoint to ensure the Presto Docker Container is ready #23226

Open
@linghengqian

Description

@linghengqian

Expected Behavior or Use Case

sdk install java 17.0.11-ms
sdk use java 17.0.11-ms

git clone [email protected]:linghengqian/testcontainers-presto-health-check-test.git
cd ./testcontainers-presto-health-check-test/
./mvnw clean test
  • Logically, this unit test is very simple.
@Testcontainers
public class PrestoTest {

    @Container
    public GenericContainer<?> container = new GenericContainer<>(DockerImageName.parse("prestodb/presto:0.288"))
            .withCopyFileToContainer(
                    MountableFile.forClasspathResource("default", Transferable.DEFAULT_DIR_MODE),
                    "/opt/presto-server/etc"
            )
            .withExposedPorts(8080)
            .waitingFor(
                    new LogMessageWaitStrategy().withRegEx(".*======== SERVER STARTED ========.*")
                            .withStartupTimeout(Duration.of(60, ChronoUnit.SECONDS))
            );

    @Test
    void test() throws SQLException {
        Properties props = new Properties();
        props.setProperty("user", "test");
        try (Connection connection = DriverManager.getConnection("jdbc:presto://" + container.getHost() + ":" + container.getMappedPort(8080) + "/", props);
             Statement statement = connection.createStatement()) {
            statement.execute("""
                    CREATE TABLE memory.default.table_with_array AS SELECT 1 id, ARRAY[1, 42, 2, 42, 4, 42] my_array
                    """);
            try (ResultSet resultSet = statement.executeQuery(
                    """
                            SELECT nationkey, element
                            FROM tpch.tiny.nation
                            JOIN memory.default.table_with_array twa ON nationkey = twa.id
                            CROSS JOIN UNNEST(my_array) a(element)
                            ORDER BY element OFFSET 1 FETCH FIRST 3 ROWS ONLY
                            """
            )
            ) {
                List<Integer> actualElements = new ArrayList<>();
                while (resultSet.next()) {
                    actualElements.add(resultSet.getInt("element"));
                }
                assertThat(actualElements, is(Arrays.asList(2, 4, 42)));
            }
        }
    }
}
  • This unit test can easily trigger the Error Log of com.facebook.presto.spi.PrestoException: No nodes available to run query. Although sometimes this unit test can be executed successfully.
java.sql.SQLException: Query failed (#20240716_105708_00000_xzrms): No nodes available to run query
        at com.facebook.presto.jdbc.PrestoResultSet.resultsException(PrestoResultSet.java:1841)
  • It would be nice if there was a simple HTTP endpoint that could be used to replace the following logic to verify that the Presto Server is running.
.waitingFor(
                    new LogMessageWaitStrategy().withRegEx(".*======== SERVER STARTED ========.*")
                            .withStartupTimeout(Duration.of(60, ChronoUnit.SECONDS))
            )

Presto Component, Service, or Connector

  • Presto Component.

Possible Implementation

  • To be honest I'm not sure.

Example Screenshots (if appropriate):

  • Normally this wouldn't require any screenshots.

Context

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions