svn commit: r572280 - in /ofbiz/trunk/framework/service: ./ servicedef/ src/org/ofbiz/service/test/ testdef/ testdef/data/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r572280 - in /ofbiz/trunk/framework/service: ./ servicedef/ src/org/ofbiz/service/test/ testdef/ testdef/data/

jonesde
Author: jonesde
Date: Mon Sep  3 03:45:24 2007
New Revision: 572280

URL: http://svn.apache.org/viewvc?rev=572280&view=rev
Log:
Added some test cases for deadlock and lock wait timeout errors to be used when developing auto retry feature in service engine; note that this isn't implemented yet so these (usually not used) test cases will fail, if that becommes a problem we can comment them out in the test def xml file

Added:
    ofbiz/trunk/framework/service/servicedef/services_test_se.xml   (with props)
    ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java   (with props)
    ofbiz/trunk/framework/service/testdef/data/
    ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml   (with props)
    ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml   (with props)
    ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml   (with props)
Modified:
    ofbiz/trunk/framework/service/ofbiz-component.xml
    ofbiz/trunk/framework/service/testdef/servicetests.xml

Modified: ofbiz/trunk/framework/service/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/ofbiz-component.xml?rev=572280&r1=572279&r2=572280&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/ofbiz-component.xml (original)
+++ ofbiz/trunk/framework/service/ofbiz-component.xml Mon Sep  3 03:45:24 2007
@@ -34,7 +34,8 @@
     <entity-resource type="data" reader-name="seed" loader="main" location="data/ServiceSecurityData.xml"/>
 
     <service-resource type="model" loader="main" location="servicedef/services.xml"/>
-
+    <service-resource type="model" loader="main" location="servicedef/services_test_se.xml"/>
+    
     <test-suite loader="main" location="testdef/servicetests.xml"/>
 
     <keystore name="rmitrust" type="jks" password="changeit" is-truststore="true"

Added: ofbiz/trunk/framework/service/servicedef/services_test_se.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/servicedef/services_test_se.xml?rev=572280&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/servicedef/services_test_se.xml (added)
+++ ofbiz/trunk/framework/service/servicedef/services_test_se.xml Mon Sep  3 03:45:24 2007
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+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.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/services.xsd">
+ <description>OFBiz Service Engine Services</description>
+ <vendor>OFBiz</vendor>
+ <version>1.0</version>
+
+    <!-- dead lock retry testing services -->
+    <service name="testServiceDeadLockRetry" engine="java" auth="false"
+        location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceDeadLockRetry">
+        <implements service="testServiceInterface"/>
+    </service>
+    <service name="testServiceDeadLockRetryThreadA" engine="java" auth="false"
+        location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceDeadLockRetryThreadA">
+    </service>
+    <service name="testServiceDeadLockRetryThreadB" engine="java" auth="false"
+        location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceDeadLockRetryThreadB">
+    </service>
+    
+    <!-- lock wait timeout retry testing services -->
+    <service name="testServiceLockWaitTimeoutRetry" engine="java" auth="false"
+        location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceLockWaitTimeoutRetry">
+        <implements service="testServiceInterface"/>
+    </service>
+    <service name="testServiceLockWaitTimeoutRetryGrabber" engine="java" auth="false"
+        location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceLockWaitTimeoutRetryGrabber">
+    </service>
+    <service name="testServiceLockWaitTimeoutRetryWaiter" engine="java" auth="false"
+        location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceLockWaitTimeoutRetryWaiter">
+    </service>
+</services>

