-
Notifications
You must be signed in to change notification settings - Fork 6
/
test-scenarios.lisp
102 lines (94 loc) · 3.75 KB
/
test-scenarios.lisp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
(in-package #:vivace-graph-v2-test)
(defparameter *basic-concurrency-1* nil)
(defparameter *basic-concurrency-2* nil)
(defparameter *triple-2* nil)
(defun basic-concurrency-1 (&optional (store *store*))
(let ((*store* store))
(let ((thr1 (make-thread
#'(lambda ()
(with-graph-transaction (*store* :timeout 10)
(let ((triple (add-triple "This" "is-a" "test" :graph "VGT")))
(format t "~%basic-concurrency-1 thr1: ~A: ~A~%"
(triple-id triple) triple)
(setq *basic-concurrency-1* triple)
(sleep 3))))))
(thr2 (make-thread
#'(lambda ()
(sleep 1)
(let ((triple (add-triple
"This" "is-a" "test" :graph "VGT")))
(if (triple? triple)
(format t "basic-concurrency-1 thr2: ~A: ~A~%"
(triple-id triple) triple)
(format t "basic-concurrency-1 thr2: ~A~%" triple))
(if (triple-equal triple *basic-concurrency-1*)
(setq *basic-concurrency-1* triple)
(setq *basic-concurrency-1* nil)))))))
(join-thread thr1)
(join-thread thr2)
(format t "basic-concurrency-1: ~A~%" *basic-concurrency-1*)
*basic-concurrency-1*)))
(defun basic-concurrency-2 (&optional (store *store*))
(let* ((*store* store)
(read-fn #'(lambda ()
(let ((*read-uncommitted* t))
(sleep (random 2.0))
(let ((triple (lookup-triple "This" "is-a" "test-2" "VGT")))
(if (triple? triple)
(format t "basic-concurrency-2 read-thr: ~A: ~A~%"
(triple-id triple) triple)
(format t "basic-concurrency-2 read-thr: ~A~%" triple))
(push (list (current-thread) triple)
*basic-concurrency-2*))))))
(let ((thr1 (make-thread
#'(lambda ()
(with-graph-transaction (*store* :timeout 10)
(let ((triple (add-triple "This" "is-a" "test-2" :graph "VGT")))
(format t "~%basic-concurrency-2 thr1: ~A: ~A~%"
(triple-id triple) triple)
(setq *triple-2* triple)
(sleep 3))))))
(thr2 (make-thread
#'(lambda ()
(sleep 1)
(let ((triple (add-triple
"This" "is-a" "test-2" :graph "VGT")))
(if (triple? triple)
(format t "basic-concurrency-2 thr2: ~A: ~A~%"
(triple-id triple) triple)
(format t "basic-concurrency-2 thr2: ~A~%" triple))
(push (list (current-thread) triple) *basic-concurrency-2*)))))
(thr3 (make-thread read-fn))
(thr4 (make-thread read-fn))
(thr5 (make-thread read-fn)))
(join-thread thr1)
(join-thread thr2)
(join-thread thr3)
(join-thread thr4)
(join-thread thr5)
(every #'(lambda (triple)
(triple-equal (second triple) *triple-2*))
*basic-concurrency-2*))))
(defun delete-undelete-test ()
(let ((triple (add-triple "This" "is-a" "delete-undelete-test")))
(let ((triple2 (lookup-triple "This" "is-a" "delete-undelete-test" "VGT")))
(unless (triple-equal triple triple2)
(error "~A not triple-equal to ~A" triple triple2))
(delete-triple triple)
(if (triple-deleted? triple)
(format t "~%Deleted ~A: ~A~%" triple (triple-deleted? triple))
(error "~A not deleted." triple))
(let ((triple3 (lookup-triple "This" "is-a" "delete-undelete-test" "VGT")))
(unless (null triple3)
(error "lookup-triple was not null: ~A!" triple3))
(format t "lookup-triple: ~A~%" triple3))
(let ((triple3 (lookup-triple "This" "is-a" "delete-undelete-test" "VGT"
:retrieve-deleted? t)))
(unless (triple? triple3)
(error "lookup-triple :retrieve-deleted? t was null: ~A!" triple3))
(format t "lookup-triple :retrieve-deleted? t: ~A~%" triple3))
(add-triple "This" "is-a" "delete-undelete-test" :graph "VGT")
(let ((triple3 (lookup-triple "This" "is-a" "delete-undelete-test" "VGT")))
(when (triple? triple3)
(format t "undeleted ~A~%" triple3))
(triple? triple3)))))