From 90bda9c6110f0344104b8ae96ea6999770ebb391 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Ozawa Date: Thu, 16 Jul 2015 16:04:55 +0900 Subject: [PATCH] HADOOP-12240. Fix tests requiring native library to be skipped in non-native profile. Contributed by Masatake Iwasaki. --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../TestCryptoStreamsWithOpensslAesCtrCryptoCodec.java | 5 ++--- .../org/apache/hadoop/io/TestSequenceFileAppend.java | 5 +++++ .../java/org/apache/hadoop/test/GenericTestUtils.java | 9 +++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 9bb7a26c23..cf79bab0c5 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -964,6 +964,9 @@ Release 2.8.0 - UNRELEASED HADOOP-10615. FileInputStream in JenkinsHash#main() is never closed. (Chen He via ozawa) + HADOOP-12240. Fix tests requiring native library to be skipped in non-native + profile. (Masatake Iwasaki via ozawa) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithOpensslAesCtrCryptoCodec.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithOpensslAesCtrCryptoCodec.java index d5f25b8096..9bbdf0a76e 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithOpensslAesCtrCryptoCodec.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithOpensslAesCtrCryptoCodec.java @@ -19,19 +19,18 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.CommonConfigurationKeysPublic; -import org.apache.hadoop.util.NativeCodeLoader; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.BeforeClass; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assume.assumeTrue; public class TestCryptoStreamsWithOpensslAesCtrCryptoCodec extends TestCryptoStreams { @BeforeClass public static void init() throws Exception { - assumeTrue(NativeCodeLoader.isNativeCodeLoaded()); + GenericTestUtils.assumeNativeCodeLoaded(); Configuration conf = new Configuration(); conf.set( CommonConfigurationKeysPublic.HADOOP_SECURITY_CRYPTO_CODEC_CLASSES_AES_CTR_NOPADDING_KEY, diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSequenceFileAppend.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSequenceFileAppend.java index 4576642c9b..7aa305fbe1 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSequenceFileAppend.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSequenceFileAppend.java @@ -34,6 +34,7 @@ import org.apache.hadoop.io.compress.DefaultCodec; import org.apache.hadoop.io.compress.GzipCodec; import org.apache.hadoop.io.serializer.JavaSerializationComparator; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -140,6 +141,7 @@ public void testAppend() throws Exception { @Test(timeout = 30000) public void testAppendRecordCompression() throws Exception { + GenericTestUtils.assumeNativeCodeLoaded(); Path file = new Path(ROOT_PATH, "testseqappendblockcompr.seq"); fs.delete(file, true); @@ -173,6 +175,7 @@ public void testAppendRecordCompression() throws Exception { @Test(timeout = 30000) public void testAppendBlockCompression() throws Exception { + GenericTestUtils.assumeNativeCodeLoaded(); Path file = new Path(ROOT_PATH, "testseqappendblockcompr.seq"); fs.delete(file, true); @@ -247,6 +250,8 @@ public void testAppendBlockCompression() throws Exception { @Test(timeout = 30000) public void testAppendSort() throws Exception { + GenericTestUtils.assumeNativeCodeLoaded(); + Path file = new Path(ROOT_PATH, "testseqappendSort.seq"); fs.delete(file, true); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java index 65c18d13ba..7d52a8a850 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java @@ -35,6 +35,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.impl.Log4JLogger; import org.apache.hadoop.fs.FileUtil; +import org.apache.hadoop.util.NativeCodeLoader; import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.Time; import org.apache.log4j.Layout; @@ -43,6 +44,7 @@ import org.apache.log4j.Logger; import org.apache.log4j.WriterAppender; import org.junit.Assert; +import org.junit.Assume; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -410,4 +412,11 @@ public static void assertNoThreadsMatching(String regex) { } } } + + /** + * Skip test if native code is not loaded. + */ + public static void assumeNativeCodeLoaded() { + Assume.assumeTrue(NativeCodeLoader.isNativeCodeLoaded()); + } }