瀏覽代碼

HADOOP-12280. Skip unit tests based on maven profile rather than NativeCodeLoader.isNativeCodeLoaded (Masatake Iwasaki via Colin P. McCabe)

(cherry picked from commit 6f83274afc1eba1159427684d72d8f13778c5a88)
(cherry picked from commit e92107b18f82b3501deaa6170d322a0fb512ec71)
(cherry picked from commit 3bd9b7459bfe2e4d81d60498832dc297cd01e003)
Colin Patrick Mccabe 10 年之前
父節點
當前提交
fb06549e9d

+ 3 - 0
hadoop-common-project/hadoop-common/CHANGES.txt

@@ -352,6 +352,9 @@ Release 2.7.0 - 2015-04-20
     HADOOP-11801. Update BUILDING.txt for Ubuntu. (Gabor Liptak via
     Arpit Agarwal)
 
+    HADOOP-12280. Skip unit tests based on maven profile rather than
+    NativeCodeLoader.isNativeCodeLoaded (Masatake Iwasaki via Colin P. McCabe)
+
   OPTIMIZATIONS
 
     HADOOP-11323. WritableComparator#compare keeps reference to byte array.

+ 3 - 8
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoCodec.java

@@ -37,6 +37,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.DataInputBuffer;
 import org.apache.hadoop.io.DataOutputBuffer;
 import org.apache.hadoop.io.RandomDatum;
+import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.util.NativeCodeLoader;
 import org.apache.hadoop.util.ReflectionUtils;
 import org.junit.Assert;
@@ -69,10 +70,7 @@ public class TestCryptoCodec {
 
   @Test(timeout=120000)
   public void testJceAesCtrCryptoCodec() throws Exception {
-    if (!"true".equalsIgnoreCase(System.getProperty("runningWithNative"))) {
-      LOG.warn("Skipping since test was not run with -Pnative flag");
-      Assume.assumeTrue(false);
-    }
+    GenericTestUtils.assumeInNativeProfile();
     if (!NativeCodeLoader.buildSupportsOpenssl()) {
       LOG.warn("Skipping test since openSSL library not loaded");
       Assume.assumeTrue(false);
@@ -91,10 +89,7 @@ public class TestCryptoCodec {
   
   @Test(timeout=120000)
   public void testOpensslAesCtrCryptoCodec() throws Exception {
-    if (!"true".equalsIgnoreCase(System.getProperty("runningWithNative"))) {
-      LOG.warn("Skipping since test was not run with -Pnative flag");
-      Assume.assumeTrue(false);
-    }
+    GenericTestUtils.assumeInNativeProfile();
     if (!NativeCodeLoader.buildSupportsOpenssl()) {
       LOG.warn("Skipping test since openSSL library not loaded");
       Assume.assumeTrue(false);

+ 2 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithOpensslAesCtrCryptoCodec.java

@@ -18,6 +18,7 @@
 package org.apache.hadoop.crypto;
 
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.test.GenericTestUtils;
 import org.junit.BeforeClass;
 
 public class TestCryptoStreamsWithOpensslAesCtrCryptoCodec 
@@ -25,6 +26,7 @@ public class TestCryptoStreamsWithOpensslAesCtrCryptoCodec
   
   @BeforeClass
   public static void init() throws Exception {
+    GenericTestUtils.assumeInNativeProfile();
     Configuration conf = new Configuration();
     codec = CryptoCodec.getInstance(conf);
   }

+ 5 - 0
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.assumeInNativeProfile();
 
     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.assumeInNativeProfile();
 
     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.assumeInNativeProfile();
+
     Path file = new Path(ROOT_PATH, "testseqappendSort.seq");
     fs.delete(file, true);
 

+ 11 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java

@@ -43,6 +43,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 +411,14 @@ public abstract class GenericTestUtils {
       }
     }
   }
+
+  /**
+   * Skip test if native build profile of Maven is not activated.
+   * Sub-project using this must set 'runningWithNative' property to true
+   * in the definition of native profile in pom.xml.
+   */
+  public static void assumeInNativeProfile() {
+    Assume.assumeTrue(
+        Boolean.valueOf(System.getProperty("runningWithNative", "false")));
+  }
 }