Propchange: ofbiz/trunk/framework/service/servicedef/services_test_se.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/service/servicedef/services_test_se.xml
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/framework/service/servicedef/services_test_se.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java?rev=572280&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java (added)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java Mon Sep  3 03:45:24 2007
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.service.test;
+
+import java.util.Map;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ServiceUtil;
+
+public class ServiceEngineTestServices {
+
+    public static final String module = ServiceEngineTestServices.class.getName();
+    
+    public static Map testServiceDeadLockRetry(DispatchContext dctx, Map context) {
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        try {
+            dispatcher.runAsync("testServiceDeadLockRetryThreadA", null, false);
+            dispatcher.runAsync("testServiceDeadLockRetryThreadB", null, false);
+        } catch (GenericServiceException e) {
+            String errMsg = "Error running deadlock test services: " + e.toString();
+            Debug.logError(e, errMsg, module);
+        }
+        
+        return ServiceUtil.returnSuccess();
+    }
+    
+    public static Map testServiceDeadLockRetryThreadA(DispatchContext dctx, Map context) {
+        GenericDelegator delegator = dctx.getDelegator();
+
+        try {
+            // grab entity SVCLRT_A by changing, then wait, then find and change SVCLRT_B
+            GenericValue testingTypeA = delegator.findByPrimaryKey("TestingType", UtilMisc.toMap("testingTypeId", "SVCLRT_A"));
+            testingTypeA.set("description", "New description for SVCLRT_A");
+            testingTypeA.store();
+            
+            // wait at least long enough for the other method to have locked resource B
+            ServiceEngineTestServices.class.wait(100);
+
+            GenericValue testingTypeB = delegator.findByPrimaryKey("TestingType", UtilMisc.toMap("testingTypeId", "SVCLRT_B"));
+            testingTypeB.set("description", "New description for SVCLRT_B");
+            testingTypeB.store();
+        } catch (GenericEntityException e) {
+            String errMsg = "Entity Engine Exception running dead lock test thread A: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        } catch (InterruptedException e) {
+            String errMsg = "Wait Interrupted Exception running dead lock test thread A: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        }
+
+        return ServiceUtil.returnSuccess();
+    }
+    public static Map testServiceDeadLockRetryThreadB(DispatchContext dctx, Map context) {
+        GenericDelegator delegator = dctx.getDelegator();
+
+        try {
+            // grab entity SVCLRT_B by changing, then wait, then change SVCLRT_A
+            GenericValue testingTypeB = delegator.findByPrimaryKey("TestingType", UtilMisc.toMap("testingTypeId", "SVCLRT_B"));
+            testingTypeB.set("description", "New description for SVCLRT_B");
+            testingTypeB.store();
+            
+            // wait at least long enough for the other method to have locked resource B
+            ServiceEngineTestServices.class.wait(100);
+
+            GenericValue testingTypeA = delegator.findByPrimaryKey("TestingType", UtilMisc.toMap("testingTypeId", "SVCLRT_A"));
+            testingTypeA.set("description", "New description for SVCLRT_A");
+            testingTypeA.store();
+        } catch (GenericEntityException e) {
+            String errMsg = "Entity Engine Exception running dead lock test thread B: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        } catch (InterruptedException e) {
+            String errMsg = "Wait Interrupted Exception running dead lock test thread B: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        }
+
+        return ServiceUtil.returnSuccess();
+    }
+
+    public static Map testServiceLockWaitTimeoutRetry(DispatchContext dctx, Map context) {
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        try {
+            dispatcher.runAsync("testServiceDeadLockRetryThreadA", null, false);
+            dispatcher.runAsync("testServiceDeadLockRetryThreadB", null, false);
+        } catch (GenericServiceException e) {
+            String errMsg = "Error running deadlock test services: " + e.toString();
+            Debug.logError(e, errMsg, module);
+        }
+        
+        return ServiceUtil.returnSuccess();
+    }
+    public static Map testServiceLockWaitTimeoutRetryGrabber(DispatchContext dctx, Map context) {
+        GenericDelegator delegator = dctx.getDelegator();
+
+        try {
+            // grab entity SVCLWTRT by changing, then wait a LONG time, ie more than the wait timeout
+            GenericValue testingType = delegator.findByPrimaryKey("TestingType", UtilMisc.toMap("testingTypeId", "SVCLWTRT"));
+            testingType.set("description", "New description for SVCLWTRT");
+            testingType.store();
+            
+            // wait at least long enough for the other method to have locked resource wiat time out
+            // wait 100 seconds
+            ServiceEngineTestServices.class.wait(100 * 1000);
+        } catch (GenericEntityException e) {
+            String errMsg = "Entity Engine Exception running lock wait timeout test Grabber thread: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        } catch (InterruptedException e) {
+            String errMsg = "Wait Interrupted Exception running lock wait timeout test Grabber thread: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        }
+
+        return ServiceUtil.returnSuccess();
+    }
+    public static Map testServiceLockWaitTimeoutRetryWaiter(DispatchContext dctx, Map context) {
+        GenericDelegator delegator = dctx.getDelegator();
+
+        try {
+            // TRY grab entity SVCLWTRT by looking up and changing, should get a lock wait timeout exception because of the Grabber thread
+            GenericValue testingType = delegator.findByPrimaryKey("TestingType", UtilMisc.toMap("testingTypeId", "SVCLWTRT"));
+            testingType.set("description", "New description for SVCLWTRT");
+            testingType.store();
+            
+        } catch (GenericEntityException e) {
+            String errMsg = "Entity Engine Exception running lock wait timeout test Waiter thread: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        }
+
+        return ServiceUtil.returnSuccess();
+    }
+}

Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml?rev=572280&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml (added)
+++ ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml Mon Sep  3 03:45:24 2007
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+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.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<entity-engine-xml>
+    <!-- assert data for service dead lock recovery test -->
+    <TestingType testingTypeId="SVCLRT_A" description="New description for SVCLRT_A"/>
+    <TestingType testingTypeId="SVCLRT_B" description="New description for SVCLRT_B"/>
+</entity-engine-xml>

Propchange: ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml?rev=572280&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml (added)
+++ ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml Mon Sep  3 03:45:24 2007
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+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.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<entity-engine-xml>
+    <!-- assert data for service lock wait timeout recovery test -->
+    <TestingType testingTypeId="SVCLWTRT" description="New description for SVCLWTRT"/>
+</entity-engine-xml>

Propchange: ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml?rev=572280&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml (added)
+++ ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml Mon Sep  3 03:45:24 2007
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+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.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<entity-engine-xml>
+    <!-- load data for service dead lock recovery test -->
+    <TestingType testingTypeId="SVCLRT_A" description="Original description for SVCLRT_A"/>
+    <TestingType testingTypeId="SVCLRT_B" description="Original description for SVCLRT_B"/>
+    
+    <!-- load data for service lock wait timeout recovery test -->
+    <TestingType testingTypeId="SVCLWTRT" description="Original description for SVCLWTRT"/>
+</entity-engine-xml>

Propchange: ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: ofbiz/trunk/framework/service/testdef/servicetests.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/testdef/servicetests.xml?rev=572280&r1=572279&r2=572280&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/testdef/servicetests.xml (original)
+++ ofbiz/trunk/framework/service/testdef/servicetests.xml Mon Sep  3 03:45:24 2007
@@ -22,4 +22,20 @@
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd">
     <test-case case-name="service-tests"><junit-test-suite class-name="org.ofbiz.service.test.ServiceEngineTests"/></test-case>
+    
+    <test-case case-name="load-service-test-data">
+        <entity-xml action="load" entity-xml-url="component://service/testdef/data/ServiceTestData.xml"/>
+    </test-case>
+    <test-case case-name="service-dead-lock-retry-test">
+        <service-test service-name="testServiceDeadLockRetry"/>
+    </test-case>
+    <test-case case-name="service-dead-lock-retry-assert-data">
+        <entity-xml action="assert" entity-xml-url="component://service/testdef/data/ServiceDeadLockRetryAssertData.xml"/>
+    </test-case>
+    <test-case case-name="service-lock-wait-timeout-retry-test">
+        <service-test service-name="testServiceDeadLockRetry"/>
+    </test-case>
+    <test-case case-name="service-lock-wait-timeout-retry-assert-data">
+        <entity-xml action="assert" entity-xml-url="component://service/testdef/data/ServiceLockTimeoutRetryAssertData.xml"/>
+    </test-case>
 </test-suite>