Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Clean up connection info test case

  • Loading branch information...
commit 8737061baf392ed7660700519e4edc4742e56183 1 parent 2d4c31e
@thobbs thobbs authored
Showing with 20 additions and 28 deletions.
  1. +20 −28 tests/test_connection_pooling.py
View
48 tests/test_connection_pooling.py
@@ -2,11 +2,10 @@
import unittest
import time
-from nose.tools import assert_raises, assert_equal
+from nose.tools import assert_raises, assert_equal, assert_true
from pycassa import ColumnFamily, ConnectionPool, PoolListener, InvalidRequestError,\
NoConnectionAvailable, MaximumRetryException, AllServersUnavailable
from pycassa.cassandra.c10.ttypes import ColumnPath
-from pycassa.pool import ConnectionWrapper
_credentials = {'username':'jsmith', 'password':'havebadpass'}
@@ -465,28 +464,27 @@ def test_queue_failure_with_no_retries(self):
pool.dispose()
- def test_queue_failure_connection_info(self):
- totest = {}
- listener = _TestListenerRequestInfo(totest)
- pool = ConnectionPool(pool_size=5, max_overflow=5, recycle=10000,
- prefill=True, max_retries=None,
+ def test_failure_connection_info(self):
+ listener = _TestListenerRequestInfo()
+ pool = ConnectionPool(pool_size=1, max_overflow=0, recycle=10000,
+ prefill=True, max_retries=0,
keyspace='PycassaTestKeyspace', credentials=_credentials,
- listeners=[listener], use_threadlocal=False,
+ listeners=[listener], use_threadlocal=True,
server_list=['localhost:9160'])
+ cf = ColumnFamily(pool, 'Counter1')
- connection_wrapper = ConnectionWrapper(pool, None, 'PycassaTestKeyspace', 'localhost:9160')
- #close it to force the error
- connection_wrapper.close()
-
- cp = ColumnPath('Standard1', column='1')
-
- try:
- connection_wrapper.get('greunt', cp, 1)
- except MaximumRetryException:
- pass
- print totest
- self.assertTrue('request' in totest['dic']['connection'].info)
+ # Corrupt the connection
+ conn = pool.get()
+ setattr(conn, 'send_get', conn._fail_once)
+ conn._should_fail = True
+ conn.return_to_pool()
+ assert_raises(MaximumRetryException, cf.get, 'greunt', columns=['col'])
+ assert_true('request' in listener.failure_dict['connection'].info)
+ request = listener.failure_dict['connection'].info['request']
+ assert_equal(request['method'], 'get')
+ assert_equal(request['args'], ('greunt', ColumnPath('Counter1', None, 'col'), 1))
+ assert_equal(request['kwargs'], {})
class _TestListener(PoolListener):
@@ -539,13 +537,7 @@ def pool_at_max(self, dic):
class _TestListenerRequestInfo(_TestListener):
- """"""
-
- def __init__(self, totest):
- """Constructor for _TestListenerRequestInfo"""
- super(_TestListenerRequestInfo, self).__init__()
- self.totest = totest
def connection_failed(self, dic):
- super(_TestListenerRequestInfo, self).connection_failed(dic)
- self.totest['dic'] = dic
+ _TestListener.connection_failed(self, dic)
+ self.failure_dict = dic
Please sign in to comment.
Something went wrong with that request. Please try again.