diff --git a/plugin/trino-google-sheets/pom.xml b/plugin/trino-google-sheets/pom.xml index 7c61bbb6e165..9aa00b3ced2f 100644 --- a/plugin/trino-google-sheets/pom.xml +++ b/plugin/trino-google-sheets/pom.xml @@ -119,6 +119,13 @@ validation-api + + + io.airlift + log-manager + runtime + + io.trino diff --git a/plugin/trino-google-sheets/src/test/java/io/trino/plugin/google/sheets/SheetsQueryRunner.java b/plugin/trino-google-sheets/src/test/java/io/trino/plugin/google/sheets/SheetsQueryRunner.java new file mode 100644 index 000000000000..e1eb229423fc --- /dev/null +++ b/plugin/trino-google-sheets/src/test/java/io/trino/plugin/google/sheets/SheetsQueryRunner.java @@ -0,0 +1,83 @@ +/* + * 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.plugin.google.sheets; + +import com.google.common.collect.ImmutableMap; +import io.airlift.log.Logger; +import io.airlift.log.Logging; +import io.trino.Session; +import io.trino.testing.DistributedQueryRunner; + +import java.util.HashMap; +import java.util.Map; + +import static io.airlift.testing.Closeables.closeAllSuppress; +import static io.trino.plugin.google.sheets.TestSheetsPlugin.TEST_METADATA_SHEET_ID; +import static io.trino.plugin.google.sheets.TestSheetsPlugin.getTestCredentialsPath; +import static io.trino.testing.TestingSession.testSessionBuilder; + +public class SheetsQueryRunner +{ + protected static final String GOOGLE_SHEETS = "gsheets"; + + private SheetsQueryRunner() {} + + public static DistributedQueryRunner createSheetsQueryRunner( + Map extraProperties, + Map connectorProperties) + throws Exception + { + DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(createSession()) + .setExtraProperties(extraProperties) + .build(); + try { + connectorProperties = new HashMap<>(ImmutableMap.copyOf(connectorProperties)); + connectorProperties.putIfAbsent("credentials-path", getTestCredentialsPath()); + connectorProperties.putIfAbsent("metadata-sheet-id", TEST_METADATA_SHEET_ID); + connectorProperties.putIfAbsent("sheets-data-max-cache-size", "1000"); + connectorProperties.putIfAbsent("sheets-data-expire-after-write", "5m"); + + queryRunner.installPlugin(new SheetsPlugin()); + queryRunner.createCatalog(GOOGLE_SHEETS, GOOGLE_SHEETS, connectorProperties); + + return queryRunner; + } + catch (Throwable e) { + closeAllSuppress(e, queryRunner); + throw e; + } + } + + private static Session createSession() + { + return testSessionBuilder() + .setCatalog(GOOGLE_SHEETS) + .setSchema("default") + .build(); + } + + public static void main(String[] args) + throws Exception + { + Logging.initialize(); + + DistributedQueryRunner queryRunner = createSheetsQueryRunner( + ImmutableMap.of("http-server.http.port", "8080"), + ImmutableMap.of()); + + Logger log = Logger.get(SheetsQueryRunner.class); + log.info("======== SERVER STARTED ========"); + log.info("\n====\n%s\n====", queryRunner.getCoordinator().getBaseUrl()); + } +} diff --git a/plugin/trino-google-sheets/src/test/java/io/trino/plugin/google/sheets/TestGoogleSheets.java b/plugin/trino-google-sheets/src/test/java/io/trino/plugin/google/sheets/TestGoogleSheets.java index 271df63d3786..0b2f2046ae17 100644 --- a/plugin/trino-google-sheets/src/test/java/io/trino/plugin/google/sheets/TestGoogleSheets.java +++ b/plugin/trino-google-sheets/src/test/java/io/trino/plugin/google/sheets/TestGoogleSheets.java @@ -14,48 +14,21 @@ package io.trino.plugin.google.sheets; import com.google.common.collect.ImmutableMap; -import io.trino.Session; import io.trino.testing.AbstractTestQueryFramework; -import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; import org.testng.annotations.Test; -import static io.trino.plugin.google.sheets.TestSheetsPlugin.TEST_METADATA_SHEET_ID; -import static io.trino.plugin.google.sheets.TestSheetsPlugin.getTestCredentialsPath; -import static io.trino.testing.TestingSession.testSessionBuilder; +import static io.trino.plugin.google.sheets.SheetsQueryRunner.createSheetsQueryRunner; import static org.testng.Assert.assertEquals; public class TestGoogleSheets extends AbstractTestQueryFramework { - protected static final String GOOGLE_SHEETS = "gsheets"; - - private static Session createSession() - { - return testSessionBuilder() - .setCatalog(GOOGLE_SHEETS) - .setSchema("default") - .build(); - } - @Override protected QueryRunner createQueryRunner() + throws Exception { - QueryRunner queryRunner; - try { - SheetsPlugin sheetsPlugin = new SheetsPlugin(); - queryRunner = DistributedQueryRunner.builder(createSession()).build(); - queryRunner.installPlugin(sheetsPlugin); - queryRunner.createCatalog(GOOGLE_SHEETS, GOOGLE_SHEETS, ImmutableMap.of( - "credentials-path", getTestCredentialsPath(), - "metadata-sheet-id", TEST_METADATA_SHEET_ID, - "sheets-data-max-cache-size", "1000", - "sheets-data-expire-after-write", "5m")); - } - catch (Exception e) { - throw new IllegalStateException(e.getMessage()); - } - return queryRunner; + return createSheetsQueryRunner(ImmutableMap.of(), ImmutableMap.of()); } @Test diff --git a/plugin/trino-google-sheets/src/test/java/io/trino/plugin/google/sheets/TestSheetsPlugin.java b/plugin/trino-google-sheets/src/test/java/io/trino/plugin/google/sheets/TestSheetsPlugin.java index 37f286bd3a0e..2448216a5e6e 100644 --- a/plugin/trino-google-sheets/src/test/java/io/trino/plugin/google/sheets/TestSheetsPlugin.java +++ b/plugin/trino-google-sheets/src/test/java/io/trino/plugin/google/sheets/TestSheetsPlugin.java @@ -26,7 +26,7 @@ import java.util.Base64; import static com.google.common.collect.Iterables.getOnlyElement; -import static io.trino.plugin.google.sheets.TestGoogleSheets.GOOGLE_SHEETS; +import static io.trino.plugin.google.sheets.SheetsQueryRunner.GOOGLE_SHEETS; import static java.io.File.createTempFile; import static java.nio.charset.StandardCharsets.UTF_8; import static org.testng.Assert.assertNotNull;