rod 0.7.1 → 0.7.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/.travis.yml +1 -1
- data/README.rdoc +38 -10
- data/Rakefile +20 -9
- data/changelog.txt +25 -0
- data/contributors.txt +1 -0
- data/data/backward/0.7.0/_join_element.dat +0 -0
- data/data/backward/0.7.0/_polymorphic_join_element.dat +0 -0
- data/data/backward/0.7.0/char.dat +0 -0
- data/data/backward/0.7.0/database.yml +58 -0
- data/data/backward/0.7.0/rod_test__automobile.dat +0 -0
- data/data/backward/0.7.0/rod_test__caveman.dat +0 -0
- data/data/backward/0.7.0/rod_test__dog.dat +0 -0
- data/data/backward/0.7.0/rod_test__test_model.dat +0 -0
- data/data/portability/_join_element.dat +0 -0
- data/data/portability/_polymorphic_join_element.dat +0 -0
- data/data/portability/char.dat +0 -0
- data/data/portability/database.yml +49 -0
- data/data/portability/rod_test__automobile.dat +0 -0
- data/data/portability/rod_test__caveman.dat +0 -0
- data/data/portability/rod_test__dog.dat +0 -0
- data/data/portability/rod_test__test_model.dat +0 -0
- data/features/backward.feature +33 -0
- data/features/basic.feature +3 -0
- data/features/collection_proxy.feature +95 -0
- data/features/flat_indexing.feature +44 -2
- data/features/hash_indexing.feature +63 -9
- data/features/portability.feature +72 -0
- data/features/segmented_indexing.feature +45 -2
- data/features/steps/collection_proxy.rb +1 -1
- data/features/steps/model.rb +48 -5
- data/features/steps/rod.rb +15 -16
- data/lib/rod.rb +11 -1
- data/lib/rod/abstract_database.rb +52 -42
- data/lib/rod/berkeley/collection_proxy.rb +96 -0
- data/lib/rod/berkeley/database.rb +337 -0
- data/lib/rod/berkeley/environment.rb +209 -0
- data/lib/rod/berkeley/sequence.rb +222 -0
- data/lib/rod/berkeley/transaction.rb +233 -0
- data/lib/rod/collection_proxy.rb +76 -1
- data/lib/rod/constants.rb +3 -2
- data/lib/rod/database.rb +127 -14
- data/lib/rod/index/base.rb +12 -3
- data/lib/rod/index/hash_index.rb +295 -70
- data/lib/rod/index/segmented_index.rb +3 -0
- data/lib/rod/model.rb +154 -531
- data/lib/rod/property/base.rb +190 -0
- data/lib/rod/property/field.rb +258 -0
- data/lib/rod/property/plural_association.rb +145 -0
- data/lib/rod/property/singular_association.rb +139 -0
- data/rod.gemspec +6 -4
- data/spec/berkeley/database.rb +83 -0
- data/spec/berkeley/environment.rb +58 -0
- data/spec/berkeley/sequence.rb +101 -0
- data/spec/berkeley/transaction.rb +92 -0
- data/spec/collection_proxy.rb +38 -0
- data/spec/database.rb +36 -0
- data/spec/model.rb +26 -0
- data/spec/property/base.rb +73 -0
- data/spec/property/field.rb +244 -0
- data/spec/property/plural_association.rb +67 -0
- data/spec/property/singular_association.rb +65 -0
- data/tests/class_compatibility_create.rb +2 -2
- data/tests/eff1_test.rb +1 -1
- data/tests/eff2_test.rb +1 -1
- data/tests/full_runs.rb +1 -1
- data/tests/generate_classes_create.rb +14 -14
- data/tests/migration_create.rb +47 -47
- data/tests/migration_verify.rb +1 -1
- data/tests/missing_class_create.rb +6 -6
- data/tests/properties_order_create.rb +4 -4
- data/tests/read_on_create.rb +33 -34
- data/tests/save_struct.rb +40 -39
- data/tests/unit/database.rb +1 -1
- data/tests/unit/model_tests.rb +73 -65
- metadata +71 -15
- data/tests/unit/model.rb +0 -36
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'rod'
|
4
|
+
|
5
|
+
describe Rod::Property::SingularAssociation do
|
6
|
+
before do
|
7
|
+
@klass = MiniTest::Mock.new
|
8
|
+
@builder = MiniTest::Mock.new
|
9
|
+
@klass.expect :nil?,false
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
@klass.verify
|
14
|
+
@builder.verify
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "a singular association" do
|
18
|
+
before do
|
19
|
+
@association = Rod::Property::SingularAssociation.new(@klass,:user,
|
20
|
+
:polymorphic => true)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "must not be a field" do
|
24
|
+
@association.field?.wont_equal true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "must be an association" do
|
28
|
+
@association.association?.must_equal true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "must be a singular association" do
|
32
|
+
@association.singular?.must_equal true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "must not be a plural association" do
|
36
|
+
@association.plural?.wont_equal true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "must produce proper metadata" do
|
40
|
+
@association.metadata.must_equal({:polymorphic => true})
|
41
|
+
end
|
42
|
+
|
43
|
+
it "must define C accessors" do
|
44
|
+
@klass.expect :struct_name, "struct_name"
|
45
|
+
@builder.expect :c,nil,[String]
|
46
|
+
@association.define_c_accessors(@builder)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "must seal C accessors" do
|
50
|
+
@klass.expect :send,nil,[:private,String]
|
51
|
+
@association.seal_c_accessors
|
52
|
+
end
|
53
|
+
|
54
|
+
it "must define getter" do
|
55
|
+
@klass.expect :send,nil,[:define_method,"user"]
|
56
|
+
@klass.expect :scope_name,"Rod"
|
57
|
+
@association.define_getter
|
58
|
+
end
|
59
|
+
|
60
|
+
it "must define setter" do
|
61
|
+
@klass.expect :send,nil,[:define_method,"user="]
|
62
|
+
@association.define_setter
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/tests/eff1_test.rb
CHANGED
data/tests/eff2_test.rb
CHANGED
data/tests/full_runs.rb
CHANGED
@@ -5,21 +5,21 @@ require File.join(".",File.dirname(__FILE__),"generate_classes_model")
|
|
5
5
|
Rod::Database.development_mode = true
|
6
6
|
|
7
7
|
|
8
|
-
Database.instance.create_database("tmp/generate_classes")
|
8
|
+
Database.instance.create_database("tmp/generate_classes") do
|
9
9
|
|
10
|
-
files = 10.times.map{|i| UserFile.new(:data => "#{i} data")}
|
11
|
-
files.each{|f| f.store}
|
10
|
+
files = 10.times.map{|i| UserFile.new(:data => "#{i} data")}
|
11
|
+
files.each{|f| f.store}
|
12
12
|
|
13
|
-
account = Account.new(:login => "john")
|
14
|
-
account.store
|
15
|
-
user = User.new(:name => "John", :account => account,
|
16
|
-
|
17
|
-
user.store
|
13
|
+
account = Account.new(:login => "john")
|
14
|
+
account.store
|
15
|
+
user = User.new(:name => "John", :account => account,
|
16
|
+
:files => [files[0],files[1],files[2]])
|
17
|
+
user.store
|
18
18
|
|
19
|
-
account = Account.new(:login => "amanda")
|
20
|
-
account.store
|
21
|
-
user = User.new(:name => "Amanda", :account => account,
|
22
|
-
|
23
|
-
user.store
|
19
|
+
account = Account.new(:login => "amanda")
|
20
|
+
account.store
|
21
|
+
user = User.new(:name => "Amanda", :account => account,
|
22
|
+
:files => [files[0],files[4],files[5],nil,files[6]])
|
23
|
+
user.store
|
24
24
|
|
25
|
-
|
25
|
+
end
|
data/tests/migration_create.rb
CHANGED
@@ -5,51 +5,51 @@ require File.join(".",File.dirname(__FILE__),"migration_model1")
|
|
5
5
|
Rod::Database.development_mode = true
|
6
6
|
|
7
7
|
FileUtils.rm_rf("tmp/migration")
|
8
|
-
Database.instance.create_database("tmp/migration")
|
9
|
-
|
10
|
-
count = (ARGV[0] || 10).to_i
|
11
|
-
puts "Count in migration test: #{count}"
|
12
|
-
|
13
|
-
files = count.times.map{|i| UserFile.new(:data => "#{i} data")}
|
14
|
-
files.each{|f| f.store}
|
15
|
-
|
16
|
-
users = []
|
17
|
-
count.times do |index|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
house = House.new(:name => "cottage house")
|
53
|
-
house.store
|
8
|
+
Database.instance.create_database("tmp/migration") do
|
9
|
+
|
10
|
+
count = (ARGV[0] || 10).to_i
|
11
|
+
puts "Count in migration test: #{count}"
|
12
|
+
|
13
|
+
files = count.times.map{|i| UserFile.new(:data => "#{i} data")}
|
14
|
+
files.each{|f| f.store}
|
15
|
+
|
16
|
+
users = []
|
17
|
+
count.times do |index|
|
18
|
+
account = Account.new(:login => "john#{index}",
|
19
|
+
:nick => "j#{index}")
|
20
|
+
account.store
|
21
|
+
user1 = User.new(:name => "John#{index}",
|
22
|
+
:surname => "Smith#{index}",
|
23
|
+
:city => "City#{index}",
|
24
|
+
:street => "Street#{index}",
|
25
|
+
:number => index,
|
26
|
+
:account => account,
|
27
|
+
:mother => users[index-1],
|
28
|
+
:father => users[index-2],
|
29
|
+
:friends => [users[index-3],users[index-4]],
|
30
|
+
:files => [files[index],files[index + 1],files[index + 2]])
|
31
|
+
user1.store
|
32
|
+
|
33
|
+
account = Account.new(:login => "amanda#{index}",
|
34
|
+
:nick => "a#{index}")
|
35
|
+
account.store
|
36
|
+
user2 = User.new(:name => "Amanda#{index}",
|
37
|
+
:surname => "Amanda#{index}",
|
38
|
+
:city => "Bigcity#{index}",
|
39
|
+
:street => "Small street#{index}",
|
40
|
+
:number => index,
|
41
|
+
:account => account,
|
42
|
+
:mother => users[index-1],
|
43
|
+
:father => users[index-2],
|
44
|
+
:friends => [users[index-5],users[index-6]],
|
45
|
+
:files => [files[index],files[index+4],files[index+5],
|
46
|
+
nil,files[index+6]])
|
47
|
+
user2.store
|
48
|
+
users << user1
|
49
|
+
users << user2
|
50
|
+
end
|
51
|
+
|
52
|
+
house = House.new(:name => "cottage house")
|
53
|
+
house.store
|
54
54
|
|
55
|
-
|
55
|
+
end
|
data/tests/migration_verify.rb
CHANGED
@@ -9,7 +9,7 @@ Database.instance.open_database("tmp/migration")
|
|
9
9
|
|
10
10
|
count = (ARGV[0] || 10).to_i
|
11
11
|
key_count = 0
|
12
|
-
User.
|
12
|
+
User.property(:street).index.each do |key,proxy|
|
13
13
|
key_count += 1
|
14
14
|
proxy.to_a.should == User.find_all_by_street(key).to_a
|
15
15
|
proxy.count.should > 0
|
@@ -13,9 +13,9 @@ end
|
|
13
13
|
|
14
14
|
Rod::Database.development_mode = true
|
15
15
|
|
16
|
-
Rod::Database.instance.create_database("tmp/missing_class")
|
17
|
-
user = User.new(:name => "John")
|
18
|
-
user.store
|
19
|
-
item = Item.new(:name => "hammer")
|
20
|
-
item.store
|
21
|
-
|
16
|
+
Rod::Database.instance.create_database("tmp/missing_class") do
|
17
|
+
user = User.new(:name => "John")
|
18
|
+
user.store
|
19
|
+
item = Item.new(:name => "hammer")
|
20
|
+
item.store
|
21
|
+
end
|
@@ -9,8 +9,8 @@ end
|
|
9
9
|
|
10
10
|
Rod::Database.development_mode = true
|
11
11
|
|
12
|
-
Rod::Database.instance.create_database("tmp/properties_order")
|
13
|
-
user = User.new(:name => "John",:surname => "Smith")
|
14
|
-
user.store
|
15
|
-
|
12
|
+
Rod::Database.instance.create_database("tmp/properties_order") do
|
13
|
+
user = User.new(:name => "John",:surname => "Smith")
|
14
|
+
user.store
|
15
|
+
end
|
16
16
|
|
data/tests/read_on_create.rb
CHANGED
@@ -6,40 +6,39 @@ puts "-- Read data while creating DB --"
|
|
6
6
|
Rod::Database.development_mode = true
|
7
7
|
|
8
8
|
|
9
|
-
RodTest::Database.instance.create_database("tmp/read_write")
|
10
|
-
my_structures = []
|
11
|
-
MAGNITUDO.times do |index|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
MAGNITUDO.times do |index|
|
28
|
-
# validate object fetched from cache
|
29
|
-
struct = RodTest::MyStruct[index]
|
30
|
-
validate(index,struct)
|
31
|
-
# validate object referenced previously
|
32
|
-
validate(index,my_structures[index])
|
33
|
-
# validate referential integrity
|
34
|
-
if struct.object_id != my_structures[index].object_id
|
35
|
-
raise "Object stored and recived are different #{struct.object_id} " +
|
36
|
-
"#{my_structures[index].object_id}"
|
9
|
+
RodTest::Database.instance.create_database("tmp/read_write") do
|
10
|
+
my_structures = []
|
11
|
+
MAGNITUDO.times do |index|
|
12
|
+
your_struct = RodTest::YourStruct.new
|
13
|
+
your_struct.counter = index
|
14
|
+
your_struct.title = "Title_#{index}"
|
15
|
+
your_struct.store
|
16
|
+
|
17
|
+
my_struct = RodTest::MyStruct.new
|
18
|
+
my_struct.count = index
|
19
|
+
my_struct.your_struct = your_struct
|
20
|
+
my_struct.title = "Title_#{index}"
|
21
|
+
my_struct.title2 = "Title2_#{index}"
|
22
|
+
|
23
|
+
my_struct.store
|
24
|
+
my_structures << my_struct
|
37
25
|
end
|
38
|
-
if struct != my_structures[index]
|
39
|
-
raise "Object stored and recived are different #{struct} " +
|
40
|
-
"#{my_structures[index]}"
|
41
|
-
end
|
42
|
-
end
|
43
26
|
|
27
|
+
MAGNITUDO.times do |index|
|
28
|
+
# validate object fetched from cache
|
29
|
+
struct = RodTest::MyStruct[index]
|
30
|
+
validate(index,struct)
|
31
|
+
# validate object referenced previously
|
32
|
+
validate(index,my_structures[index])
|
33
|
+
# validate referential integrity
|
34
|
+
if struct.object_id != my_structures[index].object_id
|
35
|
+
raise "Object stored and recived are different #{struct.object_id} " +
|
36
|
+
"#{my_structures[index].object_id}"
|
37
|
+
end
|
38
|
+
if struct != my_structures[index]
|
39
|
+
raise "Object stored and recived are different #{struct} " +
|
40
|
+
"#{my_structures[index]}"
|
41
|
+
end
|
42
|
+
end
|
44
43
|
|
45
|
-
|
44
|
+
end
|
data/tests/save_struct.rb
CHANGED
@@ -3,47 +3,48 @@ require 'structures'
|
|
3
3
|
|
4
4
|
puts "-- Save sample structures test --"
|
5
5
|
Rod::Database.development_mode = true
|
6
|
-
RodTest::Database.instance.create_database("tmp/abc")
|
6
|
+
RodTest::Database.instance.create_database("tmp/abc") do
|
7
7
|
|
8
|
-
#MAGNITUDE = 100000
|
9
|
-
MAGNITUDE = 50
|
8
|
+
#MAGNITUDE = 100000
|
9
|
+
MAGNITUDE = 50
|
10
10
|
|
11
|
-
his = []
|
12
|
-
(MAGNITUDE * 10).times do |i|
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
ys = []
|
18
|
-
(MAGNITUDE * 1).times do |i|
|
19
|
-
ys[i] = RodTest::YourStruct.new
|
20
|
-
ys[i].counter = 10
|
21
|
-
ys[i].his_structs = his[i*10...(i+1)*10]
|
22
|
-
end
|
11
|
+
his = []
|
12
|
+
(MAGNITUDE * 10).times do |i|
|
13
|
+
his[i] = RodTest::HisStruct.new
|
14
|
+
his[i].inde = i
|
15
|
+
end
|
23
16
|
|
24
|
-
|
25
|
-
(MAGNITUDE * 1).times do |i|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
ms[i].your_struct = ys[i]
|
31
|
-
ms[i].title = "title_#{i}"
|
32
|
-
ms[i].title2 = "title2_#{i}"
|
33
|
-
ms[i].body = "body_#{i}"
|
34
|
-
end
|
17
|
+
ys = []
|
18
|
+
(MAGNITUDE * 1).times do |i|
|
19
|
+
ys[i] = RodTest::YourStruct.new
|
20
|
+
ys[i].counter = 10
|
21
|
+
ys[i].his_structs = his[i*10...(i+1)*10]
|
22
|
+
end
|
35
23
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
24
|
+
ms = []
|
25
|
+
(MAGNITUDE * 1).times do |i|
|
26
|
+
ms[i] = RodTest::MyStruct.new
|
27
|
+
ms[i].count = 10 * i
|
28
|
+
ms[i].precision = 0.1 * i
|
29
|
+
ms[i].identifier = i
|
30
|
+
ms[i].your_struct = ys[i]
|
31
|
+
ms[i].title = "title_#{i}"
|
32
|
+
ms[i].title2 = "title2_#{i}"
|
33
|
+
ms[i].body = "body_#{i}"
|
44
34
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
35
|
+
|
36
|
+
RodTest::Database.instance.print_layout
|
37
|
+
ms.each_with_index{|s,i|
|
38
|
+
begin
|
39
|
+
puts i if i % 1000 == 0
|
40
|
+
s.store
|
41
|
+
rescue Exception => e
|
42
|
+
puts e
|
43
|
+
raise
|
44
|
+
end
|
45
|
+
}
|
46
|
+
ys.each{|y| y.store}
|
47
|
+
his.each{|h| h.store}
|
48
|
+
RodTest::Database.instance.print_layout
|
49
|
+
|
50
|
+
end
|
data/tests/unit/database.rb
CHANGED