Exemplo n.º 1
0
 def test_lease_False(self,
                      mock_retry,
                      mock_queue_error,
                      mock_release_lease,
                      mock_acquire_lease,
                      mock_uuid):
     mock_uuid.uuid4.return_value.hex = 'bobloblaw'
     mock_acquire_lease.return_value = False
     mock_release_lease.return_value = False
     instance = Context('name')
     instance.dispatch('event', {'foo': 'bar'})
     mock_acquire_lease.assert_called_with(
         'bobloblaw',
         0,
         0,
         primary=False
     )
     mock_release_lease.assert_called_with(
         'bobloblaw',
         0,
         0,
         False,
         primary=False
     )
     self.assertEqual(
         [
             mock.call('cache', 'System error acquiring primary=True lease.'),
             mock.call('cache', 'Could not acquire lease. Retrying.'),
             mock.call('cache', 'Could not release lease.')
         ],
         mock_queue_error.mock_calls
     )
     mock_retry.assert_called_with(
         {'foo': 'bar'}
     )
Exemplo n.º 2
0
 def test_lease_True(self,
                     mock_dispatch_and_retry,
                     mock_queue_error,
                     mock_release_lease,
                     mock_acquire_lease,
                     mock_uuid):
     mock_uuid.uuid4.return_value.hex = 'bobloblaw'
     mock_acquire_lease.return_value = 'foobar'
     mock_release_lease.return_value = 'foobar'
     instance = Context('name')
     instance.dispatch('event', {'foo': 'bar'})
     mock_acquire_lease.assert_called_with(
         'bobloblaw',
         0,
         0,
         primary=True
     )
     mock_release_lease.assert_called_with(
         'bobloblaw',
         0,
         0,
         'foobar',
         primary=True
     )
     self.assertFalse(mock_queue_error.called)
     mock_dispatch_and_retry.assert_called_with(
         'event',
         {'foo': 'bar'}
     )
Exemplo n.º 3
0
 def test_lease_fence_token_int(self, mock_retry, mock_queue_error,
                                mock_release_lease, mock_acquire_lease,
                                mock_uuid):
     mock_uuid.uuid4.return_value.hex = 'bobloblaw'
     # equivalent to long in Python 2
     mock_acquire_lease.return_value = int(500)
     mock_release_lease.return_value = False
     instance = Context('name')
     obj = {'foo': 'bar'}
     instance.dispatch('event', obj)
     self.assertTrue(
         'fence_token' in obj,
         "Fence token should be set on the object if it's a numeric type.")
     self.assertEqual(obj['fence_token'], int(500))