hyperactive 0.1.1 → 0.2.2
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.
- data/README +1 -0
- data/lib/hyperactive/list.rb +154 -0
- data/lib/hyperactive/record.rb +322 -297
- data/lib/hyperactive/tree.rb +175 -167
- data/lib/hyperactive.rb +1 -0
- data/tests/list_test.rb +76 -0
- data/tests/record_test.rb +17 -17
- data/tests/tree_benchmark.rb +8 -8
- data/tests/tree_test.rb +13 -13
- metadata +5 -2
data/lib/hyperactive/tree.rb
CHANGED
@@ -23,209 +23,217 @@ require 'rbtree'
|
|
23
23
|
module Hyperactive
|
24
24
|
|
25
25
|
#
|
26
|
-
#
|
27
|
-
#
|
26
|
+
# The package containing the Hash-like Tree class that provides any
|
27
|
+
# kind of index for your Hyperactive classes.
|
28
28
|
#
|
29
|
-
|
30
|
-
# new children on demand, and will thusly only have to check the path from
|
31
|
-
# the root node to the leaf for changes when method calls return (see Archipelago::Treasure::Chest)
|
32
|
-
# and will only have to actually store into database the leaf itself if it
|
33
|
-
# has changed.
|
34
|
-
#
|
35
|
-
class Tree < Record
|
36
|
-
|
37
|
-
attr_accessor :elements, :subtrees
|
38
|
-
|
39
|
-
WIDTH = 1 << 3
|
29
|
+
module Tree
|
40
30
|
|
41
31
|
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
def initialize(options = {})
|
45
|
-
@width = options[:width] || WIDTH
|
46
|
-
@elements = {}
|
47
|
-
@subtrees = nil
|
48
|
-
end
|
49
|
-
|
32
|
+
# A class suitable for storing large and often-changing datasets in
|
33
|
+
# an Archipelago environment.
|
50
34
|
#
|
51
|
-
#
|
35
|
+
# Is constructed like a set of nested Hashes that automatically create
|
36
|
+
# new children on demand, and will thusly only have to check the path from
|
37
|
+
# the root node to the leaf for changes when method calls return (see Archipelago::Treasure::Chest)
|
38
|
+
# and will only have to actually store into database the leaf itself if it
|
39
|
+
# has changed.
|
52
40
|
#
|
53
|
-
|
54
|
-
if @elements
|
55
|
-
@elements.delete(key)
|
56
|
-
else
|
57
|
-
subtree_for(key).delete(key)
|
58
|
-
end
|
59
|
-
end
|
41
|
+
class Root < Hyperactive::Record::Bass
|
60
42
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
43
|
+
attr_accessor :elements, :subtrees
|
44
|
+
|
45
|
+
WIDTH = 1 << 3
|
46
|
+
|
47
|
+
#
|
48
|
+
# Dont call this! Call <i>Root.get_instance(options)</i> instead!
|
49
|
+
#
|
50
|
+
def initialize(options = {})
|
51
|
+
@width = options[:width] || WIDTH
|
52
|
+
@elements = {}
|
53
|
+
@subtrees = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Deletes +key+ in this Root.
|
58
|
+
#
|
59
|
+
def delete(key)
|
60
|
+
if @elements
|
61
|
+
@elements.delete(key)
|
62
|
+
else
|
63
|
+
subtree_for(key).delete(key)
|
72
64
|
end
|
73
65
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
66
|
+
|
67
|
+
#
|
68
|
+
# Returns the size of this Root.
|
69
|
+
#
|
70
|
+
def size
|
71
|
+
if @elements
|
72
|
+
@elements.size
|
73
|
+
else
|
74
|
+
@subtrees.t_collect do |tree_id, tree|
|
75
|
+
tree.size
|
76
|
+
end.inject(0) do |sum, size|
|
77
|
+
sum + size
|
78
|
+
end
|
83
79
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Returns all keys and values returning true for +callable+.call(key, value) in this Root.
|
84
|
+
#
|
85
|
+
def select(callable)
|
86
|
+
if @elements
|
87
|
+
@elements.select do |k,v|
|
88
|
+
callable.call(k,v)
|
89
|
+
end
|
90
|
+
else
|
91
|
+
@subtrees.t_collect do |tree_id, tree|
|
92
|
+
tree.select(callable)
|
93
|
+
end.inject([]) do |sum, match|
|
94
|
+
sum + match
|
95
|
+
end
|
89
96
|
end
|
90
97
|
end
|
91
|
-
end
|
92
98
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
99
|
+
#
|
100
|
+
# Returns all keys and values returning false for +callable+.call(key, value) in this Root.
|
101
|
+
#
|
102
|
+
def reject(callable)
|
103
|
+
if @elements
|
104
|
+
@elements.reject do |k,v|
|
105
|
+
callable.call(k,v)
|
106
|
+
end
|
107
|
+
else
|
108
|
+
@subtrees.t_collect do |tree_id, tree|
|
109
|
+
tree.reject(callable)
|
110
|
+
end.inject([]) do |sum, match|
|
111
|
+
sum + match
|
112
|
+
end
|
106
113
|
end
|
107
114
|
end
|
108
|
-
end
|
109
115
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
116
|
+
#
|
117
|
+
# Puts +value+ under +key+ in this Root.
|
118
|
+
#
|
119
|
+
def []=(key, value)
|
120
|
+
if @elements
|
121
|
+
if @elements.size < @width
|
122
|
+
@elements[key] = value
|
123
|
+
else
|
124
|
+
split!
|
125
|
+
subtree_for(key)[key] = value
|
126
|
+
end
|
117
127
|
else
|
118
|
-
split!
|
119
128
|
subtree_for(key)[key] = value
|
120
129
|
end
|
121
|
-
|
122
|
-
subtree_for(key)[key] = value
|
130
|
+
return value
|
123
131
|
end
|
124
|
-
return value
|
125
|
-
end
|
126
132
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
133
|
+
#
|
134
|
+
# Returns the value for +key+ in this Root.
|
135
|
+
#
|
136
|
+
def [](key)
|
137
|
+
if @elements
|
138
|
+
return @elements[key]
|
139
|
+
else
|
140
|
+
return subtree_for(key)[key]
|
141
|
+
end
|
135
142
|
end
|
136
|
-
end
|
137
143
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
#
|
145
|
+
# Returns an Array containing +callable+.call(key, value) from all values in this Root.
|
146
|
+
#
|
147
|
+
def collect(callable)
|
148
|
+
rval = []
|
149
|
+
self.each(Proc.new do |k,v|
|
150
|
+
rval << callable.call(k,v)
|
151
|
+
end)
|
152
|
+
return rval
|
153
|
+
end
|
148
154
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
155
|
+
#
|
156
|
+
# Does +callable+.call(key, value) on all values in this Root.
|
157
|
+
#
|
158
|
+
def each(callable)
|
159
|
+
if @elements
|
160
|
+
@elements.each do |key, value|
|
161
|
+
callable.call(key, value)
|
162
|
+
end
|
163
|
+
else
|
164
|
+
@subtrees.t_each do |tree_id, tree|
|
165
|
+
tree.each(callable)
|
166
|
+
end
|
167
|
+
nil
|
160
168
|
end
|
161
|
-
nil
|
162
169
|
end
|
163
|
-
end
|
164
170
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
171
|
+
#
|
172
|
+
# Clear everything from this Tree and destroy it.
|
173
|
+
#
|
174
|
+
def destroy
|
175
|
+
if @elements
|
176
|
+
@elements.each do |key, value|
|
177
|
+
value.destroy if value.respond_to?(:destroy)
|
178
|
+
end
|
179
|
+
else
|
180
|
+
@subtrees.each do |tree_id, tree|
|
181
|
+
tree.destroy
|
182
|
+
end
|
172
183
|
end
|
173
|
-
|
174
|
-
|
175
|
-
|
184
|
+
freeze
|
185
|
+
super
|
186
|
+
end
|
187
|
+
|
188
|
+
#
|
189
|
+
# Clear everything from this Root.
|
190
|
+
#
|
191
|
+
def clear
|
192
|
+
unless @elements
|
193
|
+
@subtrees.each do |tree_id, tree|
|
194
|
+
tree.clear
|
195
|
+
end
|
196
|
+
@subtrees = nil
|
176
197
|
end
|
198
|
+
@elements = {}
|
177
199
|
end
|
178
|
-
freeze
|
179
|
-
super
|
180
|
-
end
|
181
200
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
201
|
+
private
|
202
|
+
|
203
|
+
#
|
204
|
+
# Finds the subtree responsible for +key+.
|
205
|
+
#
|
206
|
+
# Does it in this ugly way cause the nice way of just doing modulo gave
|
207
|
+
# really odd results since all hashes seem to give some modulo values
|
208
|
+
# a lot more often than expected.
|
209
|
+
#
|
210
|
+
def subtree_for(key)
|
211
|
+
key_id = Digest::SHA1.new("#{key.hash}#{self.record_id}").to_s
|
187
212
|
@subtrees.each do |tree_id, tree|
|
188
|
-
tree
|
213
|
+
return tree if tree_id > key_id
|
189
214
|
end
|
190
|
-
@subtrees
|
215
|
+
return @subtrees.values.first
|
191
216
|
end
|
192
|
-
@elements = {}
|
193
|
-
end
|
194
|
-
|
195
|
-
private
|
196
217
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
218
|
+
#
|
219
|
+
# Split this Tree by creating @subtrees,
|
220
|
+
# then putting all @elements in them and then emptying @elements.
|
221
|
+
#
|
222
|
+
def split!
|
223
|
+
raise "Cant split twice!" unless @elements
|
224
|
+
|
225
|
+
@subtrees = RBTree.new
|
226
|
+
@subtrees.extend(Archipelago::Current::ThreadedCollection)
|
227
|
+
step = (1 << 160) / @width
|
228
|
+
0.upto(@width - 1) do |n|
|
229
|
+
@subtrees["%x" % (n * step)] = Root.get_instance(:width => @width)
|
230
|
+
end
|
231
|
+
@elements.each do |key, value|
|
232
|
+
subtree_for(key)[key] = value
|
233
|
+
end
|
234
|
+
@elements = nil
|
208
235
|
end
|
209
|
-
return @subtrees.values.first
|
210
|
-
end
|
211
236
|
|
212
|
-
#
|
213
|
-
# Split this Tree by creating @subtrees,
|
214
|
-
# then putting all @elements in them and then emptying @elements.
|
215
|
-
#
|
216
|
-
def split!
|
217
|
-
raise "Cant split twice!" unless @elements
|
218
|
-
|
219
|
-
@subtrees = RBTree.new
|
220
|
-
@subtrees.extend(Archipelago::Current::ThreadedCollection)
|
221
|
-
step = (1 << 160) / @width
|
222
|
-
0.upto(@width - 1) do |n|
|
223
|
-
@subtrees["%x" % (n * step)] = Tree.get_instance(:width => @width)
|
224
|
-
end
|
225
|
-
@elements.each do |key, value|
|
226
|
-
subtree_for(key)[key] = value
|
227
|
-
end
|
228
|
-
@elements = nil
|
229
237
|
end
|
230
238
|
|
231
239
|
end
|
data/lib/hyperactive.rb
CHANGED
data/tests/list_test.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
3
|
+
|
4
|
+
class ListTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@c = TestChest.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("chest.db")))
|
8
|
+
@c.publish!
|
9
|
+
@c2 = TestChest.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("chest2.db")))
|
10
|
+
@c2.publish!
|
11
|
+
@tm = TestManager.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("tranny1.db")))
|
12
|
+
@tm.publish!
|
13
|
+
Hyperactive::Record::CAPTAIN.setup(:chest_description => {:class => 'TestChest'},
|
14
|
+
:tranny_description => {:class => 'TestManager'})
|
15
|
+
Hyperactive::Record::CAPTAIN.update_services!
|
16
|
+
assert_within(10) do
|
17
|
+
Hyperactive::Record::CAPTAIN.chests.keys.sort == [@c.service_id, @c2.service_id].sort
|
18
|
+
end
|
19
|
+
assert_within(10) do
|
20
|
+
Hyperactive::Record::CAPTAIN.trannies.keys == [@tm.service_id]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown
|
25
|
+
@c.stop!
|
26
|
+
@c.persistence_provider.unlink
|
27
|
+
@c2.stop!
|
28
|
+
@c2.persistence_provider.unlink
|
29
|
+
@tm.stop!
|
30
|
+
@tm.persistence_provider.unlink
|
31
|
+
Archipelago::Disco::MC.clear!
|
32
|
+
Hyperactive::Record::CAPTAIN.update_services!
|
33
|
+
assert_within(10) do
|
34
|
+
Hyperactive::Record::CAPTAIN.chests.empty?
|
35
|
+
end
|
36
|
+
assert_within(10) do
|
37
|
+
Hyperactive::Record::CAPTAIN.trannies.empty?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_push_unshift_pop_shift
|
42
|
+
l = Hyperactive::List::Head.get_instance
|
43
|
+
assert_equal(0, l.size)
|
44
|
+
l << (r = Hyperactive::Record::Bass.get_instance)
|
45
|
+
assert_equal(1, l.size)
|
46
|
+
assert_equal(l.first, l.last)
|
47
|
+
assert_equal(r, l.first)
|
48
|
+
l << (r2 = Hyperactive::Record::Bass.get_instance)
|
49
|
+
assert_equal(2, l.size)
|
50
|
+
assert_equal(r2, l.last)
|
51
|
+
assert_equal(r, l.first)
|
52
|
+
assert_equal(r2, l.first_element.next.value)
|
53
|
+
l.unshift(r3 = Hyperactive::Record::Bass.get_instance)
|
54
|
+
assert_equal(3, l.size)
|
55
|
+
assert_equal(r3, l.first)
|
56
|
+
assert_equal(r2, l.last)
|
57
|
+
assert_equal(r, l.first_element.next.value)
|
58
|
+
assert_equal(r2, l.first_element.next.next.value)
|
59
|
+
assert_equal(r3, l.last_element.previous.previous.value)
|
60
|
+
r4 = l.shift
|
61
|
+
assert_equal(r3, r4)
|
62
|
+
assert_equal(2, l.size)
|
63
|
+
assert_equal(r, l.first)
|
64
|
+
assert_equal(r2, l.last)
|
65
|
+
r5 = l.pop
|
66
|
+
assert_equal(1, l.size)
|
67
|
+
assert_equal(r, l.first)
|
68
|
+
assert_equal(r, l.last)
|
69
|
+
assert_equal(r2, r5)
|
70
|
+
r6 = l.pop
|
71
|
+
assert_equal(0, l.size)
|
72
|
+
assert_equal(nil, l.first_element)
|
73
|
+
assert_equal(nil, l.last_element)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/tests/record_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
3
3
|
|
4
|
-
class MyRecord < Hyperactive::Record
|
4
|
+
class MyRecord < Hyperactive::Record::Bass
|
5
5
|
attr_accessor :bajs
|
6
6
|
|
7
7
|
def self.save_hook(instance, &block)
|
@@ -35,14 +35,14 @@ class RecordTest < Test::Unit::TestCase
|
|
35
35
|
@c2.publish!
|
36
36
|
@tm = TestManager.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("tranny1.db")))
|
37
37
|
@tm.publish!
|
38
|
-
Hyperactive::CAPTAIN.setup(:chest_description => {:class => 'TestChest'},
|
38
|
+
Hyperactive::Record::CAPTAIN.setup(:chest_description => {:class => 'TestChest'},
|
39
39
|
:tranny_description => {:class => 'TestManager'})
|
40
|
-
Hyperactive::CAPTAIN.update_services!
|
40
|
+
Hyperactive::Record::CAPTAIN.update_services!
|
41
41
|
assert_within(10) do
|
42
|
-
Hyperactive::CAPTAIN.chests.keys.sort == [@c.service_id, @c2.service_id].sort
|
42
|
+
Hyperactive::Record::CAPTAIN.chests.keys.sort == [@c.service_id, @c2.service_id].sort
|
43
43
|
end
|
44
44
|
assert_within(10) do
|
45
|
-
Hyperactive::CAPTAIN.trannies.keys == [@tm.service_id]
|
45
|
+
Hyperactive::Record::CAPTAIN.trannies.keys == [@tm.service_id]
|
46
46
|
end
|
47
47
|
$BEFORE_SAVE = 0
|
48
48
|
$AFTER_SAVE = 0
|
@@ -60,12 +60,12 @@ class RecordTest < Test::Unit::TestCase
|
|
60
60
|
@tm.stop!
|
61
61
|
@tm.persistence_provider.unlink
|
62
62
|
Archipelago::Disco::MC.clear!
|
63
|
-
Hyperactive::CAPTAIN.update_services!
|
63
|
+
Hyperactive::Record::CAPTAIN.update_services!
|
64
64
|
assert_within(10) do
|
65
|
-
Hyperactive::CAPTAIN.chests.empty?
|
65
|
+
Hyperactive::Record::CAPTAIN.chests.empty?
|
66
66
|
end
|
67
67
|
assert_within(10) do
|
68
|
-
Hyperactive::CAPTAIN.trannies.empty?
|
68
|
+
Hyperactive::Record::CAPTAIN.trannies.empty?
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -99,12 +99,12 @@ class RecordTest < Test::Unit::TestCase
|
|
99
99
|
|
100
100
|
def test_select_reject
|
101
101
|
MyRecord.class_eval do
|
102
|
-
select
|
103
|
-
|
104
|
-
|
105
|
-
reject
|
106
|
-
|
107
|
-
|
102
|
+
select :brunt do |record|
|
103
|
+
record.bajs == "brunt"
|
104
|
+
end
|
105
|
+
reject :not_brunt do |record|
|
106
|
+
record.bajs == "brunt"
|
107
|
+
end
|
108
108
|
end
|
109
109
|
r1 = MyRecord.get_instance
|
110
110
|
r1.bajs = "brunt"
|
@@ -146,13 +146,13 @@ class RecordTest < Test::Unit::TestCase
|
|
146
146
|
assert_equal(2, $BEFORE_SAVE)
|
147
147
|
assert_equal(2, $AFTER_SAVE)
|
148
148
|
assert_equal("brunt", r.bajs)
|
149
|
-
assert_equal("brunt", Hyperactive::CAPTAIN[r.record_id].bajs)
|
149
|
+
assert_equal("brunt", Hyperactive::Record::CAPTAIN[r.record_id].bajs)
|
150
150
|
i = r.record_id
|
151
|
-
assert_equal(r, Hyperactive::CAPTAIN[i])
|
151
|
+
assert_equal(r, Hyperactive::Record::CAPTAIN[i])
|
152
152
|
r.destroy
|
153
153
|
assert_equal(1, $BEFORE_DESTROY)
|
154
154
|
assert_equal(1, $AFTER_DESTROY)
|
155
|
-
assert_equal(nil, Hyperactive::CAPTAIN[i])
|
155
|
+
assert_equal(nil, Hyperactive::Record::CAPTAIN[i])
|
156
156
|
end
|
157
157
|
|
158
158
|
end
|
data/tests/tree_benchmark.rb
CHANGED
@@ -10,13 +10,13 @@ class TreeBenchmark < Test::Unit::TestCase
|
|
10
10
|
@c2.publish!
|
11
11
|
@tm = TestManager.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("tranny1.db")))
|
12
12
|
@tm.publish!
|
13
|
-
Hyperactive::CAPTAIN.setup(:chest_description => {:class => 'TestChest'},
|
13
|
+
Hyperactive::Record::CAPTAIN.setup(:chest_description => {:class => 'TestChest'},
|
14
14
|
:tranny_description => {:class => 'TestManager'})
|
15
15
|
assert_within(20) do
|
16
|
-
Set.new(Hyperactive::CAPTAIN.chests.keys) == Set.new([@c.service_id, @c2.service_id])
|
16
|
+
Set.new(Hyperactive::Record::CAPTAIN.chests.keys) == Set.new([@c.service_id, @c2.service_id])
|
17
17
|
end
|
18
18
|
assert_within(20) do
|
19
|
-
Hyperactive::CAPTAIN.trannies.keys == [@tm.service_id]
|
19
|
+
Hyperactive::Record::CAPTAIN.trannies.keys == [@tm.service_id]
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -30,15 +30,15 @@ class TreeBenchmark < Test::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_set_get
|
33
|
-
h = Hyperactive::Tree.get_instance
|
34
|
-
r = Hyperactive::Record.get_instance
|
33
|
+
h = Hyperactive::Tree::Root.get_instance
|
34
|
+
r = Hyperactive::Record::Bass.get_instance
|
35
35
|
hash_test("Tree", h, r, 100)
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_regular_hash_set_get
|
39
|
-
Hyperactive::CAPTAIN["h"] = {}
|
40
|
-
h = Hyperactive::CAPTAIN["h"]
|
41
|
-
r = Hyperactive::Record.get_instance
|
39
|
+
Hyperactive::Record::CAPTAIN["h"] = {}
|
40
|
+
h = Hyperactive::Record::CAPTAIN["h"]
|
41
|
+
r = Hyperactive::Record::Bass.get_instance
|
42
42
|
hash_test("Hash", h, r, 100)
|
43
43
|
end
|
44
44
|
|
data/tests/tree_test.rb
CHANGED
@@ -19,14 +19,14 @@ class TreeTest < Test::Unit::TestCase
|
|
19
19
|
@c2.publish!
|
20
20
|
@tm = TestManager.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("tranny1.db")))
|
21
21
|
@tm.publish!
|
22
|
-
Hyperactive::CAPTAIN.setup(:chest_description => {:class => 'TestChest'},
|
22
|
+
Hyperactive::Record::CAPTAIN.setup(:chest_description => {:class => 'TestChest'},
|
23
23
|
:tranny_description => {:class => 'TestManager'})
|
24
|
-
Hyperactive::CAPTAIN.update_services!
|
24
|
+
Hyperactive::Record::CAPTAIN.update_services!
|
25
25
|
assert_within(10) do
|
26
|
-
Hyperactive::CAPTAIN.chests.keys.sort == [@c.service_id, @c2.service_id].sort
|
26
|
+
Hyperactive::Record::CAPTAIN.chests.keys.sort == [@c.service_id, @c2.service_id].sort
|
27
27
|
end
|
28
28
|
assert_within(10) do
|
29
|
-
Hyperactive::CAPTAIN.trannies.keys == [@tm.service_id]
|
29
|
+
Hyperactive::Record::CAPTAIN.trannies.keys == [@tm.service_id]
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -38,19 +38,19 @@ class TreeTest < Test::Unit::TestCase
|
|
38
38
|
@tm.stop!
|
39
39
|
@tm.persistence_provider.unlink
|
40
40
|
Archipelago::Disco::MC.clear!
|
41
|
-
Hyperactive::CAPTAIN.update_services!
|
41
|
+
Hyperactive::Record::CAPTAIN.update_services!
|
42
42
|
assert_within(10) do
|
43
|
-
Hyperactive::CAPTAIN.chests.empty?
|
43
|
+
Hyperactive::Record::CAPTAIN.chests.empty?
|
44
44
|
end
|
45
45
|
assert_within(10) do
|
46
|
-
Hyperactive::CAPTAIN.trannies.empty?
|
46
|
+
Hyperactive::Record::CAPTAIN.trannies.empty?
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_select_reject
|
51
|
-
h = Hyperactive::Tree.get_instance
|
52
|
-
r1 = Hyperactive::Record.get_instance
|
53
|
-
r2 = Hyperactive::Record.get_instance
|
51
|
+
h = Hyperactive::Tree::Root.get_instance
|
52
|
+
r1 = Hyperactive::Record::Bass.get_instance
|
53
|
+
r2 = Hyperactive::Record::Bass.get_instance
|
54
54
|
h[r1.record_id] = r1
|
55
55
|
h[r2.record_id] = r2
|
56
56
|
assert_equal(r1.record_id, h.select(RecordMatcher.new(r1.record_id)).first.first)
|
@@ -58,17 +58,17 @@ class TreeTest < Test::Unit::TestCase
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_set_get
|
61
|
-
h = Hyperactive::Tree.get_instance
|
61
|
+
h = Hyperactive::Tree::Root.get_instance
|
62
62
|
h2 = {}
|
63
63
|
10.times do
|
64
|
-
r = Hyperactive::Record.get_instance
|
64
|
+
r = Hyperactive::Record::Bass.get_instance
|
65
65
|
h[r.record_id] = r
|
66
66
|
h2[r.record_id] = r
|
67
67
|
end
|
68
68
|
|
69
69
|
h2.each do |k,v|
|
70
70
|
assert_equal(v, h[k])
|
71
|
-
assert_equal(v, Hyperactive::CAPTAIN[h.record_id][k])
|
71
|
+
assert_equal(v, Hyperactive::Record::CAPTAIN[h.record_id][k])
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: hyperactive
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-11-
|
6
|
+
version: 0.2.2
|
7
|
+
date: 2006-11-28 00:00:00 +01:00
|
8
8
|
summary: A base class for persistent objects that uses archipelago for persistence. Useful for Ruby on Rails models for example.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,8 +30,10 @@ authors:
|
|
30
30
|
files:
|
31
31
|
- lib/hyperactive.rb
|
32
32
|
- lib/hyperactive/hooker.rb
|
33
|
+
- lib/hyperactive/list.rb
|
33
34
|
- lib/hyperactive/record.rb
|
34
35
|
- lib/hyperactive/tree.rb
|
36
|
+
- tests/list_test.rb
|
35
37
|
- tests/record_test.rb
|
36
38
|
- tests/test_helper.rb
|
37
39
|
- tests/tree_benchmark.rb
|
@@ -39,6 +41,7 @@ files:
|
|
39
41
|
- GPL-2
|
40
42
|
- README
|
41
43
|
test_files:
|
44
|
+
- tests/list_test.rb
|
42
45
|
- tests/record_test.rb
|
43
46
|
- tests/tree_test.rb
|
44
47
|
- tests/test_helper.rb
|