def test_coordinator_offline(self): crd = self.get_coordinator.return_value crd.start.side_effect = tooz_coordination.ToozConnectionError('err') agent = coordination.Coordinator() self.assertRaises(tooz_coordination.ToozError, agent.start) self.assertFalse(agent.started)
def test_coordinator_lock(self): crd = self.get_coordinator.return_value crd.get_lock.side_effect = lambda n: MockToozLock(n) agent1 = coordination.Coordinator() agent1.start() agent2 = coordination.Coordinator() agent2.start() lock_string = 'lock' expected_lock = lock_string.encode('ascii') self.assertNotIn(expected_lock, MockToozLock.active_locks) with agent1.get_lock(lock_string): self.assertIn(expected_lock, MockToozLock.active_locks) self.assertRaises(Locked, agent1.get_lock(lock_string).acquire) self.assertRaises(Locked, agent2.get_lock(lock_string).acquire) self.assertNotIn(expected_lock, MockToozLock.active_locks)
def test_coordinator_start(self): crd = self.get_coordinator.return_value agent = coordination.Coordinator() agent.start() self.assertTrue(self.get_coordinator.called) self.assertTrue(crd.start.called) self.assertTrue(agent.started)
def test_coordinator_stop(self): crd = self.get_coordinator.return_value agent = coordination.Coordinator() agent.start() self.assertIsNotNone(agent.coordinator) agent.stop() self.assertTrue(crd.stop.called) self.assertIsNone(agent.coordinator) self.assertFalse(agent.started)