예제 #1
0
 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())
예제 #2
0
 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())
예제 #3
0
파일: process.py 프로젝트: Amli/mopidy
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.')
예제 #4
0
파일: process.py 프로젝트: xim/mopidy
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.')
예제 #5
0
파일: actor_test.py 프로젝트: okoye/pykka
    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()))
예제 #6
0
    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()))
예제 #7
0
    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()))
예제 #8
0
    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()))
예제 #9
0
    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()))
예제 #10
0
 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())
예제 #11
0
 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()))
예제 #12
0
 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()))
예제 #13
0
 def test_actor_is_registered_when_started(self):
     self.assert_(self.ref in ActorRegistry.get_all())
예제 #14
0
 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)
예제 #15
0
 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()))
예제 #16
0
 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())
예제 #17
0
 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())
예제 #18
0
 def test_actor_is_registered_when_started(self):
     self.assert_(self.ref in ActorRegistry.get_all())
예제 #19
0
 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())
예제 #20
0
 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)
예제 #21
0
 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()))