You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by rr...@apache.org on 2010/03/06 20:13:27 UTC

svn commit: r919818 - /ode/branches/APACHE_ODE_1.X/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java

Author: rr
Date: Sat Mar  6 19:13:27 2010
New Revision: 919818

URL: http://svn.apache.org/viewvc?rev=919818&view=rev
Log:
ODE-405: ActivityRecoveryTest fails on some machines due to timing fix

Modified:
    ode/branches/APACHE_ODE_1.X/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java

Modified: ode/branches/APACHE_ODE_1.X/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java?rev=919818&r1=919817&r2=919818&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java Sat Mar  6 19:13:27 2010
@@ -54,12 +54,12 @@
  * Test activity recovery and failure handling.
  */
 public class ActivityRecoveryTest extends MockObjectTestCase {
-	// the maximum ammout of time to wait for an instance to reach a
-	// desired status or for an activity to become available for recovery
+    // the maximum ammout of time to wait for an instance to reach a
+    // desired status or for an activity to become available for recovery
     static final int MAX_WAIT = 10000;
     // poll interval
-    static final int DELAY = 100;
-	
+    static final int DELAY = 10;
+    
     static final String   NAMESPACE = "http://ode.apache.org/bpel/unit-test";
     static final String[] ACTIONS = new String[]{ "retry", "cancel", "fault" };
     MockBpelServer        _server;
@@ -157,7 +157,8 @@
 
         execute("FailureToFault");
         assertNotNull(lastInstance(TInstanceStatus.FAILED));
-        assertTrue(OFailureHandling.FAILURE_FAULT_NAME.equals(lastInstance(TInstanceStatus.FAILED).getFaultInfo().getName()));
+        TInstanceInfo v = lastInstance(TInstanceStatus.FAILED);
+        assertTrue(OFailureHandling.FAILURE_FAULT_NAME.equals(v.getFaultInfo().getName()));
         assertNoFailures();
     }
 
@@ -327,30 +328,30 @@
      * @throws Exception
      */
     protected TInstanceInfo lastInstance(TInstanceStatus.Enum expected) throws Exception {
-    	int counter = 0;
-    	do {
-    		TInstanceInfo info = getInstanceInfo();
-    		if (info != null  && (expected == null || info.getStatus() == expected)) {
-    			return info;
-    		}
-    		if (counter * DELAY > MAX_WAIT) {
-    			throw new Exception("Timed out wait for instance to reach "+expected+
-    					" status. Actual status: "+(info==null?"missing instance" : info.getStatus()));
-    		}
-    		counter++;
-    		Thread.sleep(DELAY);
-    	} while (true);
+        int counter = 0;
+        do {
+            TInstanceInfo info = getInstanceInfo();
+            if (info != null  && (expected == null || expected != TInstanceStatus.FAILED && info.getStatus() == expected || expected == TInstanceStatus.FAILED && info.getFaultInfo() != null)) {
+                return info;
+            }
+            if (counter * DELAY > MAX_WAIT) {
+                throw new Exception("Timed out wait for instance to reach "+expected+
+                        " status. Actual status: "+(info==null?"missing instance" : info.getStatus()));
+            }
+            counter++;
+            Thread.sleep(DELAY);
+        } while (true);
     }
     /**
      * get the instance info for the last instance 
      */
     private TInstanceInfo getInstanceInfo() {
-    	TInstanceInfoList instances = _management.listInstances("", "", 1000).getInstanceInfoList();
-		int size = instances.sizeOfInstanceInfoArray();
-		if (size > 0) {
-			return instances.getInstanceInfoArray(instances.sizeOfInstanceInfoArray() - 1);
-		}
-		return null;
+        TInstanceInfoList instances = _management.listInstances("", "", 1000).getInstanceInfoList();
+        int size = instances.sizeOfInstanceInfoArray();
+        if (size > 0) {
+            return instances.getInstanceInfoArray(instances.sizeOfInstanceInfoArray() - 1);
+        }
+        return null;
     }
 
     /**
@@ -361,8 +362,17 @@
         // Process is still active, none of the completed states.
         assertNotNull(lastInstance(TInstanceStatus.ACTIVE));
         // Tests here will only generate one failure.
-        TInstanceInfo instance = lastInstance(null);
-        TFailuresInfo failures = instance.getFailures();
+        TInstanceInfo instance;
+        TFailuresInfo failures;
+        while (true) {
+            instance = lastInstance(null);
+            failures = instance.getFailures();
+            if (failures == null) {
+                Thread.sleep(DELAY);
+            } else {
+                break;
+            }
+        }
         assertTrue(failures != null && failures.getCount() == 1);
         failures = _management.getProcessInfo(_processId).getProcessInfo().getInstanceSummary().getFailures();
         assertTrue(failures != null && failures.getCount() == 1);
@@ -385,7 +395,7 @@
      * recovery channel for the activity in question.
      */
     protected void recover(String action) throws Exception {
-    	ArrayList<TActivityInfo> recoveries = getRecoveries();
+        ArrayList<TActivityInfo> recoveries = getRecoveries();
         assertTrue(recoveries.size() == 1);
         TActivityInfo activity = recoveries.get(0);
         assertNotNull(activity);
@@ -397,22 +407,22 @@
      * if MAX_WAIT exceeded
      */
     private ArrayList<TActivityInfo> getRecoveries() throws Exception {
-    	TInstanceInfo instance = null;
-    	int counter = 0;
-    	do {
-    		instance = getInstanceInfo();
-    		if (instance != null) {
-    			ArrayList<TActivityInfo> recoveries = getRecoveriesInScope(instance, null, null);
-    			if (recoveries.size() > 0) {
-    				return recoveries;
-    			}
-    		}
-    		if (counter * DELAY > MAX_WAIT) {
-    			throw new Exception("Timed out wait for recovery activities");
-    		}
-    		Thread.sleep(DELAY);
-    		counter++;
-    	} while (true);
+        TInstanceInfo instance = null;
+        int counter = 0;
+        do {
+            instance = getInstanceInfo();
+            if (instance != null) {
+                ArrayList<TActivityInfo> recoveries = getRecoveriesInScope(instance, null, null);
+                if (recoveries.size() > 0) {
+                    return recoveries;
+                }
+            }
+            if (counter * DELAY > MAX_WAIT) {
+                throw new Exception("Timed out wait for recovery activities");
+            }
+            Thread.sleep(DELAY);
+            counter++;
+        } while (true);
     }
 
     protected ArrayList<TActivityInfo> getRecoveriesInScope(TInstanceInfo instance, TScopeInfo scope,