def test_parallel_scan(self): yield from skip_if_mongos(self.cx) collection = self.collection.with_options( write_concern=WriteConcern(test.env.w)) # Enough documents that each cursor requires multiple batches. yield from collection.delete_many({}) yield from collection.insert_many(({'_id': i} for i in range(8000))) if test.env.is_replica_set: # Test that getMore messages are sent to the right server. client = self.asyncio_rsc(read_preference=Secondary()) collection = client.motor_test.test_collection docs = [] @asyncio.coroutine def f(cursor): self.assertTrue(isinstance(cursor, AsyncIOMotorCommandCursor)) while (yield from cursor.fetch_next): docs.append(cursor.next_object()) cursors = yield from collection.parallel_scan(3) yield from asyncio.wait([f(cursor) for cursor in cursors], loop=self.loop) self.assertEqual(len(docs), (yield from collection.count_documents({})))
def test_parallel_scan(self): if not (yield from at_least(self.cx, (2, 5, 5))): raise SkipTest("Requires MongoDB >= 2.5.5") yield from skip_if_mongos(self.cx) collection = self.collection # Enough documents that each cursor requires multiple batches. yield from collection.remove() yield from collection.insert(({'_id': i} for i in range(8000)), w=test.env.w) if test.env.is_replica_set: client = self.asyncio_rsc() # Test that getMore messages are sent to the right server. client.read_preference = ReadPreference.SECONDARY collection = client.motor_test.test_collection docs = [] @asyncio.coroutine def f(cursor): self.assertTrue(isinstance(cursor, AsyncIOMotorCommandCursor)) while (yield from cursor.fetch_next): docs.append(cursor.next_object()) cursors = yield from collection.parallel_scan(3) yield from asyncio.wait( [f(cursor) for cursor in cursors], loop=self.loop) self.assertEqual(len(docs), (yield from collection.count()))
def test_copy_db_auth_concurrent(self): # SERVER-6427, can't copy database via mongos with auth. yield from skip_if_mongos(self.cx) n_copies = 2 test_db_names = ['motor_test_%s' % i for i in range(n_copies)] # 1. Drop old test DBs yield from self.cx.drop_database('motor_test') yield from self.collection.insert({'_id': 1}) yield from self.drop_databases(self.cx, test_db_names) # 2. Copy a test DB N times at once client = self.get_client() try: # self.cx is logged in as root. yield from self.cx.motor_test.add_user('mike', 'password') futures = [ client.copy_database('motor_test', test_db_name, username='******', password='******') for test_db_name in test_db_names ] results, _ = yield from asyncio.wait(futures, loop=self.loop) self.assertTrue(all(isinstance(i.result(), dict) for i in results)) yield from self.check_copydb_results(client, {'_id': 1}, test_db_names) finally: yield from remove_all_users(client.motor_test) yield from self.drop_databases(self.cx, test_db_names)
def test_parallel_scan(self): yield from skip_if_mongos(self.cx) collection = self.collection.with_options( write_concern=WriteConcern(test.env.w)) # Enough documents that each cursor requires multiple batches. yield from collection.delete_many({}) yield from collection.insert_many(({'_id': i} for i in range(8000))) if test.env.is_replica_set: # Test that getMore messages are sent to the right server. client = self.asyncio_rsc(read_preference=Secondary()) collection = client.motor_test.test_collection docs = [] @asyncio.coroutine def f(cursor): self.assertTrue(isinstance(cursor, AsyncIOMotorCommandCursor)) while (yield from cursor.fetch_next): docs.append(cursor.next_object()) cursors = yield from collection.parallel_scan(3) yield from asyncio.wait( [f(cursor) for cursor in cursors], loop=self.loop) self.assertEqual(len(docs), (yield from collection.count()))
def test_copy_db_auth_concurrent(self): # SERVER-6427, can't copy database via mongos with auth. yield from skip_if_mongos(self.cx) n_copies = 2 test_db_names = ['motor_test_%s' % i for i in range(n_copies)] # 1. Drop old test DBs yield from self.cx.drop_database('motor_test') yield from self.collection.insert({'_id': 1}) yield from self.drop_databases(self.cx, test_db_names) # 2. Copy a test DB N times at once client = self.get_client() try: # self.cx is logged in as root. yield from self.cx.motor_test.add_user('mike', 'password') futures = [ client.copy_database( 'motor_test', test_db_name, username='******', password='******') for test_db_name in test_db_names] results, _ = yield from asyncio.wait(futures, loop=self.loop) self.assertTrue(all(isinstance(i.result(), dict) for i in results)) yield from self.check_copydb_results( client, {'_id': 1}, test_db_names) finally: yield from remove_all_users(client.motor_test) yield from self.drop_databases(self.cx, test_db_names)
def test_copy_db_auth(self): # SERVER-6427, can't copy database via mongos with auth. yield from skip_if_mongos(self.cx) yield from self.collection.remove() yield from self.collection.insert({'_id': 1}) try: # self.cx is logged in as root. yield from self.cx.motor_test.add_user('mike', 'password') # This will catch any socket leaks. client = self.get_client(max_pool_size=1, waitQueueTimeoutMS=1) target_db_name = 'motor_test_2' with self.assertRaises(pymongo.errors.OperationFailure): yield from client.copy_database('motor_test', target_db_name, username='******', password='******') with self.assertRaises(pymongo.errors.OperationFailure): yield from client.copy_database('motor_test', target_db_name, username='******', password='******') # Copy a database using name and password. yield from client.copy_database('motor_test', target_db_name, username='******', password='******') self.assertEqual( {'_id': 1}, (yield from client[target_db_name].test_collection.find_one())) yield from client.drop_database(target_db_name) finally: yield from remove_all_users(self.cx.motor_test)
def test_copy_db_auth(self): # SERVER-6427, can't copy database via mongos with auth. yield from skip_if_mongos(self.cx) yield from self.collection.remove() yield from self.collection.insert({'_id': 1}) try: # self.cx is logged in as root. yield from self.cx.motor_test.add_user('mike', 'password') # This will catch any socket leaks. client = self.get_client(max_pool_size=1, waitQueueTimeoutMS=1) target_db_name = 'motor_test_2' with self.assertRaises(pymongo.errors.OperationFailure): yield from client.copy_database( 'motor_test', target_db_name, username='******', password='******') with self.assertRaises(pymongo.errors.OperationFailure): yield from client.copy_database( 'motor_test', target_db_name, username='******', password='******') # Copy a database using name and password. yield from client.copy_database( 'motor_test', target_db_name, username='******', password='******') self.assertEqual( {'_id': 1}, (yield from client[target_db_name].test_collection.find_one())) yield from client.drop_database(target_db_name) finally: yield from remove_all_users(self.cx.motor_test)