示例#1
0
 def test___exit__with_exception_value_retryable(self):
     from transaction.interfaces import TransientError
     manager = DummyManager()
     inst = self._makeOne(manager)
     result = inst.__exit__(TransientError, TransientError(), None)
     self.assertTrue(result)
     self.assertFalse(manager.committed)
     self.assertTrue(manager.aborted)
示例#2
0
	def tpc_vote(self, txn):
		# check self.committed = current state
		# or there's a pending txn that's not this one
		if not self.session.active:
			raise SessionNotInitializedError(
			    'MongoDB session not initialized correctly! Be sure to'
			    ' create a new session instance or call session.begin()'
			    ' once at the start of each transaction.')
		if self.uncommitted:
			# validate new data
			keytypes = map(lambda f:type(f), self.uncommitted.keys())
			invalidkeys = filter(lambda f: f != str and f != unicode, keytypes)
			if invalidkeys:
				raise Exception('Invalid key: Documents must'
				                ' have only string or unicode keys!')
			try:
				BSON.encode(self.uncommitted) # final check that document
				                              # is BSON-compatible
			except:
				raise

		if self.committed:
			if not self.committed.has_key('_id'):
				# this should never happen
				# (if it does then we're in trouble - tpc_abort will fail)
				raise Exception(
				    'Committed document does not have an _id field!') 
			dbcommitted = self.collection.find_one(
			    {'_id': self.committed['_id']})
			if not dbcommitted:
				raise TransientError(
				    'Document to be updated does not exist in database!')
			pending_transactions = dbcommitted.pop('pending_transactions')
			if self.committed.has_key('pending_transactions'):
				raise TransientError(
				    'Concurrent modification! Transaction aborting...')
			if (len(pending_transactions) > 1 or
			        pending_transactions[0] !=
			        support.ActiveTransaction.transaction_id):
				raise TransientError(
				    'Concurrent modification! Transaction aborting...')
			if dbcommitted != self.committed:
				raise TransientError(
				    'Concurrent modification! Transaction aborting...')
示例#3
0
def testing_retry(context, request):
    model = context.model
    request.environ['_attempt'] = request.environ.get('_attempt', 0) + 1

    if request.environ['_attempt'] == 1:
        raise TransientError()

    return {
        'attempt': request.environ['_attempt'],
        'detached': inspect(model).detached,
    }
示例#4
0
def testing_retry(context, request):
    from sqlalchemy import inspect
    from transaction.interfaces import TransientError

    model = context.model
    attempt = request.environ.get('retry.attempts')

    if attempt == 0:
        raise TransientError()

    return {
        'retry.attempts': attempt,
        'detached': inspect(model).detached,
    }
示例#5
0
def testing_retry(context, request):
    from sqlalchemy import inspect
    from transaction.interfaces import TransientError

    model = context.model
    request._attempt = getattr(request, '_attempt', 0) + 1

    if request._attempt == 1:
        raise TransientError()

    return {
        'attempt': request._attempt,
        'detached': inspect(model).detached,
    }
示例#6
0
 def handler():
     raise TransientError()
示例#7
0
 def test(self):
     self.attempts.append(True)
     if len(self.attempts) == 3:
         return 'HI!'
     raise TransientError()