コード例 #1
0
from setup_cluster import killMongoProc, startMongoProc, start_cluster
from pymongo import Connection
from os import path
from threading import Timer
from elastic_doc_manager import DocManager
from mongo_connector import Connector
from optparse import OptionParser
from util import retry_until_ok
from pymongo.errors import ConnectionFailure, OperationFailure, AutoReconnect


""" Global path variables
"""
PORTS_ONE = {"PRIMARY": "27117", "SECONDARY": "27118", "ARBITER": "27119",
             "CONFIG": "27220", "MONGOS": "27217"}
elastic = DocManager('http://localhost:9200')
conn = None
NUMBER_OF_DOCS = 100


class TestSynchronizer(unittest.TestCase):

    c = None  # used for the connector

    def runTest(self):
        unittest.TestCase.__init__(self)

    def tearDown(self):
        self.c.doc_manager.auto_commit = False
        time.sleep(2)
        self.c.join()
コード例 #2
0
        for it in a:
            self.assertTrue('Paul' in it['name'])
        find_cursor = retry_until_ok(conn['test']['test'].find)
        self.assertEqual(retry_until_ok(find_cursor.count), NUMBER_OF_DOCS)

        print("PASSED TEST STRESSED ROLBACK")


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
    s = DocManager('http://localhost:9200', auto_commit=False)
    s._remove()
    start_cluster()

    conn = Connection('localhost:' + PORTS_ONE['MONGOS'],
                      replicaSet="demo-repl")
    unittest.main(argv=[sys.argv[0]])
コード例 #3
0
file = inspect.getfile(inspect.currentframe())
cmd_folder = os.path.realpath(os.path.abspath(os.path.split(file)[0]))
doc_folder = cmd_folder.rsplit("/", 2)[0]
doc_folder += '/doc_managers'
if doc_folder not in sys.path:
    sys.path.insert(0, doc_folder)

mongo_folder = cmd_folder.rsplit("/", 2)[0]
if mongo_folder not in sys.path:
    sys.path.insert(0, mongo_folder)

from elastic_doc_manager import DocManager
from pyes import ES, ESRange, RangeQuery, MatchAllQuery

ElasticDoc = DocManager("http://localhost:9200", auto_commit=False)
elastic = ES(server="http://localhost:9200")


class ElasticDocManagerTester(unittest.TestCase):
    """Test class for ElasticDocManager
    """
    def runTest(self):
        unittest.TestCase.__init__(self)

    def setUp(self):
        """Empty ElasticSearch at the start of every test
        """
        try:
            elastic.delete('test.test', 'string', '')
        except: