1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
"""
Iteration and update conflict with set based IOMemory store
https://github.com/RDFLib/rdflib/issues/286
"""
from rdflib.store import Store
from rdflib import plugin
from rdflib import Graph, Literal, Namespace
def test_concurrent1():
dns = Namespace(u"http://www.example.com/")
store = plugin.get("IOMemory", Store)()
g1 = Graph(store=store)
g1.add((dns.Name, dns.prop, Literal(u"test")))
g1.add((dns.Name, dns.prop, Literal(u"test2")))
g1.add((dns.Name, dns.prop, Literal(u"test3")))
n = len(g1)
i = 0
for t in g1.triples((None, None, None)):
i+=1
# next line causes problems because it adds a new Subject that needs
# to be indexed in __subjectIndex dictionary in IOMemory Store.
# which invalidates the iterator used to iterate over g1
g1.add(t)
assert i == n
def test_concurrent2():
dns = Namespace(u"http://www.example.com/")
store = plugin.get("IOMemory", Store)()
g1 = Graph(store=store)
g2 = Graph(store=store)
g1.add((dns.Name, dns.prop, Literal(u"test")))
g1.add((dns.Name, dns.prop, Literal(u"test2")))
g1.add((dns.Name, dns.prop, Literal(u"test3")))
n = len(g1)
i = 0
for t in g1.triples((None, None, None)):
i+=1
g2.add(t)
# next line causes problems because it adds a new Subject that needs
# to be indexed in __subjectIndex dictionary in IOMemory Store.
# which invalidates the iterator used to iterate over g1
g2.add((dns.Name1, dns.prop1, Literal(u"test")))
g2.add((dns.Name1, dns.prop, Literal(u"test")))
g2.add((dns.Name, dns.prop, Literal(u"test4")))
assert i == n
if __name__ == '__main__':
test_concurrent1()
test_concurrent2()
|