Author: kamrul
Date: Wed Mar 28 19:55:41 2012
New Revision: 1306560

URL: http://svn.apache.org/viewvc?rev=1306560&view=rev
Log:
OOZIE-781: Xerces validator used by Java gets stuck during pattern matching 
(Virag via Mohammad)

Modified:
    incubator/oozie/trunk/client/pom.xml
    
incubator/oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestValidation.java
    
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestSchemaService.java
    
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/workflow/lite/TestLiteWorkflowAppParser.java
    incubator/oozie/trunk/pom.xml
    incubator/oozie/trunk/release-log.txt

Modified: incubator/oozie/trunk/client/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/client/pom.xml?rev=1306560&r1=1306559&r2=1306560&view=diff
==============================================================================
--- incubator/oozie/trunk/client/pom.xml (original)
+++ incubator/oozie/trunk/client/pom.xml Wed Mar 28 19:55:41 2012
@@ -59,6 +59,11 @@
                 </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>xerces</groupId>
+            <artifactId>xercesImpl</artifactId>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
     <build>

Modified: 
incubator/oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestValidation.java
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestValidation.java?rev=1306560&r1=1306559&r2=1306560&view=diff
==============================================================================
--- 
incubator/oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestValidation.java
 (original)
+++ 
incubator/oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestValidation.java
 Wed Mar 28 19:55:41 2012
@@ -6,9 +6,9 @@
  * 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.
@@ -21,6 +21,7 @@ import junit.framework.TestCase;
 
 import java.net.URL;
 import java.net.URI;
+import java.util.concurrent.TimeoutException;
 import java.io.File;
 
 public class TestValidation extends TestCase {
@@ -42,4 +43,22 @@ public class TestValidation extends Test
         assertEquals(-1, new OozieCLI().run(args));
     }
 
+    // Test for Validation of workflow definition against pattern defined in 
schema to complete within 3 seconds
+    public void testTimeout() throws Exception {
+        final String[] args = new String[] { "validate", 
getPath("timeout.xml") };
+        Thread testThread = new Thread() {
+            public void run() {
+                assertEquals(-1, new OozieCLI().run(args));
+            }
+        };
+        testThread.start();
+        Thread.sleep(3000);
+        // Timeout if validation takes more than 3 seconds
+        testThread.interrupt();
+
+        if (testThread.isInterrupted()) {
+            throw new TimeoutException("The pattern validation took too long 
to complete");
+        }
+    }
+
 }

Modified: 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestSchemaService.java
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestSchemaService.java?rev=1306560&r1=1306559&r2=1306560&view=diff
==============================================================================
--- 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestSchemaService.java
 (original)
+++ 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestSchemaService.java
 Wed Mar 28 19:55:41 2012
@@ -6,9 +6,9 @@
  * 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.
@@ -22,15 +22,23 @@ import org.apache.oozie.service.SchemaSe
 import org.apache.oozie.test.XTestCase;
 import org.apache.oozie.util.XmlUtils;
 import org.jdom.Element;
+import org.xml.sax.SAXParseException;
 
 import javax.xml.validation.Validator;
 import javax.xml.transform.stream.StreamSource;
+
 import java.io.StringReader;
+import java.util.concurrent.TimeoutException;
 
 public class TestSchemaService extends XTestCase {
 
+    public static final String LONG_STRING_PATTERN_VALIDATION = 
"I_am_long_string_with_a_period_._which_is_not_allowed_according_to_schema";
+    public static final String APP_NEG_TEST = "<workflow-app 
xmlns='uri:oozie:workflow:0.1' name='"+LONG_STRING_PATTERN_VALIDATION+"'>" +
+            "<start to='end'/>" +
+            "<end name='end'/>" +
+            "</workflow-app>";
 
-    private static final String APP1 = "<workflow-app 
xmlns='uri:oozie:workflow:0.1' name='app'>" +
+       private static final String APP1 = "<workflow-app 
xmlns='uri:oozie:workflow:0.1' name='app'>" +
             "<start to='end'/>" +
             "<end name='end'/>" +
             "</workflow-app>";
@@ -106,6 +114,34 @@ public class TestSchemaService extends X
         validator.validate(new StreamSource(new StringReader(APP1)));
     }
 
