예제 #1
0
    def test_sharding_gets(self):
        """
        Ensure that the commands are correctly split by key and sent
        to the correct client.
        """
        client = YamClient(['one', 'two'], connect=False)
        transports = makeTestConnections(client)

        # Get a value that should hit first client and not second
        send = "get aaa\r\n"
        recv = ["VALUE aaa 0 3\r\nbar\r\nEND\r\n"]
        yield self._test(client.get("aaa"), transports[:1], send, recv, (0, "bar"))
        self.assertEqual(transports[1].value(), "")

        # Get a value that should hit second client and not first
        send = "get foo\r\n"
        recv = ["VALUE foo 0 3\r\nbar\r\nEND\r\n"]
        transports[0].clear()
        yield self._test(client.get("foo"), transports[1:], send, recv, (0, "bar"))
        self.assertEqual(transports[0].value(), "")
예제 #2
0
    def test_sharding_gets(self):
        """
        Ensure that the commands are correctly split by key and sent
        to the correct client.
        """
        client = YamClient(['one', 'two'], connect=False)
        transports = makeTestConnections(client)

        # Get a value that should hit first client and not second
        send = "get aaa\r\n"
        recv = ["VALUE aaa 0 3\r\nbar\r\nEND\r\n"]
        yield self._test(client.get("aaa"), transports[:1], send, recv,
                         (0, "bar"))
        self.assertEqual(transports[1].value(), "")

        # Get a value that should hit second client and not first
        send = "get foo\r\n"
        recv = ["VALUE foo 0 3\r\nbar\r\nEND\r\n"]
        transports[0].clear()
        yield self._test(client.get("foo"), transports[1:], send, recv,
                         (0, "bar"))
        self.assertEqual(transports[0].value(), "")
예제 #3
0
    def test_lost_connection(self):
        # now, try with server that has valid transport that
        # has lost its connection
        client = YamClient(['one'], connect=False)
        transports = makeTestConnections(client)
        client.factories[0].stopTrying()

        d1 = client.get("foo")
        d2 = client.get("bar")
        transports[0].loseConnection()

        done = DeferredList([d1, d2], consumeErrors=True)

        def checkFailures(results):
            for success, result in results:
                self.assertFalse(success)
                result.trap(ConnectionDone)
        return done.addCallback(checkFailures)
예제 #4
0
    def test_lost_connection(self):
        # now, try with server that has valid transport that
        # has lost its connection
        client = YamClient(['one'], connect=False)
        transports = makeTestConnections(client)
        client.factories[0].stopTrying()

        d1 = client.get("foo")
        d2 = client.get("bar")
        transports[0].loseConnection()

        done = DeferredList([d1, d2], consumeErrors=True)

        def checkFailures(results):
            for success, result in results:
                self.assertFalse(success)
                result.trap(ConnectionDone)

        return done.addCallback(checkFailures)