Ejemplo n.º 1
0
    def test_singleton_thread_failover(self):
        listener = _TestListener()
        pool = SingletonThreadPool(pool_size=5,
                                   keyspace='Keyspace1', credentials=_credentials,
                                   listeners=[listener],
                                   server_list=['localhost:9160', 'localhost:9160'])

        conn = pool.get()
        cf = ColumnFamily(conn, 'Standard1')

        for i in range(1,5):
            setattr(cf.client._local.conn.client, 'batch_mutate', _timeout)

            # The first insert attempt should fail, but failover should occur
            # and the insert should succeed
            cf.insert('key', {'col': 'val'})
            assert_equal(listener.failure_count, i)
            cf.get('key')

        pool.dispose()
        listener.reset()

        pool = SingletonThreadPool(pool_size=5,
                                   keyspace='Keyspace1', credentials=_credentials,
                                   listeners=[listener],
                                   server_list=['localhost:9160', 'localhost:9160'])

        threads = []
        args = (pool, 'key', {'col':'val'})
        for j in range(0,5):
            threads.append(threading.Thread(target=_five_tlocal_fails, args=args))
            threads[-1].start()
        for thread in threads:
            thread.join()

        assert_equal(listener.failure_count, 25)