Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.airlift.json.JsonCodec;
import io.airlift.log.Logger;
import io.airlift.units.Duration;
import io.trino.testing.ResourcePresence;
import org.testcontainers.containers.GenericContainer;

import java.io.Closeable;
Expand Down Expand Up @@ -196,9 +197,13 @@ private void refreshSizeEstimates()
@Override
public void close()
{
if (session != null) {
session.close();
}
session.close();
dockerContainer.close();
}

@ResourcePresence
public boolean isRunning()
{
return dockerContainer.getContainerId() != null;
}
}
6 changes: 6 additions & 0 deletions plugin/trino-mariadb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-testing-services</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-tpch</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.plugin.mariadb;

import io.trino.testing.ResourcePresence;
import org.testcontainers.containers.MariaDBContainer;
import org.testcontainers.utility.DockerImageName;

Expand Down Expand Up @@ -84,4 +85,10 @@ public void close()
{
container.close();
}

@ResourcePresence
public boolean isRunning()
{
return container.getContainerId() != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.trino.plugin.mongodb;

import com.mongodb.ConnectionString;
import io.trino.testing.ResourcePresence;
import org.testcontainers.containers.MongoDBContainer;

import java.io.Closeable;
Expand Down Expand Up @@ -47,4 +48,10 @@ public void close()
{
dockerContainer.close();
}

@ResourcePresence
public boolean isRunning()
{
return dockerContainer.getContainerId() != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.plugin.mysql;

import io.trino.testing.ResourcePresence;
import org.testcontainers.containers.MySQLContainer;

import java.io.Closeable;
Expand Down Expand Up @@ -117,4 +118,10 @@ public void close()
throw new UncheckedIOException(e);
}
}

@ResourcePresence
public boolean isRunning()
{
return container.getContainerId() != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.trino.plugin.jdbc.DriverConnectionFactory;
import io.trino.plugin.jdbc.RetryingConnectionFactory;
import io.trino.plugin.jdbc.credential.StaticCredentialProvider;
import io.trino.testing.ResourcePresence;
import net.jodah.failsafe.Failsafe;
import net.jodah.failsafe.RetryPolicy;
import oracle.jdbc.OracleDriver;
Expand Down Expand Up @@ -132,4 +133,10 @@ public void close()
{
container.stop();
}

@ResourcePresence
public boolean isRunning()
{
return container.getContainerId() != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.common.collect.ImmutableList;
import io.trino.plugin.jdbc.RemoteDatabaseEvent;
import io.trino.testing.ResourcePresence;
import org.intellij.lang.annotations.Language;
import org.testcontainers.containers.PostgreSQLContainer;

Expand Down Expand Up @@ -146,4 +147,10 @@ public void close()
{
dockerContainer.close();
}

@ResourcePresence
public boolean isRunning()
{
return dockerContainer.getContainerId() != null;
}
}
6 changes: 6 additions & 0 deletions plugin/trino-singlestore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-testing-services</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-tpch</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.trino.plugin.singlestore;

import com.google.common.collect.ImmutableSet;
import io.trino.testing.ResourcePresence;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.utility.DockerImageName;

Expand Down Expand Up @@ -46,11 +47,11 @@ public TestingSingleStoreServer(String dockerImageName)
addEnv("ROOT_PASSWORD", "memsql_root_password");
withCommand("sh", "-xeuc",
"/startup && " +
// Lower the size of pre-allocated log files to 1MB (minimum allowed) to reduce disk footprint
"memsql-admin update-config --yes --all --set-global --key \"log_file_size_partitions\" --value \"1048576\" && " +
"memsql-admin update-config --yes --all --set-global --key \"log_file_size_ref_dbs\" --value \"1048576\" && " +
// re-execute startup to actually start the nodes (first run performs setup but doesn't start the nodes)
"exec /startup");
// Lower the size of pre-allocated log files to 1MB (minimum allowed) to reduce disk footprint
"memsql-admin update-config --yes --all --set-global --key \"log_file_size_partitions\" --value \"1048576\" && " +
"memsql-admin update-config --yes --all --set-global --key \"log_file_size_ref_dbs\" --value \"1048576\" && " +
// re-execute startup to actually start the nodes (first run performs setup but doesn't start the nodes)
"exec /startup");
start();
}

Expand Down Expand Up @@ -103,6 +104,12 @@ public void execute(String sql)
execute(sql, getUsername(), getPassword());
}

@ResourcePresence
public boolean isResourcePresent()
{
return isRunning() || getContainerId() != null;
}

public void execute(String sql, String user, String password)
{
try (Connection connection = DriverManager.getConnection(getJdbcUrl(), user, password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.trino.plugin.sqlserver;

import io.airlift.log.Logger;
import io.trino.testing.ResourcePresence;
import io.trino.testing.sql.SqlExecutor;
import net.jodah.failsafe.Failsafe;
import net.jodah.failsafe.RetryPolicy;
Expand Down Expand Up @@ -213,6 +214,12 @@ public void close()
}
}

@ResourcePresence
public boolean isRunning()
{
return container.getContainerId() != null;
}

private static class InitializedState
{
private final MSSQLServerContainer<?> container;
Expand Down
6 changes: 6 additions & 0 deletions testing/trino-testing-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
<artifactId>jsr305</artifactId>
</dependency>

<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.testing;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Specifies a method that determines whether given resource-like class currently holds on to resources.
* The annotated method must not take parameters and must return a boolean, {@code true} indicating
* that a resource is present.
*/
@Retention(RUNTIME)
@Target(METHOD)
public @interface ResourcePresence {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.testng.services;

import com.google.errorprone.annotations.FormatMethod;
import org.testng.ITestNGListener;

import static java.lang.String.format;
Expand All @@ -26,6 +27,7 @@ private Listeners() {}
*
* @apiNote A TestNG listener cannot throw an exception, as this are not currently properly handled by TestNG.
*/
@FormatMethod
public static void reportListenerFailure(Class<? extends ITestNGListener> listenerClass, String format, Object... args)
{
System.err.println(format("FATAL: %s: ", listenerClass.getName()) + format(format, args));
Expand Down
Loading