Remove Zope 2.7 compatibility fossils

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37189 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 73f645cd
...@@ -33,10 +33,7 @@ from ZODB.POSException import ConflictError ...@@ -33,10 +33,7 @@ from ZODB.POSException import ConflictError
import sha import sha
from cStringIO import StringIO from cStringIO import StringIO
try: import transaction
from transaction import get as get_transaction
except ImportError:
pass
# Error values for message validation # Error values for message validation
EXCEPTION = -1 EXCEPTION = -1
...@@ -48,36 +45,6 @@ INVALID_ORDER = 2 ...@@ -48,36 +45,6 @@ INVALID_ORDER = 2
MAX_PROCESSING_TIME = 900 # in seconds MAX_PROCESSING_TIME = 900 # in seconds
VALIDATION_ERROR_DELAY = 30 # in seconds VALIDATION_ERROR_DELAY = 30 # in seconds
def abortTransactionSynchronously():
"""Abort a transaction in a synchronous manner.
Manual invocation of transaction abort does not synchronize
connections with databases, thus invalidations are not cleared out.
This may cause an infinite loop, because a read conflict error happens
again and again on the same object.
So, in this method, collect (potential) Connection objects used
for current transaction, and invoke the sync method on every Connection
object, then abort the transaction. In most cases, aborting the
transaction is redundant, because sync should call abort implicitly.
But if no connection is present, it is still required to call abort
explicitly, and it does not cause any harm to call abort more than once.
XXX this is really a hack. This touches the internal code of Transaction.
"""
try:
import transaction
# Zope 2.8 and later. sync is automatic.
transaction.abort()
except ImportError:
# Zope 2.7 and earlier.
t = get_transaction()
jar_list = t._get_jars(t._objects, 0)
for jar in jar_list:
if getattr(jar, 'sync', None) is not None:
jar.sync()
t.abort()
class Queue: class Queue:
""" """
Step 1: use lists Step 1: use lists
...@@ -228,7 +195,7 @@ class Queue: ...@@ -228,7 +195,7 @@ class Queue:
cached_result = validation_text_dict.get(message.order_validation_text) cached_result = validation_text_dict.get(message.order_validation_text)
if cached_result is None: if cached_result is None:
message_list = message.getDependentMessageList(self, activity_tool) message_list = message.getDependentMessageList(self, activity_tool)
get_transaction().commit() # Release locks. transaction.commit() # Release locks.
if message_list: if message_list:
# The result is not empty, so this message is not executable. # The result is not empty, so this message is not executable.
validation_text_dict[message.order_validation_text] = 0 validation_text_dict[message.order_validation_text] = 0
......
...@@ -32,10 +32,7 @@ from Queue import Queue, VALID ...@@ -32,10 +32,7 @@ from Queue import Queue, VALID
from zLOG import LOG from zLOG import LOG
try: import transaction
from transaction import get as get_transaction
except ImportError:
pass
class RAMDict(Queue): class RAMDict(Queue):
""" """
...@@ -88,11 +85,11 @@ class RAMDict(Queue): ...@@ -88,11 +85,11 @@ class RAMDict(Queue):
activity_tool.invoke(m) activity_tool.invoke(m)
if m.getExecutionState() == MESSAGE_EXECUTED: if m.getExecutionState() == MESSAGE_EXECUTED:
del self.getDict(path)[key] del self.getDict(path)[key]
get_transaction().commit() transaction.commit()
return 0 return 0
else: else:
# Start a new transaction and keep on to next message # Start a new transaction and keep on to next message
get_transaction().commit() transaction.commit()
return 1 return 1
def countMessage(self, activity_tool,path=None,method_id=None,**kw): def countMessage(self, activity_tool,path=None,method_id=None,**kw):
......
...@@ -29,10 +29,7 @@ ...@@ -29,10 +29,7 @@
from Products.CMFActivity.ActivityTool import registerActivity, MESSAGE_EXECUTED from Products.CMFActivity.ActivityTool import registerActivity, MESSAGE_EXECUTED
from Queue import Queue, VALID from Queue import Queue, VALID
try: import transaction
from transaction import get as get_transaction
except ImportError:
pass
class RAMQueue(Queue): class RAMQueue(Queue):
""" """
...@@ -67,16 +64,16 @@ class RAMQueue(Queue): ...@@ -67,16 +64,16 @@ class RAMQueue(Queue):
for m in self.getQueue(path): for m in self.getQueue(path):
if m.validate(self, activity_tool) is not VALID: if m.validate(self, activity_tool) is not VALID:
self.deleteMessage(activity_tool, m) # Trash messages which are not validated (no error handling) self.deleteMessage(activity_tool, m) # Trash messages which are not validated (no error handling)
get_transaction().commit() # Start a new transaction transaction.commit() # Start a new transaction
return 0 # Keep on ticking return 0 # Keep on ticking
activity_tool.invoke(m) activity_tool.invoke(m)
if m.getExecutionState() == MESSAGE_EXECUTED: if m.getExecutionState() == MESSAGE_EXECUTED:
self.deleteMessage(activity_tool, m) # Trash messages which are not validated (no error handling) self.deleteMessage(activity_tool, m) # Trash messages which are not validated (no error handling)
get_transaction().commit() # Start a new transaction transaction.commit() # Start a new transaction
return 0 # Keep on ticking return 0 # Keep on ticking
else: else:
# Start a new transaction and keep on to next message # Start a new transaction and keep on to next message
get_transaction().commit() transaction.commit()
return 1 # Go to sleep return 1 # Go to sleep
def countMessage(self, activity_tool,path=None,method_id=None,**kw): def countMessage(self, activity_tool,path=None,method_id=None,**kw):
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
############################################################################## ##############################################################################
from Products.CMFActivity.ActivityTool import registerActivity, MESSAGE_NOT_EXECUTED, MESSAGE_EXECUTED from Products.CMFActivity.ActivityTool import registerActivity, MESSAGE_NOT_EXECUTED, MESSAGE_EXECUTED
from Queue import VALID, INVALID_PATH, abortTransactionSynchronously from Queue import VALID, INVALID_PATH
from RAMDict import RAMDict from RAMDict import RAMDict
from Products.CMFActivity.ActiveObject import INVOKE_ERROR_STATE, VALIDATE_ERROR_STATE from Products.CMFActivity.ActiveObject import INVOKE_ERROR_STATE, VALIDATE_ERROR_STATE
from Products.CMFActivity.Errors import ActivityFlushError from Products.CMFActivity.Errors import ActivityFlushError
...@@ -40,10 +40,7 @@ from Products.CMFActivity.ActivityRuntimeEnvironment import ( ...@@ -40,10 +40,7 @@ from Products.CMFActivity.ActivityRuntimeEnvironment import (
ActivityRuntimeEnvironment, getTransactionalVariable) ActivityRuntimeEnvironment, getTransactionalVariable)
from zExceptions import ExceptionFormatter from zExceptions import ExceptionFormatter
try: import transaction
from transaction import get as get_transaction
except ImportError:
pass
from zLOG import LOG, TRACE, WARNING, ERROR, INFO, PANIC from zLOG import LOG, TRACE, WARNING, ERROR, INFO, PANIC
...@@ -334,7 +331,7 @@ class SQLDict(RAMDict, SQLBase): ...@@ -334,7 +331,7 @@ class SQLDict(RAMDict, SQLBase):
# version - to ZODB connector. # version - to ZODB connector.
# So all connectors must be committed now that we have selected # So all connectors must be committed now that we have selected
# everything needed from MySQL to get a fresh view of ZODB objects. # everything needed from MySQL to get a fresh view of ZODB objects.
get_transaction().commit() transaction.commit()
tv = getTransactionalVariable(None) tv = getTransactionalVariable(None)
tv['activity_runtime_environment'] = activity_runtime_environment tv['activity_runtime_environment'] = activity_runtime_environment
# Try to invoke # Try to invoke
...@@ -343,7 +340,7 @@ class SQLDict(RAMDict, SQLBase): ...@@ -343,7 +340,7 @@ class SQLDict(RAMDict, SQLBase):
except: except:
LOG('SQLDict', WARNING, 'Exception raised when invoking messages (uid, path, method_id) %r' % ([(m.uid, m.object_path, m.method_id) for m in message_list], ), error=sys.exc_info()) LOG('SQLDict', WARNING, 'Exception raised when invoking messages (uid, path, method_id) %r' % ([(m.uid, m.object_path, m.method_id) for m in message_list], ), error=sys.exc_info())
try: try:
abortTransactionSynchronously() transaction.abort()
except: except:
# Unfortunately, database adapters may raise an exception against abort. # Unfortunately, database adapters may raise an exception against abort.
LOG('SQLDict', PANIC, LOG('SQLDict', PANIC,
...@@ -360,18 +357,18 @@ class SQLDict(RAMDict, SQLBase): ...@@ -360,18 +357,18 @@ class SQLDict(RAMDict, SQLBase):
LOG('SQLDict', TRACE, 'Freed messages %r' % (to_free_uid_list)) LOG('SQLDict', TRACE, 'Freed messages %r' % (to_free_uid_list))
# Abort if something failed. # Abort if something failed.
if [m for m in message_list if m.getExecutionState() == MESSAGE_NOT_EXECUTED]: if [m for m in message_list if m.getExecutionState() == MESSAGE_NOT_EXECUTED]:
endTransaction = abortTransactionSynchronously endTransaction = transaction.abort
else: else:
endTransaction = get_transaction().commit endTransaction = transaction.commit
try: try:
endTransaction() endTransaction()
except: except:
LOG('SQLDict', WARNING, 'Failed to end transaction for messages (uid, path, method_id) %r' % ([(m.uid, m.object_path, m.method_id) for m in message_list], ), error=sys.exc_info()) LOG('SQLDict', WARNING, 'Failed to end transaction for messages (uid, path, method_id) %r' % ([(m.uid, m.object_path, m.method_id) for m in message_list], ), error=sys.exc_info())
if endTransaction == abortTransactionSynchronously: if endTransaction == transaction.abort:
LOG('SQLDict', PANIC, 'Failed to abort executed messages. Some objects may be modified accidentally.') LOG('SQLDict', PANIC, 'Failed to abort executed messages. Some objects may be modified accidentally.')
else: else:
try: try:
abortTransactionSynchronously() transaction.abort()
except: except:
LOG('SQLDict', PANIC, 'Failed to abort executed messages which also failed to commit. Some objects may be modified accidentally.') LOG('SQLDict', PANIC, 'Failed to abort executed messages which also failed to commit. Some objects may be modified accidentally.')
raise raise
...@@ -385,7 +382,7 @@ class SQLDict(RAMDict, SQLBase): ...@@ -385,7 +382,7 @@ class SQLDict(RAMDict, SQLBase):
else: else:
LOG('SQLDict', TRACE, 'Freed messages %r' % (message_list, )) LOG('SQLDict', TRACE, 'Freed messages %r' % (message_list, ))
self.finalizeMessageExecution(activity_tool, message_list, uid_to_duplicate_uid_list_dict) self.finalizeMessageExecution(activity_tool, message_list, uid_to_duplicate_uid_list_dict)
get_transaction().commit() transaction.commit()
return not message_list return not message_list
def hasActivity(self, activity_tool, object, method_id=None, only_valid=None, active_process_uid=None): def hasActivity(self, activity_tool, object, method_id=None, only_valid=None, active_process_uid=None):
...@@ -505,7 +502,7 @@ class SQLDict(RAMDict, SQLBase): ...@@ -505,7 +502,7 @@ class SQLDict(RAMDict, SQLBase):
offset=offset, count=READ_MESSAGE_LIMIT) offset=offset, count=READ_MESSAGE_LIMIT)
if not result: if not result:
return return
get_transaction().commit() transaction.commit()
validation_text_dict = {'none': 1} validation_text_dict = {'none': 1}
message_dict = {} message_dict = {}
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
from Products.CMFActivity.ActivityTool import registerActivity, MESSAGE_NOT_EXECUTED, MESSAGE_EXECUTED from Products.CMFActivity.ActivityTool import registerActivity, MESSAGE_NOT_EXECUTED, MESSAGE_EXECUTED
from RAMQueue import RAMQueue from RAMQueue import RAMQueue
from Queue import VALID, INVALID_PATH, abortTransactionSynchronously from Queue import VALID, INVALID_PATH
from Products.CMFActivity.ActiveObject import INVOKE_ERROR_STATE, VALIDATE_ERROR_STATE from Products.CMFActivity.ActiveObject import INVOKE_ERROR_STATE, VALIDATE_ERROR_STATE
from Products.CMFActivity.Errors import ActivityFlushError from Products.CMFActivity.Errors import ActivityFlushError
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
...@@ -40,10 +40,7 @@ from Products.CMFActivity.ActivityRuntimeEnvironment import ( ...@@ -40,10 +40,7 @@ from Products.CMFActivity.ActivityRuntimeEnvironment import (
ActivityRuntimeEnvironment, getTransactionalVariable) ActivityRuntimeEnvironment, getTransactionalVariable)
from zExceptions import ExceptionFormatter from zExceptions import ExceptionFormatter
try: import transaction
from transaction import get as get_transaction
except ImportError:
pass
from zLOG import LOG, WARNING, ERROR, INFO, PANIC, TRACE from zLOG import LOG, WARNING, ERROR, INFO, PANIC, TRACE
...@@ -214,7 +211,7 @@ class SQLQueue(RAMQueue, SQLBase): ...@@ -214,7 +211,7 @@ class SQLQueue(RAMQueue, SQLBase):
# version - to ZODB connector. # version - to ZODB connector.
# So all connectors must be committed now that we have selected # So all connectors must be committed now that we have selected
# everything needed from MySQL to get a fresh view of ZODB objects. # everything needed from MySQL to get a fresh view of ZODB objects.
get_transaction().commit() transaction.commit()
tv = getTransactionalVariable(None) tv = getTransactionalVariable(None)
for m in message_list: for m in message_list:
tv['activity_runtime_environment'] = ActivityRuntimeEnvironment(m) tv['activity_runtime_environment'] = ActivityRuntimeEnvironment(m)
...@@ -227,15 +224,15 @@ class SQLQueue(RAMQueue, SQLBase): ...@@ -227,15 +224,15 @@ class SQLQueue(RAMQueue, SQLBase):
# successfull messages to be rolled back. This commit might fail, # successfull messages to be rolled back. This commit might fail,
# so it is protected the same way as activity execution by the # so it is protected the same way as activity execution by the
# same "try" block. # same "try" block.
get_transaction().commit() transaction.commit()
else: else:
# This message failed, revert. # This message failed, abort.
abortTransactionSynchronously() transaction.abort()
except: except:
value = m.uid, m.object_path, m.method_id value = m.uid, m.object_path, m.method_id
LOG('SQLQueue', WARNING, 'Exception raised when invoking message (uid, path, method_id) %r' % (value, ), error=sys.exc_info()) LOG('SQLQueue', WARNING, 'Exception raised when invoking message (uid, path, method_id) %r' % (value, ), error=sys.exc_info())
try: try:
abortTransactionSynchronously() transaction.abort()
except: except:
# Unfortunately, database adapters may raise an exception against abort. # Unfortunately, database adapters may raise an exception against abort.
LOG('SQLQueue', PANIC, 'abort failed, thus some objects may be modified accidentally') LOG('SQLQueue', PANIC, 'abort failed, thus some objects may be modified accidentally')
...@@ -266,7 +263,7 @@ class SQLQueue(RAMQueue, SQLBase): ...@@ -266,7 +263,7 @@ class SQLQueue(RAMQueue, SQLBase):
LOG('SQLQueue', TRACE, 'Freed messages %r' % (to_free_uid_list, )) LOG('SQLQueue', TRACE, 'Freed messages %r' % (to_free_uid_list, ))
self.finalizeMessageExecution(activity_tool, self.finalizeMessageExecution(activity_tool,
message_list[:processed_count]) message_list[:processed_count])
get_transaction().commit() transaction.commit()
return not message_list return not message_list
...@@ -396,7 +393,7 @@ class SQLQueue(RAMQueue, SQLBase): ...@@ -396,7 +393,7 @@ class SQLQueue(RAMQueue, SQLBase):
offset=offset, count=READ_MESSAGE_LIMIT) offset=offset, count=READ_MESSAGE_LIMIT)
if not result: if not result:
return return
get_transaction().commit() transaction.commit()
validation_text_dict = {'none': 1} validation_text_dict = {'none': 1}
message_dict = {} message_dict = {}
......
...@@ -55,10 +55,7 @@ import random ...@@ -55,10 +55,7 @@ import random
import threading import threading
import sys import sys
try: import transaction
from transaction import get as get_transaction
except ImportError:
pass
class CommitFailed(Exception): class CommitFailed(Exception):
pass pass
...@@ -152,23 +149,23 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -152,23 +149,23 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertEquals(self.title1,organisation.getTitle()) self.assertEquals(self.title1,organisation.getTitle())
organisation.activate(activity=activity)._setTitle(self.title2) organisation.activate(activity=activity)._setTitle(self.title2)
# Needed so that the message are commited into the queue # Needed so that the message are commited into the queue
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),1) self.assertEquals(len(message_list),1)
portal.portal_activities.manageCancel(organisation.getPhysicalPath(),'_setTitle') portal.portal_activities.manageCancel(organisation.getPhysicalPath(),'_setTitle')
# Needed so that the message are removed from the queue # Needed so that the message are removed from the queue
get_transaction().commit() transaction.commit()
self.assertEquals(self.title1,organisation.getTitle()) self.assertEquals(self.title1,organisation.getTitle())
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),0) self.assertEquals(len(message_list),0)
organisation.activate(activity=activity)._setTitle(self.title2) organisation.activate(activity=activity)._setTitle(self.title2)
# Needed so that the message are commited into the queue # Needed so that the message are commited into the queue
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),1) self.assertEquals(len(message_list),1)
portal.portal_activities.manageInvoke(organisation.getPhysicalPath(),'_setTitle') portal.portal_activities.manageInvoke(organisation.getPhysicalPath(),'_setTitle')
# Needed so that the message are removed from the queue # Needed so that the message are removed from the queue
get_transaction().commit() transaction.commit()
self.assertEquals(self.title2,organisation.getTitle()) self.assertEquals(self.title2,organisation.getTitle())
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),0) self.assertEquals(len(message_list),0)
...@@ -184,7 +181,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -184,7 +181,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertEquals(self.title1,organisation.getTitle()) self.assertEquals(self.title1,organisation.getTitle())
organisation.activate(activity=activity)._setTitle(self.title2) organisation.activate(activity=activity)._setTitle(self.title2)
# Needed so that the message are commited into the queue # Needed so that the message are commited into the queue
get_transaction().commit() transaction.commit()
self.assertEquals(self.title1,organisation.getTitle()) self.assertEquals(self.title1,organisation.getTitle())
portal.portal_activities.distribute() portal.portal_activities.distribute()
portal.portal_activities.tic() portal.portal_activities.tic()
...@@ -213,7 +210,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -213,7 +210,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertEquals(0,organisation.getFoobar()) self.assertEquals(0,organisation.getFoobar())
organisation.activate(activity=activity).setFoobar() organisation.activate(activity=activity).setFoobar()
# Needed so that the message are commited into the queue # Needed so that the message are commited into the queue
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),1) self.assertEquals(len(message_list),1)
portal.portal_activities.distribute() portal.portal_activities.distribute()
...@@ -223,12 +220,12 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -223,12 +220,12 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertEquals(len(message_list),0) self.assertEquals(len(message_list),0)
organisation.activate(activity=activity).setFoobar() organisation.activate(activity=activity).setFoobar()
# Needed so that the message are commited into the queue # Needed so that the message are commited into the queue
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),1) self.assertEquals(len(message_list),1)
portal.portal_activities.manageInvoke(organisation.getPhysicalPath(),'setFoobar') portal.portal_activities.manageInvoke(organisation.getPhysicalPath(),'setFoobar')
# Needed so that the message are commited into the queue # Needed so that the message are commited into the queue
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),0) self.assertEquals(len(message_list),0)
self.assertEquals(2,organisation.getFoobar()) self.assertEquals(2,organisation.getFoobar())
...@@ -243,18 +240,18 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -243,18 +240,18 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
organisation.activate(activity=activity)._setTitle(self.title2) organisation.activate(activity=activity)._setTitle(self.title2)
organisation.flushActivity(invoke=1) organisation.flushActivity(invoke=1)
self.assertEquals(organisation.getTitle(),self.title2) self.assertEquals(organisation.getTitle(),self.title2)
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),0) self.assertEquals(len(message_list),0)
self.assertEquals(organisation.getTitle(),self.title2) self.assertEquals(organisation.getTitle(),self.title2)
# Try again with different commit order # Try again with different commit order
organisation._setTitle(self.title1) organisation._setTitle(self.title1)
organisation.activate(activity=activity)._setTitle(self.title2) organisation.activate(activity=activity)._setTitle(self.title2)
get_transaction().commit() transaction.commit()
organisation.flushActivity(invoke=1) organisation.flushActivity(invoke=1)
self.assertEquals(len(message_list),0) self.assertEquals(len(message_list),0)
self.assertEquals(organisation.getTitle(),self.title2) self.assertEquals(organisation.getTitle(),self.title2)
get_transaction().commit() transaction.commit()
def TryActivateInsideFlush(self, activity): def TryActivateInsideFlush(self, activity):
""" """
...@@ -269,10 +266,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -269,10 +266,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
organisation._setTitle(self.title1) organisation._setTitle(self.title1)
organisation.activate(activity=activity).DeferredSetTitle(self.title2) organisation.activate(activity=activity).DeferredSetTitle(self.title2)
organisation.flushActivity(invoke=1) organisation.flushActivity(invoke=1)
get_transaction().commit() transaction.commit()
portal.portal_activities.distribute() portal.portal_activities.distribute()
portal.portal_activities.tic() portal.portal_activities.tic()
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),0) self.assertEquals(len(message_list),0)
self.assertEquals(organisation.getTitle(),self.title2) self.assertEquals(organisation.getTitle(),self.title2)
...@@ -294,10 +291,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -294,10 +291,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
organisation.setDescription(None) organisation.setDescription(None)
organisation.activate(activity=activity).DeferredSetTitle(self.title1) organisation.activate(activity=activity).DeferredSetTitle(self.title1)
organisation.activate(activity=activity).DeferredSetDescription(self.title1) organisation.activate(activity=activity).DeferredSetDescription(self.title1)
get_transaction().commit() transaction.commit()
portal.portal_activities.distribute() portal.portal_activities.distribute()
portal.portal_activities.tic() portal.portal_activities.tic()
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),0) self.assertEquals(len(message_list),0)
self.assertEquals(organisation.getTitle(),self.title1) self.assertEquals(organisation.getTitle(),self.title1)
...@@ -321,10 +318,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -321,10 +318,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
organisation.activate(activity=activity).DeferredSetTitle(self.title1) organisation.activate(activity=activity).DeferredSetTitle(self.title1)
organisation.activate(activity=activity).DeferredSetDescription(self.title1) organisation.activate(activity=activity).DeferredSetDescription(self.title1)
organisation.flushActivity(invoke=1) organisation.flushActivity(invoke=1)
get_transaction().commit() transaction.commit()
portal.portal_activities.distribute() portal.portal_activities.distribute()
portal.portal_activities.tic() portal.portal_activities.tic()
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),0) self.assertEquals(len(message_list),0)
self.assertEquals(organisation.getTitle(),self.title1) self.assertEquals(organisation.getTitle(),self.title1)
...@@ -337,11 +334,11 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -337,11 +334,11 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
portal = self.getPortal() portal = self.getPortal()
def DeferredSetTitle(self,value,commit_sub=0): def DeferredSetTitle(self,value,commit_sub=0):
if commit_sub: if commit_sub:
get_transaction().savepoint(optimistic=True) transaction.savepoint(optimistic=True)
self.activate(activity=second or activity,priority=4)._setTitle(value) self.activate(activity=second or activity,priority=4)._setTitle(value)
def DeferredSetDescription(self,value,commit_sub=0): def DeferredSetDescription(self,value,commit_sub=0):
if commit_sub: if commit_sub:
get_transaction().savepoint(optimistic=True) transaction.savepoint(optimistic=True)
self.activate(activity=second or activity,priority=4)._setDescription(value) self.activate(activity=second or activity,priority=4)._setDescription(value)
from Products.ERP5Type.Document.Organisation import Organisation from Products.ERP5Type.Document.Organisation import Organisation
Organisation.DeferredSetTitle = DeferredSetTitle Organisation.DeferredSetTitle = DeferredSetTitle
...@@ -352,13 +349,13 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -352,13 +349,13 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
organisation.activate(activity=activity).DeferredSetTitle(self.title1,commit_sub=commit_sub) organisation.activate(activity=activity).DeferredSetTitle(self.title1,commit_sub=commit_sub)
organisation.flushActivity(invoke=1) organisation.flushActivity(invoke=1)
organisation.activate(activity=activity).DeferredSetDescription(self.title1,commit_sub=commit_sub) organisation.activate(activity=activity).DeferredSetDescription(self.title1,commit_sub=commit_sub)
get_transaction().commit() transaction.commit()
portal.portal_activities.distribute() portal.portal_activities.distribute()
portal.portal_activities.tic() portal.portal_activities.tic()
get_transaction().commit() transaction.commit()
portal.portal_activities.distribute() portal.portal_activities.distribute()
portal.portal_activities.tic() portal.portal_activities.tic()
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),0) self.assertEquals(len(message_list),0)
self.assertEquals(organisation.getTitle(),self.title1) self.assertEquals(organisation.getTitle(),self.title1)
...@@ -376,7 +373,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -376,7 +373,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
Organisation.crashThisActivity = crashThisActivity Organisation.crashThisActivity = crashThisActivity
organisation.activate(activity=activity).crashThisActivity() organisation.activate(activity=activity).crashThisActivity()
# Needed so that the message are commited into the queue # Needed so that the message are commited into the queue
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
LOG('Before MessageWithErrorOnActivityFails, message_list',0,[x.__dict__ for x in message_list]) LOG('Before MessageWithErrorOnActivityFails, message_list',0,[x.__dict__ for x in message_list])
self.assertEquals(len(message_list),1) self.assertEquals(len(message_list),1)
...@@ -388,7 +385,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -388,7 +385,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertEquals(len(message_list),1) self.assertEquals(len(message_list),1)
portal.portal_activities.manageCancel(organisation.getPhysicalPath(),'crashThisActivity') portal.portal_activities.manageCancel(organisation.getPhysicalPath(),'crashThisActivity')
# Needed so that the message are commited into the queue # Needed so that the message are commited into the queue
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),0) self.assertEquals(len(message_list),0)
...@@ -403,7 +400,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -403,7 +400,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertEquals(self.title1,organisation.getTitle()) self.assertEquals(self.title1,organisation.getTitle())
organisation.activate(activity=activity)._setTitle(self.title2) organisation.activate(activity=activity)._setTitle(self.title2)
# Needed so that the message are commited into the queue # Needed so that the message are commited into the queue
get_transaction().commit() transaction.commit()
self.assertEquals(self.title1,organisation.getTitle()) self.assertEquals(self.title1,organisation.getTitle())
self.assertRaises(ActivityPendingError,organisation.edit,id=self.company_id2) self.assertRaises(ActivityPendingError,organisation.edit,id=self.company_id2)
portal.portal_activities.distribute() portal.portal_activities.distribute()
...@@ -420,7 +417,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -420,7 +417,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertEquals(self.title1,organisation.getTitle()) self.assertEquals(self.title1,organisation.getTitle())
organisation.activate(activity=activity,active_process=active_process).getTitle() organisation.activate(activity=activity,active_process=active_process).getTitle()
# Needed so that the message are commited into the queue # Needed so that the message are commited into the queue
get_transaction().commit() transaction.commit()
portal.portal_activities.distribute() portal.portal_activities.distribute()
portal.portal_activities.tic() portal.portal_activities.tic()
self.assertEquals(self.title1,organisation.getTitle()) self.assertEquals(self.title1,organisation.getTitle())
...@@ -448,7 +445,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -448,7 +445,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
active_process = portal.portal_activities.newActiveProcess() active_process = portal.portal_activities.newActiveProcess()
organisation.activate(activity=activity,active_process=active_process).Organisation_test() organisation.activate(activity=activity,active_process=active_process).Organisation_test()
# Needed so that the message are commited into the queue # Needed so that the message are commited into the queue
get_transaction().commit() transaction.commit()
portal.portal_activities.distribute() portal.portal_activities.distribute()
portal.portal_activities.tic() portal.portal_activities.tic()
portal.portal_activities.distribute() portal.portal_activities.distribute()
...@@ -473,7 +470,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -473,7 +470,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o.setTitle('a') o.setTitle('a')
self.assertEquals(o.getTitle(), 'a') self.assertEquals(o.getTitle(), 'a')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
def toto(self, value): def toto(self, value):
...@@ -486,7 +483,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -486,7 +483,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o.activate(after_method_id = 'titi', activity = activity).toto('b') o.activate(after_method_id = 'titi', activity = activity).toto('b')
o.activate(activity = activity).titi('c') o.activate(activity = activity).titi('c')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
self.assertEquals(o.getTitle(), 'acb') self.assertEquals(o.getTitle(), 'acb')
...@@ -510,10 +507,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -510,10 +507,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o1.recursiveReindexObject() o1.recursiveReindexObject()
o2.recursiveReindexObject() o2.recursiveReindexObject()
o1._delOb('2') o1._delOb('2')
get_transaction().commit() transaction.commit()
portal.portal_activities.distribute() portal.portal_activities.distribute()
portal.portal_activities.tic() portal.portal_activities.tic()
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),1) self.assertEquals(len(message_list),1)
...@@ -537,10 +534,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -537,10 +534,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o1.recursiveReindexObject() o1.recursiveReindexObject()
o2.recursiveReindexObject() o2.recursiveReindexObject()
organisation_module._delOb(self.company_id2) organisation_module._delOb(self.company_id2)
get_transaction().commit() transaction.commit()
portal.portal_activities.distribute() portal.portal_activities.distribute()
portal.portal_activities.tic() portal.portal_activities.tic()
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),1) self.assertEquals(len(message_list),1)
...@@ -556,12 +553,12 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -556,12 +553,12 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o.setTitle('?') o.setTitle('?')
self.assertEquals(o.getTitle(), '?') self.assertEquals(o.getTitle(), '?')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
o.activate(after_tag = 'toto', activity = activity).setTitle('b') o.activate(after_tag = 'toto', activity = activity).setTitle('b')
o.activate(tag = 'toto', activity = activity).setTitle('a') o.activate(tag = 'toto', activity = activity).setTitle('a')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
self.assertEquals(o.getTitle(), 'b') self.assertEquals(o.getTitle(), 'b')
...@@ -571,7 +568,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -571,7 +568,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o.__class__.titi = titi o.__class__.titi = titi
o.activate(after_tag_and_method_id=('toto', 'setTitle'), activity = activity).titi() o.activate(after_tag_and_method_id=('toto', 'setTitle'), activity = activity).titi()
o.activate(activity = activity).setTitle('c') o.activate(activity = activity).setTitle('c')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
self.assertEquals(o.getCorporateName(), 'cd') self.assertEquals(o.getCorporateName(), 'cd')
...@@ -589,16 +586,16 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -589,16 +586,16 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o.setDescription('?') o.setDescription('?')
self.assertEquals(o.getTitle(), '?') self.assertEquals(o.getTitle(), '?')
self.assertEquals(o.getDescription(), '?') self.assertEquals(o.getDescription(), '?')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
o.activate(after_tag = 'toto', activity = activity).setDescription('b') o.activate(after_tag = 'toto', activity = activity).setDescription('b')
o.activate(tag = 'toto', activity = activity).setTitle('a') o.activate(tag = 'toto', activity = activity).setTitle('a')
get_transaction().commit() transaction.commit()
tool = self.getActivityTool() tool = self.getActivityTool()
self.assertRaises(ActivityFlushError,tool.manageInvoke,o.getPath(),'setDescription') self.assertRaises(ActivityFlushError,tool.manageInvoke,o.getPath(),'setDescription')
tool.manageInvoke(o.getPath(),'setTitle') tool.manageInvoke(o.getPath(),'setTitle')
get_transaction().commit() transaction.commit()
self.assertEquals(o.getTitle(), 'a') self.assertEquals(o.getTitle(), 'a')
self.assertEquals(o.getDescription(), '?') self.assertEquals(o.getDescription(), '?')
self.tic() self.tic()
...@@ -618,7 +615,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -618,7 +615,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o.setTitle('?') o.setTitle('?')
self.assertEquals(o.getTitle(), '?') self.assertEquals(o.getTitle(), '?')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
def toto(self, s): def toto(self, s):
...@@ -626,11 +623,11 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -626,11 +623,11 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o.__class__.toto = toto o.__class__.toto = toto
o.activate(tag = 'toto', activity = activity).toto('a') o.activate(tag = 'toto', activity = activity).toto('a')
get_transaction().commit() transaction.commit()
o.activate(after_tag = 'titi', activity = activity).toto('b') o.activate(after_tag = 'titi', activity = activity).toto('b')
get_transaction().commit() transaction.commit()
o.activate(tag = 'titi', after_tag = 'toto', activity = activity).setTitle('c') o.activate(tag = 'titi', after_tag = 'toto', activity = activity).setTitle('c')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
self.assertEquals(o.getTitle(), 'cb') self.assertEquals(o.getTitle(), 'cb')
...@@ -646,7 +643,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -646,7 +643,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o = portal.organisation._getOb(self.company_id) o = portal.organisation._getOb(self.company_id)
o.setTitle('') o.setTitle('')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
def toto(self, s): def toto(self, s):
...@@ -654,11 +651,11 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -654,11 +651,11 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o.__class__.toto = toto o.__class__.toto = toto
o.activate(tag='A', activity=activity).toto('a') o.activate(tag='A', activity=activity).toto('a')
get_transaction().commit() transaction.commit()
o.activate(tag='B', activity=activity).toto('b') o.activate(tag='B', activity=activity).toto('b')
get_transaction().commit() transaction.commit()
o.activate(after_tag=('A', 'B'), activity=activity).setTitle('last') o.activate(after_tag=('A', 'B'), activity=activity).setTitle('last')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
self.assertEquals(o.getTitle(), 'last') self.assertEquals(o.getTitle(), 'last')
...@@ -670,7 +667,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -670,7 +667,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
organisation_module = self.getOrganisationModule() organisation_module = self.getOrganisationModule()
if not organisation_module.hasContent(self.company_id): if not organisation_module.hasContent(self.company_id):
organisation_module.newContent(id=self.company_id) organisation_module.newContent(id=self.company_id)
get_transaction().commit() transaction.commit()
self.tic() self.tic()
def check(o): def check(o):
...@@ -683,14 +680,14 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -683,14 +680,14 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o = portal.organisation._getOb(self.company_id) o = portal.organisation._getOb(self.company_id)
for i in range(activity_count): for i in range(activity_count):
o.activate(activity=activity)._setTitle('foo') o.activate(activity=activity)._setTitle('foo')
get_transaction().commit() transaction.commit()
check(o) check(o)
portal.portal_activities.manageClearActivities() portal.portal_activities.manageClearActivities()
get_transaction().commit() transaction.commit()
check(o) check(o)
get_transaction().commit() transaction.commit()
self.tic() self.tic()
self.assertEquals(o.getTitle(), 'foo') self.assertEquals(o.getTitle(), 'foo')
...@@ -706,11 +703,11 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -706,11 +703,11 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
organisation_module.newContent(id=self.company_id) organisation_module.newContent(id=self.company_id)
o = portal.organisation._getOb(self.company_id) o = portal.organisation._getOb(self.company_id)
o.setTitle('?') o.setTitle('?')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
o.activate(tag = 'toto', activity = activity).setTitle('a') o.activate(tag = 'toto', activity = activity).setTitle('a')
get_transaction().commit() transaction.commit()
self.assertEquals(o.getTitle(), '?') self.assertEquals(o.getTitle(), '?')
self.assertEquals(portal_activities.countMessageWithTag('toto'), 1) self.assertEquals(portal_activities.countMessageWithTag('toto'), 1)
self.tic() self.tic()
...@@ -729,7 +726,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -729,7 +726,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
if not organisation_module.hasContent(self.company_id): if not organisation_module.hasContent(self.company_id):
organisation_module.newContent(id=self.company_id) organisation_module.newContent(id=self.company_id)
o = organisation_module._getOb(self.company_id) o = organisation_module._getOb(self.company_id)
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent = 1, loop_size = 10) self.flushAllActivities(silent = 1, loop_size = 10)
self.assertEquals(len(activity_tool.getMessageList()), 0) self.assertEquals(len(activity_tool.getMessageList()), 0)
...@@ -751,7 +748,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -751,7 +748,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
Queue.current_num_conflict_errors = 0 Queue.current_num_conflict_errors = 0
Queue.conflict_errors_limit = i Queue.conflict_errors_limit = i
o.activate(activity = activity).getId() o.activate(activity = activity).getId()
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent = 1, loop_size = i + 10) self.flushAllActivities(silent = 1, loop_size = i + 10)
self.assertEquals(len(activity_tool.getMessageList()), 0) self.assertEquals(len(activity_tool.getMessageList()), 0)
finally: finally:
...@@ -772,7 +769,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -772,7 +769,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
if not organisation_module.hasContent(self.company_id): if not organisation_module.hasContent(self.company_id):
organisation_module.newContent(id=self.company_id) organisation_module.newContent(id=self.company_id)
o = organisation_module._getOb(self.company_id) o = organisation_module._getOb(self.company_id)
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent = 1, loop_size = 10) self.flushAllActivities(silent = 1, loop_size = 10)
self.assertEquals(len(activity_tool.getMessageList()), 0) self.assertEquals(len(activity_tool.getMessageList()), 0)
...@@ -791,13 +788,13 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -791,13 +788,13 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
try: try:
# Test some range of conflict error occurences. # Test some range of conflict error occurences.
organisation_module.recursiveReindexObject() organisation_module.recursiveReindexObject()
get_transaction().commit() transaction.commit()
self.assertEquals(len(activity_tool.getMessageList()), 1) self.assertEquals(len(activity_tool.getMessageList()), 1)
DB.original_query = DB.query DB.original_query = DB.query
DB.query = query DB.query = query
portal.portal_activities.distribute() portal.portal_activities.distribute()
portal.portal_activities.tic() portal.portal_activities.tic()
get_transaction().commit() transaction.commit()
DB.query = DB.original_query DB.query = DB.original_query
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),1) self.assertEquals(len(message_list),1)
...@@ -812,50 +809,50 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -812,50 +809,50 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
object_a.newContent(id=self.company_id) object_a.newContent(id=self.company_id)
object_b = object_a._getOb(self.company_id) object_b = object_a._getOb(self.company_id)
activity_tool.manageClearActivities(keep=0) activity_tool.manageClearActivities(keep=0)
get_transaction().commit() transaction.commit()
# First case: creating the same activity twice must only register one. # First case: creating the same activity twice must only register one.
self.assertEquals(len(activity_tool.getMessageList()), 0) # Sanity check self.assertEquals(len(activity_tool.getMessageList()), 0) # Sanity check
object_a.activate(activity=activity).getId() object_a.activate(activity=activity).getId()
object_a.activate(activity=activity).getId() object_a.activate(activity=activity).getId()
get_transaction().commit() transaction.commit()
self.assertEquals(len(activity_tool.getMessageList()), 1) self.assertEquals(len(activity_tool.getMessageList()), 1)
activity_tool.manageClearActivities(keep=0) activity_tool.manageClearActivities(keep=0)
get_transaction().commit() transaction.commit()
# Second case: creating activity with same tag must only register one. # Second case: creating activity with same tag must only register one.
# This behaviour is actually the same as the no-tag behaviour. # This behaviour is actually the same as the no-tag behaviour.
self.assertEquals(len(activity_tool.getMessageList()), 0) # Sanity check self.assertEquals(len(activity_tool.getMessageList()), 0) # Sanity check
object_a.activate(activity=activity, tag='foo').getId() object_a.activate(activity=activity, tag='foo').getId()
object_a.activate(activity=activity, tag='foo').getId() object_a.activate(activity=activity, tag='foo').getId()
get_transaction().commit() transaction.commit()
self.assertEquals(len(activity_tool.getMessageList()), 1) self.assertEquals(len(activity_tool.getMessageList()), 1)
activity_tool.manageClearActivities(keep=0) activity_tool.manageClearActivities(keep=0)
get_transaction().commit() transaction.commit()
# Third case: creating activities with different tags must register both. # Third case: creating activities with different tags must register both.
self.assertEquals(len(activity_tool.getMessageList()), 0) # Sanity check self.assertEquals(len(activity_tool.getMessageList()), 0) # Sanity check
object_a.activate(activity=activity, tag='foo').getId() object_a.activate(activity=activity, tag='foo').getId()
object_a.activate(activity=activity, tag='bar').getId() object_a.activate(activity=activity, tag='bar').getId()
get_transaction().commit() transaction.commit()
self.assertEquals(len(activity_tool.getMessageList()), 2) self.assertEquals(len(activity_tool.getMessageList()), 2)
activity_tool.manageClearActivities(keep=0) activity_tool.manageClearActivities(keep=0)
get_transaction().commit() transaction.commit()
# Fourth case: creating activities on different objects must register # Fourth case: creating activities on different objects must register
# both. # both.
self.assertEquals(len(activity_tool.getMessageList()), 0) # Sanity check self.assertEquals(len(activity_tool.getMessageList()), 0) # Sanity check
object_a.activate(activity=activity).getId() object_a.activate(activity=activity).getId()
object_b.activate(activity=activity).getId() object_b.activate(activity=activity).getId()
get_transaction().commit() transaction.commit()
self.assertEquals(len(activity_tool.getMessageList()), 2) self.assertEquals(len(activity_tool.getMessageList()), 2)
activity_tool.manageClearActivities(keep=0) activity_tool.manageClearActivities(keep=0)
get_transaction().commit() transaction.commit()
# Fifth case: creating activities with different method must register # Fifth case: creating activities with different method must register
# both. # both.
self.assertEquals(len(activity_tool.getMessageList()), 0) # Sanity check self.assertEquals(len(activity_tool.getMessageList()), 0) # Sanity check
object_a.activate(activity=activity).getId() object_a.activate(activity=activity).getId()
object_a.activate(activity=activity).getTitle() object_a.activate(activity=activity).getTitle()
get_transaction().commit() transaction.commit()
self.assertEquals(len(activity_tool.getMessageList()), 2) self.assertEquals(len(activity_tool.getMessageList()), 2)
activity_tool.manageClearActivities(keep=0) activity_tool.manageClearActivities(keep=0)
get_transaction().commit() transaction.commit()
def test_01_DeferredSetTitleSQLDict(self, quiet=0, run=run_all_test): def test_01_DeferredSetTitleSQLDict(self, quiet=0, run=run_all_test):
# Test if we can add a complete sales order # Test if we can add a complete sales order
...@@ -1374,7 +1371,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1374,7 +1371,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# Then execute activities as seb # Then execute activities as seb
user = uf.getUserById('seb').__of__(uf) user = uf.getUserById('seb').__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
get_transaction().commit() transaction.commit()
portal.portal_activities.distribute() portal.portal_activities.distribute()
portal.portal_activities.tic() portal.portal_activities.tic()
email = organisation.get('email') email = organisation.get('email')
...@@ -1495,7 +1492,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1495,7 +1492,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
finished = 0 finished = 0
activity_tool.timeShift(3 * VALIDATION_ERROR_DELAY) activity_tool.timeShift(3 * VALIDATION_ERROR_DELAY)
get_transaction().commit() transaction.commit()
if finished: if finished:
return return
...@@ -1539,12 +1536,12 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1539,12 +1536,12 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# reset # reset
activity_tool.manageClearActivities(keep=0) activity_tool.manageClearActivities(keep=0)
obj.setTitle(original_title) obj.setTitle(original_title)
get_transaction().commit() transaction.commit()
# activate failing message and flush # activate failing message and flush
for fail_activity in activity_list: for fail_activity in activity_list:
obj.activate(activity = fail_activity).failingMethod() obj.activate(activity = fail_activity).failingMethod()
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
full_message_list = activity_tool.getMessageList() full_message_list = activity_tool.getMessageList()
remaining_messages = [a for a in full_message_list if a.method_id != remaining_messages = [a for a in full_message_list if a.method_id !=
...@@ -1558,7 +1555,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1558,7 +1555,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
new_title = 'nothing' new_title = 'nothing'
obj.activate(after_method_id = ['failingMethod'], obj.activate(after_method_id = ['failingMethod'],
activity = activity ).setTitle(new_title) activity = activity ).setTitle(new_title)
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
full_message_list = activity_tool.getMessageList() full_message_list = activity_tool.getMessageList()
remaining_messages = [a for a in full_message_list if a.method_id != remaining_messages = [a for a in full_message_list if a.method_id !=
...@@ -1618,13 +1615,13 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1618,13 +1615,13 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
Message.notifyUser = notifyUserSilent Message.notifyUser = notifyUserSilent
# First, index the object. # First, index the object.
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
self.assertEquals(len(activity_tool.getMessageList()), 0) self.assertEquals(len(activity_tool.getMessageList()), 0)
# Insert a failing active object. # Insert a failing active object.
obj.activate().failingMethod() obj.activate().failingMethod()
get_transaction().commit() transaction.commit()
self.assertEquals(len(activity_tool.getMessageList()), 1) self.assertEquals(len(activity_tool.getMessageList()), 1)
# Just wait for the active object to be abandoned. # Just wait for the active object to be abandoned.
...@@ -1641,7 +1638,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1641,7 +1638,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# Cancel it via the management interface. # Cancel it via the management interface.
message = activity_tool.getMessageList()[0] message = activity_tool.getMessageList()[0]
activity_tool.manageCancel(message.object_path, message.method_id) activity_tool.manageCancel(message.object_path, message.method_id)
get_transaction().commit() transaction.commit()
self.assertEquals(len(activity_tool.getMessageList()), 0) self.assertEquals(len(activity_tool.getMessageList()), 0)
def test_68_RetryMessageExecution(self, quiet=0): def test_68_RetryMessageExecution(self, quiet=0):
...@@ -1668,7 +1665,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1668,7 +1665,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
exec_count[0] = 0 exec_count[0] = 0
activity_tool.activate(activity=activity, priority=priority(1,6), activity_tool.activate(activity=activity, priority=priority(1,6),
**activate_kw).doSomething(retry_list) **activate_kw).doSomething(retry_list)
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1) self.flushAllActivities(silent=1)
self.assertEqual(len(retry_list), exec_count[0]) self.assertEqual(len(retry_list), exec_count[0])
self.assertEqual(fail, len(activity_tool.getMessageList())) self.assertEqual(fail, len(activity_tool.getMessageList()))
...@@ -1774,7 +1771,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1774,7 +1771,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
o1 = self.getOrganisationModule().newContent( o1 = self.getOrganisationModule().newContent(
activate_kw=dict(tag='The Tag')) activate_kw=dict(tag='The Tag'))
get_transaction().commit() transaction.commit()
messages_for_o1 = [m for m in self.getActivityTool().getMessageList() messages_for_o1 = [m for m in self.getActivityTool().getMessageList()
if m.object_path == o1.getPhysicalPath()] if m.object_path == o1.getPhysicalPath()]
self.assertNotEquals(0, len(messages_for_o1)) self.assertNotEquals(0, len(messages_for_o1))
...@@ -1790,7 +1787,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1790,7 +1787,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
orga_module = self.getOrganisationModule() orga_module = self.getOrganisationModule()
p = orga_module.newContent(portal_type='Organisation') p = orga_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
self.assertEqual(p.getDescription(), "") self.assertEqual(p.getDescription(), "")
activity_tool = self.getPortal().portal_activities activity_tool = self.getPortal().portal_activities
...@@ -1804,7 +1801,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1804,7 +1801,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# First check dequeue read same message only once # First check dequeue read same message only once
for i in xrange(10): for i in xrange(10):
p.activate(activity="SQLDict").updateDesc() p.activate(activity="SQLDict").updateDesc()
get_transaction().commit() transaction.commit()
self.assertEqual(len(activity_tool.getMessageList()), 10) self.assertEqual(len(activity_tool.getMessageList()), 10)
self.tic() self.tic()
...@@ -1813,11 +1810,11 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1813,11 +1810,11 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# Check if there is pending activity after deleting an object # Check if there is pending activity after deleting an object
for i in xrange(10): for i in xrange(10):
p.activate(activity="SQLDict").updateDesc() p.activate(activity="SQLDict").updateDesc()
get_transaction().commit() transaction.commit()
self.assertEqual(len(activity_tool.getMessageList()), 10) self.assertEqual(len(activity_tool.getMessageList()), 10)
activity_tool.flush(p, invoke=0) activity_tool.flush(p, invoke=0)
get_transaction().commit() transaction.commit()
self.assertEqual(len(activity_tool.getMessageList()), 0) self.assertEqual(len(activity_tool.getMessageList()), 0)
def test_78_IsMessageRegisteredSQLDict(self, quiet=0, run=run_all_test): def test_78_IsMessageRegisteredSQLDict(self, quiet=0, run=run_all_test):
...@@ -1833,12 +1830,12 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1833,12 +1830,12 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
def test_79_AbortTransactionSynchronously(self, quiet=0, run=run_all_test): def test_79_AbortTransactionSynchronously(self, quiet=0, run=run_all_test):
""" """
This test tests if abortTransactionSynchronously really aborts This test checks if transaction.abort() synchronizes connections. It
a transaction synchronously. didn't do so back in Zope 2.7
""" """
if not run: return if not run: return
if not quiet: if not quiet:
message = '\nTest Aborting Transaction Synchronously' message = '\nTest Aborting Transaction Synchronizes'
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
...@@ -1847,7 +1844,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1847,7 +1844,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
module = self.getOrganisationModule() module = self.getOrganisationModule()
organisation = module.newContent(portal_type = 'Organisation') organisation = module.newContent(portal_type = 'Organisation')
organisation_id = organisation.getId() organisation_id = organisation.getId()
get_transaction().commit() transaction.commit()
organisation = module[organisation_id] organisation = module[organisation_id]
# Now fake a read conflict. # Now fake a read conflict.
...@@ -1863,23 +1860,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1863,23 +1860,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
conn.db().invalidate(tid, {oid: tid}) conn.db().invalidate(tid, {oid: tid})
conn._cache.invalidate(oid) conn._cache.invalidate(oid)
# Usual abort should not remove a read conflict error. # Access to invalidated object in non-MVCC connections should raise a
# conflict error
organisation = module[organisation_id] organisation = module[organisation_id]
self.assertRaises(ReadConflictError, getattr, organisation, 'uid') self.assertRaises(ReadConflictError, getattr, organisation, 'uid')
# In Zope 2.7, abort does not sync automatically, so even after abort, # In Zope 2.7, abort does not sync automatically, so even after abort,
# ReadConflictError is raised. But in Zope 2.8, this is automatic, so # ReadConflictError would be raised. But in Zope 2.8, this is automatic.
# abort has the same effect as abortTransactionSynchronously.
# transaction.abort()
# In reality, we do not care about whether abort raises or not
# at this point. We are only interested in whether
# abortTransactionSynchronously works expectedly.
#get_transaction().abort()
#self.assertRaises(ReadConflictError, getattr, organisation, 'uid')
# Synchronous abort.
from Products.CMFActivity.Activity.Queue import abortTransactionSynchronously
abortTransactionSynchronously()
getattr(organisation, 'uid') getattr(organisation, 'uid')
...@@ -1916,7 +1905,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1916,7 +1905,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# Test group_method_id is working without group_id # Test group_method_id is working without group_id
for x in xrange(5): for x in xrange(5):
organisation.activate(activity='SQLDict', group_method_id="organisation_module/setFoobar").reindexObject(number=1) organisation.activate(activity='SQLDict', group_method_id="organisation_module/setFoobar").reindexObject(number=1)
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),5) self.assertEquals(len(message_list),5)
...@@ -1928,7 +1917,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1928,7 +1917,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# Test group_method_id is working with one group_id defined # Test group_method_id is working with one group_id defined
for x in xrange(5): for x in xrange(5):
organisation.activate(activity='SQLDict', group_method_id="organisation_module/setFoobar", group_id="1").reindexObject(number=1) organisation.activate(activity='SQLDict', group_method_id="organisation_module/setFoobar", group_id="1").reindexObject(number=1)
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),5) self.assertEquals(len(message_list),5)
...@@ -1939,13 +1928,13 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1939,13 +1928,13 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# Test group_method_id is working with many group_id defined # Test group_method_id is working with many group_id defined
for x in xrange(5): for x in xrange(5):
organisation.activate(activity='SQLDict', group_method_id="organisation_module/setFoobar", group_id="1").reindexObject(number=1) organisation.activate(activity='SQLDict', group_method_id="organisation_module/setFoobar", group_id="1").reindexObject(number=1)
get_transaction().commit() transaction.commit()
organisation.activate(activity='SQLDict', group_method_id="organisation_module/setFoobar", group_id="2").reindexObject(number=3) organisation.activate(activity='SQLDict', group_method_id="organisation_module/setFoobar", group_id="2").reindexObject(number=3)
get_transaction().commit() transaction.commit()
organisation.activate(activity='SQLDict', group_method_id="organisation_module/setFoobar", group_id="1").reindexObject(number=1) organisation.activate(activity='SQLDict', group_method_id="organisation_module/setFoobar", group_id="1").reindexObject(number=1)
get_transaction().commit() transaction.commit()
organisation.activate(activity='SQLDict', group_method_id="organisation_module/setFoobar", group_id="3").reindexObject(number=5) organisation.activate(activity='SQLDict', group_method_id="organisation_module/setFoobar", group_id="3").reindexObject(number=5)
get_transaction().commit() transaction.commit()
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list),20) self.assertEquals(len(message_list),20)
...@@ -1966,10 +1955,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1966,10 +1955,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
o1 = self.getOrganisationModule().newContent() o1 = self.getOrganisationModule().newContent()
get_transaction().commit() transaction.commit()
self.tic() self.tic()
o1.validate(activate_kw=dict(tag='The Tag')) o1.validate(activate_kw=dict(tag='The Tag'))
get_transaction().commit() transaction.commit()
messages_for_o1 = [m for m in self.getActivityTool().getMessageList() messages_for_o1 = [m for m in self.getActivityTool().getMessageList()
if m.object_path == o1.getPhysicalPath()] if m.object_path == o1.getPhysicalPath()]
self.assertNotEquals(0, len(messages_for_o1)) self.assertNotEquals(0, len(messages_for_o1))
...@@ -1985,7 +1974,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1985,7 +1974,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message = '\nCheck loss of volatile attribute doesn\'t cause message to be lost' message = '\nCheck loss of volatile attribute doesn\'t cause message to be lost'
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
message_list = activity_tool.getMessageList() message_list = activity_tool.getMessageList()
...@@ -2003,7 +1992,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2003,7 +1992,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
delete_volatiles() delete_volatiles()
# Another activity to check that first one did not get lost even if volatile disapears # Another activity to check that first one did not get lost even if volatile disapears
active_organisation_module.getId() active_organisation_module.getId()
get_transaction().commit() transaction.commit()
message_list = activity_tool.getMessageList() message_list = activity_tool.getMessageList()
self.assertEquals(len(message_list), 2) self.assertEquals(len(message_list), 2)
...@@ -2017,7 +2006,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2017,7 +2006,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message = '\nCheck activity modifications via CMFActivity connection are rolled back on error (SQLDict)' message = '\nCheck activity modifications via CMFActivity connection are rolled back on error (SQLDict)'
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
def modifySQLAndFail(self, object_list, **kw): def modifySQLAndFail(self, object_list, **kw):
...@@ -2058,7 +2047,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2058,7 +2047,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
obj.activate(activity='SQLDict', group_method_id=group_method_id).dummy() obj.activate(activity='SQLDict', group_method_id=group_method_id).dummy()
obj2 = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj2 = self.getPortal().organisation_module.newContent(portal_type='Organisation')
obj2.activate(activity='SQLDict', group_method_id=group_method_id).dummy() obj2.activate(activity='SQLDict', group_method_id=group_method_id).dummy()
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
self.assertEquals(activity_tool.countMessage(method_id='dummy_activity'), 0) self.assertEquals(activity_tool.countMessage(method_id='dummy_activity'), 0)
finally: finally:
...@@ -2075,7 +2064,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2075,7 +2064,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message = '\nCheck activity modifications via CMFActivity connection are rolled back on error (SQLQueue)' message = '\nCheck activity modifications via CMFActivity connection are rolled back on error (SQLQueue)'
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
def modifySQLAndFail(self): def modifySQLAndFail(self):
...@@ -2107,7 +2096,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2107,7 +2096,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
Organisation.modifySQLAndFail = modifySQLAndFail Organisation.modifySQLAndFail = modifySQLAndFail
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj = self.getPortal().organisation_module.newContent(portal_type='Organisation')
obj.activate(activity='SQLQueue').modifySQLAndFail() obj.activate(activity='SQLQueue').modifySQLAndFail()
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
self.assertEquals(activity_tool.countMessage(method_id='dummy_activity'), 0) self.assertEquals(activity_tool.countMessage(method_id='dummy_activity'), 0)
finally: finally:
...@@ -2142,7 +2131,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2142,7 +2131,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message = '\nCheck that activity modifications via CMFActivity connection are rolled back on ActivityTool error (SQLDict)' message = '\nCheck that activity modifications via CMFActivity connection are rolled back on ActivityTool error (SQLDict)'
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
def modifySQLAndFail(self, *arg, **kw): def modifySQLAndFail(self, *arg, **kw):
...@@ -2183,7 +2172,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2183,7 +2172,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
obj.activate(activity='SQLDict', group_method_id=group_method_id).dummy() obj.activate(activity='SQLDict', group_method_id=group_method_id).dummy()
obj2 = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj2 = self.getPortal().organisation_module.newContent(portal_type='Organisation')
obj2.activate(activity='SQLDict', group_method_id=group_method_id).dummy() obj2.activate(activity='SQLDict', group_method_id=group_method_id).dummy()
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
self.assertEquals(activity_tool.countMessage(method_id='dummy_activity'), 0) self.assertEquals(activity_tool.countMessage(method_id='dummy_activity'), 0)
finally: finally:
...@@ -2200,7 +2189,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2200,7 +2189,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message = '\nCheck that activity modifications via CMFActivity connection are rolled back on ActivityTool error (SQLQueue)' message = '\nCheck that activity modifications via CMFActivity connection are rolled back on ActivityTool error (SQLQueue)'
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
def modifySQLAndFail(self, *args, **kw): def modifySQLAndFail(self, *args, **kw):
...@@ -2238,7 +2227,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2238,7 +2227,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
Organisation.dummy = dummy Organisation.dummy = dummy
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj = self.getPortal().organisation_module.newContent(portal_type='Organisation')
obj.activate(activity='SQLQueue').dummy() obj.activate(activity='SQLQueue').dummy()
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
self.assertEquals(activity_tool.countMessage(method_id='dummy_activity'), 0) self.assertEquals(activity_tool.countMessage(method_id='dummy_activity'), 0)
finally: finally:
...@@ -2260,7 +2249,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2260,7 +2249,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message = '\nCheck processing a batch of messages with failures' message = '\nCheck processing a batch of messages with failures'
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj = self.getPortal().organisation_module.newContent(portal_type='Organisation')
...@@ -2276,7 +2265,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2276,7 +2265,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
active_obj.appendToTitle('c', fail=True) active_obj.appendToTitle('c', fail=True)
active_obj.appendToTitle('d') active_obj.appendToTitle('d')
object_id = obj.getId() object_id = obj.getId()
get_transaction().commit() transaction.commit()
self.assertEqual(obj.getTitle(), 'a') self.assertEqual(obj.getTitle(), 'a')
self.assertEqual(activity_tool.countMessage(method_id='appendToTitle'), 3) self.assertEqual(activity_tool.countMessage(method_id='appendToTitle'), 3)
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
...@@ -2297,7 +2286,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2297,7 +2286,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message = '\nCheck request isolation between messages of the same batch' message = '\nCheck request isolation between messages of the same batch'
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
get_transaction().commit() transaction.commit()
self.tic() self.tic()
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation', title='Pending') obj = self.getPortal().organisation_module.newContent(portal_type='Organisation', title='Pending')
marker_id = 'marker_%i' % (random.randint(1, 10), ) marker_id = 'marker_%i' % (random.randint(1, 10), )
...@@ -2314,7 +2303,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2314,7 +2303,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
obj.activate(activity='SQLQueue', tag='set_first').putMarkerValue(marker_id=marker_id) obj.activate(activity='SQLQueue', tag='set_first').putMarkerValue(marker_id=marker_id)
obj.activate(activity='SQLQueue', after_tag='set_first').checkMarkerValue(marker_id=marker_id) obj.activate(activity='SQLQueue', after_tag='set_first').checkMarkerValue(marker_id=marker_id)
self.assertEqual(obj.getTitle(), 'Pending') self.assertEqual(obj.getTitle(), 'Pending')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
self.assertEqual(obj.getTitle(), 'Success') self.assertEqual(obj.getTitle(), 'Success')
finally: finally:
...@@ -2322,10 +2311,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2322,10 +2311,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
delattr(Organisation, 'checkMarkerValue') delattr(Organisation, 'checkMarkerValue')
def TryUserNotificationOnActivityFailure(self, activity): def TryUserNotificationOnActivityFailure(self, activity):
get_transaction().commit() transaction.commit()
self.tic() self.tic()
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
# Use a mutable variable to be able to modify the same instance from # Use a mutable variable to be able to modify the same instance from
# monkeypatch method. # monkeypatch method.
...@@ -2341,14 +2330,14 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2341,14 +2330,14 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
try: try:
# MESSAGE_NOT_EXECUTED # MESSAGE_NOT_EXECUTED
obj.activate(activity=activity).failingMethod() obj.activate(activity=activity).failingMethod()
get_transaction().commit() transaction.commit()
self.assertEqual(len(notification_done), 0) self.assertEqual(len(notification_done), 0)
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
self.assertEqual(len(notification_done), 1) self.assertEqual(len(notification_done), 1)
# MESSAGE_NOT_EXECUTABLE # MESSAGE_NOT_EXECUTABLE
obj.getParentValue()._delObject(obj.getId()) obj.getParentValue()._delObject(obj.getId())
obj.activate(activity=activity).getId() obj.activate(activity=activity).getId()
get_transaction().commit() transaction.commit()
self.assertEqual(len(notification_done), 1) self.assertEqual(len(notification_done), 1)
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
self.assertEqual(len(notification_done), 2) self.assertEqual(len(notification_done), 2)
...@@ -2382,10 +2371,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2382,10 +2371,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.TryUserNotificationOnActivityFailure('SQLQueue') self.TryUserNotificationOnActivityFailure('SQLQueue')
def TryUserNotificationRaise(self, activity): def TryUserNotificationRaise(self, activity):
get_transaction().commit() transaction.commit()
self.tic() self.tic()
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
from Products.CMFActivity.ActivityTool import Message from Products.CMFActivity.ActivityTool import Message
original_notifyUser = Message.notifyUser original_notifyUser = Message.notifyUser
...@@ -2396,7 +2385,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2396,7 +2385,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
readMessageList = getattr(self.getPortalObject(), '%s_readMessageList'% (activity, )) readMessageList = getattr(self.getPortalObject(), '%s_readMessageList'% (activity, ))
try: try:
obj.activate(activity=activity, priority=6).failingMethod() obj.activate(activity=activity, priority=6).failingMethod()
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
with_processing_len = len(readMessageList(path=None, with_processing_len = len(readMessageList(path=None,
to_date=None, to_date=None,
...@@ -2445,7 +2434,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2445,7 +2434,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message = '\nCheck that activity modifications via CMFActivity connection are rolled back on commit error (SQLDict)' message = '\nCheck that activity modifications via CMFActivity connection are rolled back on commit error (SQLDict)'
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
def modifySQL(self, object_list, *arg, **kw): def modifySQL(self, object_list, *arg, **kw):
...@@ -2470,26 +2459,26 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2470,26 +2459,26 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
tag_list=[''], tag_list=[''],
order_validation_text_list=[''], order_validation_text_list=[''],
) )
get_transaction().__class__.commit = fake_commit transaction.get().__class__.commit = fake_commit
object_list[:] = [] object_list[:] = []
commit = get_transaction().__class__.commit commit = transaction.get().__class__.commit
def fake_commit(*args, **kw): def fake_commit(*args, **kw):
get_transaction().__class__.commit = commit transaction.get().__class__.commit = commit
raise KeyError, 'always fail' raise KeyError, 'always fail'
try: try:
Organisation.modifySQL = modifySQL Organisation.modifySQL = modifySQL
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj = self.getPortal().organisation_module.newContent(portal_type='Organisation')
group_method_id = '%s/modifySQL' % (obj.getPath(), ) group_method_id = '%s/modifySQL' % (obj.getPath(), )
obj2 = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj2 = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
obj.activate(activity='SQLDict', group_method_id=group_method_id).modifySQL() obj.activate(activity='SQLDict', group_method_id=group_method_id).modifySQL()
obj2.activate(activity='SQLDict', group_method_id=group_method_id).modifySQL() obj2.activate(activity='SQLDict', group_method_id=group_method_id).modifySQL()
get_transaction().commit() transaction.commit()
try: try:
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
finally: finally:
get_transaction().__class__.commit = commit transaction.get().__class__.commit = commit
self.assertEquals(activity_tool.countMessage(method_id='dummy_activity'), 0) self.assertEquals(activity_tool.countMessage(method_id='dummy_activity'), 0)
finally: finally:
delattr(Organisation, 'modifySQL') delattr(Organisation, 'modifySQL')
...@@ -2503,7 +2492,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2503,7 +2492,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message = '\nCheck that activity modifications via CMFActivity connection are rolled back on commit error (SQLQueue)' message = '\nCheck that activity modifications via CMFActivity connection are rolled back on commit error (SQLQueue)'
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
def modifySQL(self, *args, **kw): def modifySQL(self, *args, **kw):
...@@ -2528,22 +2517,22 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2528,22 +2517,22 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
tag_list=[''], tag_list=[''],
order_validation_text_list=[''], order_validation_text_list=[''],
) )
get_transaction().__class__.commit = fake_commit transaction.get().__class__.commit = fake_commit
commit = get_transaction().__class__.commit commit = transaction.get().__class__.commit
def fake_commit(self, *args, **kw): def fake_commit(self, *args, **kw):
get_transaction().__class__.commit = commit transaction.get().__class__.commit = commit
raise KeyError, 'always fail' raise KeyError, 'always fail'
try: try:
Organisation.modifySQL = modifySQL Organisation.modifySQL = modifySQL
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
obj.activate(activity='SQLQueue').modifySQL() obj.activate(activity='SQLQueue').modifySQL()
get_transaction().commit() transaction.commit()
try: try:
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
finally: finally:
get_transaction().__class__.commit = commit transaction.get().__class__.commit = commit
self.assertEquals(activity_tool.countMessage(method_id='dummy_activity'), 0) self.assertEquals(activity_tool.countMessage(method_id='dummy_activity'), 0)
finally: finally:
delattr(Organisation, 'modifySQL') delattr(Organisation, 'modifySQL')
...@@ -2554,20 +2543,20 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2554,20 +2543,20 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
error be raised in tpc_vote) does not cause activity connection to error be raised in tpc_vote) does not cause activity connection to
stall. stall.
""" """
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
from Shared.DC.ZRDB.TM import TM from Shared.DC.ZRDB.TM import TM
try: try:
Organisation.registerFailingTransactionManager = registerFailingTransactionManager Organisation.registerFailingTransactionManager = registerFailingTransactionManager
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
now = DateTime() now = DateTime()
obj.activate(activity=activity).registerFailingTransactionManager() obj.activate(activity=activity).registerFailingTransactionManager()
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
get_transaction().commit() transaction.commit()
# Check that cmf_activity SQL connection still works # Check that cmf_activity SQL connection still works
connection_da_pool = self.getPortalObject().cmf_activity_sql_connection() connection_da_pool = self.getPortalObject().cmf_activity_sql_connection()
import thread import thread
...@@ -2575,7 +2564,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2575,7 +2564,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertFalse(connection_da._registered) self.assertFalse(connection_da._registered)
connection_da_pool.query('select 1') connection_da_pool.query('select 1')
self.assertTrue(connection_da._registered) self.assertTrue(connection_da._registered)
get_transaction().commit() transaction.commit()
self.assertFalse(connection_da._registered) self.assertFalse(connection_da._registered)
finally: finally:
delattr(Organisation, 'registerFailingTransactionManager') delattr(Organisation, 'registerFailingTransactionManager')
...@@ -2599,19 +2588,19 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2599,19 +2588,19 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
def TryActivityRaiseInCommitDoesNotLooseMessages(self, activity): def TryActivityRaiseInCommitDoesNotLooseMessages(self, activity):
""" """
""" """
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
try: try:
Organisation.registerFailingTransactionManager = registerFailingTransactionManager Organisation.registerFailingTransactionManager = registerFailingTransactionManager
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
now = DateTime() now = DateTime()
obj.activate(activity=activity).registerFailingTransactionManager() obj.activate(activity=activity).registerFailingTransactionManager()
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
get_transaction().commit() transaction.commit()
self.assertEquals(activity_tool.countMessage(method_id='registerFailingTransactionManager'), 1) self.assertEquals(activity_tool.countMessage(method_id='registerFailingTransactionManager'), 1)
finally: finally:
delattr(Organisation, 'registerFailingTransactionManager') delattr(Organisation, 'registerFailingTransactionManager')
...@@ -2633,7 +2622,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2633,7 +2622,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.TryActivityRaiseInCommitDoesNotLooseMessages('SQLQueue') self.TryActivityRaiseInCommitDoesNotLooseMessages('SQLQueue')
def TryChangeSkinInActivity(self, activity): def TryChangeSkinInActivity(self, activity):
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
def changeSkinToNone(self): def changeSkinToNone(self):
...@@ -2641,10 +2630,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2641,10 +2630,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
Organisation.changeSkinToNone = changeSkinToNone Organisation.changeSkinToNone = changeSkinToNone
try: try:
organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation') organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
organisation.activate(activity=activity).changeSkinToNone() organisation.activate(activity=activity).changeSkinToNone()
get_transaction().commit() transaction.commit()
self.assertEquals(len(activity_tool.getMessageList()), 1) self.assertEquals(len(activity_tool.getMessageList()), 1)
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
self.assertEquals(len(activity_tool.getMessageList()), 0) self.assertEquals(len(activity_tool.getMessageList()), 0)
...@@ -2678,7 +2667,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2678,7 +2667,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation') organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
check_result_dict = {} check_result_dict = {}
...@@ -2690,7 +2679,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2690,7 +2679,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# Adds two similar but not the same activities. # Adds two similar but not the same activities.
organisation.activate(activity='SQLDict', tag='a').checkActivityCount(other_tag='b') organisation.activate(activity='SQLDict', tag='a').checkActivityCount(other_tag='b')
organisation.activate(activity='SQLDict', tag='b').checkActivityCount(other_tag='a') organisation.activate(activity='SQLDict', tag='b').checkActivityCount(other_tag='a')
get_transaction().commit() transaction.commit()
self.assertEqual(len(activity_tool.getMessageList()), 2) self.assertEqual(len(activity_tool.getMessageList()), 2)
activity_tool.distribute() activity_tool.distribute()
# after distribute, similarities are still there. # after distribute, similarities are still there.
...@@ -2713,7 +2702,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2713,7 +2702,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation') organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
check_result_dict = {} check_result_dict = {}
...@@ -2724,10 +2713,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2724,10 +2713,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
Organisation.checkActivityCount = checkActivityCount Organisation.checkActivityCount = checkActivityCount
# Adds two same activities. # Adds two same activities.
organisation.activate(activity='SQLDict', tag='a', priority=2).checkActivityCount(other_tag='a') organisation.activate(activity='SQLDict', tag='a', priority=2).checkActivityCount(other_tag='a')
get_transaction().commit() transaction.commit()
uid1, = [x.uid for x in activity_tool.getMessageList()] uid1, = [x.uid for x in activity_tool.getMessageList()]
organisation.activate(activity='SQLDict', tag='a', priority=1).checkActivityCount(other_tag='a') organisation.activate(activity='SQLDict', tag='a', priority=1).checkActivityCount(other_tag='a')
get_transaction().commit() transaction.commit()
self.assertEqual(len(activity_tool.getMessageList()), 2) self.assertEqual(len(activity_tool.getMessageList()), 2)
activity_tool.distribute() activity_tool.distribute()
# After distribute, duplicate is deleted. # After distribute, duplicate is deleted.
...@@ -2750,14 +2739,14 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2750,14 +2739,14 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
foo.activate(serialization_tag='a').getId() foo.activate(serialization_tag='a').getId()
""" """
organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation') organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
organisation.activate(serialization_tag='a').getId() organisation.activate(serialization_tag='a').getId()
get_transaction().commit() transaction.commit()
organisation.activate(serialization_tag='a', organisation.activate(serialization_tag='a',
group_method_id='portal_catalog/catalogObjectList').getTitle() group_method_id='portal_catalog/catalogObjectList').getTitle()
get_transaction().commit() transaction.commit()
self.assertEqual(len(activity_tool.getMessageList()), 2) self.assertEqual(len(activity_tool.getMessageList()), 2)
activity_tool.distribute() activity_tool.distribute()
# After distribute, there is no deletion because it is different method # After distribute, there is no deletion because it is different method
...@@ -2779,13 +2768,13 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2779,13 +2768,13 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation') organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
check_result_dict = {} check_result_dict = {}
def runAndCheck(): def runAndCheck():
check_result_dict.clear() check_result_dict.clear()
get_transaction().commit() transaction.commit()
self.assertEqual(len(check_result_dict), 0) self.assertEqual(len(check_result_dict), 0)
self.tic() self.tic()
self.assertEqual(len(check_result_dict), 2) self.assertEqual(len(check_result_dict), 2)
...@@ -2826,7 +2815,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2826,7 +2815,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
document.__class__.doSomething = extractActivityRuntimeEnvironment document.__class__.doSomething = extractActivityRuntimeEnvironment
try: try:
document.activate(activity=activity).doSomething() document.activate(activity=activity).doSomething()
get_transaction().commit() transaction.commit()
# Check that getActivityRuntimeEnvironment raises outside of activities # Check that getActivityRuntimeEnvironment raises outside of activities
self.assertRaises(KeyError, document.getActivityRuntimeEnvironment) self.assertRaises(KeyError, document.getActivityRuntimeEnvironment)
# Check Runtime isolation # Check Runtime isolation
...@@ -2864,7 +2853,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2864,7 +2853,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
def CheckSerializationTag(self, activity): def CheckSerializationTag(self, activity):
organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation') organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
result = activity_tool.getMessageList() result = activity_tool.getMessageList()
...@@ -2872,7 +2861,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2872,7 +2861,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# First scenario: activate, distribute, activate, distribute # First scenario: activate, distribute, activate, distribute
# Create first activity and distribute: it must be distributed # Create first activity and distribute: it must be distributed
organisation.activate(activity=activity, serialization_tag='1').getTitle() organisation.activate(activity=activity, serialization_tag='1').getTitle()
get_transaction().commit() transaction.commit()
result = activity_tool.getMessageList() result = activity_tool.getMessageList()
self.assertEqual(len(result), 1) self.assertEqual(len(result), 1)
activity_tool.distribute() activity_tool.distribute()
...@@ -2880,7 +2869,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2880,7 +2869,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertEqual(len([x for x in result if x.processing_node == 0]), 1) self.assertEqual(len([x for x in result if x.processing_node == 0]), 1)
# Create second activity and distribute: it must *NOT* be distributed # Create second activity and distribute: it must *NOT* be distributed
organisation.activate(activity=activity, serialization_tag='1').getTitle() organisation.activate(activity=activity, serialization_tag='1').getTitle()
get_transaction().commit() transaction.commit()
result = activity_tool.getMessageList() result = activity_tool.getMessageList()
self.assertEqual(len(result), 2) self.assertEqual(len(result), 2)
activity_tool.distribute() activity_tool.distribute()
...@@ -2894,7 +2883,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2894,7 +2883,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
organisation.activate(activity=activity, serialization_tag='1', priority=2).getTitle() organisation.activate(activity=activity, serialization_tag='1', priority=2).getTitle()
# Use a different method just so that SQLDict doesn't merge both activities prior to insertion. # Use a different method just so that SQLDict doesn't merge both activities prior to insertion.
organisation.activate(activity=activity, serialization_tag='1', priority=1).getId() organisation.activate(activity=activity, serialization_tag='1', priority=1).getId()
get_transaction().commit() transaction.commit()
result = activity_tool.getMessageList() result = activity_tool.getMessageList()
self.assertEqual(len(result), 2) self.assertEqual(len(result), 2)
activity_tool.distribute() activity_tool.distribute()
...@@ -2978,17 +2967,17 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2978,17 +2967,17 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
container = self.getPortal().organisation_module container = self.getPortal().organisation_module
organisation = container.newContent(portal_type='Organisation') organisation = container.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
organisation.activate(activity=activity).getTitle() organisation.activate(activity=activity).getTitle()
get_transaction().commit() transaction.commit()
self.assertEqual(len(activity_tool.getMessageList()), 1) self.assertEqual(len(activity_tool.getMessageList()), 1)
# Here, we delete the subobject using most low-level method, to avoid # Here, we delete the subobject using most low-level method, to avoid
# pending activity to be removed. # pending activity to be removed.
organisation_id = organisation.id organisation_id = organisation.id
container._delOb(organisation_id) container._delOb(organisation_id)
del organisation # Avoid keeping a reference to a deleted object. del organisation # Avoid keeping a reference to a deleted object.
get_transaction().commit() transaction.commit()
self.assertEqual(getattr(container, organisation_id, None), None) self.assertEqual(getattr(container, organisation_id, None), None)
self.assertEqual(len(activity_tool.getMessageList()), 1) self.assertEqual(len(activity_tool.getMessageList()), 1)
activity_tool.distribute() activity_tool.distribute()
...@@ -3035,18 +3024,18 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3035,18 +3024,18 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
container = self.getPortalObject().organisation_module container = self.getPortalObject().organisation_module
organisation = container.newContent(portal_type='Organisation') organisation = container.newContent(portal_type='Organisation')
organisation_2 = container.newContent(portal_type='Organisation') organisation_2 = container.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
organisation.reindexObject() organisation.reindexObject()
organisation_2.reindexObject() organisation_2.reindexObject()
get_transaction().commit() transaction.commit()
self.assertEqual(len(activity_tool.getMessageList()), 2) self.assertEqual(len(activity_tool.getMessageList()), 2)
# Here, we delete the subobject using most low-level method, to avoid # Here, we delete the subobject using most low-level method, to avoid
# pending activity to be removed. # pending activity to be removed.
organisation_id = organisation.id organisation_id = organisation.id
container._delOb(organisation_id) container._delOb(organisation_id)
del organisation # Avoid keeping a reference to a deleted object. del organisation # Avoid keeping a reference to a deleted object.
get_transaction().commit() transaction.commit()
self.assertEqual(getattr(container, organisation_id, None), None) self.assertEqual(getattr(container, organisation_id, None), None)
self.assertEqual(len(activity_tool.getMessageList()), 2) self.assertEqual(len(activity_tool.getMessageList()), 2)
activity_tool.distribute() activity_tool.distribute()
...@@ -3077,7 +3066,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3077,7 +3066,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
language=LANGUAGE, translation=TO_STRING, note='') language=LANGUAGE, translation=TO_STRING, note='')
organisation = portal.organisation_module.newContent( organisation = portal.organisation_module.newContent(
portal_type='Organisation') portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
Organisation.translationTest = translationTest Organisation.translationTest = translationTest
try: try:
...@@ -3085,7 +3074,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3085,7 +3074,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# Simulate what a browser would have sent to Zope # Simulate what a browser would have sent to Zope
REQUEST.environ['HTTP_ACCEPT_LANGUAGE'] = LANGUAGE REQUEST.environ['HTTP_ACCEPT_LANGUAGE'] = LANGUAGE
organisation.activate(activity=activity).translationTest() organisation.activate(activity=activity).translationTest()
get_transaction().commit() transaction.commit()
# Remove request parameter to check that it was saved at activate call # Remove request parameter to check that it was saved at activate call
# and restored at message execution. # and restored at message execution.
del REQUEST.environ['HTTP_ACCEPT_LANGUAGE'] del REQUEST.environ['HTTP_ACCEPT_LANGUAGE']
...@@ -3126,10 +3115,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3126,10 +3115,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# With Message.__call__ # With Message.__call__
# 1: activity context does not exist when activity is executed # 1: activity context does not exist when activity is executed
organisation = portal.organisation_module.newContent(portal_type='Organisation') organisation = portal.organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
organisation.activate().getTitle() # This generates the mssage we want to test. organisation.activate().getTitle() # This generates the mssage we want to test.
get_transaction().commit() transaction.commit()
message_list = activity_tool.getMessageList() message_list = activity_tool.getMessageList()
self.assertEqual(len(message_list), 1) self.assertEqual(len(message_list), 1)
message = message_list[0] message = message_list[0]
...@@ -3139,7 +3128,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3139,7 +3128,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
activity_tool.manageCancel(message.object_path, message.method_id) activity_tool.manageCancel(message.object_path, message.method_id)
# 2: activity method does not exist when activity is executed # 2: activity method does not exist when activity is executed
portal.organisation_module.activate().this_method_does_not_exist() portal.organisation_module.activate().this_method_does_not_exist()
get_transaction().commit() transaction.commit()
message_list = activity_tool.getMessageList() message_list = activity_tool.getMessageList()
self.assertEqual(len(message_list), 1) self.assertEqual(len(message_list), 1)
message = message_list[0] message = message_list[0]
...@@ -3150,10 +3139,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3150,10 +3139,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# With ActivityTool.invokeGroup # With ActivityTool.invokeGroup
# 1: activity context does not exist when activity is executed # 1: activity context does not exist when activity is executed
organisation = portal.organisation_module.newContent(portal_type='Organisation') organisation = portal.organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
organisation.activate().getTitle() # This generates the mssage we want to test. organisation.activate().getTitle() # This generates the mssage we want to test.
get_transaction().commit() transaction.commit()
message_list = activity_tool.getMessageList() message_list = activity_tool.getMessageList()
self.assertEqual(len(message_list), 1) self.assertEqual(len(message_list), 1)
message = message_list[0] message = message_list[0]
...@@ -3163,7 +3152,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3163,7 +3152,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
activity_tool.manageCancel(message.object_path, message.method_id) activity_tool.manageCancel(message.object_path, message.method_id)
# 2: activity method does not exist when activity is executed # 2: activity method does not exist when activity is executed
portal.organisation_module.activate().this_method_does_not_exist() portal.organisation_module.activate().this_method_does_not_exist()
get_transaction().commit() transaction.commit()
message_list = activity_tool.getMessageList() message_list = activity_tool.getMessageList()
self.assertEqual(len(message_list), 1) self.assertEqual(len(message_list), 1)
message = message_list[0] message = message_list[0]
...@@ -3192,7 +3181,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3192,7 +3181,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
portal.portal_skins.manage_skinLayers(add_skin=1, skinpath=[''], skinname=skin_selection_name) portal.portal_skins.manage_skinLayers(add_skin=1, skinpath=[''], skinname=skin_selection_name)
# Create a dummy document # Create a dummy document
organisation = portal.organisation_module.newContent(portal_type='Organisation') organisation = portal.organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
# Set custom methods to call as activities. # Set custom methods to call as activities.
def first(context): def first(context):
...@@ -3207,7 +3196,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3207,7 +3196,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
try: try:
organisation.activate(tag='foo', activity='SQLQueue').firstTest() organisation.activate(tag='foo', activity='SQLQueue').firstTest()
organisation.activate(after_tag='foo', activity='SQLQueue').secondTest() organisation.activate(after_tag='foo', activity='SQLQueue').secondTest()
get_transaction().commit() transaction.commit()
import gc import gc
gc.disable() gc.disable()
self.tic() self.tic()
...@@ -3246,7 +3235,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3246,7 +3235,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
portal = self.getPortalObject() portal = self.getPortalObject()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
organisation = portal.organisation_module.newContent(portal_type='Organisation') organisation = portal.organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
activity_lock = threading.Lock() activity_lock = threading.Lock()
activity_lock.acquire() activity_lock.acquire()
...@@ -3275,10 +3264,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3275,10 +3264,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# if execution should stop processing activities. # if execution should stop processing activities.
organisation.activate(activity='SQLDict', tag='foo').waitingActivity() organisation.activate(activity='SQLDict', tag='foo').waitingActivity()
organisation.activate(activity='SQLDict', after_tag='foo').getTitle() organisation.activate(activity='SQLDict', after_tag='foo').getTitle()
get_transaction().commit() transaction.commit()
self.assertEqual(len(activity_tool.getMessageList()), 2) self.assertEqual(len(activity_tool.getMessageList()), 2)
activity_tool.distribute() activity_tool.distribute()
get_transaction().commit() transaction.commit()
# Start a tic in another thread, so they can meet at rendez-vous. # Start a tic in another thread, so they can meet at rendez-vous.
class ActivityThread(threading.Thread): class ActivityThread(threading.Thread):
...@@ -3342,7 +3331,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3342,7 +3331,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
active_object = self.portal.organisation_module.newContent( active_object = self.portal.organisation_module.newContent(
portal_type='Organisation') portal_type='Organisation')
active_process = self.portal.portal_activities.newActiveProcess() active_process = self.portal.portal_activities.newActiveProcess()
get_transaction().commit() transaction.commit()
self.tic() self.tic()
self.assertFalse(active_object.hasActivity()) self.assertFalse(active_object.hasActivity())
...@@ -3351,7 +3340,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3351,7 +3340,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
def test(obj, **kw): def test(obj, **kw):
for activity in ('SQLDict', 'SQLQueue'): for activity in ('SQLDict', 'SQLQueue'):
active_object.activate(activity=activity, **kw).getTitle() active_object.activate(activity=activity, **kw).getTitle()
get_transaction().commit() transaction.commit()
self.assertTrue(obj.hasActivity(), activity) self.assertTrue(obj.hasActivity(), activity)
self.tic() self.tic()
self.assertFalse(obj.hasActivity(), activity) self.assertFalse(obj.hasActivity(), activity)
...@@ -3368,7 +3357,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3368,7 +3357,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
""" """
active_object = self.portal.organisation_module.newContent( active_object = self.portal.organisation_module.newContent(
portal_type='Organisation') portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
self.assertFalse(active_object.hasActivity()) self.assertFalse(active_object.hasActivity())
...@@ -3380,7 +3369,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3380,7 +3369,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
DB.original_query = DB.query DB.original_query = DB.query
try: try:
active_object.activate().getTitle() active_object.activate().getTitle()
get_transaction().commit() transaction.commit()
self.assertTrue(active_object.hasActivity()) self.assertTrue(active_object.hasActivity())
# Make the sql request not working # Make the sql request not working
DB.original_query = DB.query DB.original_query = DB.query
...@@ -3457,34 +3446,34 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3457,34 +3446,34 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
portal = self.getPortal() portal = self.getPortal()
activity_tool = portal.portal_activities activity_tool = portal.portal_activities
get_transaction().commit() transaction.commit()
self.tic() self.tic()
# Add 6 activities # Add 6 activities
portal.organisation_module.activate(activity='SQLDict', tag='', serialization_tag='test_115').getId() portal.organisation_module.activate(activity='SQLDict', tag='', serialization_tag='test_115').getId()
get_transaction().commit() transaction.commit()
portal.organisation_module.activate(activity='SQLDict', serialization_tag='test_115').getTitle() portal.organisation_module.activate(activity='SQLDict', serialization_tag='test_115').getTitle()
get_transaction().commit() transaction.commit()
portal.organisation_module.activate(activity='SQLDict', tag='tag_1', serialization_tag='test_115').getId() portal.organisation_module.activate(activity='SQLDict', tag='tag_1', serialization_tag='test_115').getId()
get_transaction().commit() transaction.commit()
portal.person_module.activate(activity='SQLDict', serialization_tag='test_115').getId() portal.person_module.activate(activity='SQLDict', serialization_tag='test_115').getId()
get_transaction().commit() transaction.commit()
portal.person_module.activate(activity='SQLDict', tag='tag_2').getId() portal.person_module.activate(activity='SQLDict', tag='tag_2').getId()
get_transaction().commit() transaction.commit()
portal.organisation_module.activate(activity='SQLDict', tag='', serialization_tag='test_115').getId() portal.organisation_module.activate(activity='SQLDict', tag='', serialization_tag='test_115').getId()
get_transaction().commit() transaction.commit()
# distribute and assign them to 3 nodes # distribute and assign them to 3 nodes
activity_tool.distribute() activity_tool.distribute()
get_transaction().commit() transaction.commit()
from Products.CMFActivity import ActivityTool from Products.CMFActivity import ActivityTool
ActivityTool.activity_dict['SQLDict'].getProcessableMessageList(activity_tool, 1) ActivityTool.activity_dict['SQLDict'].getProcessableMessageList(activity_tool, 1)
get_transaction().commit() transaction.commit()
ActivityTool.activity_dict['SQLDict'].getProcessableMessageList(activity_tool, 2) ActivityTool.activity_dict['SQLDict'].getProcessableMessageList(activity_tool, 2)
get_transaction().commit() transaction.commit()
ActivityTool.activity_dict['SQLDict'].getProcessableMessageList(activity_tool, 3) ActivityTool.activity_dict['SQLDict'].getProcessableMessageList(activity_tool, 3)
get_transaction().commit() transaction.commit()
result = activity_tool.SQLDict_readMessageList(include_processing=1, result = activity_tool.SQLDict_readMessageList(include_processing=1,
processing_node=None, processing_node=None,
...@@ -3518,7 +3507,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3518,7 +3507,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
# Clear activities from all nodes # Clear activities from all nodes
activity_tool.SQLBase_delMessage(table=SQLDict.sql_table, activity_tool.SQLBase_delMessage(table=SQLDict.sql_table,
uid=[message.uid for message in result]) uid=[message.uid for message in result])
get_transaction().commit() transaction.commit()
def test_116_RaiseInCommitBeforeMessageExecution(self): def test_116_RaiseInCommitBeforeMessageExecution(self):
""" """
...@@ -3532,13 +3521,13 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3532,13 +3521,13 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
try: try:
for activity in 'SQLDict', 'SQLQueue': for activity in 'SQLDict', 'SQLQueue':
activity_tool.activate(activity=activity).doSomething(activity) activity_tool.activate(activity=activity).doSomething(activity)
get_transaction().commit() transaction.commit()
activity_tool.distribute() activity_tool.distribute()
# Make first commit in dequeueMessage raise # Make first commit in dequeueMessage raise
registerFailingTransactionManager() registerFailingTransactionManager()
self.assertRaises(CommitFailed, activity_tool.tic) self.assertRaises(CommitFailed, activity_tool.tic)
# Normally, the request stops here and Zope aborts the transaction # Normally, the request stops here and Zope aborts the transaction
get_transaction().abort() transaction.abort()
self.assertEqual(processed, []) self.assertEqual(processed, [])
# Activity is already in 'processing=1' state. Check tic reselects it. # Activity is already in 'processing=1' state. Check tic reselects it.
activity_tool.tic() activity_tool.tic()
...@@ -3566,7 +3555,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3566,7 +3555,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertEquals({'activate_kw': {'tag': tag}}, \ self.assertEquals({'activate_kw': {'tag': tag}}, \
current_default_reindex_parameters) current_default_reindex_parameters)
person = portal.person_module.newContent(portal_type='Person') person = portal.person_module.newContent(portal_type='Person')
get_transaction().commit() transaction.commit()
# as we specified it in setPlacelessDefaultReindexParameters we should have # as we specified it in setPlacelessDefaultReindexParameters we should have
# an activity for this tags # an activity for this tags
self.assertEquals(1, portal.portal_activities.countMessageWithTag(tag)) self.assertEquals(1, portal.portal_activities.countMessageWithTag(tag))
...@@ -3581,10 +3570,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3581,10 +3570,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
def TryNotificationSavedOnEventLogWhenNotifyUserRaises(self, activity): def TryNotificationSavedOnEventLogWhenNotifyUserRaises(self, activity):
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
get_transaction().commit() transaction.commit()
self.tic() self.tic()
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
original_notifyUser = Message.notifyUser original_notifyUser = Message.notifyUser
def failSendingEmail(self, *args, **kw): def failSendingEmail(self, *args, **kw):
...@@ -3601,18 +3590,18 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3601,18 +3590,18 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
try: try:
import traceback import traceback
obj.activate(activity=activity, priority=6).failingMethod() obj.activate(activity=activity, priority=6).failingMethod()
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
message_list = activity_tool.getMessageList() message_list = activity_tool.getMessageList()
self.assertEqual(len(message_list), 1) self.assertEqual(len(message_list), 1)
message = message_list[0] message = message_list[0]
logged_errors = [] logged_errors = []
logged_errors = self.logged logged_errors = self.logged
get_transaction().commit() transaction.commit()
for log_record in self.logged: for log_record in self.logged:
if log_record.name == 'ActivityTool' and log_record.levelname == 'WARNING': if log_record.name == 'ActivityTool' and log_record.levelname == 'WARNING':
type, value, trace = log_record.exc_info type, value, trace = log_record.exc_info
get_transaction().commit() transaction.commit()
self.assertTrue(activity_unit_test_error is value) self.assertTrue(activity_unit_test_error is value)
finally: finally:
self._ignore_log_errors() self._ignore_log_errors()
...@@ -3646,10 +3635,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3646,10 +3635,10 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
# With Message.__call__ # With Message.__call__
# 1: activity context does not exist when activity is executed # 1: activity context does not exist when activity is executed
get_transaction().commit() transaction.commit()
self.tic() self.tic()
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation') obj = self.getPortal().organisation_module.newContent(portal_type='Organisation')
get_transaction().commit() transaction.commit()
self.tic() self.tic()
notification_done = [] notification_done = []
def fake_notifyUser(self, *args, **kw): def fake_notifyUser(self, *args, **kw):
...@@ -3662,7 +3651,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3662,7 +3651,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
Organisation.failingMethod = failingMethod Organisation.failingMethod = failingMethod
try: try:
obj.activate(activity=activity).failingMethod() obj.activate(activity=activity).failingMethod()
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent=1, loop_size=100) self.flushAllActivities(silent=1, loop_size=100)
message_list = activity_tool.getMessageList() message_list = activity_tool.getMessageList()
self.assertEqual(len(message_list), 1) self.assertEqual(len(message_list), 1)
...@@ -3701,7 +3690,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3701,7 +3690,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
if not organisation_module.hasContent(self.company_id): if not organisation_module.hasContent(self.company_id):
organisation_module.newContent(id=self.company_id) organisation_module.newContent(id=self.company_id)
o = organisation_module._getOb(self.company_id) o = organisation_module._getOb(self.company_id)
get_transaction().commit() transaction.commit()
self.flushAllActivities(silent = 1, loop_size = 10) self.flushAllActivities(silent = 1, loop_size = 10)
self.assertEquals(len(activity_tool.getMessageList()), 0) self.assertEquals(len(activity_tool.getMessageList()), 0)
class ActivityUnitTestError(Exception): class ActivityUnitTestError(Exception):
...@@ -3725,12 +3714,12 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3725,12 +3714,12 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
try: try:
o.activate(activity = activity).failingMethod() o.activate(activity = activity).failingMethod()
get_transaction().commit() transaction.commit()
self.assertEquals(len(activity_tool.getMessageList()), 1) self.assertEquals(len(activity_tool.getMessageList()), 1)
self.flushAllActivities(silent = 1) self.flushAllActivities(silent = 1)
SiteErrorLog.raising = SiteErrorLog.original_raising SiteErrorLog.raising = SiteErrorLog.original_raising
logged_errors = self.logged logged_errors = self.logged
get_transaction().commit() transaction.commit()
for log_record in self.logged: for log_record in self.logged:
if log_record.name == 'ActivityTool' and log_record.levelname == 'WARNING': if log_record.name == 'ActivityTool' and log_record.levelname == 'WARNING':
type, value, trace = log_record.exc_info type, value, trace = log_record.exc_info
...@@ -3782,7 +3771,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3782,7 +3771,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
activity_tool.__class__.doSomething = doSomething activity_tool.__class__.doSomething = doSomething
activity_tool.activate(activity='SQLQueue').doSomething() activity_tool.activate(activity='SQLQueue').doSomething()
get_transaction().commit() transaction.commit()
activity_tool.distribute() activity_tool.distribute()
activity_tool.tic() activity_tool.tic()
message_list = activity_tool.getMessageList() message_list = activity_tool.getMessageList()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment