def test_connectTCP(self):
        """
        Called on the object returned by L{loggedReactor}, C{connectTCP} calls
        the wrapped reactor's C{connectTCP} method with the original factory
        wrapped in a L{_TrafficLoggingFactory}.
        """
        class RecordDataProtocol(Protocol):
            def dataReceived(self, data):
                self.data = data

        proto = RecordDataProtocol()
        factory = ClientFactory()
        factory.protocol = lambda: proto
        reactor = MemoryReactor()
        logged = loggedReactor(reactor)
        logged.connectTCP('192.168.1.2', 1234, factory, 21, '127.0.0.2')
        [(host, port, factory, timeout, bindAddress)] = reactor.tcpClients
        self.assertEqual('192.168.1.2', host)
        self.assertEqual(1234, port)
        self.assertIsInstance(factory, _TrafficLoggingFactory)
        self.assertEqual(21, timeout)
        self.assertEqual('127.0.0.2', bindAddress)

        # Verify that the factory and protocol specified are really being used
        protocol = factory.buildProtocol(None)
        protocol.makeConnection(None)
        protocol.dataReceived("foo")
        self.assertEqual(proto.data, "foo")
    def test_getLogFiles(self):
        """
        The reactor returned by L{loggedReactor} has a C{getLogFiles} method
        which returns a L{logstate} instance containing the active and
        completed log files tracked by the logging wrapper.
        """
        wrapped = ClientFactory()
        wrapped.protocol = Discard
        reactor = MemoryReactor()
        logged = loggedReactor(reactor)
        logged.connectTCP('127.0.0.1', 1234, wrapped)
        factory = reactor.tcpClients[0][2]

        finished = factory.buildProtocol(None)
        finished.makeConnection(StringTransport())
        finished.dataReceived('finished')
        finished.connectionLost(None)

        active = factory.buildProtocol(None)
        active.makeConnection(StringTransport())
        active.dataReceived('active')

        logs = logged.getLogFiles()
        self.assertEqual(1, len(logs.finished))
        self.assertIn('finished', logs.finished[0].getvalue())
        self.assertEqual(1, len(logs.active))
        self.assertIn('active', logs.active[0].getvalue())
    def test_connectTCP(self):
        """
        Called on the object returned by L{loggedReactor}, C{connectTCP} calls
        the wrapped reactor's C{connectTCP} method with the original factory
        wrapped in a L{_TrafficLoggingFactory}.
        """
        class RecordDataProtocol(Protocol):
            def dataReceived(self, data):
                self.data = data
        proto = RecordDataProtocol()
        factory = ClientFactory()
        factory.protocol = lambda: proto
        reactor = MemoryReactor()
        logged = loggedReactor(reactor)
        logged.connectTCP('192.168.1.2', 1234, factory, 21, '127.0.0.2')
        [(host, port, factory, timeout, bindAddress)] = reactor.tcpClients
        self.assertEqual('192.168.1.2', host)
        self.assertEqual(1234, port)
        self.assertIsInstance(factory, _TrafficLoggingFactory)
        self.assertEqual(21, timeout)
        self.assertEqual('127.0.0.2', bindAddress)

        # Verify that the factory and protocol specified are really being used
        protocol = factory.buildProtocol(None)
        protocol.makeConnection(None)
        protocol.dataReceived("foo")
        self.assertEqual(proto.data, "foo")
    def test_getLogFiles(self):
        """
        The reactor returned by L{loggedReactor} has a C{getLogFiles} method
        which returns a L{logstate} instance containing the active and
        completed log files tracked by the logging wrapper.
        """
        wrapped = ClientFactory()
        wrapped.protocol = Discard
        reactor = MemoryReactor()
        logged = loggedReactor(reactor)
        logged.connectTCP('127.0.0.1', 1234, wrapped)
        factory = reactor.tcpClients[0][2]

        finished = factory.buildProtocol(None)
        finished.makeConnection(StringTransport())
        finished.dataReceived('finished')
        finished.connectionLost(None)

        active = factory.buildProtocol(None)
        active.makeConnection(StringTransport())
        active.dataReceived('active')

        logs = logged.getLogFiles()
        self.assertEqual(1, len(logs.finished))
        self.assertIn('finished', logs.finished[0].getvalue())
        self.assertEqual(1, len(logs.active))
        self.assertIn('active', logs.active[0].getvalue())
 def test_interfaces(self):
     """
     The object returned by L{loggedReactor} provides all of the interfaces
     provided by the object passed to it.
     """
     probe = Probe()
     reactor = loggedReactor(probe)
     self.assertTrue(IProbe.providedBy(reactor))
 def test_nothing(self):
     """
     L{loggedReactor} returns the object passed to it, if the object passed
     to it doesn't provide any interfaces.  This is mostly for testing
     convenience rather than a particularly useful feature.
     """
     probe = object()
     self.assertIdentical(probe, loggedReactor(probe))
 def test_interfaces(self):
     """
     The object returned by L{loggedReactor} provides all of the interfaces
     provided by the object passed to it.
     """
     probe = Probe()
     reactor = loggedReactor(probe)
     self.assertTrue(IProbe.providedBy(reactor))
 def test_nothing(self):
     """
     L{loggedReactor} returns the object passed to it, if the object passed
     to it doesn't provide any interfaces.  This is mostly for testing
     convenience rather than a particularly useful feature.
     """
     probe = object()
     self.assertIdentical(probe, loggedReactor(probe))
 def test_passthrough(self):
     """
     Methods on interfaces on the object passed to L{loggedReactor} can be
     called by calling them on the object returned by L{loggedReactor}.
     """
     expected = object()
     probe = Probe(expected)
     reactor = loggedReactor(probe)
     result = reactor.probe()
     self.assertTrue(probe._probed)
     self.assertIdentical(expected, result)
