odba 1.1.9 → 1.2.1
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 +34 -0
- data/.github/workflows/ruby.yml +8 -8
- data/.gitignore +15 -0
- data/History.md +131 -0
- data/README.md +77 -1
- data/Rakefile +3 -15
- data/devenv.lock +171 -0
- data/devenv.nix +66 -0
- data/devenv.yaml +16 -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 +666 -622
- data/test/test_cache_entry.rb +51 -71
- data/test/test_connection_pool.rb +70 -25
- data/test/test_drbwrapper.rb +31 -20
- 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/History.txt +0 -91
- data/Manifest.txt +0 -38
- data/install.rb +0 -1098
- data/lib/odba/18_19_loading_compatibility.rb +0 -77
data/test/test_hash.rb
CHANGED
|
@@ -1,112 +1,119 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# TestHash -- odba -- ??.??.???? -- hwyss@ywesee.com
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require 'minitest/autorun'
|
|
8
|
-
require 'flexmock/test_unit'
|
|
9
|
-
require 'flexmock'
|
|
10
|
-
require 'odba/persistable'
|
|
11
|
-
require 'odba/stub'
|
|
12
|
-
require 'odba/odba'
|
|
3
|
+
require_relative "helper"
|
|
4
|
+
require "odba/persistable"
|
|
5
|
+
require "odba/stub"
|
|
6
|
+
require "odba/odba"
|
|
13
7
|
|
|
14
8
|
module ODBA
|
|
15
|
-
|
|
9
|
+
class TestHash < Test::Unit::TestCase
|
|
16
10
|
include FlexMock::TestCase
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
class ODBAContainerInHash
|
|
12
|
+
include Persistable
|
|
13
|
+
attr_accessor :non_replaceable, :replaceable, :odba_id
|
|
14
|
+
end
|
|
15
|
+
|
|
21
16
|
class Container
|
|
22
17
|
attr_accessor :content
|
|
23
18
|
end
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
|
|
20
|
+
class TestStub
|
|
21
|
+
attr_accessor :receiver, :odba_replace
|
|
22
|
+
def is_a?(arg)
|
|
23
|
+
true
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def setup
|
|
28
|
+
@hash = {}
|
|
29
|
+
ODBA.cache = flexmock("cache")
|
|
30
|
+
ODBA.storage = flexmock("storage")
|
|
31
|
+
@hash.clear
|
|
32
|
+
end
|
|
33
|
+
|
|
36
34
|
def teardown
|
|
37
35
|
super
|
|
38
36
|
end
|
|
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
|
-
|
|
37
|
+
|
|
38
|
+
def test_odba_unsaved_neighbors_hash
|
|
39
|
+
repkey1 = ODBAContainerInHash.new
|
|
40
|
+
repkey2 = ODBAContainerInHash.new
|
|
41
|
+
repvalue1 = ODBAContainerInHash.new
|
|
42
|
+
repvalue2 = ODBAContainerInHash.new
|
|
43
|
+
@hash.store(repkey1, repvalue1)
|
|
44
|
+
@hash.store(repkey2, repvalue2)
|
|
45
|
+
result = @hash.odba_unsaved_neighbors(1)
|
|
46
|
+
assert_equal(true, result.include?(repkey1))
|
|
47
|
+
assert_equal(true, result.include?(repkey2))
|
|
48
|
+
assert_equal(true, result.include?(repvalue1))
|
|
49
|
+
assert_equal(true, result.include?(repvalue2))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_odba_replace_persistables_hash
|
|
53
|
+
key1 = flexmock("key")
|
|
54
|
+
value1 = flexmock("value")
|
|
55
|
+
@hash.store(key1, value1)
|
|
56
|
+
@hash.odba_replace_persistables
|
|
57
|
+
assert_equal(@hash, {})
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_odba_prefetch
|
|
61
|
+
key1 = flexmock("key")
|
|
62
|
+
val1 = flexmock("val1")
|
|
63
|
+
@hash.store(key1, val1)
|
|
64
|
+
assert_equal(false, @hash.odba_prefetch?)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_odba_unsaved_true
|
|
68
|
+
key = flexmock("key")
|
|
69
|
+
val = flexmock("val")
|
|
70
|
+
@hash.instance_variable_set(:@odba_persistent, true)
|
|
71
|
+
@hash.store(key, val)
|
|
72
|
+
val.should_receive(:is_a?).and_return { |klass| true }
|
|
73
|
+
val.should_receive(:odba_unsaved?).and_return { true }
|
|
74
|
+
|
|
75
|
+
assert_equal(true, @hash.odba_unsaved?)
|
|
76
|
+
end
|
|
77
|
+
|
|
75
78
|
def test_odba_cut_connection
|
|
76
79
|
remove_obj = Object.new
|
|
77
80
|
remove_obj.extend(ODBA::Persistable)
|
|
78
|
-
remove_obj.instance_variable_set(
|
|
81
|
+
remove_obj.instance_variable_set(:@odba_id, 2)
|
|
79
82
|
other = Object.new
|
|
80
83
|
other.extend(ODBA::Persistable)
|
|
81
|
-
other.instance_variable_set(
|
|
84
|
+
other.instance_variable_set(:@odba_id, 3)
|
|
82
85
|
receiver = ODBA::Stub.new(2, nil, remove_obj)
|
|
83
|
-
ODBA.cache.should_receive(:fetch).with(2,nil).and_return(remove_obj)
|
|
84
|
-
@hash.store(
|
|
85
|
-
@hash.store(receiver,
|
|
86
|
-
@hash.store(
|
|
87
|
-
@hash.store(other,
|
|
86
|
+
ODBA.cache.should_receive(:fetch).with(2, nil).and_return(remove_obj)
|
|
87
|
+
@hash.store("foo", receiver)
|
|
88
|
+
@hash.store(receiver, "bar")
|
|
89
|
+
@hash.store("bar", other)
|
|
90
|
+
@hash.store(other, "baz")
|
|
88
91
|
@hash.odba_cut_connection(remove_obj)
|
|
89
|
-
assert_equal({
|
|
92
|
+
assert_equal({"bar" => other, other => "baz"}, @hash)
|
|
90
93
|
end
|
|
94
|
+
|
|
91
95
|
def test_odba_collection
|
|
92
|
-
@hash.update(
|
|
93
|
-
assert_equal([[
|
|
94
|
-
|
|
96
|
+
@hash.update("foo" => "bar", "trouble" => "not")
|
|
97
|
+
assert_equal([["foo", "bar"], ["trouble", "not"]],
|
|
98
|
+
@hash.odba_collection.sort)
|
|
95
99
|
end
|
|
100
|
+
|
|
96
101
|
def test_odba_replace
|
|
97
|
-
modified = {
|
|
102
|
+
modified = {"foo" => "bar"}
|
|
98
103
|
reloaded = modified.dup
|
|
99
|
-
modified.update(
|
|
104
|
+
modified.update("foo" => "baz", "han" => "solo")
|
|
100
105
|
|
|
101
106
|
modified.odba_replace!(reloaded)
|
|
102
107
|
|
|
103
108
|
assert_equal(reloaded, modified)
|
|
104
109
|
end
|
|
110
|
+
|
|
105
111
|
def test_odba_restore
|
|
106
|
-
collection = [[:foo,
|
|
112
|
+
collection = [[:foo, "bar"], [:trouble, "not"]]
|
|
107
113
|
@hash.odba_restore(collection)
|
|
108
|
-
assert_equal({:
|
|
114
|
+
assert_equal({foo: "bar", trouble: "not"}, @hash)
|
|
109
115
|
end
|
|
116
|
+
|
|
110
117
|
def test_odba_target_ids
|
|
111
118
|
o = ODBAContainerInHash.new
|
|
112
119
|
o.odba_id = 1
|
|
@@ -114,13 +121,14 @@ module ODBA
|
|
|
114
121
|
p.odba_id = 2
|
|
115
122
|
q = ODBAContainerInHash.new
|
|
116
123
|
q.odba_id = 3
|
|
117
|
-
@hash.store(
|
|
118
|
-
@hash.store(p,
|
|
119
|
-
@hash.store(
|
|
120
|
-
@hash.store(q,
|
|
121
|
-
@hash.instance_variable_set(
|
|
122
|
-
assert_equal([1,2,3], @hash.odba_target_ids.sort)
|
|
124
|
+
@hash.store("foo", p)
|
|
125
|
+
@hash.store(p, "bar")
|
|
126
|
+
@hash.store("bar", q)
|
|
127
|
+
@hash.store(q, "baz")
|
|
128
|
+
@hash.instance_variable_set(:@var, o)
|
|
129
|
+
assert_equal([1, 2, 3], @hash.odba_target_ids.sort)
|
|
123
130
|
end
|
|
131
|
+
|
|
124
132
|
def test_odba_stubize
|
|
125
133
|
obj = Object.new
|
|
126
134
|
obj.extend(ODBA::Persistable)
|
|
@@ -129,20 +137,21 @@ module ODBA
|
|
|
129
137
|
assert_equal(11, obj.odba_id)
|
|
130
138
|
hash = {1 => obj}
|
|
131
139
|
assert_equal(12, hash.odba_id)
|
|
132
|
-
assert_equal(true, hash.odba_stubize(obj, :
|
|
140
|
+
assert_equal(true, hash.odba_stubize(obj, force: true))
|
|
133
141
|
assert_equal([1], hash.keys)
|
|
134
142
|
assert_equal false, hash.values.first.is_a?(ODBA::Stub)
|
|
135
143
|
end
|
|
144
|
+
|
|
136
145
|
def test_odba_stubize__key
|
|
137
146
|
obj = Object.new
|
|
138
147
|
obj.extend(ODBA::Persistable)
|
|
139
148
|
id = 10
|
|
140
149
|
ODBA.cache.should_receive(:next_id).times(2).and_return { id += 1 }
|
|
141
150
|
assert_equal(11, obj.odba_id)
|
|
142
|
-
hash = {obj =>
|
|
151
|
+
hash = {obj => "foo"}
|
|
143
152
|
assert_equal(12, hash.odba_id)
|
|
144
|
-
assert_equal(true, hash.odba_stubize(obj, :
|
|
145
|
-
assert_equal({obj =>
|
|
153
|
+
assert_equal(true, hash.odba_stubize(obj, force: true))
|
|
154
|
+
assert_equal({obj => "foo"}, hash)
|
|
146
155
|
end
|
|
147
|
-
|
|
156
|
+
end
|
|
148
157
|
end
|
data/test/test_id_server.rb
CHANGED
|
@@ -1,45 +1,43 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# TestIdServer -- odba -- 10.11.2004 -- hwyss@ywesee.com
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require 'minitest/autorun'
|
|
8
|
-
require 'flexmock/test_unit'
|
|
9
|
-
require 'flexmock'
|
|
10
|
-
require 'odba/id_server'
|
|
11
|
-
require 'odba/odba'
|
|
12
|
-
require 'odba/marshal'
|
|
3
|
+
require_relative "helper"
|
|
4
|
+
require "odba/id_server"
|
|
5
|
+
require "odba/odba"
|
|
6
|
+
require "odba/marshal"
|
|
13
7
|
|
|
14
8
|
module ODBA
|
|
15
|
-
|
|
9
|
+
class TestIdServer < Test::Unit::TestCase
|
|
16
10
|
include FlexMock::TestCase
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
def setup
|
|
12
|
+
@cache = ODBA.cache = flexmock("cache")
|
|
13
|
+
@id_server = IdServer.new
|
|
14
|
+
@id_server.instance_variable_set(:@odba_id, 1)
|
|
15
|
+
end
|
|
16
|
+
|
|
22
17
|
def teardown
|
|
23
18
|
@id_server = nil
|
|
24
19
|
super
|
|
25
20
|
end
|
|
26
|
-
|
|
21
|
+
|
|
22
|
+
def test_first
|
|
27
23
|
@cache.should_receive(:store).with(@id_server).times(3)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
assert_equal(1, @id_server.next_id(:foo))
|
|
25
|
+
assert_equal(1, @id_server.next_id(:bar))
|
|
26
|
+
assert_equal(1, @id_server.next_id(:baz))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_consecutive
|
|
33
30
|
@cache.should_receive(:store).with(@id_server).times(3)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
assert_equal(1, @id_server.next_id(:foo))
|
|
32
|
+
assert_equal(2, @id_server.next_id(:foo))
|
|
33
|
+
assert_equal(3, @id_server.next_id(:foo))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_dumpable
|
|
39
37
|
@cache.should_receive(:store).with(@id_server).times(1)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
@id_server.next_id(:foo)
|
|
39
|
+
dump = @id_server.odba_isolated_dump
|
|
40
|
+
assert_instance_of(ODBA::IdServer, ODBA.marshaller.load(dump))
|
|
41
|
+
end
|
|
42
|
+
end
|
|
45
43
|
end
|