def test_pull(self, asys):
        """
        Test a pull from the subscription pool
        """
        rr = asys.createActor(RoundRobinSubscriptionPool)

        suba = asys.createActor(Subscription)
        sub_puba = asys.createActor(PublisherStringActor)
        ssn = SetSubscriber(sub_puba, suba, None)
        asys.tell(suba, ssn)
        rrs = Subscribe(suba, rr, None)
        asys.tell(rr, rrs)

        subb = asys.createActor(Subscription)
        sub_pubb = asys.createActor(PublisherStringActor)
        ssn = SetSubscriber(sub_pubb, suba, None)
        asys.tell(subb, ssn)
        rrs = Subscribe(subb, rr, None)
        asys.tell(rr, rrs)

        st = asys.createActor(SubTest)
        msg = Subscribe(rr, st, None)
        asys.tell(st, msg)

        pll = Pull(50, rr, None)
        rval = asys.ask(st, pll)
        assert isinstance(rval, Push)
        assert isinstance(rval.payload, list)
        assert len(rval.payload) is 0
        tstart = datetime.now()
        while len(rval.payload) is 0 and tstart - datetime.now() < timedelta(
                seconds=120):
            pll = Pull(50, st, None)
            rval = asys.ask(st, pll)
        assert len(rval.payload) is 50
Esempio n. 2
0
 def test_broadcast(self, asys):
     psub = asys.createActor(PubSub)
     routee = asys.createActor(PubTestRoutee)
     routeeb = asys.createActor(PubTestRoutee)
     sub = Subscribe(routee, psub, None)
     asys.tell(psub, sub)
     subb = Subscribe(routeeb, psub, None)
     asys.tell(psub, subb)
     bmsg = Broadcast("Hello", psub, None)
     asys.tell(psub, bmsg)
Esempio n. 3
0
 def test_ask_routee(self, asys):
     psub = asys.createActor(PubSub)
     routee = asys.createActor(PubTestRoutee)
     routeeb = asys.createActor(PubTestRoutee)
     sub = Subscribe(routee, psub, None)
     asys.tell(psub, sub)
     subb = Subscribe(routeeb, psub, None)
     asys.tell(psub, subb)
     radd = RouteeAdd(1, psub, None)
     rask = RouteAsk(radd, psub, None)
     res_val = asys.ask(psub, rask)
     assert res_val.payload == 2
Esempio n. 4
0
 def test_desubscribe(self, asys):
     psub = asys.createActor(PubSub)
     routee = asys.createActor(PubTestRoutee)
     routeeb = asys.createActor(PubTestRoutee)
     sub = Subscribe(routee, psub, None)
     asys.tell(psub, sub)
     subb = Subscribe(routeeb, psub, None)
     asys.tell(psub, subb)
     count_msg = GetNumRoutees(None, psub, None)
     desub = DeSubscribe(routee, psub, None)
     asys.tell(psub, desub)
     ct = asys.ask(psub, count_msg)
     assert ct == 1
 def test_subscribe_routee(self, asys):
     psub = asys.createActor(RandomRouter)
     routee = asys.createActor(PubTestRoutee)
     sub = Subscribe(routee, psub, None)
     asys.tell(psub, sub)
     count_msg = GetNumRoutees(None, psub, None)
     ct = asys.ask(psub, count_msg)
     assert ct == 1
 def test_push(self, asys):
     """
     Test a push from the subscription pool
     """
     rr = asys.createActor(RatedSubscriptionPool)
     sub = asys.createActor(SubTest)
     msg = Subscribe(sub, rr, None)
     asys.tell(rr, msg)
     work = get_work_batch_array
     msg = Push(work, rr, None)
     asys.tell(rr, msg)
     cncl = Cancel(None, rr, None)
     asys.tell(rr, cncl)
Esempio n. 7
0
    def subscribe(self, subscription):
        """
        Subscribe a subscription actor

        :param subscription: The subscription to use
        :type subscription: Subscription
        """
        try:
            if isinstance(subscription, Subscription):
                sub = Subscribe(subscription, self.__pool, self.myAddress)
                self.send(self.__pool, sub)
        except Exception:
            handle_actor_system_fail()
Esempio n. 8
0
    def on_subscribe(self, msg, sender):
        """
        This subscribes to a publisher. Only one publisher is allowed.

        :param msg: The sending message
        :type msg: Message
        :param sender: The sender
        :type sender: BaseActor
        """
        if self.__subscribed is False:
            pub = msg.payload
            if isinstance(pub, BaseActor):
                Subscribe(self.__subscriber, pub, self.myAddress)
                self.send(pub, msg)
                self.__subscribed = True
 def test_subscription(self, asys):
     sp = asys.createActor(SubscriptionPool)
     sub = asys.createActor(SubscriberToTest)
     sm = Subscribe(sub, sp, None)
     asys.tell(sp, sm)
     gs = GetSubscribers(None, sp, None)
     rval = asys.ask(sp, gs)
     assert isinstance(rval, GetSubscribers)
     assert len(rval.payload) == 1
     assert rval.payload[0] == sub
     desub = DeSubscribe(sub, sp, None)
     asys.tell(sp, desub)
     gs = GetSubscribers(None, sp, None)
     rval = asys.ask(sp, gs)
     assert isinstance(rval, GetSubscribers)
     assert len(rval.payload) == 0
     cncl = Cancel(None, sp, None)
     asys.tell(sp, cncl)