odba 1.1.9 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/devenv.yml +30 -0
- data/.github/workflows/ruby.yml +8 -7
- data/.gitignore +11 -0
- data/{History.txt → History.md} +40 -20
- data/README.md +77 -1
- data/Rakefile +3 -15
- data/devenv.lock +171 -0
- data/devenv.nix +53 -0
- data/devenv.yaml +8 -0
- data/lib/odba/cache.rb +395 -344
- data/lib/odba/cache_entry.rb +42 -31
- data/lib/odba/connection_pool.rb +99 -72
- data/lib/odba/drbwrapper.rb +26 -18
- data/lib/odba/id_server.rb +20 -20
- data/lib/odba/index.rb +249 -215
- data/lib/odba/index_definition.rb +17 -17
- data/lib/odba/marshal.rb +15 -14
- data/lib/odba/odba.rb +40 -32
- data/lib/odba/odba_error.rb +4 -2
- data/lib/odba/persistable.rb +460 -414
- data/lib/odba/storage.rb +328 -277
- data/lib/odba/stub.rb +166 -153
- data/lib/odba/version.rb +1 -1
- data/lib/odba.rb +9 -9
- data/odba.gemspec +8 -3
- data/test/example.rb +47 -0
- data/test/helper.rb +6 -0
- data/test/suite.rb +7 -0
- data/test/test_array.rb +38 -33
- data/test/test_cache.rb +657 -622
- data/test/test_cache_entry.rb +51 -71
- data/test/test_connection_pool.rb +70 -25
- data/test/test_drbwrapper.rb +24 -19
- data/test/test_hash.rb +98 -89
- data/test/test_id_server.rb +30 -32
- data/test/test_index.rb +191 -158
- data/test/test_marshal.rb +15 -25
- data/test/test_persistable.rb +378 -369
- data/test/test_storage.rb +510 -471
- data/test/test_stub.rb +147 -135
- metadata +63 -20
- data/Guide.txt +0 -36
- data/Manifest.txt +0 -38
- data/install.rb +0 -1098
- data/lib/odba/18_19_loading_compatibility.rb +0 -77
data/test/test_persistable.rb
CHANGED
|
@@ -1,545 +1,553 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# TestPersistable -- odba -- ??.??.???? -- hwyss@ywesee.com
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require
|
|
8
|
-
require
|
|
9
|
-
require 'flexmock'
|
|
10
|
-
require 'odba/persistable'
|
|
11
|
-
require 'odba/stub'
|
|
12
|
-
require 'odba/cache'
|
|
13
|
-
require 'odba/odba'
|
|
14
|
-
require 'odba/storage'
|
|
15
|
-
require 'odba/marshal'
|
|
16
|
-
require 'yaml'
|
|
3
|
+
require_relative "helper"
|
|
4
|
+
require "odba/persistable"
|
|
5
|
+
require "odba/storage"
|
|
6
|
+
require "odba/cache"
|
|
7
|
+
require "odba/odba"
|
|
8
|
+
require "odba/marshal"
|
|
17
9
|
|
|
18
10
|
module ODBA
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
module Persistable
|
|
12
|
+
attr_accessor :odba_references
|
|
13
|
+
attr_writer :odba_id
|
|
14
|
+
public :odba_replace_excluded!
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class TestPersistable < Test::Unit::TestCase
|
|
25
18
|
include FlexMock::TestCase
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
19
|
+
class ODBAExcluding
|
|
20
|
+
include ODBA::Persistable
|
|
21
|
+
ODBA_EXCLUDE_VARS = ["@excluded"]
|
|
22
|
+
attr_accessor :included, :excluded
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class ODBAContainerInPersistable
|
|
26
|
+
include ODBA::Persistable
|
|
27
|
+
ODBA_SERIALIZABLE = ["@serializable"]
|
|
28
|
+
attr_accessor :non_replaceable, :replaceable, :replaceable2,
|
|
29
|
+
:array, :odba_persistent, :serializable
|
|
30
|
+
attr_accessor :odba_snapshot_level
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class Hash
|
|
34
|
+
include ODBA::Persistable
|
|
35
|
+
attr_accessor :odba_persistent
|
|
36
|
+
end
|
|
37
|
+
|
|
42
38
|
class IndexedStub
|
|
43
39
|
include Persistable
|
|
44
|
-
#attr_accessor :origin
|
|
40
|
+
# attr_accessor :origin
|
|
45
41
|
odba_index :name
|
|
46
42
|
odba_index :foo, :bar
|
|
47
43
|
odba_index :origin, :origin, :non_replaceable, ODBAContainerInPersistable
|
|
48
|
-
odba_index :redirect,
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
44
|
+
odba_index :redirect, "redirect.name"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def setup
|
|
48
|
+
ODBA.storage = flexmock("storage")
|
|
49
|
+
ODBA.marshaller = flexmock("marshaller_persistable")
|
|
50
|
+
ODBA.cache = flexmock("cache")
|
|
51
|
+
@odba = ODBAContainerInPersistable.new
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def teardown
|
|
55
|
+
ODBA.storage.flexmock_verify
|
|
56
|
+
ODBA.marshaller.flexmock_verify
|
|
57
|
+
ODBA.cache.flexmock_verify
|
|
58
|
+
ODBA.storage = nil
|
|
59
|
+
ODBA.marshaller = nil
|
|
60
|
+
ODBA.cache = nil
|
|
63
61
|
super
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
@odba.odba_take_snapshot(1)
|
|
70
|
-
assert_equal(2, @odba.odba_id)
|
|
71
|
-
ODBA.storage.flexmock_verify
|
|
72
|
-
ODBA.marshaller.flexmock_verify
|
|
73
|
-
end
|
|
74
|
-
def test_odba_delete
|
|
75
|
-
odba_container = ODBAContainerInPersistable.new
|
|
76
|
-
odba_container.odba_id = 2
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_odba_delete
|
|
65
|
+
odba_container = ODBAContainerInPersistable.new
|
|
66
|
+
odba_container.odba_id = 2
|
|
77
67
|
ODBA.cache.should_receive(:delete).with(odba_container)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
68
|
+
odba_container.odba_delete
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_odba_replace_excluded
|
|
72
|
+
odba = ODBAExcluding.new
|
|
73
|
+
odba.included = "here to stay"
|
|
74
|
+
odba.excluded = "easy come easy go"
|
|
75
|
+
odba.odba_replace_excluded!
|
|
76
|
+
assert_equal("here to stay", odba.included)
|
|
77
|
+
assert_nil(odba.excluded)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_odba_replace_stubs
|
|
81
|
+
stub = flexmock
|
|
90
82
|
stub.should_receive(:odba_id).and_return(6)
|
|
91
83
|
stub.should_receive(:is_a?).with(Stub).and_return(true)
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
@odba.replaceable = stub
|
|
85
|
+
substitution = flexmock
|
|
94
86
|
substitution.should_receive(:odba_id).and_return(6)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
87
|
+
@odba.odba_replace_stubs(6, substitution)
|
|
88
|
+
assert_equal(@odba.replaceable, substitution)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_odba_take_snapshot
|
|
92
|
+
level1 = ODBAContainerInPersistable.new
|
|
93
|
+
level2 = ODBAContainerInPersistable.new
|
|
94
|
+
@odba.replaceable = level1
|
|
95
|
+
level1.replaceable = level2
|
|
103
96
|
ODBA.cache.should_receive(:store).with(FlexMock.any).times(3).and_return(2)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
97
|
+
@odba.odba_take_snapshot
|
|
98
|
+
assert_equal(1, @odba.odba_snapshot_level)
|
|
99
|
+
assert_equal(1, level1.odba_snapshot_level)
|
|
100
|
+
assert_equal(1, level2.odba_snapshot_level)
|
|
101
|
+
ODBA.cache.flexmock_verify
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_odba_unsaved_neighbors
|
|
105
|
+
replaceable = flexmock
|
|
106
|
+
@odba.replaceable = replaceable
|
|
113
107
|
replaceable.should_receive(:is_a?).with(Persistable).and_return(true)
|
|
114
108
|
replaceable.should_receive(:odba_unsaved?).with(FlexMock.any).and_return(true)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
109
|
+
result = @odba.odba_unsaved_neighbors(2)
|
|
110
|
+
assert_equal([replaceable], result)
|
|
111
|
+
replaceable.flexmock_verify
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def test_odba_unsaved_neighbors_2
|
|
115
|
+
odba = ODBAExcluding.new
|
|
116
|
+
included = flexmock
|
|
117
|
+
excluded = flexmock
|
|
118
|
+
odba.excluded = excluded
|
|
119
|
+
odba.included = included
|
|
125
120
|
included.should_receive(:is_a?).with(Persistable).and_return(true)
|
|
126
121
|
included.should_receive(:odba_unsaved?).with(FlexMock.any).and_return(true)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
122
|
+
result = odba.odba_unsaved_neighbors(2)
|
|
123
|
+
assert_equal([included], result)
|
|
124
|
+
excluded.flexmock_verify
|
|
125
|
+
included.flexmock_verify
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_extend_enumerable
|
|
129
|
+
hash = {}
|
|
130
|
+
array = []
|
|
131
|
+
assert_equal(true, hash.is_a?(Persistable))
|
|
132
|
+
assert_equal(true, array.is_a?(Persistable))
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def test_odba_stubize
|
|
136
|
+
replaceable = ODBAContainerInPersistable.new
|
|
137
|
+
non_rep = ODBAContainerInPersistable.new
|
|
138
|
+
non_rep.odba_id = 32
|
|
139
|
+
replaceable.odba_id = 24
|
|
140
|
+
@odba.replaceable = replaceable
|
|
141
|
+
@odba.non_replaceable = non_rep
|
|
142
|
+
@odba.odba_stubize(replaceable)
|
|
143
|
+
assert_equal(24, @odba.replaceable.odba_id)
|
|
144
|
+
assert_equal(true, @odba.replaceable.is_a?(Stub))
|
|
145
|
+
assert_equal(true, @odba.non_replaceable.is_a?(ODBAContainerInPersistable))
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def test_odba_replace_persistables
|
|
149
|
+
replaceable = ODBAContainerInPersistable.new
|
|
150
|
+
replaceable.odba_id = 12
|
|
151
|
+
non_replaceable = flexmock
|
|
152
|
+
@odba.non_replaceable = non_replaceable
|
|
153
|
+
@odba.replaceable = replaceable
|
|
154
|
+
non_replaceable.should_receive(:is_a?).with(Stub)
|
|
157
155
|
.times(1).and_return(false)
|
|
158
|
-
|
|
156
|
+
non_replaceable.should_receive(:is_a?).with(Persistable)
|
|
159
157
|
.times(1).and_return(false)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
158
|
+
@odba.odba_replace_persistables
|
|
159
|
+
assert_instance_of(FlexMock, @odba.non_replaceable)
|
|
160
|
+
assert_equal(12, @odba.replaceable.odba_id)
|
|
161
|
+
assert_equal(true, @odba.replaceable.is_a?(Stub))
|
|
162
|
+
non_replaceable.flexmock_verify
|
|
163
|
+
ODBA.cache.flexmock_verify
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def test_odba_replace_persistables__stubised_serialisable
|
|
167
|
+
non_replaceable = flexmock
|
|
168
|
+
@odba.serializable = non_replaceable
|
|
170
169
|
non_replaceable.should_receive(:is_a?).with(Stub).and_return(true)
|
|
171
|
-
non_replaceable.should_receive(:odba_instance).and_return(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
170
|
+
non_replaceable.should_receive(:odba_instance).and_return("serialize this")
|
|
171
|
+
@odba.odba_replace_persistables
|
|
172
|
+
assert_equal("serialize this", @odba.serializable)
|
|
173
|
+
non_replaceable.flexmock_verify
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def test_odba_store_unsaved
|
|
177
|
+
level1 = ODBAContainerInPersistable.new
|
|
178
|
+
level2 = ODBAContainerInPersistable.new
|
|
179
|
+
saved = ODBAContainerInPersistable.new
|
|
180
|
+
@odba.replaceable = level1
|
|
181
|
+
@odba.non_replaceable = saved
|
|
182
|
+
level1.replaceable = level2
|
|
183
|
+
|
|
184
|
+
saved.odba_persistent = true
|
|
185
|
+
ODBA.cache.should_receive(:store).times(3).and_return {
|
|
186
186
|
assert(true)
|
|
187
187
|
2
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
190
|
+
@odba.odba_store_unsaved
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def test_odba_store_unsaved_hash
|
|
194
|
+
level1 = ODBAContainerInPersistable.new
|
|
195
|
+
ODBAContainerInPersistable.new
|
|
196
|
+
hash = {}
|
|
197
|
+
non_rep_hash = {}
|
|
198
|
+
level1.replaceable = hash
|
|
199
|
+
level1.non_replaceable = non_rep_hash
|
|
200
|
+
non_rep_hash.odba_persistent = true
|
|
201
|
+
|
|
202
|
+
ODBA.cache.should_receive(:store).times(2).and_return {
|
|
202
203
|
assert(true)
|
|
203
204
|
2
|
|
204
205
|
}
|
|
205
206
|
|
|
206
|
-
|
|
207
|
-
|
|
207
|
+
level1.odba_store_unsaved
|
|
208
|
+
end
|
|
209
|
+
|
|
208
210
|
def test_dup
|
|
209
211
|
twin = @odba.dup
|
|
210
|
-
assert_nil(twin.instance_variable_get(
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
stub2.should_receive(:odba_dup).with_no_args.and_return(stub2)
|
|
224
|
-
stub_container2 = nil
|
|
225
|
-
stub2.should_receive(:odba_container=).with_no_args.and_return(stub_container2)
|
|
226
|
-
odba_twin = @odba.odba_dup
|
|
227
|
-
odba_twin.replaceable.flexmock_verify
|
|
228
|
-
odba_twin.replaceable2.flexmock_verify
|
|
229
|
-
assert_equal(odba_twin, stub_container)
|
|
230
|
-
assert_equal(odba_twin, stub_container2)
|
|
231
|
-
end
|
|
232
|
-
def test_odba_unsaved_true
|
|
233
|
-
@odba.instance_variable_set("@odba_persistent", false)
|
|
234
|
-
assert_equal(true, @odba.odba_unsaved?)
|
|
235
|
-
end
|
|
236
|
-
def test_odba_target_ids
|
|
237
|
-
replaceable = flexmock("rep")
|
|
238
|
-
replaceable2 = flexmock("rep2")
|
|
239
|
-
@odba.replaceable = replaceable
|
|
240
|
-
@odba.replaceable2 = replaceable2
|
|
212
|
+
assert_nil(twin.instance_variable_get(:@odba_id))
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def test_odba_unsaved_true
|
|
216
|
+
@odba.instance_variable_set(:@odba_persistent, false)
|
|
217
|
+
assert_equal(true, @odba.odba_unsaved?)
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def test_odba_target_ids
|
|
221
|
+
replaceable = flexmock("rep")
|
|
222
|
+
replaceable2 = flexmock("rep2")
|
|
223
|
+
@odba.replaceable = replaceable
|
|
224
|
+
@odba.replaceable2 = replaceable2
|
|
241
225
|
replaceable.should_receive(:is_a?).with(ODBA::Persistable).and_return(true)
|
|
242
226
|
replaceable.should_receive(:odba_id).with_no_args.and_return(12)
|
|
243
227
|
replaceable2.should_receive(:is_a?).with(ODBA::Persistable).and_return(false)
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
228
|
+
expected = [12]
|
|
229
|
+
assert_equal(expected, @odba.odba_target_ids.sort)
|
|
230
|
+
replaceable.flexmock_verify
|
|
231
|
+
replaceable2.flexmock_verify
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def test_odba_isolated_dump
|
|
235
|
+
replaceable = flexmock("Replaceable")
|
|
236
|
+
replaceable2 = flexmock("Replaceable2")
|
|
237
|
+
@odba.replaceable = replaceable
|
|
238
|
+
@odba.replaceable2 = replaceable2
|
|
254
239
|
ODBA.cache.should_receive(:next_id).with_no_args.and_return(11)
|
|
255
240
|
|
|
256
241
|
### from odba_dup and odba_replace_persistables
|
|
257
|
-
|
|
242
|
+
replaceable2.should_receive(:is_a?).with(Stub)
|
|
258
243
|
.times(2).and_return(false)
|
|
259
|
-
|
|
244
|
+
replaceable2.should_receive(:is_a?).with(Persistable)
|
|
260
245
|
.times(1).and_return(true)
|
|
261
|
-
|
|
246
|
+
replaceable2.should_receive(:odba_id).times(1).and_return(12)
|
|
262
247
|
|
|
263
248
|
### from odba_dup
|
|
264
249
|
responses = [false, true]
|
|
265
|
-
|
|
250
|
+
replaceable.should_receive(:is_a?).with(Stub)
|
|
266
251
|
.times(2).and_return { responses.shift }
|
|
267
252
|
replaceable.should_receive(:odba_clear_receiver).times(1)
|
|
268
|
-
|
|
269
|
-
ODBA.marshaller.should_receive(:dump).and_return{ |twin|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
253
|
+
replaceable.should_receive(:odba_container=).with(@odba.class).times(1)
|
|
254
|
+
ODBA.marshaller.should_receive(:dump).and_return { |twin|
|
|
255
|
+
assert(twin.replaceable2.is_a?(ODBA::Stub))
|
|
256
|
+
"TheDump"
|
|
257
|
+
}
|
|
258
|
+
result = @odba.odba_isolated_dump
|
|
259
|
+
assert_equal(replaceable, @odba.replaceable)
|
|
260
|
+
assert_equal(replaceable2, @odba.replaceable2)
|
|
261
|
+
assert_equal("TheDump", result)
|
|
262
|
+
replaceable.flexmock_verify
|
|
263
|
+
replaceable2.flexmock_verify
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def test_odba_isolated_dump_2
|
|
267
|
+
tmp = ODBA.marshaller
|
|
268
|
+
ODBA.marshaller = ODBA::Marshal
|
|
269
|
+
odba = ODBAExcluding.new
|
|
270
|
+
odba.excluded = "foo"
|
|
271
|
+
odba.included = "baz"
|
|
283
272
|
ODBA.cache.should_receive(:next_id).and_return(1)
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
273
|
+
dump, _ = odba.odba_isolated_dump
|
|
274
|
+
obj = ODBA.marshaller.load(dump)
|
|
275
|
+
assert_nil(obj.excluded)
|
|
276
|
+
assert_equal("baz", obj.included)
|
|
277
|
+
ODBA.marshaller = tmp
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def test_odba_id
|
|
281
|
+
@odba.odba_id = nil
|
|
292
282
|
ODBA.cache.should_receive(:next_id).and_return(1)
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
283
|
+
assert_equal(1, @odba.odba_id)
|
|
284
|
+
ODBA.storage.flexmock_verify
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def test_odba_dump_has_id
|
|
288
|
+
@odba.odba_id = nil
|
|
298
289
|
ODBA.cache.should_receive(:store).with(FlexMock.any)
|
|
299
290
|
ODBA.cache.should_receive(:next_id).with(1).and_return(1)
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
291
|
+
@odba.odba_store
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
def test_odba_store_error_raised
|
|
295
|
+
@odba.odba_name = "foo"
|
|
304
296
|
ODBA.cache.should_receive(:store).with(FlexMock.any).and_return { |dump|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
297
|
+
raise DBI::ProgrammingError
|
|
298
|
+
}
|
|
299
|
+
assert_raises(DBI::ProgrammingError) {
|
|
300
|
+
@odba.odba_store("baz")
|
|
301
|
+
}
|
|
302
|
+
assert_equal("foo", @odba.odba_name)
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def test_odba_store_no_error_raised
|
|
306
|
+
@odba.odba_name = "foo"
|
|
314
307
|
ODBA.cache.should_receive(:store).with(@odba)
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
308
|
+
@odba.odba_store("bar")
|
|
309
|
+
assert_equal("bar", @odba.odba_name)
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def test_inspect_with_stub_in_array
|
|
319
313
|
ODBA.cache.should_receive(:next_id).with_no_args.and_return(12)
|
|
320
314
|
ODBA.cache.should_receive(:next_id).with_no_args.and_return(13)
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
315
|
+
content = ODBAContainerInPersistable.new
|
|
316
|
+
@odba.instance_variable_set(:@contents, [content])
|
|
317
|
+
twin = @odba.odba_isolated_twin
|
|
318
|
+
refute_nil(/@contents=#<ODBA::Stub:/.match(twin.inspect))
|
|
319
|
+
ODBA.storage.flexmock_verify
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def test_to_yaml
|
|
329
323
|
yaml = @odba.to_yaml
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
324
|
+
loaded = YAML.safe_load(yaml, permitted_classes: [ODBA::TestPersistable::ODBAContainerInPersistable])
|
|
325
|
+
assert_instance_of(ODBAContainerInPersistable, loaded)
|
|
326
|
+
end
|
|
327
|
+
|
|
333
328
|
def test_extend
|
|
334
|
-
ODBA.cache.should_receive(:store).with(
|
|
335
|
-
str =
|
|
329
|
+
ODBA.cache.should_receive(:store).with("foo")
|
|
330
|
+
str = "foo"
|
|
336
331
|
str.extend(Persistable)
|
|
337
332
|
str.odba_store
|
|
338
333
|
ODBA.cache.flexmock_verify
|
|
339
334
|
end
|
|
335
|
+
|
|
340
336
|
def test_odba_index__simple
|
|
341
337
|
stub = IndexedStub.new
|
|
342
338
|
assert_respond_to(stub, :name)
|
|
343
339
|
assert_respond_to(stub, :name=)
|
|
344
340
|
assert_respond_to(IndexedStub, :find_by_name)
|
|
345
|
-
result = flexmock(
|
|
341
|
+
result = flexmock("Result")
|
|
346
342
|
|
|
347
343
|
## search by one key
|
|
348
|
-
name =
|
|
349
|
-
args =
|
|
350
|
-
ODBA.cache.should_receive(:retrieve_from_index).with(name, args)
|
|
344
|
+
name = "odba_testpersistable_indexedstub_name"
|
|
345
|
+
args = "xan"
|
|
346
|
+
ODBA.cache.should_receive(:retrieve_from_index).with(name, args)
|
|
351
347
|
.times(1).and_return([result])
|
|
352
|
-
assert_equal([result], IndexedStub.search_by_name(
|
|
348
|
+
assert_equal([result], IndexedStub.search_by_name("xan"))
|
|
353
349
|
|
|
354
350
|
## exact search by one key
|
|
355
|
-
ODBA.cache.should_receive(:retrieve_from_index)
|
|
356
|
-
.with(name, args, ODBA::Persistable::Exact)
|
|
351
|
+
ODBA.cache.should_receive(:retrieve_from_index)
|
|
352
|
+
.with(name, args, ODBA::Persistable::Exact)
|
|
357
353
|
.times(1).and_return([result])
|
|
358
|
-
assert_equal([result], IndexedStub.search_by_exact_name(
|
|
354
|
+
assert_equal([result], IndexedStub.search_by_exact_name("xan"))
|
|
359
355
|
|
|
360
356
|
## find by one key
|
|
361
|
-
ODBA.cache.should_receive(:retrieve_from_index)
|
|
362
|
-
.with(name, args, ODBA::Persistable::Find)
|
|
357
|
+
ODBA.cache.should_receive(:retrieve_from_index)
|
|
358
|
+
.with(name, args, ODBA::Persistable::Find)
|
|
363
359
|
.times(1).and_return([result])
|
|
364
|
-
assert_equal(result, IndexedStub.find_by_name(
|
|
360
|
+
assert_equal(result, IndexedStub.find_by_name("xan"))
|
|
365
361
|
|
|
366
362
|
## list available keys
|
|
367
|
-
ODBA.cache.should_receive(:index_keys).with(name, nil)
|
|
368
|
-
.times(1).and_return([
|
|
369
|
-
assert_equal([
|
|
370
|
-
ODBA.cache.should_receive(:index_keys).with(name, 2)
|
|
371
|
-
.times(1).and_return([
|
|
372
|
-
assert_equal([
|
|
363
|
+
ODBA.cache.should_receive(:index_keys).with(name, nil)
|
|
364
|
+
.times(1).and_return(["key1", "key2"])
|
|
365
|
+
assert_equal(["key1", "key2"], IndexedStub.name_keys)
|
|
366
|
+
ODBA.cache.should_receive(:index_keys).with(name, 2)
|
|
367
|
+
.times(1).and_return(["k1", "k2"])
|
|
368
|
+
assert_equal(["k1", "k2"], IndexedStub.name_keys(2))
|
|
373
369
|
end
|
|
370
|
+
|
|
374
371
|
def test_odba_index__multikey
|
|
375
372
|
stub = IndexedStub.new
|
|
376
373
|
assert_respond_to(stub, :foo)
|
|
377
374
|
assert_respond_to(stub, :bar)
|
|
378
375
|
assert_respond_to(IndexedStub, :find_by_foo_and_bar)
|
|
379
|
-
result = flexmock(
|
|
376
|
+
result = flexmock("Result")
|
|
380
377
|
|
|
381
378
|
## search by multiple keys
|
|
382
|
-
name =
|
|
379
|
+
name = "odba_testpersistable_indexedstub_foo_and_bar"
|
|
383
380
|
args = {
|
|
384
|
-
:
|
|
385
|
-
:
|
|
381
|
+
foo: {"condition" => "like", "value" => "oof"},
|
|
382
|
+
bar: {"condition" => "like", "value" => "rab"}
|
|
386
383
|
}
|
|
387
|
-
ODBA.cache.should_receive(:retrieve_from_index).with(name, args)
|
|
384
|
+
ODBA.cache.should_receive(:retrieve_from_index).with(name, args)
|
|
388
385
|
.times(1).and_return([result])
|
|
389
386
|
assert_equal([result],
|
|
390
|
-
|
|
387
|
+
IndexedStub.search_by_foo_and_bar("oof", "rab"))
|
|
391
388
|
|
|
392
389
|
## exact search by multiple keys
|
|
393
|
-
args = {:
|
|
394
|
-
ODBA.cache.should_receive(:retrieve_from_index)
|
|
395
|
-
.with(name, args, Persistable::Exact)
|
|
390
|
+
args = {foo: "oof", bar: "rab"}
|
|
391
|
+
ODBA.cache.should_receive(:retrieve_from_index)
|
|
392
|
+
.with(name, args, Persistable::Exact)
|
|
396
393
|
.times(1).and_return([result])
|
|
397
394
|
assert_equal([result],
|
|
398
|
-
|
|
395
|
+
IndexedStub.search_by_exact_foo_and_bar("oof", "rab"))
|
|
399
396
|
|
|
400
397
|
## find by multiple keys
|
|
401
|
-
args = {:
|
|
402
|
-
:
|
|
403
|
-
ODBA.cache.should_receive(:retrieve_from_index)
|
|
404
|
-
.with(name, args, Persistable::Find)
|
|
398
|
+
args = {foo: {"value" => 7, "condition" => "="},
|
|
399
|
+
bar: {"value" => "rab", "condition" => "like"}}
|
|
400
|
+
ODBA.cache.should_receive(:retrieve_from_index)
|
|
401
|
+
.with(name, args, Persistable::Find)
|
|
405
402
|
.times(1).and_return([result])
|
|
406
|
-
assert_equal(result, IndexedStub.find_by_foo_and_bar(7,
|
|
403
|
+
assert_equal(result, IndexedStub.find_by_foo_and_bar(7, "rab"))
|
|
407
404
|
end
|
|
405
|
+
|
|
408
406
|
def test_odba_index__directional
|
|
409
407
|
stub = IndexedStub.new
|
|
410
408
|
assert_respond_to(stub, :origin)
|
|
411
409
|
assert_respond_to(stub, :origin=)
|
|
412
410
|
assert_respond_to(IndexedStub, :find_by_origin)
|
|
413
|
-
result = flexmock(
|
|
411
|
+
result = flexmock("Result")
|
|
414
412
|
|
|
415
413
|
## search by one key
|
|
416
|
-
name =
|
|
417
|
-
args =
|
|
418
|
-
ODBA.cache.should_receive(:retrieve_from_index).with(name, args)
|
|
414
|
+
name = "odba_testpersistable_indexedstub_origin"
|
|
415
|
+
args = "xan"
|
|
416
|
+
ODBA.cache.should_receive(:retrieve_from_index).with(name, args)
|
|
419
417
|
.times(1).and_return([result])
|
|
420
|
-
assert_equal([result], IndexedStub.search_by_origin(
|
|
418
|
+
assert_equal([result], IndexedStub.search_by_origin("xan"))
|
|
421
419
|
|
|
422
420
|
## exact search by one key
|
|
423
|
-
ODBA.cache.should_receive(:retrieve_from_index)
|
|
424
|
-
.with(name, args, ODBA::Persistable::Exact)
|
|
421
|
+
ODBA.cache.should_receive(:retrieve_from_index)
|
|
422
|
+
.with(name, args, ODBA::Persistable::Exact)
|
|
425
423
|
.times(1).and_return([result])
|
|
426
|
-
assert_equal([result], IndexedStub.search_by_exact_origin(
|
|
424
|
+
assert_equal([result], IndexedStub.search_by_exact_origin("xan"))
|
|
427
425
|
|
|
428
426
|
## find by one key
|
|
429
|
-
ODBA.cache.should_receive(:retrieve_from_index)
|
|
430
|
-
.with(name, args, ODBA::Persistable::Find)
|
|
427
|
+
ODBA.cache.should_receive(:retrieve_from_index)
|
|
428
|
+
.with(name, args, ODBA::Persistable::Find)
|
|
431
429
|
.times(1).and_return([result])
|
|
432
|
-
assert_equal(result, IndexedStub.find_by_origin(
|
|
430
|
+
assert_equal(result, IndexedStub.find_by_origin("xan"))
|
|
433
431
|
|
|
434
432
|
## list available keys
|
|
435
|
-
ODBA.cache.should_receive(:index_keys).with(name, nil)
|
|
436
|
-
.times(1).and_return([
|
|
437
|
-
assert_equal([
|
|
438
|
-
ODBA.cache.should_receive(:index_keys).with(name, 2)
|
|
439
|
-
.times(1).and_return([
|
|
440
|
-
assert_equal([
|
|
433
|
+
ODBA.cache.should_receive(:index_keys).with(name, nil)
|
|
434
|
+
.times(1).and_return(["key1", "key2"])
|
|
435
|
+
assert_equal(["key1", "key2"], IndexedStub.origin_keys)
|
|
436
|
+
ODBA.cache.should_receive(:index_keys).with(name, 2)
|
|
437
|
+
.times(1).and_return(["k1", "k2"])
|
|
438
|
+
assert_equal(["k1", "k2"], IndexedStub.origin_keys(2))
|
|
441
439
|
end
|
|
440
|
+
|
|
442
441
|
def test_odba_index__redirected
|
|
443
442
|
stub = IndexedStub.new
|
|
444
443
|
assert_respond_to(stub, :redirect)
|
|
445
444
|
assert_respond_to(stub, :redirect=)
|
|
446
445
|
assert_respond_to(IndexedStub, :find_by_redirect)
|
|
447
|
-
result = flexmock(
|
|
446
|
+
result = flexmock("Result")
|
|
448
447
|
|
|
449
448
|
## search by one key
|
|
450
|
-
name =
|
|
451
|
-
args =
|
|
452
|
-
ODBA.cache.should_receive(:retrieve_from_index).with(name, args)
|
|
449
|
+
name = "odba_testpersistable_indexedstub_redirect"
|
|
450
|
+
args = "xan"
|
|
451
|
+
ODBA.cache.should_receive(:retrieve_from_index).with(name, args)
|
|
453
452
|
.times(1).and_return([result])
|
|
454
|
-
assert_equal([result], IndexedStub.search_by_redirect(
|
|
453
|
+
assert_equal([result], IndexedStub.search_by_redirect("xan"))
|
|
455
454
|
|
|
456
455
|
## exact search by one key
|
|
457
|
-
ODBA.cache.should_receive(:retrieve_from_index)
|
|
458
|
-
.with(name, args, ODBA::Persistable::Exact)
|
|
456
|
+
ODBA.cache.should_receive(:retrieve_from_index)
|
|
457
|
+
.with(name, args, ODBA::Persistable::Exact)
|
|
459
458
|
.times(1).and_return([result])
|
|
460
|
-
assert_equal([result], IndexedStub.search_by_exact_redirect(
|
|
459
|
+
assert_equal([result], IndexedStub.search_by_exact_redirect("xan"))
|
|
461
460
|
|
|
462
461
|
## find by one key
|
|
463
|
-
ODBA.cache.should_receive(:retrieve_from_index)
|
|
464
|
-
.with(name, args, ODBA::Persistable::Find)
|
|
462
|
+
ODBA.cache.should_receive(:retrieve_from_index)
|
|
463
|
+
.with(name, args, ODBA::Persistable::Find)
|
|
465
464
|
.times(1).and_return([result])
|
|
466
|
-
assert_equal(result, IndexedStub.find_by_redirect(
|
|
465
|
+
assert_equal(result, IndexedStub.find_by_redirect("xan"))
|
|
467
466
|
|
|
468
467
|
## list available keys
|
|
469
|
-
ODBA.cache.should_receive(:index_keys).with(name, nil)
|
|
470
|
-
.times(1).and_return([
|
|
471
|
-
assert_equal([
|
|
472
|
-
ODBA.cache.should_receive(:index_keys).with(name, 2)
|
|
473
|
-
.times(1).and_return([
|
|
474
|
-
assert_equal([
|
|
468
|
+
ODBA.cache.should_receive(:index_keys).with(name, nil)
|
|
469
|
+
.times(1).and_return(["key1", "key2"])
|
|
470
|
+
assert_equal(["key1", "key2"], IndexedStub.redirect_keys)
|
|
471
|
+
ODBA.cache.should_receive(:index_keys).with(name, 2)
|
|
472
|
+
.times(1).and_return(["k1", "k2"])
|
|
473
|
+
assert_equal(["k1", "k2"], IndexedStub.redirect_keys(2))
|
|
475
474
|
end
|
|
475
|
+
|
|
476
476
|
def test_odba_extent
|
|
477
|
-
|
|
477
|
+
IndexedStub.new
|
|
478
478
|
assert_respond_to(IndexedStub, :odba_extent)
|
|
479
479
|
ODBA.cache.should_receive(:extent).with(IndexedStub).and_return([])
|
|
480
480
|
assert_equal([], IndexedStub.odba_extent)
|
|
481
481
|
end
|
|
482
|
+
|
|
482
483
|
def test_odba_extent__with_block
|
|
483
|
-
|
|
484
|
+
IndexedStub.new
|
|
484
485
|
assert_respond_to(IndexedStub, :odba_extent)
|
|
485
|
-
ODBA.cache.should_receive(:extent).with(IndexedStub).and_return([
|
|
486
|
+
ODBA.cache.should_receive(:extent).with(IndexedStub).and_return(["foo"])
|
|
486
487
|
IndexedStub.odba_extent { |obj|
|
|
487
|
-
assert_equal(
|
|
488
|
+
assert_equal("foo", obj)
|
|
488
489
|
}
|
|
489
490
|
end
|
|
491
|
+
|
|
490
492
|
def test_odba_replace__in_object
|
|
491
493
|
## in rollback, replace instance_variables of modified instances with
|
|
492
494
|
# newly loaded unmodified ones
|
|
493
495
|
modified = Object.new
|
|
494
496
|
modified.extend(ODBA::Persistable)
|
|
495
|
-
modified.instance_variable_set(
|
|
497
|
+
modified.instance_variable_set(:@data, "foo")
|
|
496
498
|
|
|
497
499
|
reloaded = modified.dup
|
|
498
500
|
|
|
499
|
-
modified.instance_variable_set(
|
|
500
|
-
assert_equal(
|
|
501
|
+
modified.instance_variable_set(:@data, "bar")
|
|
502
|
+
assert_equal("bar", modified.instance_variable_get(:@data))
|
|
501
503
|
|
|
502
504
|
modified.odba_replace!(reloaded)
|
|
503
|
-
assert_equal(
|
|
505
|
+
assert_equal("foo", modified.instance_variable_get(:@data))
|
|
504
506
|
end
|
|
507
|
+
|
|
505
508
|
def test_odba_add_observer
|
|
506
|
-
assert_nil(@odba.instance_variable_get(
|
|
507
|
-
obs = flexmock(
|
|
509
|
+
assert_nil(@odba.instance_variable_get(:@odba_observers))
|
|
510
|
+
obs = flexmock("Observer")
|
|
508
511
|
@odba.odba_add_observer(obs)
|
|
509
|
-
assert_equal([obs], @odba.instance_variable_get(
|
|
512
|
+
assert_equal([obs], @odba.instance_variable_get(:@odba_observers))
|
|
510
513
|
end
|
|
514
|
+
|
|
511
515
|
def test_odba_delete_observer
|
|
512
|
-
obs = flexmock(
|
|
513
|
-
@odba.instance_variable_set(
|
|
516
|
+
obs = flexmock("Observer")
|
|
517
|
+
@odba.instance_variable_set(:@odba_observers, [obs])
|
|
514
518
|
@odba.odba_delete_observer(obs)
|
|
515
|
-
assert_equal([], @odba.instance_variable_get(
|
|
519
|
+
assert_equal([], @odba.instance_variable_get(:@odba_observers))
|
|
516
520
|
end
|
|
521
|
+
|
|
517
522
|
def test_odba_delete_observers
|
|
518
|
-
obs = flexmock(
|
|
519
|
-
@odba.instance_variable_set(
|
|
523
|
+
obs = flexmock("Observer")
|
|
524
|
+
@odba.instance_variable_set(:@odba_observers, [obs])
|
|
520
525
|
@odba.odba_delete_observers
|
|
521
|
-
assert_nil(@odba.instance_variable_get(
|
|
526
|
+
assert_nil(@odba.instance_variable_get(:@odba_observers))
|
|
522
527
|
end
|
|
528
|
+
|
|
523
529
|
def test_odba_notify_observers
|
|
524
|
-
obs = flexmock(
|
|
530
|
+
obs = flexmock("Observer")
|
|
525
531
|
@odba.odba_id = 218
|
|
526
|
-
@odba.instance_variable_set(
|
|
527
|
-
obs.should_receive(:odba_update).with(:key,
|
|
532
|
+
@odba.instance_variable_set(:@odba_observers, [obs])
|
|
533
|
+
obs.should_receive(:odba_update).with(:key, "foo", "bar")
|
|
528
534
|
.and_return { assert(true) }
|
|
529
|
-
@odba.odba_notify_observers(:key,
|
|
535
|
+
@odba.odba_notify_observers(:key, "foo", "bar")
|
|
530
536
|
end
|
|
537
|
+
|
|
531
538
|
def test_odba_dup
|
|
532
539
|
o = Object.new
|
|
533
540
|
stub = ODBA::Stub.new(15, o, nil)
|
|
534
541
|
o.extend(ODBA::Persistable)
|
|
535
|
-
o.instance_variable_set(
|
|
542
|
+
o.instance_variable_set(:@stub, stub)
|
|
536
543
|
p = o.odba_dup
|
|
537
544
|
assert(p.is_a?(ODBA::Persistable))
|
|
538
|
-
stub2 = p.instance_variable_get(
|
|
545
|
+
stub2 = p.instance_variable_get(:@stub)
|
|
539
546
|
assert(stub2.is_a?(ODBA::Stub))
|
|
540
547
|
refute_equal(stub.object_id, stub2.object_id)
|
|
541
548
|
assert_equal(15, stub2.odba_id)
|
|
542
549
|
end
|
|
550
|
+
|
|
543
551
|
def test_odba_isolated_stub
|
|
544
552
|
@odba.odba_id = 214
|
|
545
553
|
stub = @odba.odba_isolated_stub
|
|
@@ -550,9 +558,10 @@ module ODBA
|
|
|
550
558
|
ODBA.cache.should_receive(:fetch).with(214, nil).times(1).and_return(@odba)
|
|
551
559
|
assert_equal(@odba, stub.odba_instance)
|
|
552
560
|
end
|
|
561
|
+
|
|
553
562
|
def test_odba_collection
|
|
554
563
|
o = ODBAContainerInPersistable.new
|
|
555
564
|
assert_equal([], o.odba_collection)
|
|
556
565
|
end
|
|
557
|
-
|
|
566
|
+
end
|
|
558
567
|
end
|