Beispiel #1
0
def generic_b_main(addr_b, addr_a):
    rpc = GenericRPC[int]

    t = Transport.from_url(addr_b, )

    with t:
        ts = EventLoop()
        tref = ts.transport_add(t)
        pt = ServiceDefn.from_cls(rpc)
        r: GenericRPC[int] = build_wrapper(pt,
                                           tref,
                                           addr_a,
                                           conf=ClientConfig(timeout_total=5))

        while True:
            try:
                a = r.process(5)

                assert a == Data(5), a
                break
            except HorizonPassedError:
                sleep(0)

        while True:
            try:
                a = r.process_blunt(5)

                assert a == 5, a
                return
            except HorizonPassedError:
                sleep(0)
Beispiel #2
0
def main(server_url, conf=ClientConfig(timeout_total=5), **kwargs):
    service_type = Broker[str, str]
    T: Type[service_type] = service_type.__class__

    t = Transport.from_url('udp://0.0.0.0')

    with t:
        ts = EventLoop()
        ets = ts.transport_add(t)
        pt = ServiceDefn.from_cls(service_type)
        r: T = build_wrapper(pt, ets, server_url, conf=conf)

        print(r.metrics())
Beispiel #3
0
    def test_udp(self):
        rpc = ExemplaryRPC

        t = Transport.from_url('udp://127.0.0.1:8905')

        with t:
            ts = EventLoop()
            tref = ts.transport_add(t)
            pt = ServiceDefn.from_cls(rpc)
            with self.assertRaises(error.TimeoutError):
                r: ExemplaryRPC = build_wrapper(
                    pt,
                    tref,
                    'udp://127.0.0.1:7483',
                    conf=ClientConfig(timeout_total=2.))

                a = r.move_something(5, 6, 8, pop='asd')
                b = r.reply(5, 6, 8, pop='asd')
Beispiel #4
0
    def __init__(
        self,
        actor: 'Actor',
        ts: EventLoop,
        sios: SocketIOEntrySet,
    ):
        self.actor = actor
        # these guys need to be able to provide the context in which we may change our sio mappings
        self.socketios = sios

        self.chans = Transports()

        self.chan = ts = ts.transport_add(self.chans)
        ts.push_raw(ELPollEntry(self.poll, self.exception_handler))

        for k, sio in self.socketios.items():
            with self.exc_ctx(sio):
                ret = self._assert_tran(sio.fn(None))
                self.chans[k] = ret
Beispiel #5
0
def client_transport(rpc: Type[T],
                     dest: str = 'udp://127.0.0.1:7483',
                     conf: Optional[ClientConfig] = None,
                     origin: str = 'udp://127.0.0.1',
                     **kwargs) -> ContextManager[T]:
    t = Transport.from_url(origin)

    if conf is None:
        conf = ClientConfig(**kwargs)

    def client_cb(p):
        raise ClientTransportCircuitBreaker(p)

    with t:
        ts = EventLoop()
        tref = ts.transport_add(t)
        # we may receive packets which are replies to things that are too late
        tref.push(
            ELPktEntry(lambda p: p.packet.type != RPCPacketType.Rep, client_cb,
                       raise_exc_handler))
        pt = ServiceDefn.from_cls(rpc)
        r: T = build_wrapper(pt, tref, dest, conf=conf)

        yield r