hprevalence 0.1.1 → 0.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.
- data/lib/hprevalence.rb +28 -181
- data/lib/internal/command_logger.rb +11 -34
- data/lib/internal/marshallers/default.rb +17 -0
- data/lib/internal/marshallers/soap_marshaller.rb +26 -0
- data/lib/internal/marshallers/yaml_marshaller.rb +22 -0
- data/lib/internal/serializer.rb +38 -52
- data/lib/internal/store_manager.rb +9 -24
- data/rakefile.rb +1 -1
- data/samples/simple/main.rb +10 -0
- data/{test → samples/simple}/task_model.rb +0 -12
- data/samples/transparent/task_model.rb +36 -0
- data/test/command_logger_test.rb +2 -6
- data/test/default_model_serializer_test.rb +9 -8
- data/test/marshaller_test.rb +68 -0
- data/test/models/task_model.rb +91 -0
- data/test/simple_engine_test.rb +22 -5
- data/test/simple_engine_with_soap_test.rb +94 -0
- data/test/simple_engine_with_yaml_test.rb +94 -0
- metadata +12 -10
- data/lib/transparent.rb +0 -245
- data/test/circular_reference_test.rb +0 -96
- data/test/dvd_store_model.rb +0 -97
- data/test/natural_object_model_test.rb +0 -143
- data/test/project_model.rb +0 -99
- data/test/restoring_test.rb +0 -54
- data/test/transparent_module_test.rb +0 -115
@@ -0,0 +1,94 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + "/../lib/")
|
2
|
+
|
3
|
+
require 'hprevalence'
|
4
|
+
require 'internal/marshallers/soap_marshaller'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'abstract_hprevalence_testcase'
|
7
|
+
require 'models/task_model'
|
8
|
+
|
9
|
+
class SimpleEngineWithSoapTest < Test::Unit::TestCase
|
10
|
+
include AbstractHPrevalenceTestHelper
|
11
|
+
|
12
|
+
def setup
|
13
|
+
reset_dir 'store/engine_soap_test'
|
14
|
+
load_engine
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
@engine.close
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_engine
|
22
|
+
teardown unless @engine.nil?
|
23
|
+
|
24
|
+
@engine = HPrevalence::EngineBuilder.build( @target_dir, SoapMarshaller.new() ) {
|
25
|
+
TaskDatabase.new()
|
26
|
+
}
|
27
|
+
|
28
|
+
assert_not_nil @engine
|
29
|
+
@system = @engine.system
|
30
|
+
assert_not_nil @system
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_add_task
|
34
|
+
task = Task.new( 'put the cat out', 'Before go sleep, put the cat out otherwise he will meow during the night' )
|
35
|
+
@engine.execute_command( AddTaskCommand.new( task ) )
|
36
|
+
|
37
|
+
assert_equal 1, @system.tasks.length
|
38
|
+
|
39
|
+
load_engine
|
40
|
+
|
41
|
+
assert_equal 1, @system.tasks.length
|
42
|
+
assert_equal 'put the cat out', @system.tasks[0].name
|
43
|
+
assert_equal 'Before go sleep, put the cat out otherwise he will meow during the night', @system.tasks[0].contents
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_same_object
|
47
|
+
task = Task.new( 'first', 'content' )
|
48
|
+
@engine.execute_command( AddTaskCommand.new( task ) )
|
49
|
+
@engine.execute_command( SetPriorityTaskCommand.new('first') )
|
50
|
+
|
51
|
+
assert_equal 1, @system.tasks.length
|
52
|
+
assert_not_nil @system.priority_task
|
53
|
+
|
54
|
+
load_engine
|
55
|
+
|
56
|
+
assert_not_nil @system.priority_task
|
57
|
+
assert_equal 1, @system.tasks.length
|
58
|
+
assert_equal @system.priority_task, @system.tasks[0]
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_add_and_remove
|
62
|
+
task = Task.new( 'one', 'Before go sleep, put the cat out otherwise he will meow during the night' )
|
63
|
+
@engine.execute_command( AddTaskCommand.new( task ) )
|
64
|
+
task = Task.new( 'two', 'Brush your teeth before go to bed' )
|
65
|
+
@engine.execute_command( AddTaskCommand.new( task ) )
|
66
|
+
|
67
|
+
assert_equal 2, @system.tasks.length
|
68
|
+
|
69
|
+
@engine.execute_command( RemoveTaskCommand.new( 'two' ) )
|
70
|
+
|
71
|
+
assert_equal 1, @system.tasks.length
|
72
|
+
|
73
|
+
load_engine
|
74
|
+
|
75
|
+
assert_equal 1, @system.tasks.length
|
76
|
+
assert_equal 'one', @system.tasks[0].name
|
77
|
+
assert_equal 'Before go sleep, put the cat out otherwise he will meow during the night', @system.tasks[0].contents
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_snapshot
|
81
|
+
task = Task.new( 'one', 'Before go sleep, put the cat out otherwise he will meow during the night' )
|
82
|
+
@engine.execute_command( AddTaskCommand.new( task ) )
|
83
|
+
task = Task.new( 'two', 'Brush your teeth before go to bed' )
|
84
|
+
@engine.execute_command( AddTaskCommand.new( task ) )
|
85
|
+
|
86
|
+
assert_equal 2, @system.tasks.length
|
87
|
+
@engine.take_snapshot
|
88
|
+
|
89
|
+
load_engine
|
90
|
+
|
91
|
+
assert_equal 2, @system.tasks.length
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + "/../lib/")
|
2
|
+
|
3
|
+
require 'hprevalence'
|
4
|
+
require 'internal/marshallers/yaml_marshaller'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'abstract_hprevalence_testcase'
|
7
|
+
require 'models/task_model'
|
8
|
+
|
9
|
+
class SimpleEngineWithSoapTest < Test::Unit::TestCase
|
10
|
+
include AbstractHPrevalenceTestHelper
|
11
|
+
|
12
|
+
def setup
|
13
|
+
reset_dir 'store/engine_yaml_test'
|
14
|
+
load_engine
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
@engine.close
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_engine
|
22
|
+
teardown unless @engine.nil?
|
23
|
+
|
24
|
+
@engine = HPrevalence::EngineBuilder.build( @target_dir, YamlMarshaller.new() ) {
|
25
|
+
TaskDatabase.new()
|
26
|
+
}
|
27
|
+
|
28
|
+
assert_not_nil @engine
|
29
|
+
@system = @engine.system
|
30
|
+
assert_not_nil @system
|
31
|
+
end
|
32
|
+
|
33
|
+
def atest_add_task
|
34
|
+
task = Task.new( 'put the cat out', 'Before go sleep, put the cat out otherwise he will meow during the night' )
|
35
|
+
@engine.execute_command( AddTaskCommand.new( task ) )
|
36
|
+
|
37
|
+
assert_equal 1, @system.tasks.length
|
38
|
+
|
39
|
+
load_engine
|
40
|
+
|
41
|
+
assert_equal 1, @system.tasks.length
|
42
|
+
assert_equal 'put the cat out', @system.tasks[0].name
|
43
|
+
assert_equal 'Before go sleep, put the cat out otherwise he will meow during the night', @system.tasks[0].contents
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_same_object
|
47
|
+
task = Task.new( 'first', 'content' )
|
48
|
+
@engine.execute_command( AddTaskCommand.new( task ) )
|
49
|
+
@engine.execute_command( SetPriorityTaskCommand.new('first') )
|
50
|
+
|
51
|
+
assert_equal 1, @system.tasks.length
|
52
|
+
assert_not_nil @system.priority_task
|
53
|
+
|
54
|
+
load_engine
|
55
|
+
|
56
|
+
assert_not_nil @system.priority_task
|
57
|
+
assert_equal 1, @system.tasks.length
|
58
|
+
assert_equal @system.priority_task, @system.tasks[0]
|
59
|
+
end
|
60
|
+
|
61
|
+
def atest_add_and_remove
|
62
|
+
task = Task.new( 'one', 'Before go sleep, put the cat out otherwise he will meow during the night' )
|
63
|
+
@engine.execute_command( AddTaskCommand.new( task ) )
|
64
|
+
task = Task.new( 'two', 'Brush your teeth before go to bed' )
|
65
|
+
@engine.execute_command( AddTaskCommand.new( task ) )
|
66
|
+
|
67
|
+
assert_equal 2, @system.tasks.length
|
68
|
+
|
69
|
+
@engine.execute_command( RemoveTaskCommand.new( 'two' ) )
|
70
|
+
|
71
|
+
assert_equal 1, @system.tasks.length
|
72
|
+
|
73
|
+
load_engine
|
74
|
+
|
75
|
+
assert_equal 1, @system.tasks.length
|
76
|
+
assert_equal 'one', @system.tasks[0].name
|
77
|
+
assert_equal 'Before go sleep, put the cat out otherwise he will meow during the night', @system.tasks[0].contents
|
78
|
+
end
|
79
|
+
|
80
|
+
def atest_snapshot
|
81
|
+
task = Task.new( 'one', 'Before go sleep, put the cat out otherwise he will meow during the night' )
|
82
|
+
@engine.execute_command( AddTaskCommand.new( task ) )
|
83
|
+
task = Task.new( 'two', 'Brush your teeth before go to bed' )
|
84
|
+
@engine.execute_command( AddTaskCommand.new( task ) )
|
85
|
+
|
86
|
+
assert_equal 2, @system.tasks.length
|
87
|
+
@engine.take_snapshot
|
88
|
+
|
89
|
+
load_engine
|
90
|
+
|
91
|
+
assert_equal 2, @system.tasks.length
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: hprevalence
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2004-
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2004-11-25
|
8
8
|
summary: Ruby based prevalence engine.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,23 +30,25 @@ files:
|
|
30
30
|
- "./rake.rb"
|
31
31
|
- "./rakefile.rb"
|
32
32
|
- "./lib/hprevalence.rb"
|
33
|
-
- "./lib/transparent.rb"
|
34
33
|
- "./lib/internal/command_logger.rb"
|
35
34
|
- "./lib/internal/iomanager.rb"
|
36
35
|
- "./lib/internal/serializer.rb"
|
37
36
|
- "./lib/internal/store_manager.rb"
|
37
|
+
- "./lib/internal/marshallers/default.rb"
|
38
|
+
- "./lib/internal/marshallers/soap_marshaller.rb"
|
39
|
+
- "./lib/internal/marshallers/yaml_marshaller.rb"
|
40
|
+
- "./samples/simple/main.rb"
|
41
|
+
- "./samples/simple/task_model.rb"
|
42
|
+
- "./samples/transparent/task_model.rb"
|
38
43
|
- "./test/abstract_hprevalence_testcase.rb"
|
39
|
-
- "./test/circular_reference_test.rb"
|
40
44
|
- "./test/command_logger_test.rb"
|
41
45
|
- "./test/default_model_serializer_test.rb"
|
42
|
-
- "./test/dvd_store_model.rb"
|
43
46
|
- "./test/file_io_manager_test.rb"
|
44
|
-
- "./test/
|
45
|
-
- "./test/project_model.rb"
|
46
|
-
- "./test/restoring_test.rb"
|
47
|
+
- "./test/marshaller_test.rb"
|
47
48
|
- "./test/simple_engine_test.rb"
|
48
|
-
- "./test/
|
49
|
-
- "./test/
|
49
|
+
- "./test/simple_engine_with_soap_test.rb"
|
50
|
+
- "./test/simple_engine_with_yaml_test.rb"
|
51
|
+
- "./test/models/task_model.rb"
|
50
52
|
test_files: []
|
51
53
|
rdoc_options: []
|
52
54
|
extra_rdoc_files: []
|
data/lib/transparent.rb
DELETED
@@ -1,245 +0,0 @@
|
|
1
|
-
|
2
|
-
module HPrevalence
|
3
|
-
|
4
|
-
module Transparent
|
5
|
-
|
6
|
-
module CustomBehavior
|
7
|
-
|
8
|
-
def self.included(type)
|
9
|
-
class << type
|
10
|
-
def method_added(symbol)
|
11
|
-
self.instance_eval do
|
12
|
-
@readonly_attributes ||= []
|
13
|
-
hierarchy = self
|
14
|
-
while hierarchy = hierarchy.superclass
|
15
|
-
if (hierarchy.instance_eval {instance_variables.include? '@readonly_attributes'})
|
16
|
-
@readonly_attributes |= hierarchy.instance_eval {@readonly_attributes}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def attr_proxy_attribute( *symbols )
|
23
|
-
@proxied_attributes ||= []
|
24
|
-
symbols.each do |symbol|
|
25
|
-
self.instance_eval {
|
26
|
-
@proxied_attributes ||= []
|
27
|
-
@proxied_attributes << symbol
|
28
|
-
}
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def attr_proxy_method( *symbols )
|
33
|
-
@proxied_attributes ||= []
|
34
|
-
symbols.each do |symbol|
|
35
|
-
self.instance_eval {
|
36
|
-
@proxied_methods ||= []
|
37
|
-
@proxied_methods << symbol
|
38
|
-
}
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def attr_read_only( *symbols )
|
43
|
-
symbols.each do |symbol|
|
44
|
-
self.instance_eval {
|
45
|
-
@readonly_attributes ||= []
|
46
|
-
@readonly_attributes << symbol
|
47
|
-
}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def _read_only_attributes()
|
54
|
-
self.class.instance_eval { @readonly_attributes ||= [] }
|
55
|
-
end
|
56
|
-
|
57
|
-
def _proxied_attributes()
|
58
|
-
self.class.instance_eval { @proxied_attributes ||= [] }
|
59
|
-
end
|
60
|
-
|
61
|
-
def _proxied_methods()
|
62
|
-
self.class.instance_eval { @proxied_methods ||= [] }
|
63
|
-
end
|
64
|
-
|
65
|
-
def _should_proxy( symbol )
|
66
|
-
if _proxied_attributes().include?( symbol )
|
67
|
-
return true if _symbol2proxy(symbol).nil?
|
68
|
-
elsif _proxied_methods().include?( symbol )
|
69
|
-
return true
|
70
|
-
end
|
71
|
-
false
|
72
|
-
end
|
73
|
-
|
74
|
-
def _symbol2proxy( symbol )
|
75
|
-
self.instance_eval {
|
76
|
-
@symbol2proxy ||= {}
|
77
|
-
@symbol2proxy[symbol]
|
78
|
-
}
|
79
|
-
end
|
80
|
-
|
81
|
-
def _set_proxy( symbol, proxy )
|
82
|
-
self.instance_eval {
|
83
|
-
@symbol2proxy ||= {}
|
84
|
-
@symbol2proxy[symbol] = proxy
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
class AutomaticCommand
|
91
|
-
|
92
|
-
def initialize( proxy_id, symbol, *args )
|
93
|
-
@proxy_id, @symbol, @args = proxy_id, symbol, args
|
94
|
-
end
|
95
|
-
|
96
|
-
def execute(system)
|
97
|
-
TransparentEngine.current() { |engine|
|
98
|
-
proxy = engine.proxy_by_id(@proxy_id)
|
99
|
-
raise 'Could not obtain proxy' if proxy.nil?
|
100
|
-
return proxy.target.send(@symbol, *arguments)
|
101
|
-
}
|
102
|
-
end
|
103
|
-
|
104
|
-
protected
|
105
|
-
|
106
|
-
def arguments()
|
107
|
-
@args ||= []
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
class NestedAutomaticCommand < AutomaticCommand
|
113
|
-
|
114
|
-
attr_reader :related_symbol, :parent_proxy_id
|
115
|
-
|
116
|
-
def initialize( related_symbol, parent_proxy_id, proxy_id, symbol, *args )
|
117
|
-
super( proxy_id, symbol, *args )
|
118
|
-
raise 'Missing related_symbol' if related_symbol.nil?
|
119
|
-
raise 'Missing parent_proxy_id' if parent_proxy_id.nil?
|
120
|
-
@related_symbol, @parent_proxy_id = related_symbol, parent_proxy_id
|
121
|
-
end
|
122
|
-
|
123
|
-
def execute(system)
|
124
|
-
TransparentEngine.current() { |engine|
|
125
|
-
proxy = engine.proxy_by_id(@proxy_id, @related_symbol, @parent_proxy_id)
|
126
|
-
raise 'Could not obtain proxy' if proxy.nil?
|
127
|
-
return proxy.target.send(@symbol, *arguments)
|
128
|
-
}
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
class TransparentProxy
|
133
|
-
attr_accessor :target, :proxy_id, :engine_id
|
134
|
-
|
135
|
-
def initialize(target, new_id = Guid.new)
|
136
|
-
raise 'A proxy must have a target' if target.nil?
|
137
|
-
raise 'Strange. A proxy is supposed to exist within an engine' unless Thread.current[:engine]
|
138
|
-
@proxy_id = new_id
|
139
|
-
@engine_id = Thread.current[:engine].engine_id
|
140
|
-
Thread.current[:engine].register_proxy(self)
|
141
|
-
@target = target
|
142
|
-
@is_custom = target.kind_of?(CustomBehavior)
|
143
|
-
# puts "New proxy with id #{@proxy_id.to_s} for #{target.class.to_s}"
|
144
|
-
end
|
145
|
-
|
146
|
-
def method_missing(symbol, *args, &block)
|
147
|
-
# puts "Sending #{symbol} to #{@target.to_s} args #{args.to_s}"
|
148
|
-
raise NoMethodError, "Undefined method" unless @target.respond_to?(symbol)
|
149
|
-
|
150
|
-
if (@is_custom)
|
151
|
-
if (@target._read_only_attributes.include?(symbol) )
|
152
|
-
return @target.send(symbol, *args, &block)
|
153
|
-
elsif (args.length == 0 && @target._should_proxy(symbol) )
|
154
|
-
# Attribute being accessed
|
155
|
-
return TransparentEngine.create_nested_proxy( @proxy_id, symbol, @engine_id )
|
156
|
-
elsif (args.length != 0 && @target._should_proxy(symbol) )
|
157
|
-
# Method being accessed
|
158
|
-
result = proceed(symbol, *args, &block)
|
159
|
-
return TransparentEngine.create_result_proxy( result, @engine_id )
|
160
|
-
# return TransparentProxy.new( result )
|
161
|
-
else
|
162
|
-
nested_proxy = @target._symbol2proxy(symbol)
|
163
|
-
# Returns the nested proxy associated with this symbol
|
164
|
-
# puts "Returning nested proxy for #{symbol} if #{nested_proxy.class.to_s}"
|
165
|
-
return nested_proxy unless nested_proxy.nil?
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
proceed(symbol, *args, &block)
|
170
|
-
end
|
171
|
-
|
172
|
-
def _dump(depth)
|
173
|
-
references = Thread.current[:references]
|
174
|
-
if (references)
|
175
|
-
if (references[self])
|
176
|
-
# puts "> serializing placeholder #{@proxy_id.to_s}"
|
177
|
-
[@proxy_id.to_s, @engine_id.to_s].pack("A40A40")
|
178
|
-
else
|
179
|
-
# puts "> serializing proxy #{@proxy_id.to_s}"
|
180
|
-
references[self] = true
|
181
|
-
[@proxy_id.to_s, @engine_id.to_s].pack("A40A40") + Marshal.dump(@target, depth)
|
182
|
-
end
|
183
|
-
else
|
184
|
-
[@proxy_id.to_s, @engine_id.to_s].pack("A40A40")
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
def TransparentProxy._load(buffer)
|
189
|
-
proxy = TransparentProxy.allocate
|
190
|
-
list = buffer.unpack("A40A40a*")
|
191
|
-
proxy.proxy_id = Guid.from_s( list[0] )
|
192
|
-
proxy.engine_id = Guid.from_s( list[1] )
|
193
|
-
TransparentEngine.current() { |engine|
|
194
|
-
proxy = engine.restore(proxy)
|
195
|
-
proxy.target = Marshal.load(list[2]) if (list[2] > "")
|
196
|
-
}
|
197
|
-
proxy
|
198
|
-
end
|
199
|
-
|
200
|
-
protected
|
201
|
-
|
202
|
-
def build_command( symbol, *args )
|
203
|
-
AutomaticCommand.new( @proxy_id, symbol, *args )
|
204
|
-
end
|
205
|
-
|
206
|
-
def proceed(symbol, *args, &block)
|
207
|
-
engine = TransparentEngine.current
|
208
|
-
result = nil
|
209
|
-
|
210
|
-
if (engine.nil?)
|
211
|
-
# In this case the invocation happens on the object by user code
|
212
|
-
raise "Blocks are not supported... yet" if block_given?
|
213
|
-
|
214
|
-
TransparentEngine.within_engine( @engine_id ) { |engine|
|
215
|
-
result = engine.execute_command( build_command(symbol, *args) )
|
216
|
-
}
|
217
|
-
else
|
218
|
-
# In this case the invocation is happening within an execute_command
|
219
|
-
result = @target.send(symbol, *args)
|
220
|
-
end
|
221
|
-
result
|
222
|
-
end
|
223
|
-
|
224
|
-
end
|
225
|
-
|
226
|
-
class NestedTransparentProxy < TransparentProxy
|
227
|
-
attr_reader :related_symbol, :parent_proxy_id, :args
|
228
|
-
|
229
|
-
def initialize(target, symbol, parent_proxy_id, *args)
|
230
|
-
raise 'A nested-proxy must have a symbol' if symbol.nil?
|
231
|
-
super(target)
|
232
|
-
@related_symbol, @parent_proxy_id, @args = symbol, parent_proxy_id, args
|
233
|
-
end
|
234
|
-
|
235
|
-
protected
|
236
|
-
|
237
|
-
def build_command( symbol, *args )
|
238
|
-
NestedAutomaticCommand.new( @related_symbol, @parent_proxy_id, @proxy_id, symbol, *args )
|
239
|
-
end
|
240
|
-
|
241
|
-
end
|
242
|
-
|
243
|
-
end
|
244
|
-
|
245
|
-
end
|