def test_large_aol_append_time():
    """Question: How long does it take to append to a large AOL file on disk?

        >>> [('aol-size-1.txt', 0.00011014938354492188),
        ...  ('aol-size-10.txt', 0.000102996826171875),
        ...  ('aol-size-100.txt', 0.00010323524475097656),
        ...  ('aol-size-1000.txt', 0.00010609626770019531),
        ...  ('aol-size-10000.txt', 0.00010776519775390625),
        ...  ('aol-size-100000.txt', 0.0001049041748046875),
        ...  ('aol-size-1000000.txt', 0.000141143798828125)]

    """
    fnames = sorted(fn for fn in os.listdir(utils.RESOURCES_PATH))
    runs = []
    for fn in fnames:
        aol_path = os.path.join(utils.RESOURCES_PATH, fn)
        aol = aol_mod.get_aol(aol_path)
        aol_to_add = utils.generate_large_test_aol(1)
        t1 = time.time()
        for quad in aol_to_add:
            aol = aol_mod.append_to_aol(aol, quad)
        t2 = time.time()
        tot_time = t2 - t1
        runs.append((fn, tot_time))
    pprint.pprint(runs)
Esempio n. 2
0
def generate_test_aol():
    """Return an AOL list of Appendable (tuple) instances
    (encoding 2 ``OLDInstance``s).
    """
    test_old_instance_1, err = domain.construct_old_instance(
        slug='oka',
        name='Okanagan OLD',
        url='http://127.0.0.1:5679/oka',
        leader='',
        state=domain.NOT_SYNCED_STATE,
        is_auto_syncing=False)
    test_old_instance_2, err = domain.construct_old_instance(
        slug='bla',
        name='Blackfoot OLD',
        url='http://127.0.0.1:5679/bla',
        leader='',
        state=domain.NOT_SYNCED_STATE,
        is_auto_syncing=False)
    test_old_instance_1_quads = aol_mod.instance_to_quads(
        test_old_instance_1, domain.OLD_INSTANCE_TYPE)
    test_old_instance_2_quads = aol_mod.instance_to_quads(
        test_old_instance_2, domain.OLD_INSTANCE_TYPE)
    aol = []
    for quad in test_old_instance_1_quads + test_old_instance_2_quads:
        aol = aol_mod.append_to_aol(aol, quad)
    return aol
Esempio n. 3
0
def generate_large_test_aol(n_old_instances):
    """Return an AOL enxoding ``n_old_instances`` OLDInstances."""
    aol = []
    for _ in range(n_old_instances):
        test_old_instance, err = domain.construct_old_instance(
            slug='oka',
            name='Okanagan OLD',
            url='http://127.0.0.1:5679/oka',
            leader='',
            state=domain.NOT_SYNCED_STATE,
            is_auto_syncing=False)
        for quad in aol_mod.instance_to_quads(test_old_instance,
                                              domain.OLD_INSTANCE_TYPE):
            aol = aol_mod.append_to_aol(aol, quad)
    return aol
Esempio n. 4
0
def generate_oi_quads():
    """Return a list of quads representing a single OI, OLDInstance.
    """
    old_instance, err = domain.construct_old_instance(
        slug='oka',
        name='Okanagan OLD',
        url='http://127.0.0.1:5679/oka',
        leader='',
        state=domain.NOT_SYNCED_STATE,
        is_auto_syncing=False)
    old_instance_quads = aol_mod.instance_to_quads(old_instance,
                                                   domain.OLD_INSTANCE_TYPE)
    aol = []
    for quad in old_instance_quads:
        aol = aol_mod.append_to_aol(aol, quad)
    return aol
Esempio n. 5
0
def _calculate_aol_from_domain_entities_dict(domain_entities):
    """Return an AOL encoding the domain entities in the dict
    ``domain_entities``. Expected shape of ``domain_entities`` is a dict from
    strings (pluralized names of domain entities) to sets of named tuples,
    where each named tuple represents a single domain entity::

        {'dative-apps': {DativeApp(url='http://127.0.0.1:5678/')},
         'old-instances': {
             OLDInstance(slug='abc', name='', url='...', leader='',
                         state='not synced', is_auto_syncing=False),
             OLDInstance(slug='def', name='', url='...', leader='',
                         state='not synced', is_auto_syncing=False)},
         'old-services': {OLDService(url='http://127.0.0.1:5679/')}}
    """
    aol = []
    for domain_entity_coll_name, domain_entity_set in domain_entities.items():
        domain_entity_type = domain_entity_coll_name[:-1]
        for domain_entity in domain_entity_set:
            for quad in aol_mod.instance_to_quads(domain_entity,
                                                  domain_entity_type):
                aol = aol_mod.append_to_aol(aol, quad)
    return aol
Esempio n. 6
0
def generate_test_aol():
    """Return an AOL encoding 2 OLDInstances, 1 DativeApp and 1 OLDService
    """
    old_instance_1, _ = domain.construct_old_instance(
        slug='oka',
        name='Okanagan OLD',
        url='http://127.0.0.1:5679/oka',
        leader='',
        state=domain.NOT_SYNCED_STATE,
        is_auto_syncing=False)
    old_instance_2, _ = domain.construct_old_instance(
        slug='bla',
        name='Blackfoot OLD',
        url='http://127.0.0.1:5679/bla',
        leader='',
        state=domain.NOT_SYNCED_STATE,
        is_auto_syncing=False)
    dative_app, _ = domain.construct_dative_app(url='http://127.0.0.1:5678/')
    old_service, _ = domain.construct_old_service(url='http://127.0.0.1:5679/')
    old_instance_1_quads = aol_mod.instance_to_quads(old_instance_1,
                                                     domain.OLD_INSTANCE_TYPE)
    old_instance_2_quads = aol_mod.instance_to_quads(old_instance_2,
                                                     domain.OLD_INSTANCE_TYPE)
    dative_app_quads = aol_mod.instance_to_quads(dative_app,
                                                 domain.DATIVE_APP_TYPE)
    old_service_quads = aol_mod.instance_to_quads(old_service,
                                                  domain.OLD_SERVICE_TYPE)
    quads = (old_instance_1_quads + old_instance_2_quads + dative_app_quads +
             old_service_quads)
    aol = []
    for quad in quads:
        aol = aol_mod.append_to_aol(aol, quad)
    domain_entities = {
        'old-instances': set([old_instance_1, old_instance_2]),
        'dative-apps': set([dative_app]),
        'old-services': set([old_service]),
    }
    return aol, domain_entities
Esempio n. 7
0
def aolit(*args):
    """Create a fake tester AOL using all of the args in ``args``."""
    aol = []
    for arg in args:
        sut.append_to_aol(aol, sut.Quad(arg, arg, arg, arg))
    return aol
Esempio n. 8
0
def generate_initial_aol():
    aol = []
    for quad in sut.instance_to_quads(OKA_OLD_INSTANCE,
                                      domain.OLD_INSTANCE_TYPE):
        sut.append_to_aol(aol, quad)
    return aol