From 267c6f4667ba403512921f57e66137a694f303d2 Mon Sep 17 00:00:00 2001 From: Mateusz Gajewski Date: Fri, 8 May 2020 13:19:43 +0200 Subject: [PATCH] Add @FileExists validation to presto-local-file --- .../io/prestosql/plugin/localfile/LocalFileConfig.java | 2 ++ .../plugin/localfile/TestLocalFileConfig.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/presto-local-file/src/main/java/io/prestosql/plugin/localfile/LocalFileConfig.java b/presto-local-file/src/main/java/io/prestosql/plugin/localfile/LocalFileConfig.java index afef665781820..a8d1f610d6e4d 100644 --- a/presto-local-file/src/main/java/io/prestosql/plugin/localfile/LocalFileConfig.java +++ b/presto-local-file/src/main/java/io/prestosql/plugin/localfile/LocalFileConfig.java @@ -15,12 +15,14 @@ import io.airlift.configuration.Config; import io.airlift.configuration.ConfigDescription; +import io.airlift.configuration.validation.FileExists; public class LocalFileConfig { private String httpRequestLogLocation = "var/log/http-request.log"; private String httpRequestLogFileNamePattern; + @FileExists public String getHttpRequestLogLocation() { return httpRequestLogLocation; diff --git a/presto-local-file/src/test/java/io/prestosql/plugin/localfile/TestLocalFileConfig.java b/presto-local-file/src/test/java/io/prestosql/plugin/localfile/TestLocalFileConfig.java index b5a4b546d0e8f..97298b453caef 100644 --- a/presto-local-file/src/test/java/io/prestosql/plugin/localfile/TestLocalFileConfig.java +++ b/presto-local-file/src/test/java/io/prestosql/plugin/localfile/TestLocalFileConfig.java @@ -16,6 +16,9 @@ import com.google.common.collect.ImmutableMap; import org.testng.annotations.Test; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Map; import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping; @@ -34,14 +37,17 @@ public void testDefaults() @Test public void testExplicitPropertyMappings() + throws IOException { + Path httpRequestLogFile = Files.createTempFile(null, null); + Map properties = new ImmutableMap.Builder() - .put("presto-logs.http-request-log.location", "/data/foo.log") + .put("presto-logs.http-request-log.location", httpRequestLogFile.toString()) .put("presto-logs.http-request-log.pattern", "bar") .build(); LocalFileConfig expected = new LocalFileConfig() - .setHttpRequestLogLocation("/data/foo.log") + .setHttpRequestLogLocation(httpRequestLogFile.toString()) .setHttpRequestLogFileNamePattern("bar"); assertFullMapping(properties, expected);