Repository: sentry Updated Branches: refs/heads/master 7d39a6ef8 -> b124675c0
SENTRY-1489: Categorize e2e tests into slow and regular tests, so that can adapt the timeout and etc. (Anne Yu, reviewed by LiLi) Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/b124675c Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/b124675c Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/b124675c Branch: refs/heads/master Commit: b124675c0d571a4b85026d5390a7758092e04842 Parents: 7d39a6e Author: Anne Yu <[email protected]> Authored: Fri Oct 28 13:44:06 2016 -0700 Committer: Anne Yu <[email protected]> Committed: Fri Oct 28 14:48:51 2016 -0700 ---------------------------------------------------------------------- .../dbprovider/AbstractTestWithDbProvider.java | 8 --- .../e2e/dbprovider/TestDbCrossOperations.java | 6 +- .../e2e/hive/AbstractTestWithHiveServer.java | 2 +- .../AbstractTestWithStaticConfiguration.java | 41 +----------- .../sentry/tests/e2e/hive/RulesForE2ETest.java | 68 ++++++++++++++++++++ .../sentry/tests/e2e/hive/SlowE2ETest.java | 26 ++++++++ 6 files changed, 99 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/b124675c/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/AbstractTestWithDbProvider.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/AbstractTestWithDbProvider.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/AbstractTestWithDbProvider.java index e7cccbf..a773a83 100644 --- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/AbstractTestWithDbProvider.java +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/AbstractTestWithDbProvider.java @@ -42,9 +42,6 @@ import org.apache.sentry.tests.e2e.hive.StaticUserGroup; import org.apache.sentry.tests.e2e.hive.hiveserver.HiveServerFactory; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.rules.Timeout; import static org.junit.Assume.assumeNotNull; @@ -54,11 +51,6 @@ import com.google.common.io.Files; public abstract class AbstractTestWithDbProvider extends AbstractTestWithHiveServer { - @ClassRule - public static Timeout classTimeout = new Timeout(600000); //millis, each class runs less than 600s (10m) - @Rule - public Timeout timeout = new Timeout(180000); //millis, each test runs less than 180s (3m) - protected static final String SERVER_HOST = "localhost"; protected static Map<String, String> properties = Maps.newHashMap(); http://git-wip-us.apache.org/repos/asf/sentry/blob/b124675c/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbCrossOperations.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbCrossOperations.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbCrossOperations.java index 60812cf..6dbe62b 100644 --- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbCrossOperations.java +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbCrossOperations.java @@ -17,8 +17,6 @@ package org.apache.sentry.tests.e2e.dbprovider; -import java.io.File; -import java.io.FileOutputStream; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; @@ -26,6 +24,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration; +import org.apache.sentry.tests.e2e.hive.SlowE2ETest; import org.junit.Before; import org.junit.BeforeClass; @@ -34,8 +33,7 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.io.Resources; - +@SlowE2ETest public class TestDbCrossOperations extends AbstractTestWithStaticConfiguration { private static final Logger LOGGER = LoggerFactory. getLogger(TestDbCrossOperations.class); http://git-wip-us.apache.org/repos/asf/sentry/blob/b124675c/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithHiveServer.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithHiveServer.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithHiveServer.java index a314c0d..c4ee1c0 100644 --- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithHiveServer.java +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithHiveServer.java @@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory; import com.google.common.io.Files; -public abstract class AbstractTestWithHiveServer { +public abstract class AbstractTestWithHiveServer extends RulesForE2ETest { private static final Logger LOGGER = LoggerFactory .getLogger(AbstractTestWithHiveServer.class); protected static File baseDir; http://git-wip-us.apache.org/repos/asf/sentry/blob/b124675c/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java index 62da025..11e8164 100644 --- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.security.PrivilegedExceptionAction; import java.sql.Connection; import java.sql.ResultSet; -import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Arrays; @@ -37,17 +36,10 @@ import java.util.HashSet; import com.google.common.collect.Sets; import org.apache.sentry.tests.e2e.hive.fs.TestFSContants; import org.junit.After; -import org.junit.Assert; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.rules.RuleChain; -import org.junit.rules.Timeout; -import org.junit.rules.TestRule; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; import org.apache.commons.io.FileUtils; import org.apache.hadoop.conf.Configuration; @@ -88,39 +80,10 @@ import javax.security.auth.Subject; import javax.security.auth.kerberos.KerberosPrincipal; import javax.security.auth.login.LoginContext; -public abstract class AbstractTestWithStaticConfiguration { +public abstract class AbstractTestWithStaticConfiguration extends RulesForE2ETest { private static final Logger LOGGER = LoggerFactory .getLogger(AbstractTestWithStaticConfiguration.class); - @ClassRule - public final static TestRule timeoutClass = RuleChain - .outerRule(new TestWatcher() { - @Override - protected void failed(Throwable e, Description description) { - LOGGER.error("Time out = " + e); - if (e != null) { - if (e.getMessage().contains("test timed out after")) { - LOGGER.error("Test class time out, but caught by rule, description = " + description + "ex = " + e); - } else {{ - LOGGER.error("Unexpected error: " + e + ", " + e.getStackTrace() + ", " + e.getMessage()); - }} - } - } - }) - .around(new Timeout(600000)); //millis, each test runs less than 600s (or 10m) - - @Rule - public final TestRule timeout = RuleChain - .outerRule(new TestWatcher() { - @Override - protected void failed(Throwable e, Description description) { - if (e.getMessage().contains("test timed out after")) { - LOGGER.error("Test method time out, but caught by rule, description = " + description + "ex = " + e); - } - } - }) - .around(new Timeout(180000)); //millis, each test runs less than 180s (or 3m) - protected static final String SINGLE_TYPE_DATA_FILE_NAME = "kv1.dat"; protected static final String ALL_DB1 = "server=server1->db=db_1", ALL_DB2 = "server=server1->db=db_2", http://git-wip-us.apache.org/repos/asf/sentry/blob/b124675c/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/RulesForE2ETest.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/RulesForE2ETest.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/RulesForE2ETest.java new file mode 100644 index 0000000..5d09b92 --- /dev/null +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/RulesForE2ETest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.sentry.tests.e2e.hive; + +import org.junit.Rule; +import org.junit.ClassRule; +import org.junit.internal.runners.statements.FailOnTimeout; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class contains rules to run e2e tests. + * The way to use a rule is to create an annotation class; + * then add the rule specifically for test classes annotated by that particular class. + */ +public abstract class RulesForE2ETest { + private static final Logger LOGGER = LoggerFactory + .getLogger(RulesForE2ETest.class); + + final static int slowTestClassRunTime = 900000; //millis, each test runs less than 900s (or 15m) + final static int avgTestClassRunTime = 600000; //millis, each test runs less than 600s (or 10m) + final static int slowTestRunTime = 600000; //millis, each test runs less than 600s (or 10m) + final static int avgTestRunTime = 180000; //millis, each test runs less than 180s (or 3m) + + @ClassRule + public final static TestRule timeoutClass = new TestRule() { + @Override + public Statement apply(Statement base, Description description) { + if (description != null && description.getAnnotation(SlowE2ETest.class) != null) { + LOGGER.info("SlowE2ETest class time out is configured as " + slowTestClassRunTime + " s."); + return new FailOnTimeout(base, slowTestClassRunTime); + } + LOGGER.info("Average class time out is configured as " + avgTestClassRunTime + " s."); + return new FailOnTimeout(base, avgTestClassRunTime); //millis, each test runs less than 600s (or 10m) + } + }; + + @Rule + public final TestRule timeout = new TestRule() { + @Override + public Statement apply(Statement base, Description description) { + if (description != null && description.getAnnotation(SlowE2ETest.class) != null) { + LOGGER.info("SlowE2ETest time out is configured as " + slowTestRunTime + " s."); + return new FailOnTimeout(base, slowTestRunTime); + } + LOGGER.info("Average test time out is configured as " + avgTestRunTime + " s."); + return new FailOnTimeout(base, avgTestRunTime); + } + }; +} http://git-wip-us.apache.org/repos/asf/sentry/blob/b124675c/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/SlowE2ETest.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/SlowE2ETest.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/SlowE2ETest.java new file mode 100644 index 0000000..4eee40e --- /dev/null +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/SlowE2ETest.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.sentry.tests.e2e.hive; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(value=RetentionPolicy.RUNTIME) +public @interface SlowE2ETest { + // Just for tagging a test class and method to adapt the timeout +}
