def test_actor_may_be_unregistered_multiple_times_without_error(self): ActorRegistry.unregister(self.ref) self.assert_(self.ref not in ActorRegistry.get_all()) ActorRegistry.unregister(self.ref) self.assert_(self.ref not in ActorRegistry.get_all()) ActorRegistry.register(self.ref) self.assert_(self.ref in ActorRegistry.get_all())
def stop_all_actors(): num_actors = len(ActorRegistry.get_all()) while num_actors: logger.debug(u'Seeing %d actor and %d non-actor thread(s): %s', num_actors, threading.active_count() - num_actors, ', '.join([t.name for t in threading.enumerate()])) logger.debug(u'Stopping %d actor(s)...', num_actors) ActorRegistry.stop_all() num_actors = len(ActorRegistry.get_all()) logger.debug(u'All actors stopped.')
def stop_remaining_actors(): num_actors = len(ActorRegistry.get_all()) while num_actors: logger.error( u'There are actor threads still running, this is probably a bug') logger.debug(u'Seeing %d actor and %d non-actor thread(s): %s', num_actors, threading.active_count() - num_actors, ', '.join([t.name for t in threading.enumerate()])) logger.debug(u'Stopping %d actor(s)...', num_actors) ActorRegistry.stop_all() num_actors = len(ActorRegistry.get_all()) logger.debug(u'All actors stopped.')
def test_all_actors_are_stopped_on_base_exception(self): start_event = self.event_class() stop_event = self.event_class() fail_event = self.event_class() registered_event = self.event_class() another_actor = self.AnActor.start(start_event, stop_event, fail_event, registered_event) self.assertEqual(2, len(ActorRegistry.get_all())) self.assertFalse(self.on_stop_was_called.is_set()) self.actor_ref.send_one_way({'command': 'raise base exception'}) self.on_stop_was_called.wait() self.assert_(1 >= len(ActorRegistry.get_all())) stop_event.wait() self.assertEqual(0, len(ActorRegistry.get_all()))
def test_actor_processes_all_messages_before_stop_on_self_stops_it(self): self.actor_ref.ask({'command': 'message self then stop'}) self.greetings_was_received.wait(5) self.assertTrue(self.greetings_was_received.is_set()) self.on_stop_was_called.wait(5) self.assertEqual(0, len(ActorRegistry.get_all()))
def test_all_actors_are_stopped_on_base_exception(self): start_event = self.event_class() stop_event = self.event_class() fail_event = self.event_class() registered_event = self.event_class() greetings_event = self.event_class() self.AnActor.start(start_event, stop_event, fail_event, registered_event, greetings_event) self.assertEqual(2, len(ActorRegistry.get_all())) self.assertFalse(self.on_stop_was_called.is_set()) self.actor_ref.tell({'command': 'raise base exception'}) self.on_stop_was_called.wait(5) self.assertTrue(self.on_stop_was_called.is_set()) self.assert_(1 >= len(ActorRegistry.get_all())) stop_event.wait(5) self.assertTrue(stop_event.is_set()) self.assertEqual(0, len(ActorRegistry.get_all()))
def test_all_actors_are_stopped_on_base_exception(self): start_event = self.event_class() stop_event = self.event_class() fail_event = self.event_class() registered_event = self.event_class() greetings_event = self.event_class() self.AnActor.start( on_start_was_called=start_event, on_stop_was_called=stop_event, on_failure_was_called=fail_event, actor_was_registered_before_on_start_was_called=registered_event, greetings_was_received=greetings_event) self.assertEqual(2, len(ActorRegistry.get_all())) self.assertFalse(self.on_stop_was_called.is_set()) self.actor_ref.tell({'command': 'raise base exception'}) self.on_stop_was_called.wait(5) self.assertTrue(self.on_stop_was_called.is_set()) self.assert_(1 >= len(ActorRegistry.get_all())) stop_event.wait(5) self.assertTrue(stop_event.is_set()) self.assertEqual(0, len(ActorRegistry.get_all()))
def test_actor_is_unregistered_when_stopped(self): self.assert_(self.ref in ActorRegistry.get_all()) self.ref.stop() self.assert_(self.ref not in ActorRegistry.get_all())
def test_actor_is_stopped_when_unhandled_exceptions_are_raised(self): self.assertFalse(self.on_failure_was_called.is_set()) self.actor_ref.tell({'command': 'raise exception'}) self.on_failure_was_called.wait(5) self.assertTrue(self.on_failure_was_called.is_set()) self.assertEqual(0, len(ActorRegistry.get_all()))
def test_actor_is_registered_when_started(self): self.assert_(self.ref in ActorRegistry.get_all())
def test_broadcast_sends_message_to_all_actors_if_no_target(self): ActorRegistry.broadcast({'command': 'foo'}) for actor_ref in ActorRegistry.get_all(): received_messages = actor_ref.proxy().received_messages.get() self.assert_({'command': 'foo'} in received_messages)
def test_all_actors_can_be_stopped_through_registry(self): self.assertEquals(9, len(ActorRegistry.get_all())) ActorRegistry.stop_all(block=True) self.assertEquals(0, len(ActorRegistry.get_all()))
def test_actor_may_be_registered_manually(self): ActorRegistry.unregister(self.ref) self.assert_(self.ref not in ActorRegistry.get_all()) ActorRegistry.register(self.ref) self.assert_(self.ref in ActorRegistry.get_all())