From d343cdebaef96edb5872a1a82938591464903d20 Mon Sep 17 00:00:00 2001 From: Mateusz Gajewski Date: Fri, 8 May 2020 12:24:54 +0200 Subject: [PATCH] Add @FileExists validation to presto-atop --- .../io/prestosql/plugin/atop/AtopConnectorConfig.java | 2 ++ .../io/prestosql/plugin/atop/LocalAtopQueryRunner.java | 3 ++- .../prestosql/plugin/atop/TestAtopConnectorConfig.java | 10 ++++++++-- .../io/prestosql/plugin/atop/TestAtopSecurity.java | 8 +++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/presto-atop/src/main/java/io/prestosql/plugin/atop/AtopConnectorConfig.java b/presto-atop/src/main/java/io/prestosql/plugin/atop/AtopConnectorConfig.java index c2d94f0721afa..ac14459e2b71b 100644 --- a/presto-atop/src/main/java/io/prestosql/plugin/atop/AtopConnectorConfig.java +++ b/presto-atop/src/main/java/io/prestosql/plugin/atop/AtopConnectorConfig.java @@ -15,6 +15,7 @@ import io.airlift.configuration.Config; import io.airlift.configuration.ConfigDescription; +import io.airlift.configuration.validation.FileExists; import io.airlift.units.Duration; import io.airlift.units.MinDuration; @@ -54,6 +55,7 @@ public AtopConnectorConfig setSecurity(AtopSecurity security) } @NotNull + @FileExists public String getExecutablePath() { return executablePath; diff --git a/presto-atop/src/test/java/io/prestosql/plugin/atop/LocalAtopQueryRunner.java b/presto-atop/src/test/java/io/prestosql/plugin/atop/LocalAtopQueryRunner.java index 34041a1b07a68..33e71dfa494e3 100644 --- a/presto-atop/src/test/java/io/prestosql/plugin/atop/LocalAtopQueryRunner.java +++ b/presto-atop/src/test/java/io/prestosql/plugin/atop/LocalAtopQueryRunner.java @@ -30,7 +30,7 @@ private LocalAtopQueryRunner() {} public static LocalQueryRunner createQueryRunner() { - return createQueryRunner(ImmutableMap.of(), TestingAtopFactory.class); + return createQueryRunner(ImmutableMap.of("atop.executable-path", "/dev/null"), TestingAtopFactory.class); } public static LocalQueryRunner createQueryRunner(Map catalogProperties, Class factoryClass) @@ -48,6 +48,7 @@ public static LocalQueryRunner createQueryRunner(Map catalogProp ImmutableMap.Builder properties = ImmutableMap.builder() .putAll(catalogProperties) .put("atop.max-history-days", "1"); + queryRunner.createCatalog("atop", connectorFactory, properties.build()); return queryRunner; diff --git a/presto-atop/src/test/java/io/prestosql/plugin/atop/TestAtopConnectorConfig.java b/presto-atop/src/test/java/io/prestosql/plugin/atop/TestAtopConnectorConfig.java index ad139418e190c..0435e96fa33af 100644 --- a/presto-atop/src/test/java/io/prestosql/plugin/atop/TestAtopConnectorConfig.java +++ b/presto-atop/src/test/java/io/prestosql/plugin/atop/TestAtopConnectorConfig.java @@ -18,6 +18,9 @@ import io.prestosql.plugin.atop.AtopConnectorConfig.AtopSecurity; import org.testng.annotations.Test; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Map; import java.util.TimeZone; @@ -42,9 +45,12 @@ public void testDefaults() @Test public void testExplicitPropertyMappings() + throws IOException { + Path atopExecutable = Files.createTempFile(null, null); + Map properties = new ImmutableMap.Builder() - .put("atop.executable-path", "/test/atop") + .put("atop.executable-path", atopExecutable.toString()) .put("atop.concurrent-readers-per-node", "10") .put("atop.executable-read-timeout", "1m") .put("atop.security", "file") @@ -53,7 +59,7 @@ public void testExplicitPropertyMappings() .build(); AtopConnectorConfig expected = new AtopConnectorConfig() - .setExecutablePath("/test/atop") + .setExecutablePath(atopExecutable.toString()) .setConcurrentReadersPerNode(10) .setSecurity(AtopSecurity.FILE) .setReadTimeout(new Duration(1, MINUTES)) diff --git a/presto-atop/src/test/java/io/prestosql/plugin/atop/TestAtopSecurity.java b/presto-atop/src/test/java/io/prestosql/plugin/atop/TestAtopSecurity.java index d72e261c1e40f..04deec9edfbf3 100644 --- a/presto-atop/src/test/java/io/prestosql/plugin/atop/TestAtopSecurity.java +++ b/presto-atop/src/test/java/io/prestosql/plugin/atop/TestAtopSecurity.java @@ -22,6 +22,10 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + import static io.prestosql.plugin.atop.LocalAtopQueryRunner.createQueryRunner; import static io.prestosql.testing.TestingSession.testSessionBuilder; @@ -31,9 +35,11 @@ public class TestAtopSecurity @BeforeClass public void setUp() + throws IOException { + Path atopExecutable = Files.createTempFile(null, null); String path = this.getClass().getResource("security.json").getPath(); - queryRunner = createQueryRunner(ImmutableMap.of("atop.security", "file", "security.config-file", path), TestingAtopFactory.class); + queryRunner = createQueryRunner(ImmutableMap.of("atop.security", "file", "security.config-file", path, "atop.executable-path", atopExecutable.toString()), TestingAtopFactory.class); } @AfterClass(alwaysRun = true)