async def test_double_registration_error(rpc_server): rpc_server.register(DefaultExecutor("TEST", MockService())) with pytest.raises(NamespaceError): rpc_server.register(DefaultExecutor("TEST", MockService())) await rpc_server.rpc_commlayer.close()
async def main(args): """ The RPC client (and server) need a communicationlayer to communicate. Below the default Redis implementation is used together with the default msgpack serialization. """ rpc_commlayer = await RPCRedisCommLayer.create( subchannel=b'pub', pubchannel=b'sub', # Inverse of client host=args.redis_host, serialization=msgpack_serialization) # Create a RPC Server with the commlayer rpc_server = RPCServer(rpc_commlayer) # Register the Service above with the default executor in # the TEST namespace # # The executor receives a RPCStack from the commlayer # and will try to execute the provided function names (with # args & kwargs) executor = DefaultExecutor(namespace="TEST", instance=Service()) # Register executor. rpc_server.register(executor) print('Start serving') await rpc_server.serve()
async def test_simple_call_with_client_processing(do_rpc_call): test_service_client = ServiceClient(None) result = await do_rpc_call(test_service_client, DefaultExecutor("TEST", Service()), test_service_client.multiply(100, 100), client_processing=True) assert result == 100 * 100
async def test_custom_data_model(do_rpc_call): test_service_client = ServiceClient(None) value = CustomDataModel(100, 100) result = await do_rpc_call( test_service_client, DefaultExecutor("TEST", Service()), test_service_client.multiply_with_dataclass(value), custom_dataclasses=[CustomDataModel]) assert result == value.multiply()
async def main(args): rpc_commlayer = await RPCRedisCommLayer.create( subchannel=b'pub', pubchannel=b'sub', # Inverse of client host=args.redis_host, serialization=msgpack_serialization) rpc_server = RPCServer(rpc_commlayer) # Register the Service above with the the default executor in # the TEST namespace executor = DefaultExecutor(namespace="TEST", instance=Service()) # Register executor rpc_server.register(executor) print('Start serving') await rpc_server.serve()
async def main(args): rpc_commlayer = await RPCRedisCommLayer.create( subchannel=b'pub', pubchannel=b'sub', # Inverse of client host=args.redis_host, serialization=msgpack_serialization) rpc_server = RPCServer(rpc_commlayer) # Register the Service above with the the default executor in # the TEST namespace executor = DefaultExecutor( namespace="TEST", instance=Service()) # IMPORTANT: Register dataclasses to allow serialization/deserialization rpc_server.register_models([Integer, MultiplyResult]) # Register executor rpc_server.register(executor) print('Start serving') await rpc_server.serve()
async def test_registration(rpc_server): rpc_server.register(DefaultExecutor("TEST", MockService())) await rpc_server.rpc_commlayer.close()
async def test_not_builtin_exception(do_rpc_call): test_service_client = ServiceClient(None) with pytest.raises(WrappedException): await do_rpc_call(test_service_client, DefaultExecutor("TEST", Service()), test_service_client.custom_error())
async def test_key_error(do_rpc_call): test_service_client = ServiceClient(None) with pytest.raises(KeyError): await do_rpc_call(test_service_client, DefaultExecutor("TEST", Service()), test_service_client.get_item('bar'))
async def test_property(do_rpc_call): test_service_client = ServiceClient(None) result = await do_rpc_call(test_service_client, DefaultExecutor("TEST", Service()), test_service_client.data) assert result == {'foo': 'bar'}
async def test_simple_call2(do_rpc_call): test_service_client = ServiceClient(None) result = await do_rpc_call(test_service_client, DefaultExecutor("TEST", Service()), test_service_client.get_item('foo')) assert result == 'bar'