From 90c5bf0605951dd1689453737884c68f98887ebc 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. (cherry picked from commit 90bda9c6110f0344104b8ae96ea6999770ebb391) --- 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 4b2d76783fd..370bd7f255b 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -478,6 +478,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 d5f25b80960..9bbdf0a76e7 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 @@ package org.apache.hadoop.crypto; 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 4576642c9b0..7aa305fbe16 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.SequenceFile.Writer.Option; 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 class TestSequenceFileAppend { @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 class TestSequenceFileAppend { @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 class TestSequenceFileAppend { @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 65c18d13ba7..7d52a8a8509 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 java.util.regex.Pattern; 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.LogManager; 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 abstract class GenericTestUtils { } } } + + /** + * Skip test if native code is not loaded. + */ + public static void assumeNativeCodeLoaded() { + Assume.assumeTrue(NativeCodeLoader.isNativeCodeLoaded()); + } }