You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by pr...@apache.org on 2014/03/10 02:57:03 UTC

svn commit: r1575791 - in /pig/trunk: CHANGES.txt test/org/apache/pig/test/TestBlackAndWhitelistValidator.java test/org/apache/pig/test/Util.java

Author: prkommireddi
Date: Mon Mar 10 01:57:03 2014
New Revision: 1575791

URL: http://svn.apache.org/r1575791
Log:
PIG-3802: Fix TestBlackAndWhitelistValidator failures (prkommireddi)

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/test/org/apache/pig/test/TestBlackAndWhitelistValidator.java
    pig/trunk/test/org/apache/pig/test/Util.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1575791&r1=1575790&r2=1575791&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Mon Mar 10 01:57:03 2014
@@ -30,6 +30,8 @@ PIG-2207: Support custom counters for ag
 
 IMPROVEMENTS
 
+PIG-3802: Fix TestBlackAndWhitelistValidator failures (prkommireddi)
+
 PIG-3765: Ability to disable Pig commands and operators (prkommireddi)
 
 PIG-3731: Ability to specify local-mode specific configuration (useful for local/auto-local mode) (aniket486)

Modified: pig/trunk/test/org/apache/pig/test/TestBlackAndWhitelistValidator.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestBlackAndWhitelistValidator.java?rev=1575791&r1=1575790&r2=1575791&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestBlackAndWhitelistValidator.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestBlackAndWhitelistValidator.java Mon Mar 10 01:57:03 2014
@@ -20,6 +20,7 @@ package org.apache.pig.test;
 import static org.apache.pig.builtin.mock.Storage.resetData;
 import static org.apache.pig.builtin.mock.Storage.tuple;
 import static org.apache.pig.newplan.logical.relational.LOTestHelper.newLOLoad;
