Exemplo n.º 1
0
 def setUp(self):
     self.count = 10
     self.client_pool = ClientPool(_server, self.count)
     self.client_mocks = []
     for i in range(0, self.count):
         mock = MockClient()
         self.client_mocks.append(mock)
         self.client_pool._free_clients.append(mock)
Exemplo n.º 2
0
 def setUp(self):
     self.client = MockClient()
     self.client_pool = ClientPool(_server, 1)
     self.client_pool._free_clients.append(self.client)
Exemplo n.º 3
0
class ClientPoolSingleClientTests(TestCase):
    def setUp(self):
        self.client = MockClient()
        self.client_pool = ClientPool(_server, 1)
        self.client_pool._free_clients.append(self.client)

    def test_set_value(self):
        result = self.client_pool.set(_TEST_KEY, _TEST_VALUE)
        self.assertTrue(result)
        self.assertEqual(_TEST_VALUE, self.client.data[_TEST_KEY])

    def test_get_value(self):
        self.client.data[_TEST_KEY] = _TEST_VALUE
        result = self.client_pool.get(_TEST_KEY)
        self.assertEqual(_TEST_VALUE, result)

    def test_get_no_value(self):
        result = self.client_pool.get(_TEST_KEY)
        self.assertEqual(_EMPTY_VALUE, result)

    def test_set_exists(self):
        result = self.client_pool.set(_TEST_KEY, _TEST_VALUE)
        self.assertTrue(result)
        result = self.client_pool.set(_TEST_KEY, _TEST_VALUE)
        self.assertFalse(result)

    def test_can_execute(self):
        self.assertTrue(self.client_pool.can_execute())
        self.client_pool._free_clients.clear()
        self.client_pool._used_clients.append(self.client)
        self.assertFalse(self.client_pool.can_execute())

    def test_max_clients_reached(self):
        with self.client_pool._client() as client1:
            with self.assertRaises(DriverConnectionLimitExceededException):
                self.assertFalse(self.client_pool.can_execute())
                with self.client_pool._client() as client2:
                    self.assertTrue(False)

    def test_max_clients_reached_unlocked(self):
        self.client_pool._free_clients.clear()
        self.client_pool._used_clients.append(self.client)
        with self.assertRaises(DriverConnectionLimitExceededException):
            with self.client_pool._client() as client:
                self.assertTrue(False)

    def test_can_execute_with_lock(self):
        self.assertTrue(self.client_pool.can_execute())
        with self.client_pool._client() as client:
            self.assertFalse(self.client_pool.can_execute())
            self.assertEqual(0, len(self.client_pool._free_clients))
            self.assertEqual(1, len(self.client_pool._used_clients))

    def test_dispose(self):
        self.client_pool.dispose()
        self.assertFalse(self.client.connected)
        self.assertEqual(0, len(self.client_pool._free_clients))