You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2007/09/08 12:32:19 UTC
svn commit: r573813 - in /ofbiz/trunk/framework/service: servicedef/
src/org/ofbiz/service/test/ testdef/ testdef/data/
Author: jonesde
Date: Sat Sep 8 03:32:18 2007
New Revision: 573813
URL: http://svn.apache.org/viewvc?rev=573813&view=rev
Log:
These failure cases are now running properly, though for the first lock wait timeout I still don't like the error results because it is hard to identify for retry purposes; whatever the case, here they are; NOTE these WILL all fail right now and that is expected, these are in anticipation of new Service Engine features to automatically recover from these errors
Added:
ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryCantRecoverAssertData.xml (with props)
Modified:
ofbiz/trunk/framework/service/servicedef/services_test_se.xml
ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java
ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml
ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml
ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml
ofbiz/trunk/framework/service/testdef/servicetests.xml
Modified: 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=573813&r1=573812&r2=573813&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/servicedef/services_test_se.xml (original)
+++ ofbiz/trunk/framework/service/servicedef/services_test_se.xml Sat Sep 8 03:32:18 2007
@@ -29,10 +29,10 @@
location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceDeadLockRetry">
<implements service="testServiceInterface"/>
</service>
- <service name="testServiceDeadLockRetryThreadA" engine="java" auth="false"
+ <service name="testServiceDeadLockRetryThreadA" engine="java" auth="false" transaction-timeout="10"
location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceDeadLockRetryThreadA">
</service>
- <service name="testServiceDeadLockRetryThreadB" engine="java" auth="false"
+ <service name="testServiceDeadLockRetryThreadB" engine="java" auth="false" transaction-timeout="4"
location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceDeadLockRetryThreadB">
</service>
@@ -41,10 +41,19 @@
location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceLockWaitTimeoutRetry">
<implements service="testServiceInterface"/>
</service>
- <service name="testServiceLockWaitTimeoutRetryGrabber" engine="java" auth="false"
+ <service name="testServiceLockWaitTimeoutRetryGrabber" engine="java" auth="false" transaction-timeout="6"
location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceLockWaitTimeoutRetryGrabber">
</service>
- <service name="testServiceLockWaitTimeoutRetryWaiter" engine="java" auth="false"
+ <service name="testServiceLockWaitTimeoutRetryWaiter" engine="java" auth="false" transaction-timeout="2"
location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceLockWaitTimeoutRetryWaiter">
+ </service>
+
+ <!-- lock wait timeout retry testing services - a scenario that I can't figure out yet how to recover automatically -->
+ <service name="testServiceLockWaitTimeoutRetryCantRecover" engine="java" auth="false" transaction-timeout="2"
+ location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceLockWaitTimeoutRetryCantRecover">
+ <implements service="testServiceInterface"/>
+ </service>
+ <service name="testServiceLockWaitTimeoutRetryCantRecoverWaiter" engine="java" auth="false" transaction-timeout="4"
+ location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceLockWaitTimeoutRetryCantRecoverWaiter">
</service>
</services>
Modified: 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=573813&r1=573812&r2=573813&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java Sat Sep 8 03:32:18 2007
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*
* 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
@@ -15,7 +15,7 @@
* 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;
@@ -26,6 +26,7 @@
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.GenericResultWaiter;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ServiceUtil;
@@ -37,11 +38,16 @@
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) {
+ // NOTE using persist=false so that the lock retry will have to fix the problem instead of the job poller picking it up again
+ GenericResultWaiter threadAWaiter = dispatcher.runAsyncWait("testServiceDeadLockRetryThreadA", null, false);
+ GenericResultWaiter threadBWaiter = dispatcher.runAsyncWait("testServiceDeadLockRetryThreadB", null, false);
+ // make sure to wait for these to both finish to make sure results aren't checked until they are done
+ threadAWaiter.waitForResult();
+ threadBWaiter.waitForResult();
+ } catch (Exception e) {
String errMsg = "Error running deadlock test services: " + e.toString();
Debug.logError(e, errMsg, module);
+ return ServiceUtil.returnError(errMsg);
}
return ServiceUtil.returnSuccess();
@@ -53,14 +59,16 @@
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.set("description", "New description for SVCLRT_A from Thread A");
testingTypeA.store();
// wait at least long enough for the other method to have locked resource B
- ServiceEngineTestServices.class.wait(100);
+ Debug.logInfo("In testServiceDeadLockRetryThreadA just updated SVCLRT_A, beginning wait", module);
+ UtilMisc.staticWait(100);
+ Debug.logInfo("In testServiceDeadLockRetryThreadA done with wait, updating SVCLRT_B", module);
GenericValue testingTypeB = delegator.findByPrimaryKey("TestingType", UtilMisc.toMap("testingTypeId", "SVCLRT_B"));
- testingTypeB.set("description", "New description for SVCLRT_B");
+ testingTypeB.set("description", "New description for SVCLRT_B from Thread A");
testingTypeB.store();
} catch (GenericEntityException e) {
String errMsg = "Entity Engine Exception running dead lock test thread A: " + e.toString();
@@ -80,14 +88,16 @@
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.set("description", "New description for SVCLRT_B from Thread B");
testingTypeB.store();
// wait at least long enough for the other method to have locked resource B
- ServiceEngineTestServices.class.wait(100);
+ Debug.logInfo("In testServiceDeadLockRetryThreadB just updated SVCLRT_B, beginning wait", module);
+ UtilMisc.staticWait(100);
+ Debug.logInfo("In testServiceDeadLockRetryThreadB done with wait, updating SVCLRT_A", module);
GenericValue testingTypeA = delegator.findByPrimaryKey("TestingType", UtilMisc.toMap("testingTypeId", "SVCLRT_A"));
- testingTypeA.set("description", "New description for SVCLRT_A");
+ testingTypeA.set("description", "New description for SVCLRT_A from Thread B");
testingTypeA.store();
} catch (GenericEntityException e) {
String errMsg = "Entity Engine Exception running dead lock test thread B: " + e.toString();
@@ -105,11 +115,16 @@
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) {
+ // NOTE using persist=false so that the lock retry will have to fix the problem instead of the job poller picking it up again
+ GenericResultWaiter grabberWaiter = dispatcher.runAsyncWait("testServiceLockWaitTimeoutRetryGrabber", null, false);
+ GenericResultWaiter waiterWaiter = dispatcher.runAsyncWait("testServiceLockWaitTimeoutRetryWaiter", null, false);
+ // make sure to wait for these to both finish to make sure results aren't checked until they are done
+ grabberWaiter.waitForResult();
+ waiterWaiter.waitForResult();
+ } catch (Exception e) {
String errMsg = "Error running deadlock test services: " + e.toString();
Debug.logError(e, errMsg, module);
+ return ServiceUtil.returnError(errMsg);
}
return ServiceUtil.returnSuccess();
@@ -120,12 +135,14 @@
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.set("description", "New description for SVCLWTRT from the GRABBER service, this should be replaced by Waiter service in the service engine auto-retry");
testingType.store();
+
+ Debug.logInfo("In testServiceLockWaitTimeoutRetryGrabber just updated SVCLWTRT, beginning wait", module);
- // wait at least long enough for the other method to have locked resource wiat time out
- // wait 100 seconds
- ServiceEngineTestServices.class.wait(100 * 1000);
+ // wait at least long enough for the other method to have locked resource wait time out
+ // (tx timeout 6s on this the Grabber and 2s on the Waiter): wait 4 seconds because timeout on this
+ UtilMisc.staticWait(4 * 1000);
} catch (GenericEntityException e) {
String errMsg = "Entity Engine Exception running lock wait timeout test Grabber thread: " + e.toString();
Debug.logError(e, errMsg, module);
@@ -142,11 +159,79 @@
GenericDelegator delegator = dctx.getDelegator();
try {
+ // wait for a small amount of time to make sure the grabber does it's thing first
+ UtilMisc.staticWait(100);
+
+ Debug.logInfo("In testServiceLockWaitTimeoutRetryWaiter about to update SVCLWTRT, wait starts here", module);
+
// 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.set("description", "New description for SVCLWTRT from Waiter service, this is the value that should be there.");
+ testingType.store();
+
+ Debug.logInfo("In testServiceLockWaitTimeoutRetryWaiter successfully updated SVCLWTRT", module);
+ } 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);
+ } catch (InterruptedException e) {
+ String errMsg = "Wait Interrupted Exception running lock wait timeout test Waiter thread: " + e.toString();
+ Debug.logError(e, errMsg, module);
+ return ServiceUtil.returnError(errMsg);
+ }
+
+ return ServiceUtil.returnSuccess();
+ }
+
+ /**
+ * NOTE that this is a funny case where the auto-retry in the service engine for the call to
+ * testServiceLockWaitTimeoutRetryCantRecoverWaiter would NOT be able to recover because it would try again
+ * given the new transaction and all, but the lock for the waiting thread would still be there... so it will fail
+ * repeatedly.
+ *
+ * TODO: there's got to be some way to do this, but how?!? :(
+ *
+ * @param dctx
+ * @param context
+ * @return
+ */
+ public static Map testServiceLockWaitTimeoutRetryCantRecover(DispatchContext dctx, Map context) {
+ GenericDelegator delegator = dctx.getDelegator();
+ LocalDispatcher dispatcher = dctx.getDispatcher();
+ try {
+ // grab entity SVCLWTRTCR by changing, then wait a LONG time, ie more than the wait timeout
+ GenericValue testingType = delegator.findByPrimaryKey("TestingType", UtilMisc.toMap("testingTypeId", "SVCLWTRTCR"));
+ testingType.set("description", "New description for SVCLWTRTCR from Lock Wait Timeout Lock GRABBER, this should be replaced by the one in the Waiter service.");
+ testingType.store();
+
+ Debug.logInfo("In testServiceLockWaitTimeoutRetryCantRecover (grabber) just updated SVCLWTRTCR, running sub-service in own transaction", module);
+ // timeout is 5 seconds so it is longer than the tx timeout for this service, so will fail quickly; with this transaction keeping a lock on the record and that one trying to get it, bam we cause the error
+ dispatcher.runSync("testServiceLockWaitTimeoutRetryCantRecoverWaiter", null, 5, true);
+
+ Debug.logInfo("In testServiceLockWaitTimeoutRetryCantRecover (grabber) successfully finished running sub-service in own transaction", module);
+ } catch (GenericServiceException e) {
+ String errMsg = "Error running deadlock test services: " + e.toString();
+ Debug.logError(e, errMsg, module);
+ } catch (GenericEntityException e) {
+ String errMsg = "Entity Engine Exception running lock wait timeout test main/Grabber thread: " + e.toString();
+ Debug.logError(e, errMsg, module);
+ return ServiceUtil.returnError(errMsg);
+ }
+
+ return ServiceUtil.returnSuccess();
+ }
+ public static Map testServiceLockWaitTimeoutRetryCantRecoverWaiter(DispatchContext dctx, Map context) {
+ GenericDelegator delegator = dctx.getDelegator();
+
+ try {
+ Debug.logInfo("In testServiceLockWaitTimeoutRetryCantRecoverWaiter updating SVCLWTRTCR", module);
+
+ // TRY grab entity SVCLWTRTCR 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", "SVCLWTRTCR"));
+ testingType.set("description", "New description for SVCLWTRTCR from Lock Wait Timeout Lock Waiter, this is the value that should be there.");
testingType.store();
+ Debug.logInfo("In testServiceLockWaitTimeoutRetryCantRecoverWaiter successfully updated SVCLWTRTCR", module);
} catch (GenericEntityException e) {
String errMsg = "Entity Engine Exception running lock wait timeout test Waiter thread: " + e.toString();
Debug.logError(e, errMsg, module);
Modified: ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml?rev=573813&r1=573812&r2=573813&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml (original)
+++ ofbiz/trunk/framework/service/testdef/data/ServiceDeadLockRetryAssertData.xml Sat Sep 8 03:32:18 2007
@@ -19,6 +19,6 @@
-->
<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"/>
+ <TestingType testingTypeId="SVCLRT_A" description="New description for SVCLRT_A from Thread B"/>
+ <TestingType testingTypeId="SVCLRT_B" description="New description for SVCLRT_B from Thread A"/>
</entity-engine-xml>
Modified: ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml?rev=573813&r1=573812&r2=573813&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml (original)
+++ ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryAssertData.xml Sat Sep 8 03:32:18 2007
@@ -19,5 +19,5 @@
-->
<entity-engine-xml>
<!-- assert data for service lock wait timeout recovery test -->
- <TestingType testingTypeId="SVCLWTRT" description="New description for SVCLWTRT"/>
+ <TestingType testingTypeId="SVCLWTRT" description="New description for SVCLWTRT from Waiter service, this is the value that should be there."/>
</entity-engine-xml>
Added: ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryCantRecoverAssertData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryCantRecoverAssertData.xml?rev=573813&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryCantRecoverAssertData.xml (added)
+++ ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryCantRecoverAssertData.xml Sat Sep 8 03:32:18 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 SVCLWTRTCR from Lock Wait Timeout Lock Waiter, this is the value that should be there."/>
+</entity-engine-xml>
Propchange: ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryCantRecoverAssertData.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryCantRecoverAssertData.xml
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/trunk/framework/service/testdef/data/ServiceLockTimeoutRetryCantRecoverAssertData.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml?rev=573813&r1=573812&r2=573813&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml (original)
+++ ofbiz/trunk/framework/service/testdef/data/ServiceTestData.xml Sat Sep 8 03:32:18 2007
@@ -24,4 +24,7 @@
<!-- load data for service lock wait timeout recovery test -->
<TestingType testingTypeId="SVCLWTRT" description="Original description for SVCLWTRT"/>
+
+ <!-- load data for service lock wait timeout recovery test - case that can't find a way to auto-fix -->
+ <TestingType testingTypeId="SVCLWTRTCR" description="Original description for SVCLWTRTCR"/>
</entity-engine-xml>
Modified: ofbiz/trunk/framework/service/testdef/servicetests.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/testdef/servicetests.xml?rev=573813&r1=573812&r2=573813&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/testdef/servicetests.xml (original)
+++ ofbiz/trunk/framework/service/testdef/servicetests.xml Sat Sep 8 03:32:18 2007
@@ -33,9 +33,16 @@
<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"/>
+ <service-test service-name="testServiceLockWaitTimeoutRetry"/>
</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-case case-name="service-lock-wait-timeout-retry-test">
+ <service-test service-name="testServiceLockWaitTimeoutRetryCantRecover"/>
+ </test-case>
+ <test-case case-name="service-lock-wait-timeout-retry-assert-data">
+ <entity-xml action="assert" entity-xml-url="component://service/testdef/data/ServiceLockTimeoutRetryCantRecoverAssertData.xml"/>
</test-case>
</test-suite>