+import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.util.Properties;
@@ -46,9 +47,7 @@ import org.apache.pig.tools.grunt.GruntP
 import org.apache.pig.validator.BlackAndWhitelistFilter;
 import org.apache.pig.validator.BlackAndWhitelistValidator;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 /**
  * 
@@ -59,9 +58,6 @@ import org.junit.rules.ExpectedException
 public class TestBlackAndWhitelistValidator {
     private PigContext ctx;
 
-    @Rule
-    public ExpectedException expectedEx = ExpectedException.none();
-
     @Before
     public void setUp() throws Exception {
         ctx = new PigContext(ExecType.LOCAL, new Properties());
@@ -76,22 +72,26 @@ public class TestBlackAndWhitelistValida
      */
     @Test
     public void testBlacklist() throws Exception {
-        expectedEx.expect(FrontendException.class);
-        expectedEx.expectMessage("SET command is not permitted");
-        ctx.getProperties().setProperty(PigConfiguration.PIG_BLACKLIST, "set");
-        PigServer pigServer = new PigServer(ctx);
-        Data data = resetData(pigServer);
-
-        data.set("foo", tuple("a", 1, "b"), tuple("b", 2, "c"),
-                tuple("c", 3, "d"));
-
-        StringBuilder script = new StringBuilder();
-        script.append("set io.sort.mb 1000;")
-                .append("A = LOAD 'foo' USING mock.Storage() AS (f1:chararray,f2:int,f3:chararray);")
-                .append("B = order A by f1,f2,f3 DESC;")
-                .append("STORE B INTO 'bar' USING mock.Storage();");
-
-        pigServer.registerScript(IOUtils.toInputStream(script));
+        try {
+            ctx.getProperties().setProperty(PigConfiguration.PIG_BLACKLIST, "set");
+            PigServer pigServer = new PigServer(ctx);
+            Data data = resetData(pigServer);
+
+            data.set("foo", tuple("a", 1, "b"), tuple("b", 2, "c"),
+                    tuple("c", 3, "d"));
+
+            StringBuilder script = new StringBuilder();
+            script.append("set io.sort.mb 1000;")
+                    .append("A = LOAD 'foo' USING mock.Storage() AS (f1:chararray,f2:int,f3:chararray);")
+                    .append("B = order A by f1,f2,f3 DESC;")
+                    .append("STORE B INTO 'bar' USING mock.Storage();");
+
+            pigServer.registerScript(IOUtils.toInputStream(script));
+            fail();
+        } catch (Exception e) {
+            Util.assertExceptionAndMessage(FrontendException.class, e,
+                    "SET command is not permitted. ");
+        }
     }
 
     /**
@@ -103,16 +103,19 @@ public class TestBlackAndWhitelistValida
      */
     @Test
     public void testValidator() throws Exception {
-        expectedEx.expect(FrontendException.class);
-        expectedEx.expectMessage("filter is disabled");
-        // disabling filter
-        ctx.getProperties().setProperty(PigConfiguration.PIG_BLACKLIST,
-                "filter");
-
-        LogicalPlan plan = generateLogicalPlan("foo", "bar", ctx.getDfs());
-
-        LogicalRelationalNodeValidator executor = new BlackAndWhitelistValidator(ctx, plan);
-        executor.validate();
+        try {
+            // disabling filter
+            ctx.getProperties().setProperty(PigConfiguration.PIG_BLACKLIST, "filter");
+
+            LogicalPlan plan = generateLogicalPlan("foo", "bar", ctx.getDfs());
+
+            LogicalRelationalNodeValidator executor = new BlackAndWhitelistValidator(ctx, plan);
+            executor.validate();
+            fail();
+        } catch (Exception e) {
+            Util.assertExceptionAndMessage(FrontendException.class, e,
+                    "filter is disabled. ");
+        }
     }
 
     /**
@@ -134,17 +137,19 @@ public class TestBlackAndWhitelistValida
 
     @Test
     public void testWhitelist2() throws Exception {
-        expectedEx.expect(FrontendException.class);
-        expectedEx.expectMessage("filter is disabled");
-        // only load and store are allowed. Having a filter in the logical plan
-        // must
-        // cause the script to fail
-        ctx.getProperties().setProperty(PigConfiguration.PIG_WHITELIST,
-                "load, store");
-        LogicalPlan plan = generateLogicalPlan("foo", "bar", ctx.getDfs());
-
-        LogicalRelationalNodeValidator executor = new BlackAndWhitelistValidator(ctx, plan);
-        executor.validate();
+        try {
+            // only load and store are allowed. Having a filter in the logical
+            // plan must cause the script to fail
+            ctx.getProperties().setProperty(PigConfiguration.PIG_WHITELIST, "load, store");
+            LogicalPlan plan = generateLogicalPlan("foo", "bar", ctx.getDfs());
+
+            LogicalRelationalNodeValidator executor = new BlackAndWhitelistValidator(ctx, plan);
+            executor.validate();
+            fail();
+        } catch (Exception e) {
+            Util.assertExceptionAndMessage(FrontendException.class, e,
+                    "filter is disabled. ");
+        }
     }
 
     /**
@@ -155,18 +160,18 @@ public class TestBlackAndWhitelistValida
      */
     @Test
     public void testBlackAndWhitelist() throws Exception {
-        expectedEx.expect(IllegalStateException.class);
-        expectedEx
-                .expectMessage("Conflict between whitelist and blacklist. 'filter' appears in both.");
-
-        ctx.getProperties().setProperty(PigConfiguration.PIG_WHITELIST,
-                "load, store, filter");
-        ctx.getProperties().setProperty(PigConfiguration.PIG_BLACKLIST,
-                "filter");
-        LogicalPlan plan = generateLogicalPlan("foo", "bar", ctx.getDfs());
-
-        LogicalRelationalNodeValidator executor = new BlackAndWhitelistValidator(ctx, plan);
-        executor.validate();
+        try {
+            ctx.getProperties().setProperty(PigConfiguration.PIG_WHITELIST, "load, store, filter");
+            ctx.getProperties().setProperty(PigConfiguration.PIG_BLACKLIST, "filter");
+            LogicalPlan plan = generateLogicalPlan("foo", "bar", ctx.getDfs());
+
+            LogicalRelationalNodeValidator executor = new BlackAndWhitelistValidator(ctx, plan);
+            executor.validate();
+            fail();
+        } catch (Exception e) {
+            Util.assertExceptionAndMessage(IllegalStateException.class, e,
+                    "Conflict between whitelist and blacklist. 'filter' appears in both.");
+        }
     }
 
     /**
@@ -175,8 +180,7 @@ public class TestBlackAndWhitelistValida
      */
     @Test(expected = FrontendException.class)
     public void testBlacklistWithPigServer() throws Exception {
-        ctx.getProperties()
-                .setProperty(PigConfiguration.PIG_BLACKLIST, "order");
+        ctx.getProperties().setProperty(PigConfiguration.PIG_BLACKLIST, "order");
         PigServer pigServer = new PigServer(ctx);
         Data data = resetData(pigServer);
 
@@ -193,13 +197,15 @@ public class TestBlackAndWhitelistValida
      */
     @Test
     public void testBlacklistCmdWithPigServer() throws Exception {
-        expectedEx.expect(FrontendException.class);
-        expectedEx.expectMessage("LS command is not permitted");
-
-        ctx.getProperties().setProperty(PigConfiguration.PIG_BLACKLIST, "ls");
-        PigServer pigServer = new PigServer(ctx);
-
-        pigServer.listPaths("foo");
+        try {
+            ctx.getProperties().setProperty(PigConfiguration.PIG_BLACKLIST, "ls");
+            PigServer pigServer = new PigServer(ctx);
+            pigServer.listPaths("foo");
+            fail();
+        } catch (Exception e) {
+            Util.assertExceptionAndMessage(FrontendException.class, e,
+                    "LS command is not permitted. ");
+        }
     }
 
     /**

Modified: pig/trunk/test/org/apache/pig/test/Util.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/Util.java?rev=1575791&r1=1575790&r2=1575791&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/Util.java (original)
+++ pig/trunk/test/org/apache/pig/test/Util.java Mon Mar 10 01:57:03 2014
@@ -1257,4 +1257,19 @@ public class Util {
             return true;
         return false;
     }
+
+    /**
+     * 
+     * @param expected
+     *            Exception class that is expected to be thrown
+     * @param found
+     *            Exception that occurred in the test
+     * @param message
+     *            expected String to verify against
+     */
+    public static void assertExceptionAndMessage(Class<?> expected,
+            Exception found, String message) {
+        assertEquals(expected, found.getClass());
+        assertEquals(found.getMessage(), message);
+    }
 }