Пример #1
0
 def _createResources(cwd, timeout, quiet):
     #    Create our listener:
     target = Queue()
     marshaller = MarshallerFactory.get(MarshallerFactory.DEFAULT, quiet=quiet)
     tQs = QueueServer(host="127.0.0.1", port=54000, target=target, marshaller=marshaller, quiet=quiet).start().waitUntilRunning()
     details = tQs.details()
     return (target, tQs, details)
Пример #2
0
class TestSameProcessInlineServer(TestServer):
    def _createQueueServer(self):
        #    Create the QueueServer programatically in our Process (not vi a a shell-out (yet))...
        self.qs = QueueServer(host=self.host,
                              port=self.port,
                              target=self.target,
                              marshaller=self.m,
                              hunt=True,
                              quiet=self.quiet,
                              maxClients=self.maxClients,
                              recvChunkSize=self.recvChunkSize,
                              readTimeout=self.readTimeout,
                              )
        #    ...and set it serving:
        self.qs.start().waitUntilRunning()
        #    not forgetting to save it's connection details.
        self.details = self.qs.details()
    def testDoubleClose(self):
        assert self.qs.close()
        assert self.qs.close()
    def testSimpleSend(self):
        #    Send some data and check that it's put onto the target queue.
        eResult = {"hello.world!":{123:456}}
        self.qw.put(eResult)
        received = self.target.get(True, timeout=self.TIMEOUT)
        assert received==eResult
Пример #3
0
class TestSameProcessExternalServer(TestServer):
    def tearDown(self):
        try:    self.rqs.close()
        except: pass
        super(TestSameProcessExternalServer, self).tearDown()
    def testDoubleClose(self):
        assert self.qs.close()
        assert self.qs.close()
    def _createQueueServer(self):
        #    Create the QueueServer by using os.system or Subprocess.
        #    Create a reply-to Ping server:
        self.rqs= QueueServer(host=self.host,
                              port=self.portReplyTo,
                              target=self.target,
                              marshaller=self.m,
                              hunt=True,
                              quiet=self.quiet,
                              maxClients=self.maxClients,
                              recvChunkSize=self.recvChunkSize,
                              readTimeout=self.readTimeout,
                              )
        self.rqs.start().waitUntilRunning()
        #    Now create the subprocess server:
        desiredPort = 50001
        linkage = Linkage.create(Pinger)
        self.qs = SubprocessQueueServer(handlerClazz=Linkage.create(QueueServerHandler),
                                        desiredPort=desiredPort,
                                        linkage=linkage,
                                        quiet=self.quiet)
        self.details = self.qs.details()
    def testSimpleSendPingRoundtrip(self):
        details = self.rqs.details()
        eResult = Ping(replyTo=details, data={"hello.world!":{123:456}}, quiet=self.quiet)
        self.qw.put(eResult)
        received = self.target.get(True, timeout=self.TIMEOUT)
        assert received==eResult
Пример #4
0
def _loadHost(options, handlerClazz, **kwargs):
    servicesClazzpath = options.servicesClazzpath
    servicesClazz = options.servicesClazz
    quiet = options.quiet
    if (servicesClazzpath!=None) and (len(servicesClazzpath)>0) and (servicesClazz!=None) and (len(servicesClazz)>0):
        services = _importModule(options.servicesClazzpath, options.servicesClazz)
        from PyRQ import PyRQTimeUtils
        PyRQTimeUtils.set_getTime(services.getSystemUptimeInteger)
        PyRQTimeUtils.set_delayTime(services.timeSleep)
        b = PyRQTimeUtils.getTime()
        if not quiet: sys.stderr.write("subprocess getTime()...%(T)s\r\n"%{"T":b})
    if options.handlerClazz!=None:
        handlerClazz = _getClass(options.handlerClazz)
        hC = Linkage.create(handlerClazz)
    else:
        msg = "No HandlerClazz specified!!!"
        sys.stderr.write(msg)
        raise Exception(msg)
#        hC = Linkage.create(RRQHandler)
#        handlerClazz = _getClass(".".join([hC.clazzpath(), hC.clazz()]))
    if not quiet: sys.stderr.write("BootQueueServer::handlerClazz... %(H)s  .  %(P)s\r\n"%{"H":hC.clazzpath(), "P":hC.clazz()})
    from multiprocessing.queues import Queue
    mt = options.marshallerType
    mt = int(mt)
    target=Queue()
    kwargs["maxClients"] = options.maxClients
    kwargs["quiet"] = quiet
    kwargs["recvChunkSize"] = int(options.socketRecvChunkSize)
    kwargs["readTimeout"] = int(options.socketReadTimeout)
    kwargs["loggerModule"] = _loadLoggingModule(options.loggingModule)
    qs = QueueServer(host=options.host,
                     port=options.port,
                     marshaller=MarshallerFactory.get(mt, quiet=quiet),
                     target=target,
                     handlerClazz=handlerClazz,
                     **kwargs)
    qs.start().waitUntilRunning()
    if options.ackHost and options.ackPort:
        #    Send the ack back!
        if not quiet: sys.stderr.write("BootQueueServer::load...[0.1]: %(H)s:%(P)s[1]\r\n"%{"H":options.ackHost, "P":options.ackPort})
        from PyRQ.Core.QueueWriter.QueueWriter import QueueWriter
#        import pydevd
#        pydevd.settrace(stdoutToServer = True, stderrToServer = True)
        qw = QueueWriter(target=QueueServerDetails(options.ackHost, options.ackPort),
                        marshaller=MarshallerFactory.get(mt, quiet=quiet),
                        autoConnect=True,
                        sockTimeout=10,
                        quiet=quiet
                        )
        if not quiet: sys.stderr.write("BootQueueServer::load...[1.0]\r\n")
        qw.start()
        details = qs.details()
        if not quiet: sys.stderr.write("BootQueueServer::load...[1.2]: %(D)s\r\n"%{"D":details})
        qw.put(details)
        if not quiet: sys.stderr.write("BootQueueServer::load...[1.2]\r\n")
    #    Now we have a queue which we can use to receive messages on:    'target'.
    importedModule = None
    if options.clazzpath!=None and options.clazz!=None:
        if not quiet: sys.stderr.write("BootQueueServer::load...Launching %(P)s.%(C)s with target queue: %(Q)s\r\n"%{"P":options.clazzpath, "C":options.clazz, "Q":target})
        try:
            importedModule = _importModule(options.clazzpath, options.clazz)(qs)
        except Exception, _e:
            sys.stderr.write("Error Launching %(P)s.%(C)s with target queue: %(Q)s\r\n%(T)s\r\n"%{"P":options.clazzpath, "C":options.clazz, "Q":target, "T":traceback.format_exc()})
Пример #5
0
            return genericSinkMethod
        return object.__getattribute__(self, name)

if __name__ == '__main__':
    md = RRQDebugger()
    a = md.finish_end("peerName", "relativeTime")
    print a
    md.start(filename="mock.file")
    a = md.setup_start("peerName123", "relativeTime123")
    print a
    #    Start a dummyQueueServer:
    q = Queue()
    m = MarshallerFactory.get(MarshallerFactory.DEFAULT)
    QS = QueueServer(port=22334, target=q, quiet=True, marshaller=m)
    QS.start()
    details = QS.details()
    md.start(server=details)
    a = md.setup_start("peerName123", "relativeTime123")
    print a
    data = q.get(block=True, timeout=10)
    QS.close()