line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XAO::testcases::FS::transact; |
2
|
1
|
|
|
1
|
|
770
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
476
|
use XAO::Utils; |
|
1
|
|
|
|
|
18822
|
|
|
1
|
|
|
|
|
74
|
|
4
|
1
|
|
|
1
|
|
498
|
use XAO::Objects; |
|
1
|
|
|
|
|
5396
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
7
|
use Error qw(:try); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
129
|
use base qw(XAO::testcases::FS::base); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
475
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub test_transact { |
10
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
my $odb=$self->{odb}; |
13
|
0
|
|
0
|
|
|
|
$self->assert(defined($odb) && ref($odb), |
14
|
|
|
|
|
|
|
'Object database creating failure'); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
## |
17
|
|
|
|
|
|
|
# Testing just normal stuff, this should work even where there is no |
18
|
|
|
|
|
|
|
# support of transactions. |
19
|
|
|
|
|
|
|
# |
20
|
0
|
|
|
|
|
|
my $customer=$odb->fetch('/Customers/c1'); |
21
|
0
|
|
|
|
|
|
$self->assert(! $odb->transact_active, |
22
|
|
|
|
|
|
|
"1 - Transaction is active before transact_begin()"); |
23
|
0
|
|
|
|
|
|
$odb->transact_begin; |
24
|
0
|
|
|
|
|
|
$self->assert($odb->transact_active, |
25
|
|
|
|
|
|
|
"1 - Transaction is not active after transact_begin()"); |
26
|
0
|
|
|
|
|
|
my $text='test' . time; |
27
|
0
|
|
|
|
|
|
$customer->put(name => $text); |
28
|
0
|
|
|
|
|
|
$customer=$odb->fetch('/Customers')->get('c1'); |
29
|
0
|
|
|
|
|
|
my $got=$customer->get('name'); |
30
|
0
|
|
|
|
|
|
$self->assert($got eq $text, |
31
|
|
|
|
|
|
|
"1a - Got wrong value '$got', expected '$text'"); |
32
|
0
|
|
|
|
|
|
$odb->transact_commit; |
33
|
0
|
|
|
|
|
|
$self->assert(! $odb->transact_active, |
34
|
|
|
|
|
|
|
"1 - Transaction is still active after transact_commit()"); |
35
|
0
|
|
|
|
|
|
$customer=$odb->fetch('/Customers')->get('c1'); |
36
|
0
|
|
|
|
|
|
$got=$customer->get('name'); |
37
|
0
|
|
|
|
|
|
$self->assert($got eq $text, |
38
|
|
|
|
|
|
|
"1b - Got wrong value '$got', expected '$text'"); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
## |
41
|
|
|
|
|
|
|
# Testing roll back. Will only work if there is real support for |
42
|
|
|
|
|
|
|
# transactions. We still go through the ordeal and then check if |
43
|
|
|
|
|
|
|
# driver correctly reports its transactions support status. |
44
|
|
|
|
|
|
|
# |
45
|
0
|
|
|
|
|
|
my $pname=$odb->fetch('/')->get('project'); |
46
|
0
|
|
|
|
|
|
$odb->transact_begin; |
47
|
0
|
|
|
|
|
|
my $newtext=$text."NEW"; |
48
|
0
|
|
|
|
|
|
$customer->put(name => $newtext); |
49
|
0
|
|
|
|
|
|
$got=$odb->fetch('/Customers/c1/name'); |
50
|
0
|
|
|
|
|
|
$self->assert($got eq $newtext, |
51
|
|
|
|
|
|
|
"2a - Got wrong value '$got', expected '$newtext'"); |
52
|
0
|
|
|
|
|
|
$odb->fetch('/')->put(project => 'foobar'); |
53
|
0
|
|
|
|
|
|
$odb->transact_rollback; |
54
|
0
|
|
|
|
|
|
$got=$odb->fetch('/Customers/c1/name'); |
55
|
0
|
0
|
|
|
|
|
if($odb->transact_can) { |
56
|
0
|
|
|
|
|
|
$self->assert($got eq $text, |
57
|
|
|
|
|
|
|
"2b - Got wrong value '$got', expected '$text'"); |
58
|
0
|
|
|
|
|
|
$self->assert($odb->fetch('/project') eq $pname, |
59
|
|
|
|
|
|
|
"2c - Got wrong value for /project, expected '$pname'"); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
0
|
|
|
|
|
|
$self->assert($got eq $newtext, |
63
|
|
|
|
|
|
|
"2d - Got a value that would be expected from\n" . |
64
|
|
|
|
|
|
|
"a driver that supports transaction ($got),\n" . |
65
|
|
|
|
|
|
|
"expected '$newtext'"); |
66
|
0
|
|
|
|
|
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub test_isolation { |
71
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $odb1=$self->{odb}; |
74
|
0
|
|
0
|
|
|
|
$self->assert(defined($odb1) && ref($odb1), |
75
|
|
|
|
|
|
|
'1 - Object database creating failure'); |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if(! $odb1->transact_can) { |
78
|
0
|
|
|
|
|
|
print STDERR "Driver does not support transactions\n"; |
79
|
0
|
|
|
|
|
|
return; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $oa=$self->{odb_args}; |
83
|
|
|
|
|
|
|
my $odb2=XAO::Objects->new(objname => 'FS::Glue', |
84
|
|
|
|
|
|
|
dsn => $oa->{dsn}, |
85
|
|
|
|
|
|
|
user => $oa->{user}, |
86
|
0
|
|
|
|
|
|
password => $oa->{password}); |
87
|
0
|
|
0
|
|
|
|
$self->assert(defined($odb2) && ref($odb2), |
88
|
|
|
|
|
|
|
'2 - Object database creating failure'); |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $o1c1=$odb1->fetch('/Customers/c1'); |
91
|
0
|
|
|
|
|
|
my $o1c2=$odb1->fetch('/Customers/c2'); |
92
|
0
|
|
|
|
|
|
my $o2c1=$odb2->fetch('/Customers/c1'); |
93
|
0
|
|
|
|
|
|
my $o2c2=$odb2->fetch('/Customers/c2'); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
$o1c2->put(name => 'c2_init'); |
96
|
0
|
|
|
|
|
|
$o1c1->put(name => 'o1c1_before'); |
97
|
0
|
|
|
|
|
|
$odb1->transact_begin; |
98
|
0
|
|
|
|
|
|
$o1c1->put(name => 'o1c1_after'); |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $got=$o1c1->get('name'); |
101
|
0
|
|
|
|
|
|
$self->assert($got eq 'o1c1_after', |
102
|
|
|
|
|
|
|
"3 - isolation failure - got '$got', expected 'o1c1_after'"); |
103
|
0
|
|
|
|
|
|
$got=$o2c1->get('name'); |
104
|
0
|
|
|
|
|
|
$self->assert($got eq 'o1c1_before', |
105
|
|
|
|
|
|
|
"4 - isolation failure - got '$got', expected 'o1c1_before'"); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# Once we begin a transaction values are frozen and o1c2 should read |
108
|
|
|
|
|
|
|
# c2_init even after it was changed outside of odb2 transaction. |
109
|
|
|
|
|
|
|
# |
110
|
0
|
|
|
|
|
|
$o2c2->put(name => 'o2c2_before'); |
111
|
0
|
|
|
|
|
|
$got=$o2c2->get('name'); |
112
|
0
|
|
|
|
|
|
$self->assert($got eq 'o2c2_before', |
113
|
|
|
|
|
|
|
"5 - isolation failure - got '$got', expected 'o2c2_before'"); |
114
|
0
|
|
|
|
|
|
$got=$o1c2->get('name'); |
115
|
0
|
|
|
|
|
|
$self->assert($got eq 'c2_init', |
116
|
|
|
|
|
|
|
"6 - isolation failure - got '$got', expected 'c2_init'"); |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$odb2->transact_begin; |
119
|
0
|
|
|
|
|
|
$o2c2->put(name => 'o2c2_after'); |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
$got=$o2c2->get('name'); |
122
|
0
|
|
|
|
|
|
$self->assert($got eq 'o2c2_after', |
123
|
|
|
|
|
|
|
"7 - isolation failure - got '$got', expected 'o2c2_after'"); |
124
|
0
|
|
|
|
|
|
$got=$o1c2->get('name'); |
125
|
0
|
|
|
|
|
|
$self->assert($got eq 'c2_init', |
126
|
|
|
|
|
|
|
"8 - isolation failure - got '$got', expected 'c2_init'"); |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$odb1->transact_commit; |
129
|
0
|
|
|
|
|
|
$got=$o1c1->get('name'); |
130
|
0
|
|
|
|
|
|
$self->assert($got eq 'o1c1_after', |
131
|
|
|
|
|
|
|
"9 - isolation failure - got '$got', expected 'o1c1_after'"); |
132
|
0
|
|
|
|
|
|
$got=$o2c1->get('name'); |
133
|
0
|
|
|
|
|
|
$self->assert($got eq 'o1c1_before', |
134
|
|
|
|
|
|
|
"10 - isolation failure - got '$got', expected 'o1c1_before'"); |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
$odb2->transact_rollback; |
137
|
0
|
|
|
|
|
|
$got=$o1c2->get('name'); |
138
|
0
|
|
|
|
|
|
$self->assert($got eq 'o2c2_before', |
139
|
|
|
|
|
|
|
"11 - isolation failure - got '$got', expected 'o2c2_before'"); |
140
|
0
|
|
|
|
|
|
$got=$o2c2->get('name'); |
141
|
0
|
|
|
|
|
|
$self->assert($got eq 'o2c2_before', |
142
|
|
|
|
|
|
|
"12 - isolation failure - got '$got', expected 'o2c2_before'"); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# once our transaction has been rolled back we should start getting |
145
|
|
|
|
|
|
|
# the value committed by odb1 transaction |
146
|
|
|
|
|
|
|
# |
147
|
0
|
|
|
|
|
|
$got=$o2c1->get('name'); |
148
|
0
|
|
|
|
|
|
$self->assert($got eq 'o1c1_after', |
149
|
|
|
|
|
|
|
"13 - isolation failure - got '$got', expected 'o1c1_after'"); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |