PYTHON-885 - Support maxPoolSize URI option.
This commit is contained in:
parent
a08f16d9dc
commit
e405ef91cf
@ -336,7 +336,8 @@ VALIDATORS = {
|
||||
'gssapiservicename': validate_basestring,
|
||||
'authmechanismproperties': validate_auth_mechanism_properties,
|
||||
'uuidrepresentation': validate_uuid_representation,
|
||||
'socketkeepalive': validate_boolean
|
||||
'socketkeepalive': validate_boolean,
|
||||
'maxpoolsize': validate_positive_integer_or_none
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -140,6 +140,8 @@ class MongoClient(common.BaseObject):
|
||||
|
||||
| **Other optional parameters can be passed as keyword arguments:**
|
||||
|
||||
- `maxPoolSize` (optional): Alias for max_pool_size. Takes
|
||||
precedence over max_pool_size.
|
||||
- `socketTimeoutMS`: (integer or None) How long (in milliseconds) a
|
||||
send or receive on a socket can take before timing out. Defaults to
|
||||
``None`` (no timeout).
|
||||
@ -312,8 +314,10 @@ class MongoClient(common.BaseObject):
|
||||
options['codec_options'] = CodecOptions(
|
||||
document_class, tz_aware, uuid_representation)
|
||||
|
||||
self.__max_pool_size = common.validate_positive_integer_or_none(
|
||||
'max_pool_size', max_pool_size)
|
||||
self.__max_pool_size = options.get(
|
||||
'maxpoolsize',
|
||||
common.validate_positive_integer_or_none('max_pool_size',
|
||||
max_pool_size))
|
||||
|
||||
self.__cursor_manager = CursorManager(self)
|
||||
|
||||
|
||||
@ -490,6 +490,8 @@ class MongoReplicaSetClient(common.BaseObject):
|
||||
precedence.
|
||||
- `port`: For compatibility with :class:`~mongo_client.MongoClient`.
|
||||
The default port number to use for hosts.
|
||||
- `maxpoolsize` (optional): Alias for max_pool_size. Takes
|
||||
precendence over max_pool_size.
|
||||
- `socketTimeoutMS`: (integer or None) How long (in milliseconds) a
|
||||
send or receive on a socket can take before timing out. Defaults to
|
||||
``None`` (no timeout).
|
||||
@ -595,8 +597,6 @@ class MongoReplicaSetClient(common.BaseObject):
|
||||
self.__index_cache = {}
|
||||
self.__auth_credentials = {}
|
||||
|
||||
self.__max_pool_size = common.validate_positive_integer_or_none(
|
||||
'max_pool_size', max_pool_size)
|
||||
self.__monitor = None
|
||||
self.__closed = False
|
||||
|
||||
@ -633,6 +633,11 @@ class MongoReplicaSetClient(common.BaseObject):
|
||||
self.__opts[option] = value
|
||||
self.__opts.update(options)
|
||||
|
||||
self.__max_pool_size = self.__opts.get(
|
||||
'maxpoolsize',
|
||||
common.validate_positive_integer_or_none('max_pool_size',
|
||||
max_pool_size))
|
||||
|
||||
common.validate_boolean('tz_aware', tz_aware)
|
||||
uuid_representation = options.pop('uuidrepresentation', PYTHON_LEGACY)
|
||||
self.__opts['codec_options'] = CodecOptions(
|
||||
|
||||
@ -331,6 +331,31 @@ class TestClient(unittest.TestCase, TestRequestMixin):
|
||||
finally:
|
||||
ctx.exit()
|
||||
|
||||
def test_backport_maxpoolsize_uri(self):
|
||||
uri = "mongodb://%s:%s" % (host, port)
|
||||
mps_uri = ("mongodb://%s:%d/?maxPoolSize=10" % (host, port))
|
||||
|
||||
client = MongoClient(uri)
|
||||
self.assertEqual(client.max_pool_size, 100)
|
||||
|
||||
client = MongoClient(uri, maxPoolSize=10)
|
||||
self.assertEqual(client.max_pool_size, 10)
|
||||
|
||||
client = MongoClient(uri, max_pool_size=8, maxPoolSize=10)
|
||||
self.assertEqual(client.max_pool_size, 10)
|
||||
|
||||
client = MongoClient(mps_uri)
|
||||
self.assertEqual(client.max_pool_size, 10)
|
||||
|
||||
client = MongoClient(mps_uri, maxPoolSize=8)
|
||||
self.assertEqual(client.max_pool_size, 10)
|
||||
|
||||
client = MongoClient(mps_uri, max_pool_size=8)
|
||||
self.assertEqual(client.max_pool_size, 10)
|
||||
|
||||
client = MongoClient(mps_uri, max_pool_size=6, maxPoolSize=8)
|
||||
self.assertEqual(client.max_pool_size, 10)
|
||||
|
||||
def test_backport_localthresholdms_uri(self):
|
||||
uri = "mongodb://%s:%s" % (host, port)
|
||||
lt_uri = "mongodb://%s:%d/?localThresholdMS=10" % (host, port)
|
||||
|
||||
@ -402,6 +402,20 @@ class _TestPooling(_TestPoolingBase):
|
||||
c = MongoClient(host=host, port=port, max_pool_size=100)
|
||||
self.assertEqual(c.max_pool_size, 100)
|
||||
|
||||
def test_maxpoolsize_validation(self):
|
||||
self.assertRaises(
|
||||
ConfigurationError, MongoClient, host=host, port=port,
|
||||
maxpoolsize=-1
|
||||
)
|
||||
|
||||
self.assertRaises(
|
||||
ConfigurationError, MongoClient, host=host, port=port,
|
||||
maxpoolsize='foo'
|
||||
)
|
||||
|
||||
c = MongoClient(host=host, port=port, maxpoolsize=100)
|
||||
self.assertEqual(c.max_pool_size, 100)
|
||||
|
||||
def test_no_disconnect(self):
|
||||
run_cases(self, [NoRequest, NonUnique, Unique, SaveAndFind])
|
||||
|
||||
|
||||
@ -692,6 +692,12 @@ class TestReplicaSetClient(TestReplicaSetClientBase, TestRequestMixin):
|
||||
self.assertEqual(pool.wait_queue_multiple, 2)
|
||||
self.assertEqual(pool._socket_semaphore.waiter_semaphore.counter, 6)
|
||||
|
||||
def test_waitQueueMultiple_backport_maxpoolsize(self):
|
||||
client = self._get_client(maxpoolsize=3, waitQueueMultiple=2)
|
||||
pool = get_pool(client)
|
||||
self.assertEqual(pool.wait_queue_multiple, 2)
|
||||
self.assertEqual(pool._socket_semaphore.waiter_semaphore.counter, 6)
|
||||
|
||||
def test_socketKeepAlive(self):
|
||||
client = self._get_client(socketKeepAlive=True)
|
||||
pool = get_pool(client)
|
||||
@ -743,6 +749,32 @@ class TestReplicaSetClient(TestReplicaSetClientBase, TestRequestMixin):
|
||||
self.assertTrue("pymongo_test_bernie" in dbs)
|
||||
client.close()
|
||||
|
||||
def test_backport_repl_maxpoolsize_uri(self):
|
||||
uri = "mongodb://%s/?replicaSet=%s" % (pair, self.name)
|
||||
mps_uri = ("mongodb://%s/?replicaSet=%s;maxPoolSize=10"
|
||||
% (pair, self.name))
|
||||
|
||||
client = MongoReplicaSetClient(uri)
|
||||
self.assertEqual(client.max_pool_size, 100)
|
||||
|
||||
client = MongoReplicaSetClient(uri, maxPoolSize=10)
|
||||
self.assertEqual(client.max_pool_size, 10)
|
||||
|
||||
client = MongoReplicaSetClient(uri, max_pool_size=8, maxPoolSize=10)
|
||||
self.assertEqual(client.max_pool_size, 10)
|
||||
|
||||
client = MongoReplicaSetClient(mps_uri)
|
||||
self.assertEqual(client.max_pool_size, 10)
|
||||
|
||||
client = MongoReplicaSetClient(mps_uri, max_pool_size=8)
|
||||
self.assertEqual(client.max_pool_size, 10)
|
||||
|
||||
client = MongoReplicaSetClient(mps_uri, maxPoolSize=8)
|
||||
self.assertEqual(client.max_pool_size, 10)
|
||||
|
||||
client = MongoReplicaSetClient(mps_uri, max_pool_size=6, maxPoolSize=8)
|
||||
self.assertEqual(client.max_pool_size, 10)
|
||||
|
||||
def test_backport_repl_localthresholdms_uri(self):
|
||||
uri = ("mongodb://%s/?replicaSet=%s" % (pair, self.name))
|
||||
lt_uri = ("mongodb://%s/?replicaSet=%s;localThresholdMS=10"
|
||||
|
||||
@ -136,8 +136,7 @@ class TestURI(unittest.TestCase):
|
||||
self.assertRaises(ConfigurationError,
|
||||
split_options, 'authMechanism=foo')
|
||||
self.assertEqual({'authsource': 'foobar'}, split_options('authSource=foobar'))
|
||||
# maxPoolSize isn't yet a documented URI option.
|
||||
self.assertRaises(ConfigurationError, split_options, 'maxpoolsize=50')
|
||||
self.assertEqual({'maxpoolsize': 50}, split_options('maxpoolsize=50'))
|
||||
self.assertEqual({'localthresholdms': 300},
|
||||
split_options('localThresholdMS=300'))
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user