diff --git a/presto-benchmark-runner/src/test/java/com/facebook/presto/benchmark/retry/TestRetryDriver.java b/presto-benchmark-runner/src/test/java/com/facebook/presto/benchmark/retry/TestRetryDriver.java index ddd11b71d633c..7601fae3ec96a 100644 --- a/presto-benchmark-runner/src/test/java/com/facebook/presto/benchmark/retry/TestRetryDriver.java +++ b/presto-benchmark-runner/src/test/java/com/facebook/presto/benchmark/retry/TestRetryDriver.java @@ -16,7 +16,6 @@ import com.facebook.airlift.log.Logging; import com.facebook.presto.benchmark.framework.QueryException; import io.airlift.units.Duration; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.net.SocketTimeoutException; @@ -64,23 +63,10 @@ public Integer run() private static final QueryException RETRYABLE_EXCEPTION = QueryException.forClusterConnection(new SocketTimeoutException()); private static final QueryException NON_RETRYABLE_EXCEPTION = QueryException.forPresto(new RuntimeException(), Optional.of(REMOTE_HOST_GONE), Optional.empty()); - private RetryDriver retryDriver; - - @BeforeMethod - public void setup() - { - retryDriver = new RetryDriver( - new RetryConfig() - .setMaxAttempts(5) - .setMinBackoffDelay(new Duration(10, MILLISECONDS)) - .setMaxBackoffDelay(new Duration(100, MILLISECONDS)) - .setScaleFactor(2), - exception -> (exception instanceof QueryException) ? (((QueryException) exception).getType() == CLUSTER_CONNECTION) : FALSE); - } - @Test public void testSuccess() { + RetryDriver retryDriver = getRetryDriverForMethods(); assertEquals( retryDriver.run("test", new MockOperation(5, RETRYABLE_EXCEPTION)), Integer.valueOf(5)); @@ -89,12 +75,14 @@ public void testSuccess() @Test(expectedExceptions = QueryException.class) public void testMaxAttemptsExceeded() { + RetryDriver retryDriver = getRetryDriverForMethods(); retryDriver.run("test", new MockOperation(6, RETRYABLE_EXCEPTION)); } @Test(expectedExceptions = QueryException.class) public void testNonRetryableFailure() { + RetryDriver retryDriver = getRetryDriverForMethods(); retryDriver.run("test", new MockOperation(3, NON_RETRYABLE_EXCEPTION)); } @@ -110,4 +98,17 @@ public void testBackoffTimeCapped() exception -> (exception instanceof QueryException) ? (((QueryException) exception).getType() == CLUSTER_CONNECTION) : FALSE); retryDriver.run("test", new MockOperation(5, RETRYABLE_EXCEPTION)); } + + private RetryDriver getRetryDriverForMethods() + { + RetryDriver retryDriver = new RetryDriver( + new RetryConfig() + .setMaxAttempts(5) + .setMinBackoffDelay(new Duration(10, MILLISECONDS)) + .setMaxBackoffDelay(new Duration(100, MILLISECONDS)) + .setScaleFactor(2), + exception -> (exception instanceof QueryException) ? (((QueryException) exception).getType() == CLUSTER_CONNECTION) : FALSE); + + return retryDriver; + } } diff --git a/presto-main/src/test/java/com/facebook/presto/execution/TestThriftTaskStatus.java b/presto-main/src/test/java/com/facebook/presto/execution/TestThriftTaskStatus.java index 88429a1347479..d4151a4fab7a0 100644 --- a/presto-main/src/test/java/com/facebook/presto/execution/TestThriftTaskStatus.java +++ b/presto-main/src/test/java/com/facebook/presto/execution/TestThriftTaskStatus.java @@ -31,7 +31,7 @@ import com.facebook.presto.util.Failures; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeTest; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -77,13 +77,7 @@ public class TestThriftTaskStatus public static final int TOTAL_CPU_TIME_IN_NANOS = 1002; public static final int TASK_AGE = 1003; public static final HostAddress REMOTE_HOST = HostAddress.fromParts("www.fake.invalid", 8080); - private TaskStatus taskStatus; - - @BeforeMethod - public void setUp() - { - taskStatus = getTaskStatus(); - } + private static TaskStatus taskStatus; @DataProvider public Object[][] codecCombinations() @@ -96,6 +90,12 @@ public Object[][] codecCombinations() }; } + @BeforeTest + public void setup() + { + taskStatus = getTaskStatus(); + } + @Test(dataProvider = "codecCombinations") public void testRoundTripSerializeBinaryProtocol(ThriftCodec readCodec, ThriftCodec writeCodec) throws Exception diff --git a/presto-parser/src/test/java/com/facebook/presto/sql/parser/ParsingExceptionTest.java b/presto-parser/src/test/java/com/facebook/presto/sql/parser/ParsingExceptionTest.java index b1b6351a44e06..fa76538d2bf67 100644 --- a/presto-parser/src/test/java/com/facebook/presto/sql/parser/ParsingExceptionTest.java +++ b/presto-parser/src/test/java/com/facebook/presto/sql/parser/ParsingExceptionTest.java @@ -14,17 +14,17 @@ package com.facebook.presto.sql.parser; import com.facebook.presto.sql.tree.NodeLocation; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; public class ParsingExceptionTest { - private ParsingException parsingException; + private static ParsingException parsingException; - @BeforeMethod - public void setUp() + @BeforeTest + public void setup() { parsingException = new ParsingException("ParsingException", new NodeLocation(100, 1)); } diff --git a/presto-verifier/src/test/java/com/facebook/presto/verifier/framework/TestQueryConfiguration.java b/presto-verifier/src/test/java/com/facebook/presto/verifier/framework/TestQueryConfiguration.java index b1fa7b5450cfb..116ae66758afd 100644 --- a/presto-verifier/src/test/java/com/facebook/presto/verifier/framework/TestQueryConfiguration.java +++ b/presto-verifier/src/test/java/com/facebook/presto/verifier/framework/TestQueryConfiguration.java @@ -14,7 +14,7 @@ package com.facebook.presto.verifier.framework; import com.google.common.collect.ImmutableMap; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.util.Map; @@ -50,9 +50,9 @@ public class TestQueryConfiguration Optional.of(PASSWORD_OVERRIDE), Optional.of(SESSION_PROPERTIES_OVERRIDE)); - private QueryConfigurationOverridesConfig overrides; + private static QueryConfigurationOverridesConfig overrides; - @BeforeMethod + @BeforeTest public void setup() { overrides = new QueryConfigurationOverridesConfig() diff --git a/presto-verifier/src/test/java/com/facebook/presto/verifier/framework/TestVerificationManager.java b/presto-verifier/src/test/java/com/facebook/presto/verifier/framework/TestVerificationManager.java index d036603a1a729..ad6b8ae7cd698 100644 --- a/presto-verifier/src/test/java/com/facebook/presto/verifier/framework/TestVerificationManager.java +++ b/presto-verifier/src/test/java/com/facebook/presto/verifier/framework/TestVerificationManager.java @@ -29,7 +29,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.util.ArrayList; @@ -120,19 +119,13 @@ public List getEvents() QUERY_CONFIGURATION); private static final VerifierConfig VERIFIER_CONFIG = new VerifierConfig().setTestId("test"); - private MockEventClient eventClient; - - @BeforeMethod - public void setup() - { - this.eventClient = new MockEventClient(); - } - // TODO(leiqing): Add a test where the first submission fails but resubmission succeeds. @Test public void testFailureResubmitted() { - VerificationManager manager = getVerificationManager(ImmutableList.of(SOURCE_QUERY), new MockPrestoAction(HIVE_PARTITION_DROPPED_DURING_QUERY), VERIFIER_CONFIG); + MockEventClient eventClient = new MockEventClient(); + VerificationManager manager = getVerificationManager(ImmutableList.of(SOURCE_QUERY), new MockPrestoAction(HIVE_PARTITION_DROPPED_DURING_QUERY), + VERIFIER_CONFIG, eventClient); manager.start(); assertEquals(manager.getQueriesSubmitted().get(), 3); assertEquals(eventClient.getEvents().size(), 1); @@ -142,7 +135,9 @@ public void testFailureResubmitted() @Test public void testFailureNotSubmitted() { - VerificationManager manager = getVerificationManager(ImmutableList.of(SOURCE_QUERY), new MockPrestoAction(GENERIC_INTERNAL_ERROR), VERIFIER_CONFIG); + MockEventClient eventClient = new MockEventClient(); + VerificationManager manager = getVerificationManager(ImmutableList.of(SOURCE_QUERY), new MockPrestoAction(GENERIC_INTERNAL_ERROR), + VERIFIER_CONFIG, eventClient); manager.start(); assertEquals(manager.getQueriesSubmitted().get(), 1); assertEquals(eventClient.getEvents().size(), 1); @@ -152,6 +147,7 @@ public void testFailureNotSubmitted() @Test public void testFilters() { + MockEventClient eventClient = new MockEventClient(); List queries = ImmutableList.of( createSourceQuery("q1", "CREATE TABLE t1 (x int)", "CREATE TABLE t1 (x int)"), createSourceQuery("q2", "CREATE TABLE t1 (x int)", "CREATE TABLE t1 (x int)"), @@ -165,7 +161,8 @@ public void testFilters() new VerifierConfig() .setTestId("test") .setWhitelist("q2,q3,q4,q5,q6") - .setBlacklist("q2")); + .setBlacklist("q2"), + eventClient); manager.start(); assertEquals(manager.getQueriesSubmitted().get(), 0); @@ -180,7 +177,9 @@ public void testFilters() @Test public void testVerifierError() { - VerificationManager manager = getVerificationManager(ImmutableList.of(SOURCE_QUERY), new MockPrestoAction(new RuntimeException()), VERIFIER_CONFIG); + MockEventClient eventClient = new MockEventClient(); + VerificationManager manager = getVerificationManager(ImmutableList.of(SOURCE_QUERY), new MockPrestoAction(new RuntimeException()), + VERIFIER_CONFIG, eventClient); manager.start(); List events = eventClient.getEvents(); @@ -202,7 +201,8 @@ private static void assertSkippedEvent(VerifierQueryEvent event, String name, Sk assertEquals(event.getSkippedReason(), skippedReason.name()); } - private VerificationManager getVerificationManager(List sourceQueries, PrestoAction prestoAction, VerifierConfig verifierConfig) + private VerificationManager getVerificationManager(List sourceQueries, PrestoAction prestoAction, + VerifierConfig verifierConfig, MockEventClient eventClient) { return new VerificationManager( () -> sourceQueries, diff --git a/src/checkstyle/presto-checks.xml b/src/checkstyle/presto-checks.xml index 96b8e427af01e..1b68492d6a6e8 100644 --- a/src/checkstyle/presto-checks.xml +++ b/src/checkstyle/presto-checks.xml @@ -91,6 +91,10 @@ + + + +