def test_rpc_server(self): node = Mock(spec=NodeB) svc = SimpleService() rpcs = RPCServer(node=node, from_name="testrpc", service=svc) # build a command object to be returned by the mocked channel class FakeMsg(object): def __init__(self): self.named = ["ein", "zwei"] cvalue = FakeMsg() listen_channel_mock = self._setup_mock_channel(ch_type=ServerChannel) rpcs.node.channel.return_value = listen_channel_mock # tell our channel to return a mocked handler channel when accepted (listen() implementation detail) listen_channel_mock.accept.return_value.__enter__.return_value = self._setup_mock_channel( ch_type=ServerChannel.BidirAcceptChannel, value=cvalue, op="simple" ) rpcs.listen() # wait for first message to get passed in ret = svc._ar.get() self.assertIsInstance(ret, list) self.assertEquals(ret, ["ein", "zwei"])
def test_rpc_with_xn(self): # get an xn to use for send/recv xn = self.container.ex_manager.create_xn_service('hello') self.addCleanup(xn.delete) # create an RPCServer for a hello service hs = HelloService() rpcs = RPCServer(from_name=xn, service=hs) # spawn the listener, kill on test exit (success/fail/error should cover?) gl_listen = spawn(rpcs.listen) def cleanup(): rpcs.close() gl_listen.join(timeout=2) gl_listen.kill() self.addCleanup(cleanup) # wait for listen to be ready rpcs.get_ready_event().wait(timeout=5) # ok, now create a client using same xn hsc = HelloServiceClient(to_name=xn) # try to message it! ret = hsc.hello('hi there') # did we get back what we expected? self.assertEquals(ret, 'BACK:hi there')
class TransformBase(SimpleProcess): ''' TransformBase is the base class for all Transform Processes ''' def __init__(self): super(TransformBase,self).__init__() self._stats = {} # Container for statistics information def on_start(self): ''' Begins listening for incoming RPC calls. ''' super(TransformBase,self).on_start() self._rpc_server = RPCServer(self, from_name=self.id) self._listener = gevent.spawn(self._rpc_server.listen) def on_quit(self): ''' Closes the listener. ''' self._rpc_server.close() self._listener.join(5) super(TransformBase, self).on_quit() def _stat(self): return self._stats @classmethod def stats(cls,pid): ''' RPC Method for querying a Transform's internal statistics ''' rpc_cli = RPCClient(to_name=pid) return rpc_cli.request({},op='_stat')
def test_rpc_server(self): node = Mock(spec=NodeB) svc = SimpleService() rpcs = RPCServer(node=node, from_name="testrpc", service=svc) node.interceptors = {} # build a command object to be returned by the mocked channel class FakeMsg(object): def __init__(self): self.named = ["ein", "zwei"] cvalue = FakeMsg() listen_channel_mock = self._setup_mock_channel(ch_type=ServerChannel) rpcs.node.channel.return_value = listen_channel_mock # tell our channel to return a mocked handler channel when accepted (listen() implementation detail) listen_channel_mock.accept.return_value = self._setup_mock_channel( ch_type=ServerChannel.BidirAcceptChannel, value=cvalue, op="simple") rpcs.listen() # wait for first message to get passed in ret = svc._ar.get() self.assertIsInstance(ret, list) self.assertEquals(ret, ["ein", "zwei"])
def on_start(self): ''' Begins listening for incoming RPC calls. ''' super(TransformBase, self).on_start() self._rpc_server = RPCServer(self, from_name=self.id) self._listener = gevent.spawn(self._rpc_server.listen)
class TransformBase(SimpleProcess): ''' TransformBase is the base class for all Transform Processes ''' def __init__(self): super(TransformBase, self).__init__() self._stats = {} # Container for statistics information def on_start(self): ''' Begins listening for incoming RPC calls. ''' super(TransformBase, self).on_start() self._rpc_server = RPCServer(self, from_name=self.id) self._listener = gevent.spawn(self._rpc_server.listen) def on_quit(self): ''' Closes the listener. ''' self._rpc_server.close() self._listener.join(5) super(TransformBase, self).on_quit() def _stat(self): return self._stats @classmethod def stats(cls, pid): ''' RPC Method for querying a Transform's internal statistics ''' rpc_cli = RPCClient(to_name=pid) return rpc_cli.request({}, op='_stat')
def __init__(self, process=None, routing_call=None, **kwargs): assert process self._process = process self._routing_call = routing_call # don't make people set service and process when they're almost always the same if not "service" in kwargs: kwargs = kwargs.copy() kwargs['service'] = process RPCServer.__init__(self, **kwargs)
def __init__(self, process=None, routing_call=None, **kwargs): assert process self._process = process self._routing_call = routing_call # don't make people set service and process when they're almost always the same if "service" not in kwargs: kwargs = kwargs.copy() kwargs['service'] = process RPCServer.__init__(self, **kwargs)
def on_start(self): ''' Begins listening for incoming RPC calls. ''' super(TransformBase,self).on_start() self._rpc_server = RPCServer(self, from_name=self.id) self._listener = gevent.spawn(self._rpc_server.listen)
def start(self): # Start the CC-Agent API listen_name = self.container.create_process_xn(self.container.name, auto_delete=True) rsvc = RPCServer(from_name=listen_name, service=self.container) # Start an ION process with the right kind of endpoint factory proc = self.container.proc_manager.proc_sup.spawn( name=self.container.name, listeners=[rsvc], service=self.container) self.container.proc_manager.proc_sup.ensure_ready(proc) proc.start_listeners() # Start a heartbeat self.heartbeat_cfg = CFG.get_safe( "container.execution_engine.heartbeat") or {} self.heartbeat_enabled = self.heartbeat_cfg.get("enabled", False) is True if self.heartbeat_enabled: self.heartbeater = ContainerHeartbeater(self.container, self.heartbeat_cfg) self.heartbeater.start()
def create_endpoint(self, **kwargs): newkwargs = kwargs.copy() newkwargs['process'] = self._process newkwargs['routing_call'] = self._routing_call return RPCServer.create_endpoint(self, **newkwargs)
def __init__(self, process=None, routing_call=None, **kwargs): assert process self._process = process self._routing_call = routing_call RPCServer.__init__(self, **kwargs)
node,iowat=make_node() bs = BankService() rpcs = RPCServer(node=node, name="bank", service=bs) mooo=rpcs.listen() gevent.joinall([mooo]) """ """ from pyon.container.cc import Container cc=Container() cc.start() cc.start_rel_from_url('res/deploy/r2deploy.yml') cc.serve_forever() """ from pyon.net.endpoint import RPCServer from examples.service.hello_service import HelloService hs=HelloService() from pyon.net.messaging import make_node n,io=make_node() rpcs=RPCServer(service=hs, node=n, name=('qq', 'hello')) rpcs.listen()