コード例 #1
0
 def setUp(self):
     """
     Create a L{MemCacheClientFactory} instance and and give it a
     L{StubConnectionPool} instance.
     """
     super(MemCacheClientFactoryTests, self).setUp()
     self.pool = StubConnectionPool()
     self.factory = MemCacheClientFactory()
     self.factory.connectionPool = self.pool
     self.protocol = self.factory.buildProtocol(None)
コード例 #2
0
class MemCacheClientFactoryTests(TestCase):
    """
    Tests for the L{MemCacheClientFactory}

    @ivar factory: A L{MemCacheClientFactory} instance with a
        L{StubConnectionPool}.
    @ivar protocol: A L{PooledMemCacheProtocol} that was built by
        L{MemCacheClientFactory.buildProtocol}.
    @ivar pool: The L{StubConnectionPool} attached to C{self.factory} and
        C{self.protocol}.
    """

    def setUp(self):
        """
        Create a L{MemCacheClientFactory} instance and and give it a
        L{StubConnectionPool} instance.
        """
        super(MemCacheClientFactoryTests, self).setUp()
        self.pool = StubConnectionPool()
        self.factory = MemCacheClientFactory()
        self.factory.connectionPool = self.pool
        self.protocol = self.factory.buildProtocol(None)

    def test_clientConnectionFailedNotifiesPool(self):
        """
        Test that L{MemCacheClientFactory.clientConnectionFailed} notifies
        the it's connectionPool that it is busy.
        """
        self.factory.clientConnectionFailed(StubConnector(), None)
        self.assertEquals(self.factory.connectionPool.calls,
                          [('busy', self.protocol)])

    def test_clientConnectionLostNotifiesPool(self):
        """
        Test that L{MemCacheClientFactory.clientConnectionLost} notifies
        the it's connectionPool that it is busy.
        """
        self.factory.clientConnectionLost(StubConnector(), None)
        self.assertEquals(self.factory.connectionPool.calls,
                          [('busy', self.protocol)])

    def test_buildProtocolRemovesExistingClient(self):
        """
        Test that L{MemCacheClientFactory.buildProtocol} notifies
        the connectionPool when an old protocol instance is going away.

        This will happen when we get reconnected.  We'll remove the old protocol
        and add a new one.
        """
        self.factory.buildProtocol(None)
        self.assertEquals(self.factory.connectionPool.calls,
                          [('gone', self.protocol)])

    def tearDown(self):
        """
        Make sure the L{MemCacheClientFactory} isn't trying to reconnect
        anymore.
        """
        self.factory.stopTrying()
コード例 #3
0
    def test_clientBusyAddsNewClient(self):
        """
        Test that a client not in the free set gets added to the busy set.
        """
        p = MemCacheClientFactory().buildProtocol(None)
        self.pool.clientBusy(p)

        self.assertEquals(self.pool._busyClients, set([p]))
コード例 #4
0
 def setUp(self):
     """
     Create a L{MemCacheClientFactory} instance and and give it a
     L{StubConnectionPool} instance.
     """
     super(MemCacheClientFactoryTests, self).setUp()
     self.pool = StubConnectionPool()
     self.factory = MemCacheClientFactory()
     self.factory.connectionPool = self.pool
     self.protocol = self.factory.buildProtocol(None)
コード例 #5
0
    def test_clientGoneRemovesBusyClient(self):
        """
        Test that a client in the busy set gets removed when
        L{MemCachePool.clientGone} is called.
        """
        p = MemCacheClientFactory().buildProtocol(None)
        self.pool.clientBusy(p)
        self.assertEquals(self.pool._busyClients, set([p]))
        self.assertEquals(self.pool._freeClients, set([]))

        self.pool.clientGone(p)
        self.assertEquals(self.pool._busyClients, set([]))
コード例 #6
0
    def test_connectionMadeFiresDeferred(self):
        """
        Test that L{PooledMemCacheProtocol.connectionMade} fires the factory's
        deferred.
        """
        p = PooledMemCacheProtocol()
        p.factory = MemCacheClientFactory()
        p.connectionPool = StubConnectionPool()
        d = p.factory.deferred
        d.addCallback(self.assertEquals, p)

        p.connectionMade()
        return d
コード例 #7
0
class MemCacheClientFactoryTests(TestCase):
    """
    Tests for the L{MemCacheClientFactory}

    @ivar factory: A L{MemCacheClientFactory} instance with a
        L{StubConnectionPool}.
    @ivar protocol: A L{PooledMemCacheProtocol} that was built by
        L{MemCacheClientFactory.buildProtocol}.
    @ivar pool: The L{StubConnectionPool} attached to C{self.factory} and
        C{self.protocol}.
    """
    def setUp(self):
        """
        Create a L{MemCacheClientFactory} instance and and give it a
        L{StubConnectionPool} instance.
        """
        super(MemCacheClientFactoryTests, self).setUp()
        self.pool = StubConnectionPool()
        self.factory = MemCacheClientFactory()
        self.factory.connectionPool = self.pool
        self.protocol = self.factory.buildProtocol(None)


    def test_clientConnectionFailedNotifiesPool(self):
        """
        Test that L{MemCacheClientFactory.clientConnectionFailed} notifies
        the it's connectionPool that it is busy.
        """
        self.factory.clientConnectionFailed(StubConnector(), None)
        self.assertEquals(self.factory.connectionPool.calls,
                          [('busy', self.protocol)])


    def test_clientConnectionLostNotifiesPool(self):
        """
        Test that L{MemCacheClientFactory.clientConnectionLost} notifies
        the it's connectionPool that it is busy.
        """
        self.factory.clientConnectionLost(StubConnector(), None)
        self.assertEquals(self.factory.connectionPool.calls,
                          [('busy', self.protocol)])


    def test_buildProtocolRemovesExistingClient(self):
        """
        Test that L{MemCacheClientFactory.buildProtocol} notifies
        the connectionPool when an old protocol instance is going away.

        This will happen when we get reconnected.  We'll remove the old protocol
        and add a new one.
        """
        self.factory.buildProtocol(None)
        self.assertEquals(self.factory.connectionPool.calls,
                          [('gone', self.protocol)])


    def tearDown(self):
        """
        Make sure the L{MemCacheClientFactory} isn't trying to reconnect
        anymore.
        """
        self.factory.stopTrying()