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 test_exc_raised(self):
        class A1:
            @rpc()
            def mopo(self):
                raise ValueError()

        class A2:
            @regular()
            def reg(self) -> float:
                s = service(A1, url_a)
                s.mopo()
                return 2.

        act1 = A1()
        act2 = A2()
        el = EventLoop()
        sr = SignalRunner(el)

        url_a = 'udp://127.0.0.1:23456'

        actor_create(el, sr, A1, act1, [url_a])
        actor_create(el, sr, A2, act1, {DEFAULT_GROUP: 'udp://127.0.0.1'})

        try:
            el.loop()
        except ValueError:
            self.assertEqual('1', '1')
        except EventLoopEmpty:
            self.assertEqual('1', '0')
Beispiel #3
0
def run_server(cls,
               cls_inst,
               bind_urls: Dict[str, str],
               horizon_each=60.,
               actor_name=None):
    el = EventLoop()
    sr = SignalRunner(el)

    if actor_name is None:
        if hasattr(cls, '__name__'):
            actor_name = cls.__name__
        else:
            actor_name = str(cls)

    act = actor_create(el,
                       sr,
                       cls,
                       cls_inst,
                       bind_urls,
                       horizon_each,
                       name=actor_name)

    try:
        el.loop()
    except EventLoopEmpty:
        pass
    except:
        act.terminate('exit')
        raise
Beispiel #4
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 #5
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 #6
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 #7
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
Beispiel #8
0
    def __init__(
        self,
        actor: 'Actor',
        el: EventLoop,
        regulars: RegularEntrySet,
    ):
        # if we integrate max_waits into the RPCTransportStack

        self.actor = actor

        self.wait = el.wait_add(
            ELWaitEntry(self.max_wait, self.timeout, self.exception_handler))

        self.regulars = regulars

        self.states_regulars: Dict[str, Optional[datetime]] = {
            k: time_now() + timedelta(seconds=x.conf.initial)
            if x.conf.initial is not None else None
            for k, x in self.regulars.items()
        }