def setUp(self):
     ActorRuntime._actor_managers = {}
     ActorRuntime.set_actor_config(ActorRuntimeConfig())
     self._serializer = DefaultJSONSerializer()
     _run(ActorRuntime.register_actor(FakeSimpleActor))
     _run(ActorRuntime.register_actor(FakeMultiInterfacesActor))
     _run(ActorRuntime.register_actor(FakeSimpleTimerActor))
 def setUp(self):
     ActorRuntime._actor_managers = {}
     ActorRuntime.set_actor_config(
         ActorRuntimeConfig(reentrancy=ActorReentrancyConfig(enabled=True)))
     self._serializer = DefaultJSONSerializer()
     _run(ActorRuntime.register_actor(FakeReentrantActor))
     _run(ActorRuntime.register_actor(FakeSlowReentrantActor))
     _run(ActorRuntime.register_actor(FakeMultiInterfacesActor))
Beispiel #3
0
    def test_entities_update(self):
        # Clean up managers
        ActorRuntime._actor_managers = {}
        ActorRuntime.set_actor_config(ActorRuntimeConfig())

        config = ActorRuntime.get_actor_config()
        with self.assertRaises(ValueError):
            config._entities.index(FakeSimpleActor.__name__)

        _run(ActorRuntime.register_actor(FakeSimpleActor))
        config = ActorRuntime.get_actor_config()
        self.assertTrue(config._entities.index(FakeSimpleActor.__name__) >= 0)
    def test_header_passthrough_reentrancy_disabled(self):
        config = ActorRuntimeConfig(reentrancy=None)
        ActorRuntime.set_actor_config(config)
        _run(ActorRuntime.register_actor(FakeReentrantActor))
        _run(ActorRuntime.register_actor(FakeSlowReentrantActor))

        request_body = self._serializer.serialize({
            "message": "Normal",
        })

        async def expected_return_value(*args, **kwargs):
            return ["expected", "None"]

        reentrancy_id = "f6319f23-dc0a-4880-90d9-87b23c19c20a"
        actor = FakeSlowReentrantActor.__name__
        method = 'ReentrantMethod'

        with mock.patch('dapr.clients.http.client.DaprHttpClient.send_bytes'
                        ) as mocked:

            mocked.side_effect = expected_return_value
            _run(
                ActorRuntime.dispatch(FakeReentrantActor.__name__,
                                      'test-id',
                                      'ReentrantMethodWithPassthrough',
                                      request_body,
                                      reentrancy_id=reentrancy_id))

            mocked.assert_called_with(
                method="POST",
                url=
                f'http://127.0.0.1:3500/v1.0/actors/{actor}/test-id/method/{method}',
                data=None,
                headers={})

        _run(ActorRuntime.deactivate(FakeReentrantActor.__name__, 'test-id'))

        # Ensure test-id is deactivated
        with self.assertRaises(ValueError):
            _run(
                ActorRuntime.deactivate(FakeReentrantActor.__name__,
                                        'test-id'))
Beispiel #5
0
    def test_actor_config(self):
        config = ActorRuntime.get_actor_config()

        self.assertTrue(config._drain_rebalanced_actors)
        self.assertEqual(timedelta(hours=1), config._actor_idle_timeout)
        self.assertEqual(timedelta(seconds=30), config._actor_scan_interval)
        self.assertEqual(timedelta(minutes=1), config._drain_ongoing_call_timeout)
        self.assertEqual(2, len(config._entities))

        # apply new config
        new_config = ActorRuntimeConfig(
            timedelta(hours=3), timedelta(seconds=10), timedelta(minutes=1), False)

        ActorRuntime.set_actor_config(new_config)
        config = ActorRuntime.get_actor_config()

        self.assertFalse(config._drain_rebalanced_actors)
        self.assertEqual(timedelta(hours=3), config._actor_idle_timeout)
        self.assertEqual(timedelta(seconds=10), config._actor_scan_interval)
        self.assertEqual(timedelta(minutes=1), config._drain_ongoing_call_timeout)
        self.assertEqual(2, len(config._entities))