hyperactive 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +3 -0
- data/TODO +1 -1
- data/lib/hyperactive.rb +2 -7
- data/lib/hyperactive/hash.rb +8 -6
- data/lib/hyperactive/index.rb +5 -1
- data/lib/hyperactive/list.rb +3 -3
- data/lib/hyperactive/record.rb +27 -3
- data/lib/hyperactive/tree.rb +115 -0
- data/tests/hash_benchmark.rb +0 -26
- data/tests/hash_test.rb +0 -27
- data/tests/list_benchmark.rb +0 -26
- data/tests/list_test.rb +0 -27
- data/tests/record_test.rb +1 -25
- data/tests/test_helper.rb +37 -0
- data/tests/tree_test.rb +15 -0
- metadata +14 -10
data/README
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
It uses archipelago for persistence, and is meaningful only in an environment where the server process doesnt restart at each request. This means that cgi environment is not really an option.
|
4
4
|
|
5
|
+
== Dependencies:
|
6
|
+
archipelago
|
7
|
+
|
5
8
|
== Sub packages:
|
6
9
|
|
7
10
|
Hyperactive::Record:: The base class package itself, providing you with cached selectors and rejectors, along with cached finders for any number of attributes.
|
data/TODO
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
|
2
2
|
* Create a validation framework for Hyperactive::Record::Bass
|
3
3
|
|
4
|
-
* Create a sorted data structure, for example AA trees: http://www.eternallyconfuzzled.com/tuts/
|
4
|
+
* Create a sorted data structure, for example AA trees: http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_andersson.aspx
|
data/lib/hyperactive.rb
CHANGED
@@ -15,12 +15,7 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
17
|
|
18
|
+
require 'rubygems'
|
19
|
+
require 'fastthread'
|
18
20
|
$: << File.dirname(__FILE__)
|
19
21
|
|
20
|
-
require 'hyperactive/hooker'
|
21
|
-
require 'hyperactive/index'
|
22
|
-
require 'hyperactive/transactions'
|
23
|
-
require 'hyperactive/cleaner'
|
24
|
-
require 'hyperactive/record'
|
25
|
-
require 'hyperactive/hash'
|
26
|
-
require 'hyperactive/list'
|
data/lib/hyperactive/hash.rb
CHANGED
@@ -17,14 +17,16 @@
|
|
17
17
|
|
18
18
|
|
19
19
|
require 'rubygems'
|
20
|
-
require 'archipelago'
|
20
|
+
require 'archipelago/pirate'
|
21
|
+
require 'hyperactive/list'
|
22
|
+
require 'hyperactive/cleaner'
|
21
23
|
require 'digest/sha1'
|
22
24
|
|
23
25
|
module Hyperactive
|
24
26
|
|
25
27
|
#
|
26
|
-
# The package containing the Hash class that provides
|
27
|
-
#
|
28
|
+
# The package containing the Hash class that provides unsorted
|
29
|
+
# indices for your Hyperactive classes.
|
28
30
|
#
|
29
31
|
# Is supposed to be constantly scaling, but preliminary benchmarks show some
|
30
32
|
# problems with that assumption?
|
@@ -108,7 +110,7 @@ module Hyperactive
|
|
108
110
|
# Insert +value+ under +key+ in this Hash.
|
109
111
|
#
|
110
112
|
def []=(key, value)
|
111
|
-
self.list
|
113
|
+
self.list ||= Hyperactive::List::Head.get_instance_with_transaction(@transaction)
|
112
114
|
|
113
115
|
if (element = Archipelago::Pirate::BLACKBEARD[my_key_for(key), @transaction])
|
114
116
|
element.value = value
|
@@ -124,7 +126,7 @@ module Hyperactive
|
|
124
126
|
# Delete +key+ from this Hash.
|
125
127
|
#
|
126
128
|
def delete(key)
|
127
|
-
self.list
|
129
|
+
self.list ||= Hyperactive::List::Head.get_instance_with_transaction(@transaction)
|
128
130
|
|
129
131
|
return_value = nil
|
130
132
|
|
@@ -175,7 +177,7 @@ module Hyperactive
|
|
175
177
|
# Get my private key for a given +key+.
|
176
178
|
#
|
177
179
|
def my_key_for(key)
|
178
|
-
Digest::SHA1.hexdigest("
|
180
|
+
Digest::SHA1.hexdigest("Hyperactive::Hash::Head:#{self.record_id}:#{Marshal.dump(key)}")
|
179
181
|
end
|
180
182
|
|
181
183
|
end
|
data/lib/hyperactive/index.rb
CHANGED
@@ -15,6 +15,10 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
17
|
|
18
|
+
require 'hyperactive/hash'
|
19
|
+
require 'hyperactive/tree'
|
20
|
+
require 'hyperactive/hooker'
|
21
|
+
|
18
22
|
module Hyperactive
|
19
23
|
|
20
24
|
#
|
@@ -139,7 +143,7 @@ module Hyperactive
|
|
139
143
|
super
|
140
144
|
base.class_eval do
|
141
145
|
#
|
142
|
-
# We depend on
|
146
|
+
# We depend on hooks.
|
143
147
|
#
|
144
148
|
include(Hyperactive::Hooker::Pimp)
|
145
149
|
end
|
data/lib/hyperactive/list.rb
CHANGED
@@ -15,9 +15,8 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
17
|
|
18
|
-
|
19
|
-
require '
|
20
|
-
require 'archipelago'
|
18
|
+
require 'hyperactive/record'
|
19
|
+
require 'archipelago/current'
|
21
20
|
|
22
21
|
module Hyperactive
|
23
22
|
|
@@ -102,6 +101,7 @@ module Hyperactive
|
|
102
101
|
end
|
103
102
|
self.size -= 1
|
104
103
|
element.destroy!
|
104
|
+
return nil
|
105
105
|
end
|
106
106
|
|
107
107
|
#
|
data/lib/hyperactive/record.rb
CHANGED
@@ -15,9 +15,17 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
17
|
|
18
|
+
module Hyperactive
|
19
|
+
module Record
|
20
|
+
class Bass
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
18
24
|
|
19
25
|
require 'rubygems'
|
20
|
-
require 'archipelago'
|
26
|
+
require 'archipelago/pirate'
|
27
|
+
require 'hyperactive/index'
|
28
|
+
require 'hyperactive/transactions'
|
21
29
|
|
22
30
|
#
|
23
31
|
# A utility module to provide the functionality required for example
|
@@ -57,6 +65,10 @@ module Hyperactive
|
|
57
65
|
# The transaction we are currently in.
|
58
66
|
#
|
59
67
|
attr_reader :transaction
|
68
|
+
#
|
69
|
+
# We depend on hooks.
|
70
|
+
#
|
71
|
+
include(Hyperactive::Hooker::Pimp)
|
60
72
|
end
|
61
73
|
|
62
74
|
base.extend(ClassMethods)
|
@@ -78,11 +90,12 @@ module Hyperactive
|
|
78
90
|
# See Hyperactive::List::Head and Hyperactive::Hash::Head for examples of this behaviour.
|
79
91
|
#
|
80
92
|
def with_transaction(transaction, &block)
|
93
|
+
old_transaction = @transaction if defined?(@transaction)
|
81
94
|
@transaction = transaction
|
82
95
|
begin
|
83
96
|
return yield
|
84
97
|
ensure
|
85
|
-
@transaction =
|
98
|
+
@transaction = old_transaction
|
86
99
|
end
|
87
100
|
end
|
88
101
|
|
@@ -125,6 +138,7 @@ module Hyperactive
|
|
125
138
|
Archipelago::Pirate::BLACKBEARD.delete(@record_id, @transaction)
|
126
139
|
self.freeze
|
127
140
|
end
|
141
|
+
return nil
|
128
142
|
end
|
129
143
|
|
130
144
|
module ClassMethods
|
@@ -167,9 +181,19 @@ module Hyperactive
|
|
167
181
|
# which is not what you usually want. Every other time you fetch it using a select or other
|
168
182
|
# method you will instead receive a proxy object to the database. This means that nothing you
|
169
183
|
# do to it at that point will be persistent or even necessarily have a defined result.
|
170
|
-
# Therefore: do not use the instantiated object, instead call <b>my_instance.
|
184
|
+
# Therefore: do not use the instantiated object, instead call <b>my_instance.create</b> or <b>MyClass.get_instance</b>
|
171
185
|
# to get a proxy to the object stored into the database.
|
172
186
|
#
|
187
|
+
# NB: When a subclass is created with <b>get_instance</b>, <b>initialize</b> is called
|
188
|
+
# and then <b>create</b> is called and its return value returned.
|
189
|
+
# If you instead use <b>get_instance_with_transaction</b>, <b>initialize</b> will be called (like before)
|
190
|
+
# and then <b>create</b> with the given transaction. This means that you can not use transactions in
|
191
|
+
# <b>initialize</b> and at the same time make <b>get_instance_with_transaction</b> work, since
|
192
|
+
# the <b>initialize</b> method wont know about the transaction sent to <b>get_instance_with_transaction</b>.
|
193
|
+
# Of course, this can be avoided using varying degrees of ugly hack, but a simpler way is to try and
|
194
|
+
# make initialize <i>not</i> do transaction-dependant stuff, like create new Hyperactive::Record::Bass
|
195
|
+
# instances, but instead do that in (for example) <i>create_hooks</i> (See Hyperactive::Hooker::Pimp).
|
196
|
+
#
|
173
197
|
class Bass
|
174
198
|
|
175
199
|
include Hyperactive::Record::Persistent
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# Archipelago - a distributed computing toolkit for ruby
|
2
|
+
# Copyright (C) 2006 Martin Kihlgren <zond at troja dot ath dot cx>
|
3
|
+
#
|
4
|
+
# This program is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU General Public License
|
6
|
+
# as published by the Free Software Foundation; either version 2
|
7
|
+
# of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
|
+
|
18
|
+
|
19
|
+
require 'rubygems'
|
20
|
+
require 'archipelago/pirate'
|
21
|
+
require 'hyperactive/record'
|
22
|
+
require 'digest/sha1'
|
23
|
+
|
24
|
+
module Hyperactive
|
25
|
+
|
26
|
+
#
|
27
|
+
# The package containing the Tree class that provides sorted
|
28
|
+
# indices for your Hyperactive classes.
|
29
|
+
#
|
30
|
+
# Is supposed to be logarithmically scaling.
|
31
|
+
#
|
32
|
+
module Tree
|
33
|
+
|
34
|
+
class Node < Hyperactive::Record::Bass
|
35
|
+
|
36
|
+
@@nil_node = nil
|
37
|
+
@@nil_node_record_id = nil
|
38
|
+
|
39
|
+
include Hyperactive::Cleaner::Accessors
|
40
|
+
|
41
|
+
attr_accessor :right, :left, :level, :value, :key
|
42
|
+
|
43
|
+
def initialize(options = {})
|
44
|
+
super()
|
45
|
+
self.right = options[:right] || self.class.nil_node
|
46
|
+
self.right = self if self.right == :self
|
47
|
+
self.left = options[:left] || self.class.nil_node
|
48
|
+
self.left = self if self.left == :self
|
49
|
+
self.level = options[:level] || 1
|
50
|
+
self.value = options[:value]
|
51
|
+
self.key = options[:key]
|
52
|
+
end
|
53
|
+
|
54
|
+
def insert(key, value)
|
55
|
+
if self.nil_node?
|
56
|
+
return Node.get_instance_with_transaction(transaction, :key => key, :value => value)
|
57
|
+
else
|
58
|
+
side = :left
|
59
|
+
side = :right if self.key < key
|
60
|
+
self.send("#{side}=", self.send(side).insert(key, value))
|
61
|
+
rval = self.skew
|
62
|
+
rval = rval.split
|
63
|
+
return rval
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def skew
|
68
|
+
end
|
69
|
+
|
70
|
+
def split
|
71
|
+
end
|
72
|
+
|
73
|
+
def nil_node?
|
74
|
+
self.record_id == self.class.nil_node_record_id
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.nil_node_record_id
|
78
|
+
@@nil_node_record_id ||= self.nil_node.record_id
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.nil_node
|
82
|
+
nil_node_key = Digest::SHA1.hexdigest("Hyperactive::Tree::Node::nil_node")
|
83
|
+
@@nil_node ||= if (existing_element = Archipelago::Pirate::BLACKBEARD[nil_node_key])
|
84
|
+
existing_element
|
85
|
+
else
|
86
|
+
rval = Node.get_instance(:left => :self,
|
87
|
+
:right => :self,
|
88
|
+
:level => 0)
|
89
|
+
Archipelago::Pirate::BLACKBEARD[nil_node_key] = rval
|
90
|
+
rval
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
class Root < Hyperactive::Record::Bass
|
97
|
+
|
98
|
+
include Hyperactive::Cleaner::Accessors
|
99
|
+
|
100
|
+
attr_accessor :root
|
101
|
+
|
102
|
+
def initialize
|
103
|
+
super
|
104
|
+
self.root = Node.nil_node
|
105
|
+
end
|
106
|
+
|
107
|
+
def []=(key, value)
|
108
|
+
self.root = root.insert(key, value)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
data/tests/hash_benchmark.rb
CHANGED
@@ -3,32 +3,6 @@ require File.join(File.dirname(__FILE__), 'test_helper')
|
|
3
3
|
|
4
4
|
class HashBenchmark < Test::Unit::TestCase
|
5
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
|
-
Archipelago::Pirate::BLACKBEARD.setup(:chest_description => {:class => 'TestChest'},
|
14
|
-
:tranny_description => {:class => 'TestManager'})
|
15
|
-
assert_within(20) do
|
16
|
-
Set.new(Archipelago::Pirate::BLACKBEARD.chests.keys) == Set.new([@c.service_id, @c2.service_id])
|
17
|
-
end
|
18
|
-
assert_within(20) do
|
19
|
-
Archipelago::Pirate::BLACKBEARD.trannies.keys == [@tm.service_id]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def teardown
|
24
|
-
@c.stop!
|
25
|
-
@c.persistence_provider.unlink!
|
26
|
-
@c2.stop!
|
27
|
-
@c2.persistence_provider.unlink!
|
28
|
-
@tm.stop!
|
29
|
-
@tm.persistence_provider.unlink!
|
30
|
-
end
|
31
|
-
|
32
6
|
def test_set_get
|
33
7
|
h = Hyperactive::Hash::Head.get_instance
|
34
8
|
r = Hyperactive::Record::Bass.get_instance
|
data/tests/hash_test.rb
CHANGED
@@ -11,33 +11,6 @@ class RecordMatcher
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class HashTest < Test::Unit::TestCase
|
14
|
-
|
15
|
-
def setup
|
16
|
-
@c = TestChest.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("chest.db")))
|
17
|
-
@c.publish!
|
18
|
-
@c2 = TestChest.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("chest2.db")))
|
19
|
-
@c2.publish!
|
20
|
-
@tm = TestManager.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("tranny1.db")))
|
21
|
-
@tm.publish!
|
22
|
-
Archipelago::Pirate::BLACKBEARD.setup(:chest_description => {:class => 'TestChest'},
|
23
|
-
:tranny_description => {:class => 'TestManager'})
|
24
|
-
Archipelago::Pirate::BLACKBEARD.update_services!
|
25
|
-
assert_within(10) do
|
26
|
-
Archipelago::Pirate::BLACKBEARD.chests.keys.sort == [@c.service_id, @c2.service_id].sort
|
27
|
-
end
|
28
|
-
assert_within(10) do
|
29
|
-
Archipelago::Pirate::BLACKBEARD.trannies.keys == [@tm.service_id]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def teardown
|
34
|
-
@c.stop!
|
35
|
-
@c.persistence_provider.unlink!
|
36
|
-
@c2.stop!
|
37
|
-
@c2.persistence_provider.unlink!
|
38
|
-
@tm.stop!
|
39
|
-
@tm.persistence_provider.unlink!
|
40
|
-
end
|
41
14
|
|
42
15
|
def test_select_reject
|
43
16
|
h = Hyperactive::Hash::Head.get_instance
|
data/tests/list_benchmark.rb
CHANGED
@@ -3,32 +3,6 @@ require File.join(File.dirname(__FILE__), 'test_helper')
|
|
3
3
|
|
4
4
|
class ListBenchmark < Test::Unit::TestCase
|
5
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
|
-
Archipelago::Pirate::BLACKBEARD.setup(:chest_description => {:class => 'TestChest'},
|
14
|
-
:tranny_description => {:class => 'TestManager'})
|
15
|
-
assert_within(20) do
|
16
|
-
Set.new(Archipelago::Pirate::BLACKBEARD.chests.keys) == Set.new([@c.service_id, @c2.service_id])
|
17
|
-
end
|
18
|
-
assert_within(20) do
|
19
|
-
Archipelago::Pirate::BLACKBEARD.trannies.keys == [@tm.service_id]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def teardown
|
24
|
-
@c.stop!
|
25
|
-
@c.persistence_provider.unlink!
|
26
|
-
@c2.stop!
|
27
|
-
@c2.persistence_provider.unlink!
|
28
|
-
@tm.stop!
|
29
|
-
@tm.persistence_provider.unlink!
|
30
|
-
end
|
31
|
-
|
32
6
|
def test_set_get
|
33
7
|
l = Hyperactive::List::Head.get_instance
|
34
8
|
r = Hyperactive::Record::Bass.get_instance
|
data/tests/list_test.rb
CHANGED
@@ -11,33 +11,6 @@ end
|
|
11
11
|
|
12
12
|
class ListTest < Test::Unit::TestCase
|
13
13
|
|
14
|
-
def setup
|
15
|
-
@c = TestChest.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("chest.db")))
|
16
|
-
@c.publish!
|
17
|
-
@c2 = TestChest.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("chest2.db")))
|
18
|
-
@c2.publish!
|
19
|
-
@tm = TestManager.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("tranny1.db")))
|
20
|
-
@tm.publish!
|
21
|
-
Archipelago::Pirate::BLACKBEARD.setup(:chest_description => {:class => 'TestChest'},
|
22
|
-
:tranny_description => {:class => 'TestManager'})
|
23
|
-
Archipelago::Pirate::BLACKBEARD.update_services!
|
24
|
-
assert_within(10) do
|
25
|
-
Archipelago::Pirate::BLACKBEARD.chests.keys.sort == [@c.service_id, @c2.service_id].sort
|
26
|
-
end
|
27
|
-
assert_within(10) do
|
28
|
-
Archipelago::Pirate::BLACKBEARD.trannies.keys == [@tm.service_id]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def teardown
|
33
|
-
@c.stop!
|
34
|
-
@c.persistence_provider.unlink!
|
35
|
-
@c2.stop!
|
36
|
-
@c2.persistence_provider.unlink!
|
37
|
-
@tm.stop!
|
38
|
-
@tm.persistence_provider.unlink!
|
39
|
-
end
|
40
|
-
|
41
14
|
def test_clear
|
42
15
|
l = Hyperactive::List::Head.get_instance
|
43
16
|
l << (r = Hyperactive::Record::Bass.get_instance)
|
data/tests/record_test.rb
CHANGED
@@ -31,21 +31,7 @@ end
|
|
31
31
|
class RecordTest < Test::Unit::TestCase
|
32
32
|
|
33
33
|
def setup
|
34
|
-
|
35
|
-
@c.publish!
|
36
|
-
@c2 = TestChest.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("chest2.db")))
|
37
|
-
@c2.publish!
|
38
|
-
@tm = TestManager.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("tranny1.db")))
|
39
|
-
@tm.publish!
|
40
|
-
Archipelago::Pirate::BLACKBEARD.setup(:chest_description => {:class => 'TestChest'},
|
41
|
-
:tranny_description => {:class => 'TestManager'})
|
42
|
-
Archipelago::Pirate::BLACKBEARD.update_services!
|
43
|
-
assert_within(10) do
|
44
|
-
Archipelago::Pirate::BLACKBEARD.chests.keys.sort == [@c.service_id, @c2.service_id].sort
|
45
|
-
end
|
46
|
-
assert_within(10) do
|
47
|
-
Archipelago::Pirate::BLACKBEARD.trannies.keys == [@tm.service_id]
|
48
|
-
end
|
34
|
+
super
|
49
35
|
$BEFORE_SAVE = 0
|
50
36
|
$AFTER_SAVE = 0
|
51
37
|
$BEFORE_DESTROY = 0
|
@@ -54,15 +40,6 @@ class RecordTest < Test::Unit::TestCase
|
|
54
40
|
$AFTER_CREATE = 0
|
55
41
|
end
|
56
42
|
|
57
|
-
def teardown
|
58
|
-
@c.stop!
|
59
|
-
@c.persistence_provider.unlink!
|
60
|
-
@c2.stop!
|
61
|
-
@c2.persistence_provider.unlink!
|
62
|
-
@tm.stop!
|
63
|
-
@tm.persistence_provider.unlink!
|
64
|
-
end
|
65
|
-
|
66
43
|
def test_index_find
|
67
44
|
MyRecord.class_eval do
|
68
45
|
index_by :bajs
|
@@ -75,7 +52,6 @@ class RecordTest < Test::Unit::TestCase
|
|
75
52
|
r3.bajs = "gult"
|
76
53
|
r4 = MyRecord.get_instance
|
77
54
|
r4.bajs = "beige"
|
78
|
-
|
79
55
|
assert_equal(Set.new([r2.record_id,r1.record_id]), Set.new(MyRecord.find_by_bajs("brunt").t_collect(Proc.new do |k,v|
|
80
56
|
v.record_id
|
81
57
|
end)))
|
data/tests/test_helper.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
|
2
|
+
BLACKBEARD_OPTIONS = {
|
3
|
+
:chest_description => {:class => 'TestChest'},
|
4
|
+
:tranny_description => {:class => 'TestManager'},
|
5
|
+
:initial_lookup_timeout => 0
|
6
|
+
}
|
7
|
+
|
2
8
|
home = File.expand_path(File.dirname(__FILE__))
|
3
9
|
$: << File.join(home, "..", "lib")
|
4
10
|
|
5
11
|
require 'hyperactive'
|
12
|
+
require 'hyperactive/record'
|
6
13
|
require 'pp'
|
7
14
|
require 'test/unit'
|
8
15
|
require 'benchmark'
|
@@ -30,6 +37,8 @@ class TestManager < Archipelago::Tranny::Manager
|
|
30
37
|
end
|
31
38
|
end
|
32
39
|
|
40
|
+
Archipelago::Treasure::Dubloon.debug_callable = (Proc.new do |m| puts m end)
|
41
|
+
|
33
42
|
class TestJockey < Archipelago::Disco::Jockey
|
34
43
|
attr_reader :remote_services, :local_services
|
35
44
|
end
|
@@ -63,4 +72,32 @@ class Test::Unit::TestCase
|
|
63
72
|
assert(rval)
|
64
73
|
end
|
65
74
|
|
75
|
+
def setup
|
76
|
+
Archipelago::Pirate::BLACKBEARD.setup(:chest_description => {:class => 'TestChest'},
|
77
|
+
:tranny_description => {:class => 'TestManager'})
|
78
|
+
@c = TestChest.new(:persistence_directory => Pathname.new(__FILE__).parent.join("chest.db"))
|
79
|
+
@c.publish!
|
80
|
+
@c2 = TestChest.new(:persistence_directory => Pathname.new(__FILE__).parent.join("chest2.db"))
|
81
|
+
@c2.publish!
|
82
|
+
@tm = TestManager.new(:persistence_directory => Pathname.new(__FILE__).parent.join("tranny1.db"))
|
83
|
+
@tm.publish!
|
84
|
+
assert_within(10) do
|
85
|
+
Archipelago::Pirate::BLACKBEARD.update_services!
|
86
|
+
Archipelago::Pirate::BLACKBEARD.chests.keys.sort == [@c.service_id, @c2.service_id].sort
|
87
|
+
end
|
88
|
+
assert_within(10) do
|
89
|
+
Archipelago::Pirate::BLACKBEARD.update_services!
|
90
|
+
Archipelago::Pirate::BLACKBEARD.trannies.keys == [@tm.service_id]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def teardown
|
95
|
+
@c.close!
|
96
|
+
@c.persistence_provider.unlink!
|
97
|
+
@c2.close!
|
98
|
+
@c2.persistence_provider.unlink!
|
99
|
+
@tm.close!
|
100
|
+
@tm.persistence_provider.unlink!
|
101
|
+
end
|
102
|
+
|
66
103
|
end
|
data/tests/tree_test.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
3
|
+
|
4
|
+
class TreeTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_insert
|
7
|
+
t = Hyperactive::Tree::Root.get_instance
|
8
|
+
assert(t.root.nil_node?)
|
9
|
+
t["epa"] = "apa"
|
10
|
+
assert_equal("apa", t.root.value)
|
11
|
+
assert(t.root.left.nil_node?)
|
12
|
+
assert(t.root.right.nil_node?)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: hyperactive
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date:
|
6
|
+
version: 0.3.0
|
7
|
+
date: 2007-06-07 00:00:00 +02: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
|
@@ -25,30 +25,34 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
25
25
|
platform: ruby
|
26
26
|
signing_key:
|
27
27
|
cert_chain:
|
28
|
+
post_install_message:
|
28
29
|
authors:
|
29
30
|
- Martin Kihlgren
|
30
31
|
files:
|
31
32
|
- lib/hyperactive.rb
|
32
|
-
- lib/hyperactive/cleaner.rb
|
33
33
|
- lib/hyperactive/hash.rb
|
34
34
|
- lib/hyperactive/hooker.rb
|
35
35
|
- lib/hyperactive/index.rb
|
36
|
+
- lib/hyperactive/transactions.rb
|
37
|
+
- lib/hyperactive/cleaner.rb
|
38
|
+
- lib/hyperactive/tree.rb
|
36
39
|
- lib/hyperactive/list.rb
|
37
40
|
- lib/hyperactive/record.rb
|
38
|
-
- lib/hyperactive/transactions.rb
|
39
|
-
- tests/hash_benchmark.rb
|
40
|
-
- tests/hash_test.rb
|
41
|
-
- tests/list_benchmark.rb
|
42
41
|
- tests/list_test.rb
|
42
|
+
- tests/hash_test.rb
|
43
43
|
- tests/record_test.rb
|
44
44
|
- tests/test_helper.rb
|
45
|
+
- tests/tree_test.rb
|
46
|
+
- tests/hash_benchmark.rb
|
47
|
+
- tests/list_benchmark.rb
|
45
48
|
- GPL-2
|
46
49
|
- TODO
|
47
50
|
- README
|
48
51
|
test_files:
|
49
|
-
- tests/hash_test.rb
|
50
52
|
- tests/list_test.rb
|
53
|
+
- tests/hash_test.rb
|
51
54
|
- tests/record_test.rb
|
55
|
+
- tests/tree_test.rb
|
52
56
|
- tests/test_helper.rb
|
53
57
|
rdoc_options:
|
54
58
|
- --line-numbers
|
@@ -69,5 +73,5 @@ dependencies:
|
|
69
73
|
requirements:
|
70
74
|
- - ">="
|
71
75
|
- !ruby/object:Gem::Version
|
72
|
-
version: 0.
|
76
|
+
version: 0.3.0
|
73
77
|
version:
|