def test_fire_reminder_for_non_reminderable(self): test_type_info = ActorTypeInformation.create(FakeSimpleActor) ctx = ActorRuntimeContext( test_type_info, self._serializer, self._serializer, self._fake_client) manager = ActorManager(ctx) with self.assertRaises(ValueError): _run(manager.fire_reminder(ActorId('testid'), 'test_reminder', self._test_reminder_req))
def setUp(self): self._test_type_info = ActorTypeInformation.create(FakeMultiInterfacesActor) self._serializer = DefaultJSONSerializer() self._fake_client = FakeDaprActorClient self._runtime_ctx = ActorRuntimeContext( self._test_type_info, self._serializer, self._serializer, self._fake_client) self._manager = ActorManager(self._runtime_ctx)
def test_fire_reminder_success(self): test_actor_id = ActorId('testid') test_type_info = ActorTypeInformation.create(FakeSimpleReminderActor) ctx = ActorRuntimeContext( test_type_info, self._serializer, self._serializer, self._fake_client) manager = ActorManager(ctx) _run(manager.activate_actor(test_actor_id)) _run(manager.fire_reminder(test_actor_id, 'test_reminder', self._test_reminder_req))
class ActorManagerTests(unittest.TestCase): def setUp(self): self._test_type_info = ActorTypeInformation.create( FakeMultiInterfacesActor) self._serializer = DefaultJSONSerializer() self._fake_client = FakeDaprActorClient self._runtime_ctx = ActorRuntimeContext(self._test_type_info, self._serializer, self._serializer, self._fake_client) self._manager = ActorManager(self._runtime_ctx) def test_activate_actor(self): """Activate ActorId(1)""" test_actor_id = ActorId('1') _run(self._manager.activate_actor(test_actor_id)) # assert self.assertEqual(test_actor_id, self._manager._active_actors[test_actor_id.id].id) self.assertTrue( self._manager._active_actors[test_actor_id.id].activated) self.assertFalse( self._manager._active_actors[test_actor_id.id].deactivated) def test_deactivate_actor(self): """Activate ActorId('2') and deactivate it""" test_actor_id = ActorId('2') _run(self._manager.activate_actor(test_actor_id)) # assert self.assertEqual(test_actor_id, self._manager._active_actors[test_actor_id.id].id) self.assertTrue( self._manager._active_actors[test_actor_id.id].activated) self.assertFalse( self._manager._active_actors[test_actor_id.id].deactivated) _run(self._manager.deactivate_actor(test_actor_id)) self.assertIsNone(self._manager._active_actors.get(test_actor_id.id)) def test_dispatch_success(self): """dispatch ActionMethod""" test_actor_id = ActorId('dispatch') _run(self._manager.activate_actor(test_actor_id)) request_body = { "message": "hello dapr", } test_request_body = self._serializer.serialize(request_body) response = _run( self._manager.dispatch(test_actor_id, "ActionMethod", test_request_body)) self.assertEqual(b'"hello dapr"', response)
async def register_actor( cls, actor: Type[Actor], message_serializer: Serializer = DefaultJSONSerializer(), state_serializer: Serializer = DefaultJSONSerializer(), http_timeout_seconds: int = settings.DAPR_HTTP_TIMEOUT_SECONDS ) -> None: """Registers an :class:`Actor` object with the runtime. Args: actor (:class:`Actor`): Actor implementation. message_serializer (:class:`Serializer`): A serializer that serializes message between actors. state_serializer (:class:`Serializer`): Serializer that serializes state values. http_timeout_seconds (:int:): a configurable timeout value """ type_info = ActorTypeInformation.create(actor) # TODO: We will allow to use gRPC client later. actor_client = DaprActorHttpClient(message_serializer, timeout=http_timeout_seconds) ctx = ActorRuntimeContext(type_info, message_serializer, state_serializer, actor_client) # Create an ActorManager, override existing entry if registered again. async with cls._actor_managers_lock: cls._actor_managers[type_info.type_name] = ActorManager(ctx) cls._actor_config.update_entities( ActorRuntime.get_registered_actor_types())
def test_fire_timer_success(self): test_actor_id = ActorId('testid') test_type_info = ActorTypeInformation.create(FakeSimpleTimerActor) ctx = ActorRuntimeContext(test_type_info, self._serializer, self._serializer, self._fake_client) manager = ActorManager(ctx) _run(manager.activate_actor(test_actor_id)) actor = manager._active_actors.get(test_actor_id.id, None) # Setup timer _run( actor.register_timer('test_timer', actor.timer_callback, "timer call", timedelta(seconds=1), timedelta(seconds=1))) # Fire timer _run(manager.fire_timer(test_actor_id, 'test_timer')) self.assertTrue(actor.timer_called)