def test_incoming_copy(**kwargs):
    handler = IncomingCopyHandler().getInstance()
    assert handler != None, "Should have a singleton"

    resource_data_database = s[config["couchdb.db.resourcedata"]]
    changes, incoming_database, initial_doc_count, num_docs = get_changes()
    prechanges_handler_thread_count = threading.activeCount()

    num_changes = 0

    ids = []
    for change in changes:
        num_changes += 1
        if "doc" in change and "doc_ID" in change["doc"]:
            ids.append(change["doc"]["doc_ID"])
        handler.handle(change, incoming_database)

    assert num_changes >= (initial_doc_count + num_docs), (
        "Not enough changes handled. Expected: %(expected)s Got: %(got)s"
        % {"expected": (initial_doc_count + num_docs), "got": num_changes}
    )
    # assert num_changes > 0, "There should be some changes."
    assert len(ids) > 0, "No ID's in changes."
    # while threading.activeCount() > prechanges_handler_thread_count:
    while handler.isRunning():
        time.sleep(0.5)
        log.info("Waiting for handler to stop. Current count %s", handler.threadCount())
    for doc_id in ids:
        try:
            assert resource_data_database[doc_id] is not None, "Expected document for _id: %s" % (doc_id)
        except couchdb.ResourceNotFound as rnf:
            assert rnf == None, "Expected to find document for _id: %s" % (doc_id,)
示例#2
0
def test_incoming_copy():
    handler = IncomingCopyHandler()
    resource_data_database = s[config['couchdb.db.resourcedata']]
    changes, incoming_database, initial_doc_count = get_changes()
    prechanges_handler_thread_count = threading.activeCount()
    ids = []
    for change in changes:
        if 'doc' in change and 'doc_ID' in change['doc']:
            ids.append(change['doc']['doc_ID'])
        handler.handle(change, incoming_database)
    while threading.activeCount() > prechanges_handler_thread_count:
        time.sleep(.5)
    for doc_id in ids:
        assert resource_data_database[doc_id] is not None
示例#3
0
def test_incoming_delete():
    handler = IncomingCopyHandler()
    changes, incoming_database, initial_doc_count = get_changes()
    prechanges_handler_thread_count = threading.activeCount()
    ids = []
    for change in changes:
        if 'doc' in change and 'doc_ID' in change['doc']:
            ids.append(change['doc']['doc_ID'])
        handler.handle(change, incoming_database)
    while threading.activeCount() > prechanges_handler_thread_count:
        time.sleep(.5)
    assert incoming_database.info()['doc_count'] == initial_doc_count
    resource_data_database = s[config['couchdb.db.resourcedata']]
    for i in ids:
        del resource_data_database[i]
示例#4
0
def test_incoming_delete(**kwargs):
    handler = IncomingCopyHandler().getInstance()
    assert handler != None, "Should have a singleton"

    changes, incoming_database, initial_doc_count, num_docs = get_changes()
    prechanges_handler_thread_count = threading.activeCount()
    ids = []

    num_changes = 0

    for change in changes:
        num_changes +=1
        if 'doc' in change and 'doc_ID' in change['doc']:
            ids.append(change['doc']['doc_ID'])
        handler.handle(change, incoming_database)
    
    assert num_changes >= (initial_doc_count + num_docs), "Not enough changes handled. Expected: %(expected)s Got: %(got)s" % {"expected":(initial_doc_count + num_docs), "got":num_changes}


    # while threading.activeCount() > prechanges_handler_thread_count:
    while handler.isRunning():
        time.sleep(.5)
        log.info("Waiting for handler to stop. Current count %s", handler.threadCount())
    assert incoming_database.info()['doc_count'] <= initial_doc_count, "Unexpected counts! Incoming: {0}  Initial Count {1}".format(incoming_database.info()['doc_count'], initial_doc_count)
    resource_data_database = s[config['couchdb.db.resourcedata']]
    for i in ids:
        try:
            del resource_data_database[i]
        except couchdb.ResourceNotFound as rnf:
            log.warning("Unable to delete _id: %s", i, exc_info=1)
示例#5
0
def test_incoming_copy(**kwargs):
    handler = IncomingCopyHandler().getInstance()
    assert handler != None, "Should have a singleton"

    resource_data_database = s[config['couchdb.db.resourcedata']]
    changes, incoming_database, initial_doc_count, num_docs = get_changes()
    prechanges_handler_thread_count = threading.activeCount()

    num_changes = 0

    ids = []
    for change in changes:
        num_changes +=1
        if 'doc' in change and 'doc_ID' in change['doc']:
            ids.append(change['doc']['doc_ID'])
        handler.handle(change, incoming_database)

    assert num_changes >= (initial_doc_count + num_docs), "Not enough changes handled. Expected: %(expected)s Got: %(got)s" % {"expected":(initial_doc_count + num_docs), "got":num_changes}
    # assert num_changes > 0, "There should be some changes."
    assert len(ids) > 0, "No ID's in changes."
    # while threading.activeCount() > prechanges_handler_thread_count:
    while handler.isRunning():
        time.sleep(.5)
        log.info("Waiting for handler to stop. Current count %s", handler.threadCount())
    for doc_id in ids:
        try:
            assert resource_data_database[doc_id] is not None, "Expected document for _id: %s" % (doc_id)
        except couchdb.ResourceNotFound as rnf:
            assert rnf==None, "Expected to find document for _id: %s" % (doc_id,)
def test_incoming_delete(**kwargs):
    handler = IncomingCopyHandler().getInstance()
    assert handler != None, "Should have a singleton"

    changes, incoming_database, initial_doc_count, num_docs = get_changes()
    prechanges_handler_thread_count = threading.activeCount()
    ids = []

    num_changes = 0

    for change in changes:
        num_changes += 1
        if "doc" in change and "doc_ID" in change["doc"]:
            ids.append(change["doc"]["doc_ID"])
        handler.handle(change, incoming_database)

    assert num_changes >= (initial_doc_count + num_docs), (
        "Not enough changes handled. Expected: %(expected)s Got: %(got)s"
        % {"expected": (initial_doc_count + num_docs), "got": num_changes}
    )

    # while threading.activeCount() > prechanges_handler_thread_count:
    while handler.isRunning():
        time.sleep(0.5)
        log.info("Waiting for handler to stop. Current count %s", handler.threadCount())
    assert (
        incoming_database.info()["doc_count"] <= initial_doc_count
    ), "Unexpected counts! Incoming: {0}  Initial Count {1}".format(
        incoming_database.info()["doc_count"], initial_doc_count
    )
    resource_data_database = s[config["couchdb.db.resourcedata"]]
    for i in ids:
        try:
            del resource_data_database[i]
        except couchdb.ResourceNotFound as rnf:
            log.warning("Unable to delete _id: %s", i, exc_info=1)