dm-rinda-adapter 0.1.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/Manifest +16 -0
- data/Rakefile +47 -0
- data/dm-rinda-adapter.gemspec +29 -0
- data/lib/rinda-patch.rb +25 -0
- data/lib/rinda_adapter.rb +448 -0
- data/spec/legacy/README +6 -0
- data/spec/legacy/adapter_shared_spec.rb +331 -0
- data/spec/legacy/spec_helper.rb +3 -0
- data/spec/lib/adapter_helpers.rb +105 -0
- data/spec/lib/collection_helpers.rb +18 -0
- data/spec/lib/counter_adapter.rb +34 -0
- data/spec/lib/pending_helpers.rb +46 -0
- data/spec/lib/rspec_immediate_feedback_formatter.rb +54 -0
- data/spec/rcov.opts +6 -0
- data/spec/rinda-adapter_spec.rb +168 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +110 -0
- metadata +88 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'legacy/adapter_shared_spec'))
|
3
|
+
|
4
|
+
require "rinda/tuplespace"
|
5
|
+
require 'thread'
|
6
|
+
|
7
|
+
describe 'Adapter' do
|
8
|
+
supported_by :rinda do
|
9
|
+
describe DataMapper::Adapters::RindaAdapter do
|
10
|
+
|
11
|
+
it_should_behave_like 'An Adapter'
|
12
|
+
|
13
|
+
before(:all) do
|
14
|
+
DataMapper.setup(:default, { :adapter => "Rinda",:local =>Rinda::TupleSpace.new})
|
15
|
+
#DataMapper::Logger.new("data.log", :debug)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#notify' do
|
19
|
+
before do
|
20
|
+
@heffalump = Heffalump.create(:color => 'indigo')
|
21
|
+
@heffalump.save
|
22
|
+
|
23
|
+
class ::Receiver
|
24
|
+
attr_accessor :results
|
25
|
+
def initialize()
|
26
|
+
@results=Queue.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def callback_method(result)
|
30
|
+
@results << result
|
31
|
+
# puts "color> #{result.color}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should respond on changed element after subscription' do
|
37
|
+
@heffalump.color = 'black'
|
38
|
+
@receiver = Receiver.new()
|
39
|
+
|
40
|
+
Heffalump.notify("write", { :color =>"black" },@receiver.method(:callback_method))
|
41
|
+
@heffalump.save
|
42
|
+
|
43
|
+
@receiver.results.pop.should == @heffalump
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should properly respond to double element #update# after subscription by notify' do
|
47
|
+
|
48
|
+
@receiver = Receiver.new()
|
49
|
+
|
50
|
+
Heffalump.notify("write", { :color =>"black" },@receiver.method(:callback_method))
|
51
|
+
Heffalump.notify("write", { :color =>"green" },@receiver.method(:callback_method))
|
52
|
+
|
53
|
+
100.times do
|
54
|
+
@heffalump.update(:color => 'black')
|
55
|
+
@heffalump.update(:color => 'green')
|
56
|
+
end
|
57
|
+
|
58
|
+
@receiver.results.length.should == 199 # warum? ist erstes elemen = 0
|
59
|
+
|
60
|
+
100.times do
|
61
|
+
@receiver.results.pop.color.should == "black"
|
62
|
+
@receiver.results.pop.color.should == "green"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should properly respond to double element #create# after subscription by notify' do
|
67
|
+
pending
|
68
|
+
@receiver = Receiver.new()
|
69
|
+
|
70
|
+
Heffalump.notify("write", { :color =>"black" },@receiver.method(:callback_method))
|
71
|
+
Heffalump.notify("write", { :color =>"green" },@receiver.method(:callback_method))
|
72
|
+
|
73
|
+
100.times do
|
74
|
+
Heffalump.create(:color => 'black').save
|
75
|
+
Heffalump.create(:color => 'green').save
|
76
|
+
end
|
77
|
+
|
78
|
+
@receiver.results.length.should == 199 # warum? ist erstes element = 0 ?
|
79
|
+
|
80
|
+
100.times do
|
81
|
+
@receiver.results.pop.color.should == "black"
|
82
|
+
@receiver.results.pop.color.should == "green"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
describe 'inheritance' do
|
89
|
+
|
90
|
+
before :all do
|
91
|
+
|
92
|
+
class Element
|
93
|
+
include DataMapper::Resource
|
94
|
+
property :id, Serial # the serial id is required as the first key since otherwise the sorting does not work as expected. (it would be ordered by ascending names - the second key!
|
95
|
+
property :type, Discriminator
|
96
|
+
property :name, String, :key => true
|
97
|
+
end
|
98
|
+
|
99
|
+
class Layoutelement < Element
|
100
|
+
property :size, String
|
101
|
+
property :pos, Integer
|
102
|
+
belongs_to :layoutcontainer # defaults to :required => true
|
103
|
+
end
|
104
|
+
|
105
|
+
class Layoutcontainer < Layoutelement
|
106
|
+
has n, :layoutelements
|
107
|
+
end
|
108
|
+
end
|
109
|
+
before(:each) do
|
110
|
+
DataMapper.setup(:default, { :adapter => "Rinda",:local =>Rinda::TupleSpace.new})
|
111
|
+
#DataMapper::Logger.new("data.log", :debug)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should preserve the order ' do
|
115
|
+
p = Layoutcontainer .new(:name => "container")
|
116
|
+
c1= Layoutcontainer.new(:name =>"a_comment_1")
|
117
|
+
c2=Layoutcontainer.new(:name => "x_comment_2")
|
118
|
+
c1.layoutelements=[]
|
119
|
+
p.layoutelements =[c2,c1]
|
120
|
+
p.save
|
121
|
+
Layoutelement.first(:name =>"container").layoutelements.should == [c2,c1]
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should preserve the order even after attribute update' do
|
125
|
+
p = Layoutcontainer .new(:name => "container")
|
126
|
+
c1= Layoutcontainer.new(:name =>"a_comment_1")
|
127
|
+
c2=Layoutcontainer.new(:name => "x_comment_2")
|
128
|
+
c4 =Layoutcontainer.new(:name => "x_child1")
|
129
|
+
c5 = Layoutcontainer.new(:name => "a_child2")
|
130
|
+
c1.layoutelements=[]
|
131
|
+
p.layoutelements =[c2,c1]
|
132
|
+
c1.layoutelements=[c4,c5]
|
133
|
+
p.save
|
134
|
+
up = Layoutelement.first(:name=>"a_comment_1")
|
135
|
+
up.update(:size =>"test")
|
136
|
+
|
137
|
+
Layoutelement.first(:name =>"container").layoutelements.should == [c2,up]
|
138
|
+
Layoutelement.first(:name =>"container").layoutelements[1].layoutelements.should == [c4,c5]
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should preserve the order in the structure after save and find even for large arrays' do
|
142
|
+
p = Layoutcontainer .new(:name => "container",:layoutelements => [])
|
143
|
+
for i in 0..30
|
144
|
+
c = Layoutcontainer.new(:name => "name_#{i}", :pos=>i)
|
145
|
+
for j in 0..30
|
146
|
+
c.layoutelements << Layoutelement.new(:name =>"child_#{j}", :pos =>j)
|
147
|
+
end
|
148
|
+
p.layoutelements << c
|
149
|
+
end
|
150
|
+
|
151
|
+
old = p.layoutelements
|
152
|
+
|
153
|
+
p.save
|
154
|
+
|
155
|
+
test = Layoutelement.first(:name=>"container").layoutelements
|
156
|
+
|
157
|
+
test.each_with_index do |e,i|
|
158
|
+
e.pos.should == i
|
159
|
+
e.layoutelements.each_with_index do |f,j|
|
160
|
+
f.pos.should == j
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
require 'addressable/uri'
|
5
|
+
require 'spec'
|
6
|
+
require "rinda/tuplespace"
|
7
|
+
|
8
|
+
SPEC_ROOT = Pathname(__FILE__).dirname.expand_path
|
9
|
+
$LOAD_PATH.unshift(SPEC_ROOT.parent + 'lib')
|
10
|
+
|
11
|
+
require 'dm-core'
|
12
|
+
|
13
|
+
ENV['PLUGINS'].to_s.strip.split(/\s+/).each do |plugin|
|
14
|
+
require plugin
|
15
|
+
end
|
16
|
+
|
17
|
+
Pathname.glob((SPEC_ROOT + '{lib,*/shared}/**/*.rb').to_s).each { |file| require file }
|
18
|
+
|
19
|
+
# create sqlite3_fs directory if it doesn't exist
|
20
|
+
temp_db_dir = SPEC_ROOT.join('db')
|
21
|
+
temp_db_dir.mkpath
|
22
|
+
|
23
|
+
ENV['ADAPTERS'] ||= 'all'
|
24
|
+
|
25
|
+
HAS_DO = DataMapper::Adapters.const_defined?('DataObjectsAdapter')
|
26
|
+
|
27
|
+
ADAPTERS = []
|
28
|
+
|
29
|
+
PRIMARY = {
|
30
|
+
'rinda' => { :adapter => "rinda", :local =>Rinda::TupleSpace.new},
|
31
|
+
}
|
32
|
+
|
33
|
+
ALTERNATE = {
|
34
|
+
'rinda' => { :adapter => "Rinda", :local =>Rinda::TupleSpace.new},
|
35
|
+
}
|
36
|
+
|
37
|
+
# These environment variables will override the default connection string:
|
38
|
+
# MYSQL_SPEC_URI
|
39
|
+
# POSTGRES_SPEC_URI
|
40
|
+
# SQLITE3_SPEC_URI
|
41
|
+
#
|
42
|
+
# For example, in the bash shell, you might use:
|
43
|
+
# export MYSQL_SPEC_URI="mysql://localhost/dm_core_test?socket=/opt/local/var/run/mysql5/mysqld.sock"
|
44
|
+
|
45
|
+
adapters = ENV['ADAPTERS'].split(' ').map { |adapter_name| adapter_name.strip.downcase }.uniq
|
46
|
+
adapters = PRIMARY.keys if adapters.include?('all')
|
47
|
+
|
48
|
+
PRIMARY.only(*adapters).each do |name, default|
|
49
|
+
connection_string = ENV["#{name.upcase}_SPEC_URI"] || default
|
50
|
+
begin
|
51
|
+
adapter = DataMapper.setup(name.to_sym, connection_string)
|
52
|
+
|
53
|
+
# test the connection if possible
|
54
|
+
if adapter.respond_to?(:query)
|
55
|
+
name == 'oracle' ? adapter.select('SELECT 1 FROM dual') : adapter.select('SELECT 1')
|
56
|
+
end
|
57
|
+
|
58
|
+
ADAPTERS << name
|
59
|
+
PRIMARY[name] = connection_string # ensure *_SPEC_URI is saved
|
60
|
+
rescue Exception => exception
|
61
|
+
puts "Could not connect to the database using #{connection_string.inspect} because: #{exception.inspect}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# speed up test execution on Oracle
|
66
|
+
if defined?(DataMapper::Adapters::OracleAdapter)
|
67
|
+
DataMapper::Adapters::OracleAdapter.instance_eval do
|
68
|
+
auto_migrate_with :delete # table data will be deleted instead of dropping and creating table
|
69
|
+
auto_migrate_reset_sequences false # primary key sequences will not be reset
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
ADAPTERS.freeze
|
74
|
+
PRIMARY.freeze
|
75
|
+
|
76
|
+
logger = DataMapper::Logger.new(SPEC_ROOT.parent / 'log' / 'dm.log', :debug)
|
77
|
+
logger.auto_flush = true
|
78
|
+
|
79
|
+
Spec::Runner.configure do |config|
|
80
|
+
config.extend(DataMapper::Spec::AdapterHelpers)
|
81
|
+
config.include(DataMapper::Spec::PendingHelpers)
|
82
|
+
|
83
|
+
config.after :all do
|
84
|
+
# global model cleanup
|
85
|
+
descendants = DataMapper::Model.descendants.to_a
|
86
|
+
while model = descendants.shift
|
87
|
+
descendants.concat(model.descendants.to_a - [ model ])
|
88
|
+
|
89
|
+
parts = model.name.split('::')
|
90
|
+
constant_name = parts.pop.to_sym
|
91
|
+
base = parts.empty? ? Object : Object.full_const_get(parts.join('::'))
|
92
|
+
|
93
|
+
if base.const_defined?(constant_name)
|
94
|
+
base.send(:remove_const, constant_name)
|
95
|
+
end
|
96
|
+
|
97
|
+
DataMapper::Model.descendants.delete(model)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# remove the Resource#send method to ensure specs/internals do no rely on it
|
103
|
+
module RemoveSend
|
104
|
+
def self.included(model)
|
105
|
+
model.send(:undef_method, :send)
|
106
|
+
model.send(:undef_method, :freeze)
|
107
|
+
end
|
108
|
+
|
109
|
+
DataMapper::Model.append_inclusions self
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dm-rinda-adapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Sebastian Feuerstack
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-30 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A datamapper adapter to connect to a rinda tuplespace
|
22
|
+
email: sebastian @nospam@ feuerstack.de
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- lib/rinda-patch.rb
|
29
|
+
- lib/rinda_adapter.rb
|
30
|
+
files:
|
31
|
+
- Manifest
|
32
|
+
- Rakefile
|
33
|
+
- lib/rinda-patch.rb
|
34
|
+
- lib/rinda_adapter.rb
|
35
|
+
- spec/legacy/README
|
36
|
+
- spec/legacy/adapter_shared_spec.rb
|
37
|
+
- spec/legacy/spec_helper.rb
|
38
|
+
- spec/lib/adapter_helpers.rb
|
39
|
+
- spec/lib/collection_helpers.rb
|
40
|
+
- spec/lib/counter_adapter.rb
|
41
|
+
- spec/lib/pending_helpers.rb
|
42
|
+
- spec/lib/rspec_immediate_feedback_formatter.rb
|
43
|
+
- spec/rcov.opts
|
44
|
+
- spec/rinda-adapter_spec.rb
|
45
|
+
- spec/spec.opts
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
- dm-rinda-adapter.gemspec
|
48
|
+
homepage: http://github.com/sfeu/dm-rinda-adapter
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --line-numbers
|
54
|
+
- --inline-source
|
55
|
+
- --title
|
56
|
+
- Dm-rinda-adapter
|
57
|
+
- --main
|
58
|
+
- README.rdoc
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 11
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 2
|
79
|
+
version: "1.2"
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project: dm-rinda-adapter
|
83
|
+
rubygems_version: 1.8.5
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: A datamapper adapter to connect to a rinda tuplespace
|
87
|
+
test_files: []
|
88
|
+
|