Skip to content

Commit

Permalink
Add @fileexists validation to presto-atop
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo authored and losipiuk committed Jun 9, 2020
1 parent a779a8a commit d343cde
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -54,6 +55,7 @@ public AtopConnectorConfig setSecurity(AtopSecurity security)
}

@NotNull
@FileExists
public String getExecutablePath()
{
return executablePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> catalogProperties, Class<? extends AtopFactory> factoryClass)
Expand All @@ -48,6 +48,7 @@ public static LocalQueryRunner createQueryRunner(Map<String, String> catalogProp
ImmutableMap.Builder<String, String> properties = ImmutableMap.<String, String>builder()
.putAll(catalogProperties)
.put("atop.max-history-days", "1");

queryRunner.createCatalog("atop", connectorFactory, properties.build());

return queryRunner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -42,9 +45,12 @@ public void testDefaults()

@Test
public void testExplicitPropertyMappings()
throws IOException
{
Path atopExecutable = Files.createTempFile(null, null);

Map<String, String> properties = new ImmutableMap.Builder<String, String>()
.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")
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down

0 comments on commit d343cde

Please sign in to comment.