コード例 #1
0
 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))
コード例 #2
0
 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))
コード例 #3
0
    def test_interleaved_reentrant_actor_dispatch(self):
        _run(ActorRuntime.register_actor(FakeReentrantActor))
        _run(ActorRuntime.register_actor(FakeSlowReentrantActor))

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

        normal_reentrancy_id = "f6319f23-dc0a-4880-90d9-87b23c19c20a"
        slow_reentrancy_id = "b1653a2f-fe54-4514-8197-98b52d156454"

        async def dispatchReentrantCall(actorName: str, method: str,
                                        reentrancy_id: str):
            return await ActorRuntime.dispatch(actorName,
                                               'test-id',
                                               method,
                                               request_body,
                                               reentrancy_id=reentrancy_id)

        async def run_parallel_actors():
            slow = dispatchReentrantCall(FakeSlowReentrantActor.__name__,
                                         "ReentrantMethod", slow_reentrancy_id)
            normal = dispatchReentrantCall(FakeReentrantActor.__name__,
                                           "ReentrantMethod",
                                           normal_reentrancy_id)

            res = await asyncio.gather(slow, normal)
            self.slow_res = res[0]
            self.normal_res = res[1]

        _run(run_parallel_actors())

        self.assertEqual(self.normal_res,
                         bytes('"' + normal_reentrancy_id + '"', 'utf-8'))
        self.assertEqual(self.slow_res,
                         bytes('"' + slow_reentrancy_id + '"', 'utf-8'))

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

        # Ensure test-id is deactivated
        with self.assertRaises(ValueError):
            _run(
                ActorRuntime.deactivate(FakeSlowReentrantActor.__name__,
                                        'test-id'))
            _run(
                ActorRuntime.deactivate(FakeReentrantActor.__name__,
                                        'test-id'))
コード例 #4
0
    def test_reentrant_dispatch(self):
        _run(ActorRuntime.register_actor(FakeMultiInterfacesActor))

        request_body = {
            "message": "hello dapr",
        }

        reentrancy_id = "0faa4c8b-f53a-4dff-9a9d-c50205035085"

        test_request_body = self._serializer.serialize(request_body)
        response = _run(
            ActorRuntime.dispatch(FakeMultiInterfacesActor.__name__,
                                  'test-id',
                                  "ReentrantMethod",
                                  test_request_body,
                                  reentrancy_id=reentrancy_id))

        self.assertEqual(b'"hello dapr"', response)

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

        # Ensure test-id is deactivated
        with self.assertRaises(ValueError):
            _run(
                ActorRuntime.deactivate(FakeMultiInterfacesActor.__name__,
                                        'test-id'))
コード例 #5
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'))
コード例 #6
0
ファイル: test_actor.py プロジェクト: artursouza/python-sdk
    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)
コード例 #7
0
ファイル: test_actor.py プロジェクト: artursouza/python-sdk
    def test_dispatch(self):
        _run(ActorRuntime.register_actor(FakeMultiInterfacesActor))

        request_body = {
            "message": "hello dapr",
        }

        test_request_body = self._serializer.serialize(request_body)
        response = _run(ActorRuntime.dispatch(
            FakeMultiInterfacesActor.__name__, 'test-id',
            "ActionMethod", test_request_body))

        self.assertEqual(b'"hello dapr"', response)

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

        # Ensure test-id is deactivated
        with self.assertRaises(ValueError):
            _run(ActorRuntime.deactivate(FakeMultiInterfacesActor.__name__, 'test-id'))