Exemplo n.º 1
0
    def setUp(self):
        self.clock = task.Clock()
        #reactor.callLater = self.clock.callLater

        self.endpoint = 'tcp://127.0.0.1:15656'
        self.broker = txmdp.make_socket( 'broker', self.endpoint, None )

        self.service = 'service_a'
        self.worker = TxWorkerEcho( txmdp.factory, self.endpoint, self.service )
        self.client = txmdp.make_socket( 'client', self.endpoint, self.service )
Exemplo n.º 2
0
    def test_recv_2(self):
        """
        frontend != backend
        """
        def asserts( reply, original, things ):
            self.assertEqual( reply[0], original )
            map( lambda t: t.shutdown(), things )

        broker = txmdp.make_socket( 'broker', 'tcp://127.0.0.1:25656', 'tcp://127.0.0.1:25657' )
        worker = TxWorkerEcho( txmdp.factory, broker.backend_ep[1], self.service )
        client = txmdp.make_socket( 'client', broker.frontend_ep[1], self.service )

        msg = 'get me some'
        d = self.client.request( self.service, msg, 1 )
        d.addCallback( asserts, msg, [broker,worker,client] )
        return d
Exemplo n.º 3
0
 def setUp(self):
     self.endpoint = 'tcp://127.0.0.1:15656'
     self.client = txmdp.make_socket( 'client', self.endpoint, 'service_a' )
     self.clock = task.Clock()
     reactor.callLater = self.clock.callLater
Exemplo n.º 4
0
 def test_creation_2(self):
     self.broker.shutdown()
     self.broker = txmdp.make_socket( 'broker', self.endpoint, 'tcp://127.0.0.1:15657' )
     self.assertIsNot( self.broker.backend, self.broker.frontend )
Exemplo n.º 5
0
        elif msg_type == b'\x02': # request
            # remaining parts are the user message
            envelope, msg = split_address(msg)
            envelope.append(b'')
            envelope = [ b'', self._mdp_ver, b'\x03'] + envelope # REPLY
            self.envelope = envelope

            logger.debug( "%s <- num frames %d", self, len(msg) )
            self.on_request(self,msg)
        else:
            logger.warn( "%s <- unknown message: %s", self, msg )


    def on_request(self, worker, msg):
        """Public method called when a request arrived.

        Must be overloaded!
        """
        raise NotImplementedError("please override TxMDPClient.on_request")

class TxWorkerEcho( TxMDPWorker ):
    def on_request( self, _, msg ):
        self.reply(msg)


if __name__ == "__main__":
    from txmdp import make_socket
    endpoint = 'tcp://127.0.0.1:5656'
    broker = make_socket( 'worker', endpoint, 'service_a' )
    reactor.run()
Exemplo n.º 6
0
        d_waiting.errback( RequestTimeout() )

    def _on_message(self, msg):
        """
        internal callback for when we receive a message
        fires d_waiting with the msg

        :param msg:   list of message frames
        :type msg:    list of str
        """
        logger.debug( "%s <- num frames %d", self, len(msg) )

        msg.pop(0) # strip proto ver
        msg.pop(0) # strip service
        return msg


if __name__ == "__main__":
    from twisted.internet import task

    def stop(*args):
        reactor.stop()

    from txmdp import make_socket
    endpoint = 'tcp://127.0.0.1:5656'
    client = make_socket( 'client', endpoint, 'service_a' )
    d = client.request('service_a', 'get me some', 0.25)
    d.addBoth( stop )

    reactor.run()
Exemplo n.º 7
0
        :param wid:    the workers id
        :type wid:     str
        :rtype:        bool
        """
        return wid in self.q

    def __len__(self):
        return len(self.q)

    def remove(self, wid):
        try:
            self.q.remove(wid)
        except ValueError:
            pass

    def put(self, wid, *args, **kwargs):
        if wid not in self.q:
            self.q.append(wid)

    def get(self):
        if not self.q:
            return None
        return self.q.pop(0)


if __name__ == "__main__":
    from txmdp import make_socket
    endpoint = 'tcp://127.0.0.1:5656'
    broker = make_socket( 'broker', endpoint, None )
    reactor.run()