def test_connector(self): """Test whether the connector initiates properly """ c = Connector(main_address, 'config.txt', None, ['test.test'], '_id', None, None) c.start() while len(c.shard_set) != 1: time.sleep(2) c.join() self.assertFalse(c.can_run) time.sleep(5) for thread in c.shard_set.values(): self.assertFalse(thread.running)
def test_connector(self): """Test whether the connector initiates properly """ if not self.flag: self.fail("Shards cannot be added to mongos") conn = Connector(MAIN_ADDRESS, 'config.txt', None, ['test.test'], '_id', None, None) conn.start() while len(conn.shard_set) != 1: time.sleep(2) conn.join() self.assertFalse(conn.can_run) time.sleep(5) for thread in conn.shard_set.values(): self.assertFalse(thread.running)
class TestSynchronizer(unittest.TestCase): c = None # used for the Connector def runTest(self): unittest.TestCase.__init__(self) def setUp(self): self.c = Connector('localhost:' + PORTS_ONE["MAIN"], 'config.txt', 'http://localhost:8080/solr', ['test.test'], '_id', None, cmd_folder + '/../../doc_managers/solr_doc_manager.py') self.c.start() while len(self.c.shard_set) == 0: time.sleep(1) count = 0 while (True): try: conn['test']['test'].remove(safe=True) break except (AutoReconnect, OperationFailure): time.sleep(1) count += 1 if count > 60: string = 'Call to remove failed too many times' string += ' in setUp' logging.error(string) sys.exit(1) while (len(s.search('*:*')) != 0): time.sleep(1) def tearDown(self): self.c.doc_manager.auto_commit = False time.sleep(2) self.c.join() def test_shard_length(self): """Tests the shard_length to see if the shard set was recognized """ self.assertEqual(len(self.c.shard_set), 1) print("PASSED TEST SHARD LENGTH") def test_initial(self): """Tests search and assures that the databases are clear. """ while (True): try: conn['test']['test'].remove(safe=True) break except: continue s.delete(q='*:*') self.assertEqual(conn['test']['test'].find().count(), 0) self.assertEqual(len(s.search('*:*')), 0) print("PASSED TEST INITIAL") def test_insert(self): """Tests insert """ conn['test']['test'].insert({'name': 'paulie'}, safe=True) while (len(s.search('*:*')) == 0): time.sleep(1) a = s.search('paulie') self.assertEqual(len(a), 1) b = conn['test']['test'].find_one() for it in a: self.assertEqual(it['_id'], str(b['_id'])) self.assertEqual(it['name'], b['name']) print("PASSED TEST INSERT") def test_remove(self): """Tests remove """ conn['test']['test'].remove({'name': 'paulie'}, safe=True) while (len(s.search('*:*')) == 1): time.sleep(1) a = s.search('paulie') self.assertEqual(len(a), 0) print("PASSED TEST REMOVE") def test_rollback(self): """Tests rollback. We force a rollback by inserting one doc, killing primary, adding another doc, killing the new primary, and restarting both the servers. """ primary_conn = Connection('localhost', int(PORTS_ONE['PRIMARY'])) conn['test']['test'].insert({'name': 'paul'}, safe=True) while conn['test']['test'].find({'name': 'paul'}).count() != 1: time.sleep(1) while len(s.search('*:*')) != 1: time.sleep(1) killMongoProc('localhost', PORTS_ONE['PRIMARY']) new_primary_conn = Connection('localhost', int(PORTS_ONE['SECONDARY'])) admin_db = new_primary_conn['admin'] while admin_db.command("isMaster")['ismaster'] is False: time.sleep(1) time.sleep(5) count = 0 while True: try: a = conn['test']['test'].insert({'name': 'pauline'}, safe=True) break except: count += 1 if count > 60: string = 'Call to insert failed too many times' string += ' in test_rollback' logging.error(string) sys.exit(1) time.sleep(1) continue while (len(s.search('*:*')) != 2): time.sleep(1) a = s.search('pauline') b = conn['test']['test'].find_one({'name': 'pauline'}) self.assertEqual(len(a), 1) for it in a: self.assertEqual(it['_id'], str(b['_id'])) killMongoProc('localhost', PORTS_ONE['SECONDARY']) startMongoProc(PORTS_ONE['PRIMARY'], "demo-repl", "/replset1a", "/replset1a.log", None) while primary_conn['admin'].command("isMaster")['ismaster'] is False: time.sleep(1) startMongoProc(PORTS_ONE['SECONDARY'], "demo-repl", "/replset1b", "/replset1b.log", None) time.sleep(2) a = s.search('pauline') self.assertEqual(len(a), 0) a = s.search('paul') self.assertEqual(len(a), 1) print("PASSED TEST ROLLBACK") def test_stress(self): """Test stress by inserting and removing a large amount of docs. """ #stress test for i in range(0, NUMBER_OF_DOCS): conn['test']['test'].insert({'name': 'Paul ' + str(i)}) time.sleep(5) while len(s.search('*:*', rows=NUMBER_OF_DOCS)) != NUMBER_OF_DOCS: time.sleep(5) for i in range(0, NUMBER_OF_DOCS): a = s.search('Paul ' + str(i)) b = conn['test']['test'].find_one({'name': 'Paul ' + str(i)}) for it in a: self.assertEqual(it['_id'], it['_id']) print("PASSED TEST STRESS") def test_stressed_rollback(self): """Test stressed rollback with number of documents equal to specified in global variable. The rollback is performed the same way as before but with more docs """ conn['test']['test'].remove() while len(s.search('*:*', rows=NUMBER_OF_DOCS)) != 0: time.sleep(1) for i in range(0, NUMBER_OF_DOCS): conn['test']['test'].insert({'name': 'Paul ' + str(i)}, safe=True) while len(s.search('*:*', rows=NUMBER_OF_DOCS)) != NUMBER_OF_DOCS: time.sleep(1) primary_conn = Connection('localhost', int(PORTS_ONE['PRIMARY'])) killMongoProc('localhost', PORTS_ONE['PRIMARY']) new_primary_conn = Connection('localhost', int(PORTS_ONE['SECONDARY'])) admin_db = new_primary_conn['admin'] while admin_db.command("isMaster")['ismaster'] is False: time.sleep(1) time.sleep(5) count = -1 while count + 1 < NUMBER_OF_DOCS: try: count += 1 conn['test']['test'].insert({'name': 'Pauline ' + str(count)}, safe=True) except (OperationFailure, AutoReconnect): time.sleep(1) while (len(s.search('*:*', rows=NUMBER_OF_DOCS * 2)) != conn['test']['test'].find().count()): time.sleep(1) a = s.search('Pauline', rows=NUMBER_OF_DOCS * 2, sort='_id asc') for it in a: b = conn['test']['test'].find_one({'name': it['name']}) self.assertEqual(it['_id'], str(b['_id'])) killMongoProc('localhost', PORTS_ONE['SECONDARY']) startMongoProc(PORTS_ONE['PRIMARY'], "demo-repl", "/replset1a", "/replset1a.log", None) while primary_conn['admin'].command("isMaster")['ismaster'] is False: time.sleep(1) startMongoProc(PORTS_ONE['SECONDARY'], "demo-repl", "/replset1b", "/replset1b.log", None) while (len(s.search('Pauline', rows=NUMBER_OF_DOCS * 2)) != 0): time.sleep(15) a = s.search('Pauline', rows=NUMBER_OF_DOCS * 2) self.assertEqual(len(a), 0) a = s.search('Paul', rows=NUMBER_OF_DOCS * 2) self.assertEqual(len(a), NUMBER_OF_DOCS) print("PASSED TEST STRESSED ROLBACK") def abort_test(self): print("TEST FAILED") sys.exit(1)
parser = OptionParser() #-m is for the main address, which is a host:port pair, ideally of the #mongos. For non sharded clusters, it can be the primary. parser.add_option("-m", "--main", action="store", type="string", dest="main_addr", default="27217") (options, args) = parser.parse_args() PORTS_ONE['MONGOS'] = options.main_addr connection = Connector('localhost:' + PORTS_ONE["MONGOS"], 'config.txt', None, ['test.test'], '_id', None, None) doc_manager = connection.doc_manager if options.main_addr != "27217": start_cluster(use_mongos=False) else: start_cluster() conn = Connection('localhost:' + PORTS_ONE['MONGOS'], replicaSet="demo-repl") t = Timer(60, abort_test) t.start() connection.start() while len(connection.shard_set) == 0: pass t.cancel() unittest.main(argv=[sys.argv[0]]) connection.join()
class TestSynchronizer(unittest.TestCase): c = None # used for the Connector def runTest(self): unittest.TestCase.__init__(self) def setUp(self): self.c = Connector( 'localhost:' + PORTS_ONE["MAIN"], 'config.txt', 'http://localhost:8080/solr', ['test.test'], '_id', None, cmd_folder + '/../../doc_managers/solr_doc_manager.py') self.c.start() while len(self.c.shard_set) == 0: time.sleep(1) count = 0 while (True): try: conn['test']['test'].remove(safe=True) break except (AutoReconnect, OperationFailure): time.sleep(1) count += 1 if count > 60: string = 'Call to remove failed too many times' string += ' in setUp' logging.error(string) sys.exit(1) while (len(s.search('*:*')) != 0): time.sleep(1) def tearDown(self): self.c.doc_manager.auto_commit = False time.sleep(2) self.c.join() def test_shard_length(self): """Tests the shard_length to see if the shard set was recognized """ self.assertEqual(len(self.c.shard_set), 1) print("PASSED TEST SHARD LENGTH") def test_initial(self): """Tests search and assures that the databases are clear. """ while (True): try: conn['test']['test'].remove(safe=True) break except: continue s.delete(q='*:*') self.assertEqual(conn['test']['test'].find().count(), 0) self.assertEqual(len(s.search('*:*')), 0) print("PASSED TEST INITIAL") def test_insert(self): """Tests insert """ conn['test']['test'].insert({'name': 'paulie'}, safe=True) while (len(s.search('*:*')) == 0): time.sleep(1) a = s.search('paulie') self.assertEqual(len(a), 1) b = conn['test']['test'].find_one() for it in a: self.assertEqual(it['_id'], str(b['_id'])) self.assertEqual(it['name'], b['name']) print("PASSED TEST INSERT") def test_remove(self): """Tests remove """ conn['test']['test'].remove({'name': 'paulie'}, safe=True) while (len(s.search('*:*')) == 1): time.sleep(1) a = s.search('paulie') self.assertEqual(len(a), 0) print("PASSED TEST REMOVE") def test_rollback(self): """Tests rollback. We force a rollback by inserting one doc, killing primary, adding another doc, killing the new primary, and restarting both the servers. """ primary_conn = Connection('localhost', int(PORTS_ONE['PRIMARY'])) conn['test']['test'].insert({'name': 'paul'}, safe=True) while conn['test']['test'].find({'name': 'paul'}).count() != 1: time.sleep(1) while len(s.search('*:*')) != 1: time.sleep(1) killMongoProc('localhost', PORTS_ONE['PRIMARY']) new_primary_conn = Connection('localhost', int(PORTS_ONE['SECONDARY'])) admin_db = new_primary_conn['admin'] while admin_db.command("isMaster")['ismaster'] is False: time.sleep(1) time.sleep(5) count = 0 while True: try: a = conn['test']['test'].insert({'name': 'pauline'}, safe=True) break except: count += 1 if count > 60: string = 'Call to insert failed too many times' string += ' in test_rollback' logging.error(string) sys.exit(1) time.sleep(1) continue while (len(s.search('*:*')) != 2): time.sleep(1) a = s.search('pauline') b = conn['test']['test'].find_one({'name': 'pauline'}) self.assertEqual(len(a), 1) for it in a: self.assertEqual(it['_id'], str(b['_id'])) killMongoProc('localhost', PORTS_ONE['SECONDARY']) startMongoProc(PORTS_ONE['PRIMARY'], "demo-repl", "/replset1a", "/replset1a.log", None) while primary_conn['admin'].command("isMaster")['ismaster'] is False: time.sleep(1) startMongoProc(PORTS_ONE['SECONDARY'], "demo-repl", "/replset1b", "/replset1b.log", None) time.sleep(2) a = s.search('pauline') self.assertEqual(len(a), 0) a = s.search('paul') self.assertEqual(len(a), 1) print("PASSED TEST ROLLBACK") def test_stress(self): """Test stress by inserting and removing a large amount of docs. """ #stress test for i in range(0, NUMBER_OF_DOCS): conn['test']['test'].insert({'name': 'Paul ' + str(i)}) time.sleep(5) while len(s.search('*:*', rows=NUMBER_OF_DOCS)) != NUMBER_OF_DOCS: time.sleep(5) for i in range(0, NUMBER_OF_DOCS): a = s.search('Paul ' + str(i)) b = conn['test']['test'].find_one({'name': 'Paul ' + str(i)}) for it in a: self.assertEqual(it['_id'], it['_id']) print("PASSED TEST STRESS") def test_stressed_rollback(self): """Test stressed rollback with number of documents equal to specified in global variable. The rollback is performed the same way as before but with more docs """ conn['test']['test'].remove() while len(s.search('*:*', rows=NUMBER_OF_DOCS)) != 0: time.sleep(1) for i in range(0, NUMBER_OF_DOCS): conn['test']['test'].insert({'name': 'Paul ' + str(i)}, safe=True) while len(s.search('*:*', rows=NUMBER_OF_DOCS)) != NUMBER_OF_DOCS: time.sleep(1) primary_conn = Connection('localhost', int(PORTS_ONE['PRIMARY'])) killMongoProc('localhost', PORTS_ONE['PRIMARY']) new_primary_conn = Connection('localhost', int(PORTS_ONE['SECONDARY'])) admin_db = new_primary_conn['admin'] while admin_db.command("isMaster")['ismaster'] is False: time.sleep(1) time.sleep(5) count = -1 while count + 1 < NUMBER_OF_DOCS: try: count += 1 conn['test']['test'].insert({'name': 'Pauline ' + str(count)}, safe=True) except (OperationFailure, AutoReconnect): time.sleep(1) while (len(s.search('*:*', rows=NUMBER_OF_DOCS * 2)) != conn['test']['test'].find().count()): time.sleep(1) a = s.search('Pauline', rows=NUMBER_OF_DOCS * 2, sort='_id asc') for it in a: b = conn['test']['test'].find_one({'name': it['name']}) self.assertEqual(it['_id'], str(b['_id'])) killMongoProc('localhost', PORTS_ONE['SECONDARY']) startMongoProc(PORTS_ONE['PRIMARY'], "demo-repl", "/replset1a", "/replset1a.log", None) while primary_conn['admin'].command("isMaster")['ismaster'] is False: time.sleep(1) startMongoProc(PORTS_ONE['SECONDARY'], "demo-repl", "/replset1b", "/replset1b.log", None) while (len(s.search('Pauline', rows=NUMBER_OF_DOCS * 2)) != 0): time.sleep(15) a = s.search('Pauline', rows=NUMBER_OF_DOCS * 2) self.assertEqual(len(a), 0) a = s.search('Paul', rows=NUMBER_OF_DOCS * 2) self.assertEqual(len(a), NUMBER_OF_DOCS) print("PASSED TEST STRESSED ROLBACK") def abort_test(self): print("TEST FAILED") sys.exit(1)
print ("PASSED INITIAL DUMP TEST") def abort_test(self): print("TEST FAILED") sys.exit(1) if __name__ == '__main__': os.system('rm config.txt; touch config.txt') parser = OptionParser() #-m is for the main address, which is a host:port pair, ideally of the #mongos. For non sharded clusters, it can be the primary. parser.add_option("-m", "--main", action="store", type="string", dest="main_addr", default="27217") (options, args) = parser.parse_args() PORTS_ONE['MONGOS'] = options.main_addr connector = Connector('localhost:' + PORTS_ONE["MONGOS"], 'config.txt', None, ['test.test'], '_id', None, None) doc_manager = connector.doc_manager if options.main_addr != "27217": start_cluster(use_mongos=False) else: start_cluster() conn = Connection('localhost:' + PORTS_ONE['MONGOS'], replicaSet="demo-repl") unittest.main(argv=[sys.argv[0]]) connector.join()
if __name__ == '__main__': os.system('rm config.txt; touch config.txt') parser = OptionParser() #-m is for the main address, which is a host:port pair, ideally of the #mongos. For non sharded clusters, it can be the primary. parser.add_option("-m", "--main", action="store", type="string", dest="main_addr", default="27217") (options, args) = parser.parse_args() PORTS_ONE['MONGOS'] = options.main_addr connection = Connector('localhost:' + PORTS_ONE["MONGOS"], 'config.txt', None, ['test.test'], '_id', None, None) doc_manager = connection.doc_manager if options.main_addr != "27217": start_cluster(use_mongos=False) else: start_cluster() conn = Connection('localhost:' + PORTS_ONE['MONGOS'], replicaSet="demo-repl") t = Timer(60, abort_test) t.start() connection.start() while len(connection.shard_set) == 0: pass t.cancel() unittest.main(argv=[sys.argv[0]]) connection.join()
if __name__ == '__main__': os.system('rm config.txt; touch config.txt') parser = OptionParser() #-m is for the main address, which is a host:port pair, ideally of the #mongos. For non sharded clusters, it can be the primary. parser.add_option("-m", "--main", action="store", type="string", dest="main_addr", default="27217") (options, args) = parser.parse_args() PORTS_ONE['MONGOS'] = options.main_addr c = Connector('localhost:' + PORTS_ONE["MONGOS"], 'config.txt', None, ['test.test'], '_id', None, None) s = c.doc_manager if options.main_addr != "27217": start_cluster(use_mongos=False) else: start_cluster() conn = Connection('localhost:' + PORTS_ONE['MONGOS'], replicaSet="demo-repl") t = Timer(60, abort_test) t.start() c.start() while len(c.shard_set) == 0: pass t.cancel() unittest.main(argv=[sys.argv[0]]) c.join()
print("TEST FAILED") sys.exit(1) if __name__ == '__main__': os.system('rm config.txt; touch config.txt') parser = OptionParser() #-m is for the main address, which is a host:port pair, ideally of the #mongos. For non sharded clusters, it can be the primary. parser.add_option("-m", "--main", action="store", type="string", dest="main_addr", default="27217") (options, args) = parser.parse_args() PORTS_ONE['MONGOS'] = options.main_addr connector = Connector('localhost:' + PORTS_ONE["MONGOS"], 'config.txt', None, ['test.test'], '_id', None, None) doc_manager = connector.doc_manager if options.main_addr != "27217": start_cluster(use_mongos=False) else: start_cluster() conn = Connection('localhost:' + PORTS_ONE['MONGOS'], replicaSet="demo-repl") unittest.main(argv=[sys.argv[0]]) connector.join()
parser = OptionParser() #-m is for the main address, which is a host:port pair, ideally of the #mongos. For non sharded clusters, it can be the primary. parser.add_option("-m", "--main", action="store", type="string", dest="main_addr", default="27217") (options, args) = parser.parse_args() PORTS_ONE['MONGOS'] = options.main_addr c = Connector('localhost:' + PORTS_ONE["MONGOS"], 'config.txt', None, ['test.test'], '_id', None, None) s = c.doc_manager if options.main_addr != "27217": start_cluster(use_mongos=False) else: start_cluster() conn = Connection('localhost:' + PORTS_ONE['MONGOS'], replicaSet="demo-repl") t = Timer(60, abort_test) t.start() c.start() while len(c.shard_set) == 0: pass t.cancel() unittest.main(argv=[sys.argv[0]]) c.join()
class TestSynchronizer(unittest.TestCase): """ Tests Solr """ def runTest(self): """ Runs tests """ unittest.TestCase.__init__(self) @classmethod def setUpClass(cls): cls.flag = start_cluster() if cls.flag: cls.conn = Connection('localhost:' + PORTS_ONE['MAIN'], replicaSet="demo-repl") # Creating a Solr object with an invalid URL # doesn't create an exception cls.solr_conn = Solr('http://localhost:8983/solr') try: cls.solr_conn.commit() except (SolrError, MissingSchema): cls.err_msg = "Cannot connect to Solr!" cls.flag = False if cls.flag: cls.solr_conn.delete(q='*:*') else: cls.err_msg = "Shards cannot be added to mongos" def setUp(self): if not self.flag: self.fail(self.err_msg) self.connector = Connector('localhost:' + PORTS_ONE["MAIN"], 'config.txt', 'http://localhost:8983/solr', ['test.test'], '_id', None, '../mongo_connector/doc_managers/solr_doc_manager.py') self.connector.start() while len(self.connector.shard_set) == 0: time.sleep(1) count = 0 while (True): try: self.conn['test']['test'].remove(safe=True) break except (AutoReconnect, OperationFailure): time.sleep(1) count += 1 if count > 60: unittest.SkipTest('Call to remove failed too ' 'many times in setup') while (len(self.solr_conn.search('*:*')) != 0): time.sleep(1) def tearDown(self): self.connector.doc_manager.auto_commit = False time.sleep(2) self.connector.join() def test_shard_length(self): """Tests the shard_length to see if the shard set was recognized """ self.assertEqual(len(self.connector.shard_set), 1) def test_initial(self): """Tests search and assures that the databases are clear. """ while (True): try: self.conn['test']['test'].remove(safe=True) break except OperationFailure: continue self.solr_conn.delete(q='*:*') self.assertEqual(self.conn['test']['test'].find().count(), 0) self.assertEqual(len(self.solr_conn.search('*:*')), 0) def test_insert(self): """Tests insert """ self.conn['test']['test'].insert({'name': 'paulie'}, safe=True) while (len(self.solr_conn.search('*:*')) == 0): time.sleep(1) result_set_1 = self.solr_conn.search('paulie') self.assertEqual(len(result_set_1), 1) result_set_2 = self.conn['test']['test'].find_one() for item in result_set_1: self.assertEqual(item['_id'], str(result_set_2['_id'])) self.assertEqual(item['name'], result_set_2['name']) def test_remove(self): """Tests remove """ self.conn['test']['test'].remove({'name': 'paulie'}, safe=True) while (len(self.solr_conn.search('*:*')) == 1): time.sleep(1) result_set_1 = self.solr_conn.search('paulie') self.assertEqual(len(result_set_1), 0) def test_rollback(self): """Tests rollback. We force a rollback by inserting one doc, killing primary, adding another doc, killing the new primary, and restarting both the servers. """ primary_conn = Connection('localhost', int(PORTS_ONE['PRIMARY'])) self.conn['test']['test'].insert({'name': 'paul'}, safe=True) while self.conn['test']['test'].find({'name': 'paul'}).count() != 1: time.sleep(1) while len(self.solr_conn.search('*:*')) != 1: time.sleep(1) kill_mongo_proc('localhost', PORTS_ONE['PRIMARY']) new_primary_conn = Connection('localhost', int(PORTS_ONE['SECONDARY'])) admin_db = new_primary_conn['admin'] while admin_db.command("isMaster")['ismaster'] is False: time.sleep(1) time.sleep(5) count = 0 while True: try: self.conn['test']['test'].insert( {'name': 'pauline'}, safe=True) break except OperationFailure: count += 1 if count > 60: self.fail('Call to insert failed too ' 'many times in test_rollback') time.sleep(1) continue while (len(self.solr_conn.search('*:*')) != 2): time.sleep(1) result_set_1 = self.solr_conn.search('pauline') result_set_2 = self.conn['test']['test'].find_one({'name': 'pauline'}) self.assertEqual(len(result_set_1), 1) for item in result_set_1: self.assertEqual(item['_id'], str(result_set_2['_id'])) kill_mongo_proc('localhost', PORTS_ONE['SECONDARY']) start_mongo_proc(PORTS_ONE['PRIMARY'], "demo-repl", "/replset1a", "/replset1a.log", None) while primary_conn['admin'].command("isMaster")['ismaster'] is False: time.sleep(1) start_mongo_proc(PORTS_ONE['SECONDARY'], "demo-repl", "/replset1b", "/replset1b.log", None) time.sleep(2) result_set_1 = self.solr_conn.search('pauline') self.assertEqual(len(result_set_1), 0) result_set_2 = self.solr_conn.search('paul') self.assertEqual(len(result_set_2), 1) def test_stress(self): """Test stress by inserting and removing a large amount of docs. """ #stress test for i in range(0, NUMBER_OF_DOC_DIRS): self.conn['test']['test'].insert({'name': 'Paul ' + str(i)}) time.sleep(5) while (len(self.solr_conn.search('*:*', rows=NUMBER_OF_DOC_DIRS)) != NUMBER_OF_DOC_DIRS): time.sleep(5) for i in range(0, NUMBER_OF_DOC_DIRS): result_set_1 = self.solr_conn.search('Paul ' + str(i)) for item in result_set_1: self.assertEqual(item['_id'], item['_id']) def test_stressed_rollback(self): """Test stressed rollback with number of documents equal to specified in global variable. The rollback is performed the same way as before but with more docs """ self.conn['test']['test'].remove() while len(self.solr_conn.search('*:*', rows=NUMBER_OF_DOC_DIRS)) != 0: time.sleep(1) for i in range(0, NUMBER_OF_DOC_DIRS): self.conn['test']['test'].insert( {'name': 'Paul ' + str(i)}, safe=True) while (len(self.solr_conn.search('*:*', rows=NUMBER_OF_DOC_DIRS)) != NUMBER_OF_DOC_DIRS): time.sleep(1) primary_conn = Connection('localhost', int(PORTS_ONE['PRIMARY'])) kill_mongo_proc('localhost', PORTS_ONE['PRIMARY']) new_primary_conn = Connection('localhost', int(PORTS_ONE['SECONDARY'])) admin_db = new_primary_conn['admin'] while admin_db.command("isMaster")['ismaster'] is False: time.sleep(1) time.sleep(5) count = -1 while count + 1 < NUMBER_OF_DOC_DIRS: try: count += 1 self.conn['test']['test'].insert( {'name': 'Pauline ' + str(count)}, safe=True) except (OperationFailure, AutoReconnect): time.sleep(1) while (len(self.solr_conn.search('*:*', rows=NUMBER_OF_DOC_DIRS * 2)) != self.conn['test']['test'].find().count()): time.sleep(1) result_set_1 = self.solr_conn.search('Pauline', rows=NUMBER_OF_DOC_DIRS * 2, sort='_id asc') for item in result_set_1: result_set_2 = self.conn['test']['test'].find_one( {'name': item['name']}) self.assertEqual(item['_id'], str(result_set_2['_id'])) kill_mongo_proc('localhost', PORTS_ONE['SECONDARY']) start_mongo_proc(PORTS_ONE['PRIMARY'], "demo-repl", "/replset1a", "/replset1a.log", None) while primary_conn['admin'].command("isMaster")['ismaster'] is False: time.sleep(1) start_mongo_proc(PORTS_ONE['SECONDARY'], "demo-repl", "/replset1b", "/replset1b.log", None) while (len(self.solr_conn.search('Pauline', rows=NUMBER_OF_DOC_DIRS * 2)) != 0): time.sleep(15) result_set_1 = self.solr_conn.search('Pauline', rows=NUMBER_OF_DOC_DIRS * 2) self.assertEqual(len(result_set_1), 0) result_set_2 = self.solr_conn.search('Paul', rows=NUMBER_OF_DOC_DIRS * 2) self.assertEqual(len(result_set_2), NUMBER_OF_DOC_DIRS)