Пример #10
0
 def test_passthrough(self):
     """
     Methods on interfaces on the object passed to L{loggedReactor} can be
     called by calling them on the object returned by L{loggedReactor}.
     """
     expected = object()
     probe = Probe(expected)
     reactor = loggedReactor(probe)
     result = reactor.probe()
     self.assertTrue(probe._probed)
     self.assertIdentical(expected, result)
Пример #11
0
    def add(self, numClients, clientsPerUser):
        instanceNumber = 0
        for _ignore_n in range(numClients):
            number = self._nextUserNumber()

            for _ignore_peruser in range(clientsPerUser):
                clientType = self._pop.next()
                if (number % self.workerCount) != self.workerIndex:
                    # If we're in a distributed work scenario and we are worker N,
                    # we have to skip all but every Nth request (since every node
                    # runs the same arrival policy).
                    continue

                record, _ignore_user, auth = self._createUser(number)

                reactor = loggedReactor(self.reactor)
                client = clientType.new(
                    reactor,
                    self.servers[record.podID],
                    self.principalPathTemplate,
                    self.serializationPath,
                    record,
                    auth,
                    instanceNumber
                )
                instanceNumber += 1
                self.clients.append(client)
                d = client.run()
                d.addErrback(self._clientFailure, reactor)

                for profileType in clientType.profileTypes:
                    profile = profileType(reactor, self, client, number)
                    if profile.enabled:
                        d = profile.initialize()

                        def _run(result):
                            d2 = profile.run()
                            d2.addErrback(self._profileFailure, profileType, reactor)
                            return d2
                        d.addCallback(_run)

        # XXX this status message is prone to be slightly inaccurate, but isn't
        # really used by much anyway.
        msg(type="status", clientCount=self._user - 1)
Пример #12
0
    def add(self, numClients, clientsPerUser):
        for _ignore_n in range(numClients):
            number = self._nextUserNumber()

            for _ignore_peruser in range(clientsPerUser):
                clientType = self._pop.next()
                if (number % self.workerCount) != self.workerIndex:
                    # If we're in a distributed work scenario and we are worker N,
                    # we have to skip all but every Nth request (since every node
                    # runs the same arrival policy).
                    continue

                _ignore_user, auth = self._createUser(number)

                reactor = loggedReactor(self.reactor)
                client = clientType.new(
                    reactor,
                    self.server,
                    self.principalPathTemplate,
                    self.serializationPath,
                    self.getUserRecord(number),
                    auth,
                )
                self.clients.append(client)
                d = client.run()
                d.addErrback(self._clientFailure, reactor)

                for profileType in clientType.profileTypes:
                    profile = profileType(reactor, self, client, number)
                    if profile.enabled:
                        d = profile.initialize()
                        def _run(result):
                            d2 = profile.run()
                            d2.addErrback(self._profileFailure, profileType, reactor)
                            return d2
                        d.addCallback(_run)

        # XXX this status message is prone to be slightly inaccurate, but isn't
        # really used by much anyway.
        msg(type="status", clientCount=self._user - 1)