Пример #1
0
    def test_getClient(self):
        """
        Ensure that we can split by key correctly.
        """
        yclient = YamClient(['one', 'two'], connect=False)
        makeTestConnections(yclient)
        self.assertEqual(yclient.getClient('aaa'), yclient.factories[0].client)
        self.assertEqual(yclient.getClient('foo'), yclient.factories[1].client)

        # now lose first connection
        yclient.factories[0].stopTrying()
        # next line is handled by clientConnectionLost which is called when an actual
        # internet.tcp.Connector has a failed connection
        yclient.factories[0].client = None
        self.assertEqual(yclient.getClient('aaa'), yclient.factories[1].client)
        self.assertEqual(yclient.getClient('foo'), yclient.factories[1].client)
Пример #2
0
    def test_getClient(self):
        """
        Ensure that we can split by key correctly.
        """
        yclient = YamClient(['one', 'two'], connect=False)
        makeTestConnections(yclient)
        self.assertEqual(yclient.getClient('aaa'), yclient.factories[0].client)
        self.assertEqual(yclient.getClient('foo'), yclient.factories[1].client)

        # now lose first connection
        yclient.factories[0].stopTrying()
        # next line is handled by clientConnectionLost which is called when an actual
        # internet.tcp.Connector has a failed connection
        yclient.factories[0].client = None
        self.assertEqual(yclient.getClient('aaa'), yclient.factories[1].client)
        self.assertEqual(yclient.getClient('foo'), yclient.factories[1].client)
Пример #3
0
    def test_getClientWithConsistentHashing(self):
        """
        Ensure that the client that has a key remains the same if the total number
        of hosts goes up or down.
        """
        yclient = YamClient(map(str, range(9)), connect=False)
        makeTestConnections(yclient)
        self.assertEqual(yclient.factories[6].client, yclient.getClient('sdusdfsdf'))

        yclient = YamClient(map(str, range(10)), connect=False)
        makeTestConnections(yclient)
        self.assertEqual(yclient.factories[6].client, yclient.getClient('sdusdfsdf'))

        yclient = YamClient(map(str, range(11)), connect=False)
        makeTestConnections(yclient)
        self.assertEqual(yclient.factories[6].client, yclient.getClient('sdusdfsdf'))
Пример #4
0
    def test_getClientWithConsistentHashing(self):
        """
        Ensure that the client that has a key remains the same if the total number
        of hosts goes up or down.
        """
        yclient = YamClient(map(str, range(9)), connect=False)
        makeTestConnections(yclient)
        self.assertEqual(yclient.factories[6].client,
                         yclient.getClient('sdusdfsdf'))

        yclient = YamClient(map(str, range(10)), connect=False)
        makeTestConnections(yclient)
        self.assertEqual(yclient.factories[6].client,
                         yclient.getClient('sdusdfsdf'))

        yclient = YamClient(map(str, range(11)), connect=False)
        makeTestConnections(yclient)
        self.assertEqual(yclient.factories[6].client,
                         yclient.getClient('sdusdfsdf'))
Пример #5
0
    def test_getClientIsDistributed(self):
        yclient = YamClient(map(str, range(10)), connect=False)
        makeTestConnections(yclient)
        counts = {f.client: 0 for f in yclient.factories}
        for _ in xrange(200):
            client = yclient.getClient(str(uuid.uuid4()))
            counts[client] += 1

        # Expect at least 5% of the values are stored on each client
        for count in counts.values():
            self.assertTrue(count > 10)
Пример #6
0
    def test_getClientIsDistributed(self):
        yclient = YamClient(map(str, range(10)), connect=False)
        makeTestConnections(yclient)
        counts = {f.client: 0 for f in yclient.factories}
        for _ in xrange(200):
            client = yclient.getClient(str(uuid.uuid4()))
            counts[client] += 1

        # Expect at least 5% of the values are stored on each client
        for count in counts.values():
            self.assertTrue(count > 10)