Beispiel #1
0
 def __init__(self, test, requestsPerSocket=3, socketCount=2):
     # Similar to MaxRequests in the configuration.
     self.requestsPerSocket = requestsPerSocket
     # Similar to ProcessCount in the configuration.
     self.socketCount = socketCount
     self.limiter = ConnectionLimiter(2,
                                      maxRequests=requestsPerSocket *
                                      socketCount)
     self.dispatcher = self.limiter.dispatcher
     self.dispatcher.reactor = ReaderAdder()
     self.service = Service()
     self.limiter.addPortService("TCP", 4321, "127.0.0.1", 5,
                                 self.serverServiceMakerMaker(self.service))
     for ignored in xrange(socketCount):
         subskt = self.dispatcher.addSocket()
         subskt.start()
         subskt.restarted()
     # Has to be running in order to add stuff.
     self.limiter.startService()
     self.port = self.service.myPort
 def __init__(self, test, requestsPerSocket=3, socketCount=2):
     # Similar to MaxRequests in the configuration.
     self.requestsPerSocket = requestsPerSocket
     # Similar to ProcessCount in the configuration.
     self.socketCount = socketCount
     self.limiter = ConnectionLimiter(
         2, maxRequests=requestsPerSocket * socketCount
     )
     self.dispatcher = self.limiter.dispatcher
     self.dispatcher.reactor = ReaderAdder()
     self.service = Service()
     self.limiter.addPortService("TCP", 4321, "127.0.0.1", 5,
                                 self.serverServiceMakerMaker(self.service))
     for ignored in xrange(socketCount):
         self.dispatcher.addSocket()
     # Has to be running in order to add stuff.
     self.limiter.startService()
     self.port = self.service.myPort
Beispiel #3
0
 def setUp(self):
     self.dispatcher = InheritedSocketDispatcher(ConnectionLimiter(2, 20))
     self.dispatcher.reactor = ReaderAdder()
Beispiel #4
0
class LimiterBuilder(object):
    """
    A L{LimiterBuilder} can build a L{ConnectionLimiter} and associated objects
    for a given unit test.
    """
    def __init__(self, test, requestsPerSocket=3, socketCount=2):
        # Similar to MaxRequests in the configuration.
        self.requestsPerSocket = requestsPerSocket
        # Similar to ProcessCount in the configuration.
        self.socketCount = socketCount
        self.limiter = ConnectionLimiter(2,
                                         maxRequests=requestsPerSocket *
                                         socketCount)
        self.dispatcher = self.limiter.dispatcher
        self.dispatcher.reactor = ReaderAdder()
        self.service = Service()
        self.limiter.addPortService("TCP", 4321, "127.0.0.1", 5,
                                    self.serverServiceMakerMaker(self.service))
        for ignored in xrange(socketCount):
            subskt = self.dispatcher.addSocket()
            subskt.start()
            subskt.restarted()
        # Has to be running in order to add stuff.
        self.limiter.startService()
        self.port = self.service.myPort

    def highestLoad(self):
        return max(skt.status.effective()
                   for skt in self.limiter.dispatcher._subprocessSockets)

    def serverServiceMakerMaker(self, s):
        """
        Make a serverServiceMaker for use with
        L{ConnectionLimiter.addPortService}.
        """
        class NotAPort(object):
            def startReading(self):
                self.reading = True

            def stopReading(self):
                self.reading = False

        def serverServiceMaker(port, factory, *a, **k):
            s.factory = factory
            s.myPort = NotAPort()
            # TODO: technically, the following should wait for startService
            s.myPort.startReading()
            factory.myServer = s
            return s

        return serverServiceMaker

    def fillUp(self, acknowledged=True, count=0):
        """
        Fill up all the slots on the connection limiter.

        @param acknowledged: Should the virtual connections created by this
            method send a message back to the dispatcher indicating that the
            subprocess has acknowledged receipt of the file descriptor?

        @param count: Amount of load to add; default to the maximum that the
            limiter.
        """
        for _ignore_x in range(count or self.limiter.maxRequests):
            self.dispatcher.sendFileDescriptor(None, "SSL")
            if acknowledged:
                self.dispatcher.statusMessage(
                    self.dispatcher._subprocessSockets[0], "+")

    def processRestart(self):
        self.dispatcher._subprocessSockets[0].stop()
        self.dispatcher._subprocessSockets[0].start()
        self.dispatcher.statusMessage(self.dispatcher._subprocessSockets[0],
                                      "0")

    def loadDown(self):
        self.dispatcher.statusMessage(self.dispatcher._subprocessSockets[0],
                                      "-")
Beispiel #5
0
class LimiterBuilder(object):
    """
    A L{LimiterBuilder} can build a L{ConnectionLimiter} and associated objects
    for a given unit test.
    """

    def __init__(self, test, requestsPerSocket=3, socketCount=2):
        # Similar to MaxRequests in the configuration.
        self.requestsPerSocket = requestsPerSocket
        # Similar to ProcessCount in the configuration.
        self.socketCount = socketCount
        self.limiter = ConnectionLimiter(
            2, maxRequests=requestsPerSocket * socketCount
        )
        self.dispatcher = self.limiter.dispatcher
        self.dispatcher.reactor = ReaderAdder()
        self.service = Service()
        self.limiter.addPortService("TCP", 4321, "127.0.0.1", 5,
                                    self.serverServiceMakerMaker(self.service))
        for ignored in xrange(socketCount):
            subskt = self.dispatcher.addSocket()
            subskt.start()
            subskt.restarted()
        # Has to be running in order to add stuff.
        self.limiter.startService()
        self.port = self.service.myPort


    def highestLoad(self):
        return max(
            skt.status.effective()
            for skt in self.limiter.dispatcher._subprocessSockets
        )


    def serverServiceMakerMaker(self, s):
        """
        Make a serverServiceMaker for use with
        L{ConnectionLimiter.addPortService}.
        """
        class NotAPort(object):
            def startReading(self):
                self.reading = True
            def stopReading(self):
                self.reading = False

        def serverServiceMaker(port, factory, *a, **k):
            s.factory = factory
            s.myPort = NotAPort()
            # TODO: technically, the following should wait for startService
            s.myPort.startReading()
            factory.myServer = s
            return s
        return serverServiceMaker


    def fillUp(self, acknowledged=True, count=0):
        """
        Fill up all the slots on the connection limiter.

        @param acknowledged: Should the virtual connections created by this
            method send a message back to the dispatcher indicating that the
            subprocess has acknowledged receipt of the file descriptor?

        @param count: Amount of load to add; default to the maximum that the
            limiter.
        """
        for _ignore_x in range(count or self.limiter.maxRequests):
            self.dispatcher.sendFileDescriptor(None, "SSL")
            if acknowledged:
                self.dispatcher.statusMessage(
                    self.dispatcher._subprocessSockets[0], "+"
                )


    def processRestart(self):
        self.dispatcher._subprocessSockets[0].stop()
        self.dispatcher._subprocessSockets[0].start()
        self.dispatcher.statusMessage(
            self.dispatcher._subprocessSockets[0], "0"
        )


    def loadDown(self):
        self.dispatcher.statusMessage(
            self.dispatcher._subprocessSockets[0], "-"
        )