コード例 #1
0
ファイル: jsonRpcTests.py プロジェクト: humblec/vdsm
    def test(self, rt, ssl):
        data = dummyTextGenerator(((2 ** 10) * 200))

        echosrv = _EchoServer()

        def serve(reactor):
            try:
                reactor.process_requests()
            except socket.error as e:
                pass
            except Exception as e:
                self.log.error("Reactor died unexpectedly", exc_info=True)
                self.fail("Reactor died: (%s) %s" % (type(e), e))

        with constructReactor(rt, ssl) as \
                (reactor, clientReactor, laddr):

            t = threading.Thread(target=echosrv.serve)
            t.setDaemon(True)
            t.start()

            reactor.createListener(laddr, echosrv.accept)

            clientNum = 2
            repeats = 10
            subRepeats = 10

            clients = []
            for i in range(clientNum):
                c = ReactorClientSyncWrapper(
                    clientReactor.createClient(laddr))
                c.connect()
                clients.append(c)

            for i in range(repeats):
                for client in clients:
                    for i in range(subRepeats):
                        self.log.info("Sending message...")
                        client.send(data)

            for i in range(repeats * subRepeats):
                for client in clients:
                    self.log.info("Waiting for reply...")
                    retData = client.recv(CALL_TIMEOUT)
                    self.log.info("Asserting reply...")
                    self.assertTrue(isinstance(retData,
                                               (str, unicode)))
                    plen = 20  # Preview len, used for debugging
                    self.assertEquals(
                        retData, data,
                        "Data is not as expected " +
                        "'%s...%s' (%d chars) != '%s...%s' (%d chars)" %
                        (retData[:plen], retData[-plen:], len(retData),
                         data[:plen], data[-plen:], len(data)))
コード例 #2
0
ファイル: jsonRpcTests.py プロジェクト: lukas-bednar/vdsm
    def test(self, reactorType):
        data = dummyTextGenerator(((2 ** 10) * 200))
        queue = Queue()

        echosrv = _EchoServer()

        def serve(reactor):
            try:
                reactor.process_requests()
            except socket.error as e:
                pass
            except Exception as e:
                self.log.error("Reactor died unexpectedly", exc_info=True)
                self.fail("Reactor died: (%s) %s" % (type(e), e))

        with constructReactor(reactorType) as \
                (reactor, clientFactory, laddr):

            t = threading.Thread(target=echosrv.serve)
            t.setDaemon(True)
            t.start()

            reactor.createListener(laddr, echosrv.accept)

            clientNum = 4
            repeats = 2
            subRepeats = 4

            clients = []
            try:
                for i in range(clientNum):
                    c = clientFactory()
                    c.connect()
                    clients.append(c)

                for i in range(repeats):
                    for client in clients:
                        for i in range(subRepeats):
                            self.log.info("Sending message...")
                            client.send(data, CALL_TIMEOUT)

                for i in range(repeats * subRepeats):
                    for client in clients:
                            self.log.info("Waiting for reply...")
                            retData = client.recv(CALL_TIMEOUT)
                            self.log.info("Asserting reply...")
                            self.assertEquals(
                                retData, data,
                                "Data is not as expected " +
                                "'%s...%s' != '%s...%s'" %
                                (retData[:10], retData[-10:],
                                 data[:10], data[-10:]))
            finally:
                queue.put((None, None))
コード例 #3
0
ファイル: jsonRpcTests.py プロジェクト: rexhsu/vdsm-ubuntu
    def test(self, reactorType):
        data = dummyTextGenerator(((2**10) * 200))
        queue = Queue()

        echosrv = _EchoServer()

        def serve(reactor):
            try:
                reactor.process_requests()
            except socket.error as e:
                pass
            except Exception as e:
                self.log.error("Reactor died unexpectedly", exc_info=True)
                self.fail("Reactor died: (%s) %s" % (type(e), e))

        with constructReactor(reactorType) as \
                (reactor, clientFactory, laddr):

            t = threading.Thread(target=echosrv.serve)
            t.setDaemon(True)
            t.start()

            reactor.createListener(laddr, echosrv.accept)

            clientNum = 4
            repeats = 2
            subRepeats = 4

            clients = []
            try:
                for i in range(clientNum):
                    c = clientFactory()
                    c.connect()
                    clients.append(c)

                for i in range(repeats):
                    for client in clients:
                        for i in range(subRepeats):
                            self.log.info("Sending message...")
                            client.send(data, CALL_TIMEOUT)

                for i in range(repeats * subRepeats):
                    for client in clients:
                        self.log.info("Waiting for reply...")
                        retData = client.recv(CALL_TIMEOUT)
                        self.log.info("Asserting reply...")
                        self.assertEquals(
                            retData, data, "Data is not as expected " +
                            "'%s...%s' != '%s...%s'" %
                            (retData[:10], retData[-10:], data[:10],
                             data[-10:]))
            finally:
                queue.put((None, None))
コード例 #4
0
ファイル: jsonRpcTests.py プロジェクト: fzkbass/vdsm
    def test(self, rt, ssl):
        data = dummyTextGenerator(((2**10) * 200))

        echosrv = _EchoServer()

        def serve(reactor):
            try:
                reactor.process_requests()
            except socket.error as e:
                pass
            except Exception as e:
                self.log.error("Reactor died unexpectedly", exc_info=True)
                self.fail("Reactor died: (%s) %s" % (type(e), e))

        with constructReactor(rt, ssl) as \
                (reactor, clientReactor, laddr):

            t = threading.Thread(target=echosrv.serve)
            t.setDaemon(True)
            t.start()

            reactor.createListener(laddr, echosrv.accept)

            clientNum = 2
            repeats = 10
            subRepeats = 10

            clients = []
            for i in range(clientNum):
                c = ReactorClientSyncWrapper(clientReactor.createClient(laddr))
                c.connect()
                clients.append(c)

            for i in range(repeats):
                for client in clients:
                    for i in range(subRepeats):
                        self.log.info("Sending message...")
                        client.send(data)

            for i in range(repeats * subRepeats):
                for client in clients:
                    self.log.info("Waiting for reply...")
                    retData = client.recv(CALL_TIMEOUT)
                    self.log.info("Asserting reply...")
                    self.assertTrue(isinstance(retData, (str, unicode)))
                    plen = 20  # Preview len, used for debugging
                    self.assertEquals(
                        retData, data, "Data is not as expected " +
                        "'%s...%s' (%d chars) != '%s...%s' (%d chars)" %
                        (retData[:plen], retData[-plen:], len(retData),
                         data[:plen], data[-plen:], len(data)))