def test(): server = couchdbkit.Server(r'http://*****:*****@127.0.0.1:5984/') def test_ers(): """Model independent tests""" assert ers.db.doc_exist('_design/index') ers.add_data(s, p, v, g3) assert ers.exist(s, 'bad_graph') == False assert ers.exist(s, g3) == True ers.delete_entity(s, g3) assert ers.exist(s, g3) == False for o in objects: ers.add_data(s, p, o, g) ers.add_data(s, p2, o, g) for o in objects2: ers.add_data(s, p, o, g2) ers.add_data(s, p2, o, g2) data = ers.get_data(s, g) assert set(data[p]) == objects data2 = ers.get_data(s) # get data from all graphs assert set(data2[p]) == local_objects ers.delete_value(entity, p2) assert p2 not in ers.get_annotation(entity) # Test data s = entity = 'urn:ers:meta:testEntity' p = 'urn:ers:meta:predicates:hasValue' v = 'urn:ers:meta:testValue' p2 = 'urn:ers:meta:predicates:property' g = 'urn:ers:meta:testGraph' g2 = 'urn:ers:meta:testGraph2' g3 = 'urn:ers:meta:testGraph3' objects = set(['value 1', 'value 2']) objects2 = set(['value 3', 'value 4']) local_objects = objects | objects2 remote_objects = set(['value 5', 'value 6']) all_objects = local_objects | remote_objects # Test local ers using differend document models for model in [ModelS()]: dbname = 'ers_' + model.__class__.__name__.lower() ers = ERSLocal(dbname=dbname, model=model, reset_database=True) test_ers() # Prepare remote ers ers_remote = ERSLocal(dbname='ers_remote') for o in remote_objects: ers_remote.add_data(entity, p, o, g3) # Query remote ers_local = ERSLocal(dbname='ers_models', fixed_peers=[{'url': r'http://*****:*****@127.0.0.1:5984/', 'dbname': 'ers_remote'}]) assert set(ers_local.get_annotation(entity)[p]) == all_objects assert set(ers_local.get_values(entity, p)) == all_objects assert set(ers_local.search(p)) == set((s, graph) for graph in (g, g2, g3)) ers_local.delete_entity(entity) assert set(ers_local.get_annotation(entity)[p]) == remote_objects print "Tests pass"
def rand_digits(count): return ''.join((random.choice('0123456789') for _ in xrange(count))) parser = argparse.ArgumentParser() parser.add_argument("-i", "--interval", help="average interval between writes (seconds)", type=float, default=10.0) parser.add_argument("-s", "--stddev", help="standard deviation for above", type=float, default=1.0) parser.add_argument("-b", "--batch_size", help="number of tuples in a batch", type=int, default=10) parser.add_argument("-e", "--entities", help="entities in a batch", type=int, default=2) args = parser.parse_args() ers = ERSLocal() print "Doing writes approx every {0} second(s), use CTRL+C to abort".format(args.interval) while True: graph_name = 'urn:ers:testData:graph:' + rand_digits(32) entities = ['urn:ers:testData:entity:' + rand_digits(32) for _ in xrange(args.entities)] tuples = [] for _ in xrange(args.batch_size): tuples.append((random.choice(entities), 'urn:ers:testData:property:' + rand_digits(32), 'urn:ers:testData:value:' + rand_digits(32))) for e, p, v in tuples: ers.add_data(e, p, v, graph_name) time.sleep(random.normalvariate(args.interval, args.stddev))