+    // Test for validation of workflow definition against pattern defined in 
schema to complete within 3 seconds
+    public void testWfSchemaFailure() throws Exception {
+        SchemaService wss = Services.get().get(SchemaService.class);
+        final Validator validator = 
wss.getSchema(SchemaName.WORKFLOW).newValidator();
+        Thread testThread = new Thread() {
+            public void run() {
+                try {
+                    // Validate against wf def
+                    validator.validate(new StreamSource(new 
StringReader(APP_NEG_TEST)));
+                    fail("Expected to catch ParseException but didn't 
encounter any");
+                } catch (SAXParseException saxpe) {
+                    // Expected
+                } catch (Exception e) {
+                    fail("Expected to catch ParseException but an unexpected 
error happened " + e.getMessage());
+                }
+            }
+        };
+
+        testThread.start();
+        Thread.sleep(3000);
+        // Timeout if validation takes more than 3 seconds
+        testThread.interrupt();
+
+        if (testThread.isInterrupted()) {
+            throw new TimeoutException("the pattern validation took too long 
to complete");
+        }
+    }
+
     public void testWfSchemaV2() throws Exception {
         SchemaService wss = Services.get().get(SchemaService.class);
         Validator validator = 
wss.getSchema(SchemaName.WORKFLOW).newValidator();

Modified: 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/workflow/lite/TestLiteWorkflowAppParser.java
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/workflow/lite/TestLiteWorkflowAppParser.java?rev=1306560&r1=1306559&r2=1306560&view=diff
==============================================================================
--- 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/workflow/lite/TestLiteWorkflowAppParser.java
 (original)
+++ 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/workflow/lite/TestLiteWorkflowAppParser.java
 Wed Mar 28 19:55:41 2012
@@ -18,16 +18,22 @@
 package org.apache.oozie.workflow.lite;
 
 
+import java.io.StringReader;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.TimeoutException;
+
 
 
 import org.apache.oozie.service.LiteWorkflowStoreService;
+import org.apache.oozie.service.SchemaService;
 import org.apache.oozie.service.Services;
 import org.apache.oozie.service.ActionService;
+import org.apache.oozie.service.SchemaService.SchemaName;
+import org.apache.oozie.service.TestSchemaService;
 import org.apache.oozie.workflow.WorkflowException;
 import 
org.apache.oozie.workflow.lite.TestLiteWorkflowLib.TestActionNodeHandler;
 import 
org.apache.oozie.workflow.lite.TestLiteWorkflowLib.TestDecisionNodeHandler;
@@ -102,6 +108,37 @@ public class TestLiteWorkflowAppParser e
         }
     }
 
+    // Test for validation of workflow definition against pattern defined in 
schema to complete within 3 seconds
+    public void testWfValidationFailure() throws Exception {
+        SchemaService wss = Services.get().get(SchemaService.class);
+        final LiteWorkflowAppParser parser = new 
LiteWorkflowAppParser(wss.getSchema(SchemaName.WORKFLOW),
+                LiteWorkflowStoreService.LiteDecisionHandler.class, 
LiteWorkflowStoreService.LiteActionHandler.class);
+
+        Thread testThread = new Thread() {
+            public void run() {
+                try {
+                    // Validate against wf def
+                    parser.validateAndParse(new 
StringReader(TestSchemaService.APP_NEG_TEST));
+                    fail("Expected to catch WorkflowException but didn't 
encounter any");
+                } catch (WorkflowException we) {
+                    assertEquals(ErrorCode.E0701, we.getErrorCode());
+                    
assertTrue(we.getCause().toString().contains("SAXParseException"));
+                } catch (Exception e) {
+                    fail("Expected to catch WorkflowException but an 
unexpected error happened");
+                }
+
+            }
+        };
+        testThread.start();
+        Thread.sleep(3000);
+        // Timeout if validation takes more than 3 seconds
+        testThread.interrupt();
+
+        if (testThread.isInterrupted()) {
+            throw new TimeoutException("the pattern validation took too long 
to complete");
+        }
+    }
+
     /*
      * 1->ok->2
      * 2->ok->end

Modified: incubator/oozie/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/pom.xml?rev=1306560&r1=1306559&r2=1306560&view=diff
==============================================================================
--- incubator/oozie/trunk/pom.xml (original)
+++ incubator/oozie/trunk/pom.xml Wed Mar 28 19:55:41 2012
@@ -621,6 +621,12 @@
                 <version>3.0.1</version>
             </dependency>
 
+            <dependency>
+                <groupId>xerces</groupId>
+                <artifactId>xercesImpl</artifactId>
+                <version>2.10.0</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>
 

Modified: incubator/oozie/trunk/release-log.txt
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/release-log.txt?rev=1306560&r1=1306559&r2=1306560&view=diff
==============================================================================
--- incubator/oozie/trunk/release-log.txt (original)
+++ incubator/oozie/trunk/release-log.txt Wed Mar 28 19:55:41 2012
@@ -1,5 +1,6 @@
 -- Oozie 3.2.0 release
 
+OOZIE-781: Xerces validator used by Java gets stuck during pattern matching 
(Virag via Mohammad)
 OOZIE-788 JavaActionExecutor should not set yarn.resourcemanager.address (tucu)
 OOZIE-785 No JsonToBean mapping for coord pausetime(shwetha via Mohammad)
 OOZIE-786 tomcat should stop if oozie does not start correctly (tucu)


Reply via email to