strokedb 0.0.2.1 → 0.0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +18 -20
- data/bench.html +4001 -0
- data/bin/strokedb +14 -0
- data/examples/movies.rb +105 -0
- data/examples/movies2.rb +97 -0
- data/examples/strokewiki/README +28 -0
- data/examples/strokewiki/view/edit.xhtml +27 -0
- data/examples/strokewiki/view/new.xhtml +26 -0
- data/examples/strokewiki/view/pages.xhtml +27 -0
- data/examples/strokewiki/view/show.xhtml +40 -0
- data/examples/strokewiki/view/versions.xhtml +25 -0
- data/examples/strokewiki/wiki.rb +106 -0
- data/examples/todo.rb +92 -0
- data/lib/strokedb.rb +85 -0
- data/lib/{config → strokedb}/config.rb +14 -9
- data/lib/strokedb/console.rb +87 -0
- data/lib/strokedb/core_ext.rb +10 -0
- data/lib/{util/ext → strokedb/core_ext}/blank.rb +1 -1
- data/lib/{util/ext → strokedb/core_ext}/enumerable.rb +0 -0
- data/lib/{util/ext → strokedb/core_ext}/fixnum.rb +0 -0
- data/lib/strokedb/core_ext/float.rb +4 -0
- data/lib/{util/ext → strokedb/core_ext}/hash.rb +0 -0
- data/lib/strokedb/core_ext/infinity.rb +33 -0
- data/lib/strokedb/core_ext/kernel.rb +41 -0
- data/lib/strokedb/core_ext/object.rb +16 -0
- data/lib/{util/ext → strokedb/core_ext}/string.rb +28 -1
- data/lib/strokedb/core_ext/symbol.rb +13 -0
- data/lib/strokedb/data_structures.rb +5 -0
- data/lib/strokedb/data_structures/chunked_skiplist.rb +123 -0
- data/lib/{data_structures → strokedb/data_structures}/inverted_list.rb +0 -0
- data/lib/{data_structures → strokedb/data_structures}/point_query.rb +0 -0
- data/lib/strokedb/data_structures/simple_skiplist.rb +350 -0
- data/lib/{data_structures → strokedb/data_structures}/skiplist.rb +1 -1
- data/lib/{document → strokedb}/document.rb +180 -71
- data/lib/{document → strokedb/document}/callback.rb +0 -0
- data/lib/{document → strokedb/document}/delete.rb +2 -2
- data/lib/strokedb/document/dsl.rb +4 -0
- data/lib/{document → strokedb/document/dsl}/associations.rb +0 -0
- data/lib/{document → strokedb/document/dsl}/coercions.rb +0 -0
- data/lib/strokedb/document/dsl/meta_dsl.rb +7 -0
- data/lib/{document → strokedb/document/dsl}/validations.rb +26 -21
- data/lib/{document → strokedb/document/dsl}/virtualize.rb +0 -0
- data/lib/{document → strokedb/document}/meta.rb +92 -29
- data/lib/{document → strokedb/document}/slot.rb +17 -5
- data/lib/{document → strokedb/document}/util.rb +0 -0
- data/lib/{document → strokedb/document}/versions.rb +2 -2
- data/lib/strokedb/index.rb +2 -0
- data/lib/strokedb/nsurl.rb +24 -0
- data/lib/strokedb/store.rb +149 -0
- data/lib/strokedb/stores.rb +6 -0
- data/lib/{stores → strokedb/stores}/chainable_storage.rb +20 -14
- data/lib/strokedb/stores/file_storage.rb +118 -0
- data/lib/{stores/inverted_list_index → strokedb/stores}/inverted_list_file_storage.rb +50 -0
- data/lib/strokedb/stores/memory_storage.rb +80 -0
- data/lib/{stores → strokedb/stores}/remote_store.rb +10 -4
- data/lib/strokedb/sync.rb +4 -0
- data/lib/{sync → strokedb/sync}/chain_sync.rb +0 -0
- data/lib/{sync → strokedb/sync}/diff.rb +12 -1
- data/lib/{sync/stroke_diff → strokedb/sync/diff}/array.rb +1 -1
- data/lib/{sync/stroke_diff → strokedb/sync/diff}/default.rb +0 -0
- data/lib/{sync/stroke_diff → strokedb/sync/diff}/hash.rb +1 -1
- data/lib/{sync/stroke_diff → strokedb/sync/diff}/string.rb +1 -1
- data/lib/{sync → strokedb/sync}/lamport_timestamp.rb +0 -0
- data/lib/{sync → strokedb/sync}/store_sync.rb +15 -7
- data/lib/strokedb/transaction.rb +78 -0
- data/lib/{util → strokedb}/util.rb +14 -7
- data/lib/strokedb/util/attach_dsl.rb +29 -0
- data/lib/{util → strokedb/util}/blankslate.rb +0 -0
- data/lib/strokedb/util/class_optimization.rb +93 -0
- data/lib/{util → strokedb/util}/inflect.rb +0 -0
- data/lib/strokedb/util/java_util.rb +13 -0
- data/lib/{util → strokedb/util}/lazy_array.rb +0 -0
- data/lib/{util → strokedb/util}/lazy_mapping_array.rb +4 -0
- data/lib/{util → strokedb/util}/lazy_mapping_hash.rb +0 -0
- data/lib/{util → strokedb/util}/serialization.rb +21 -0
- data/lib/strokedb/util/uuid.rb +159 -0
- data/lib/{util → strokedb/util}/xml.rb +0 -0
- data/lib/{view → strokedb}/view.rb +2 -2
- data/lib/strokedb/volumes.rb +5 -0
- data/lib/strokedb/volumes/archive_volume.rb +165 -0
- data/lib/strokedb/volumes/block_volume.rb +169 -0
- data/lib/strokedb/volumes/distributed_pointer.rb +43 -0
- data/lib/strokedb/volumes/fixed_length_skiplist_volume.rb +109 -0
- data/lib/strokedb/volumes/map_volume.rb +268 -0
- data/meta/MANIFEST +175 -0
- data/script/console +2 -70
- data/spec/integration/remote_store_spec.rb +70 -0
- data/spec/integration/search_spec.rb +76 -0
- data/spec/integration/spec_helper.rb +1 -0
- data/spec/lib/spec_helper.rb +1 -0
- data/spec/lib/strokedb/config_spec.rb +250 -0
- data/spec/lib/strokedb/core_ext/blank_spec.rb +20 -0
- data/spec/lib/strokedb/core_ext/extract_spec.rb +42 -0
- data/spec/lib/strokedb/core_ext/float_spec.rb +62 -0
- data/spec/lib/strokedb/core_ext/infinity_spec.rb +40 -0
- data/spec/lib/strokedb/core_ext/spec_helper.rb +1 -0
- data/spec/lib/strokedb/core_ext/string_spec.rb +25 -0
- data/spec/lib/strokedb/core_ext/symbol_spec.rb +8 -0
- data/spec/lib/strokedb/data_structures/chunked_skiplist_spec.rb +144 -0
- data/spec/lib/strokedb/data_structures/inverted_list_spec.rb +172 -0
- data/spec/lib/strokedb/data_structures/simple_skiplist_spec.rb +200 -0
- data/spec/lib/strokedb/data_structures/skiplist_spec.rb +253 -0
- data/spec/lib/strokedb/data_structures/spec_helper.rb +1 -0
- data/spec/lib/strokedb/document/associations_spec.rb +319 -0
- data/spec/lib/strokedb/document/callbacks_spec.rb +134 -0
- data/spec/lib/strokedb/document/coercions_spec.rb +110 -0
- data/spec/lib/strokedb/document/document_spec.rb +1063 -0
- data/spec/lib/strokedb/document/meta_meta_spec.rb +30 -0
- data/spec/lib/strokedb/document/meta_spec.rb +435 -0
- data/spec/lib/strokedb/document/metaslot_spec.rb +43 -0
- data/spec/lib/strokedb/document/slot_spec.rb +130 -0
- data/spec/lib/strokedb/document/spec_helper.rb +1 -0
- data/spec/lib/strokedb/document/validations_spec.rb +1081 -0
- data/spec/lib/strokedb/document/virtualize_spec.rb +80 -0
- data/spec/lib/strokedb/nsurl_spec.rb +73 -0
- data/spec/lib/strokedb/spec_helper.rb +1 -0
- data/spec/lib/strokedb/stores/chained_storages_spec.rb +116 -0
- data/spec/lib/strokedb/stores/spec_helper.rb +1 -0
- data/spec/lib/strokedb/stores/store_spec.rb +201 -0
- data/spec/lib/strokedb/stores/transaction_spec.rb +107 -0
- data/spec/lib/strokedb/sync/chain_sync_spec.rb +43 -0
- data/spec/lib/strokedb/sync/diff_spec.rb +111 -0
- data/spec/lib/strokedb/sync/lamport_timestamp_spec.rb +174 -0
- data/spec/lib/strokedb/sync/slot_diff_spec.rb +164 -0
- data/spec/lib/strokedb/sync/spec_helper.rb +1 -0
- data/spec/lib/strokedb/sync/store_sync_spec.rb +181 -0
- data/spec/lib/strokedb/sync/stroke_diff/array_spec.rb +97 -0
- data/spec/lib/strokedb/sync/stroke_diff/complex_spec.rb +58 -0
- data/spec/lib/strokedb/sync/stroke_diff/hash_spec.rb +144 -0
- data/spec/lib/strokedb/sync/stroke_diff/scalar_spec.rb +23 -0
- data/spec/lib/strokedb/sync/stroke_diff/spec_helper.rb +25 -0
- data/spec/lib/strokedb/sync/stroke_diff/string_spec.rb +61 -0
- data/spec/lib/strokedb/util/attach_dsl_spec.rb +45 -0
- data/spec/lib/strokedb/util/inflect_spec.rb +14 -0
- data/spec/lib/strokedb/util/lazy_array_spec.rb +157 -0
- data/spec/lib/strokedb/util/lazy_mapping_array_spec.rb +174 -0
- data/spec/lib/strokedb/util/lazy_mapping_hash_spec.rb +92 -0
- data/spec/lib/strokedb/util/spec_helper.rb +1 -0
- data/spec/lib/strokedb/util/uuid_spec.rb +46 -0
- data/spec/lib/strokedb/view_spec.rb +228 -0
- data/spec/lib/strokedb/volumes/archive_volume_spec.rb +105 -0
- data/spec/lib/strokedb/volumes/block_volume_spec.rb +100 -0
- data/spec/lib/strokedb/volumes/distributed_pointer_spec.rb +14 -0
- data/spec/lib/strokedb/volumes/fixed_length_skiplist_volume_spec.rb +177 -0
- data/spec/lib/strokedb/volumes/map_volume_spec.rb +172 -0
- data/spec/lib/strokedb/volumes/spec_helper.rb +1 -0
- data/spec/regression/docref_spec.rb +94 -0
- data/spec/regression/meta_spec.rb +23 -0
- data/spec/regression/spec_helper.rb +1 -0
- data/spec/regression/sync_spec.rb +36 -0
- data/spec/spec.opts +7 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/temp/storages/TIMESTAMP +1 -0
- data/spec/temp/storages/UUID +1 -0
- data/spec/temp/storages/database-sync/TIMESTAMP +1 -0
- data/spec/temp/storages/database-sync/UUID +1 -0
- data/spec/temp/storages/database-sync/config +1 -0
- data/spec/temp/storages/database-sync/file/LAST +1 -0
- data/spec/temp/storages/database-sync/file/bd/f6/bdf675e5-8a7b-494e-97f2-f74a14ccd95d.av +0 -0
- data/spec/temp/storages/database-sync/file/uindex.wal +0 -0
- data/spec/temp/storages/database-sync/inverted_list_file/INVERTED_INDEX +1 -0
- data/spec/temp/storages/inverted_list_storage/INVERTED_INDEX +0 -0
- data/strokedb.gemspec +120 -0
- data/task/benchmark.task +9 -0
- data/task/ditz.task +30 -0
- data/task/echoe.rb +17 -0
- data/task/rcov.task +50 -0
- data/task/rdoc.task +10 -0
- data/task/rspec.task +0 -0
- data/vendor/java_inline.rb +106 -0
- data/vendor/rbmodexcl/mrimodexcl.rb +82 -0
- data/vendor/rbmodexcl/rbmodexcl.rb +5 -0
- data/vendor/rbmodexcl/rbxmodexcl.rb +48 -0
- data/vendor/rbmodexcl/spec/unextend_spec.rb +50 -0
- data/vendor/rbmodexcl/spec/uninclude_spec.rb +26 -0
- metadata +271 -79
- data/CONTRIBUTORS +0 -7
- data/CREDITS +0 -13
- data/bin/sdbc +0 -2
- data/lib/init.rb +0 -57
- data/lib/stores/inverted_list_index/inverted_list_index.rb +0 -49
- data/lib/stores/skiplist_store/chunk.rb +0 -119
- data/lib/stores/skiplist_store/chunk_storage.rb +0 -21
- data/lib/stores/skiplist_store/file_chunk_storage.rb +0 -44
- data/lib/stores/skiplist_store/memory_chunk_storage.rb +0 -37
- data/lib/stores/skiplist_store/skiplist_store.rb +0 -217
- data/lib/stores/store.rb +0 -5
- data/lib/sync/stroke_diff/stroke_diff.rb +0 -9
- data/lib/util/ext/object.rb +0 -8
- data/lib/util/java_util.rb +0 -9
- data/lib/util/trigger_partition.rb +0 -136
- data/strokedb.rb +0 -75
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
def setup
|
4
|
+
setup_default_store
|
5
|
+
setup_index
|
6
|
+
Object.send!(:remove_const, 'Foo') if defined? Foo
|
7
|
+
Object.send!(:remove_const, 'Bar') if defined? Bar
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "Document slot virtualization" do
|
11
|
+
before :each do
|
12
|
+
setup
|
13
|
+
|
14
|
+
Foo = Meta.new do
|
15
|
+
virtualizes [ :virtual_slot, :another_slot ]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should act like a slot" do
|
20
|
+
f = Foo.new(:virtual_slot => 123)
|
21
|
+
f.virtual_slot.should == 123
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should retain its value after save" do
|
25
|
+
f = Foo.new(:virtual_slot => 123, :another_slot => 456)
|
26
|
+
f.virtual_slot.should == 123
|
27
|
+
f.another_slot.should == 456
|
28
|
+
f.save!
|
29
|
+
f.virtual_slot.should == 123
|
30
|
+
f.another_slot.should == 456
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should not serialize slot value" do
|
34
|
+
f = Foo.create!(:virtual_slot => 123)
|
35
|
+
|
36
|
+
f_copy = Foo.find(f.uuid)
|
37
|
+
f_copy.has_slot?("virtual_slot").should_not be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should preserve version after saving document" do
|
41
|
+
f = Foo.new(:virtual_slot => 123)
|
42
|
+
lambda do
|
43
|
+
f.save!
|
44
|
+
end.should_not change(f,:version)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should preserve previous version after saving document" do
|
48
|
+
f = Foo.new(:virtual_slot => 123)
|
49
|
+
lambda do
|
50
|
+
f.save!
|
51
|
+
end.should_not change(f,:previous_version)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should allow to validate the virtual slot" do
|
55
|
+
Bar = Meta.new do
|
56
|
+
virtualizes :mylovelyslot
|
57
|
+
validates_presence_of :mylovelyslot
|
58
|
+
end
|
59
|
+
|
60
|
+
b = Bar.new(:mylovelyslot => 456)
|
61
|
+
b.should be_valid
|
62
|
+
lambda { b.save! }.should_not raise_error(InvalidDocumentError)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "shouldn't restore virtual slot with :restore set to false" do
|
66
|
+
Bar = Meta.new { virtualizes :mylovelyslot, :restore => false }
|
67
|
+
b = Bar.new(:mylovelyslot => "abc")
|
68
|
+
b.mylovelyslot.should == "abc"
|
69
|
+
b.save!
|
70
|
+
b.has_slot?(:mylovelyslot).should be_false
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should preserve version after saving document with :restore set to false" do
|
74
|
+
Bar = Meta.new { virtualizes :mylovelyslot, :restore => false }
|
75
|
+
b = Bar.new(:mylovelyslot => "abc")
|
76
|
+
lambda do
|
77
|
+
b.save!
|
78
|
+
end.should_not change(b,:version)
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Some", Module do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@module = Module.new
|
7
|
+
Module.reset_nsurls
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:each) do
|
11
|
+
Module.reset_nsurls
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have nil nsurl by default" do
|
15
|
+
@module.nsurl.should be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be able to change nsurl" do
|
19
|
+
@module.nsurl 'http://some.url'
|
20
|
+
@module.nsurl.should == 'http://some.url'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should be findable by nsurl" do
|
24
|
+
@module.nsurl 'http://some.url'
|
25
|
+
Module.find_by_nsurl(@module.nsurl).should == @module
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be able to change nsurl to the same value" do
|
29
|
+
@module.nsurl 'http://some.url'
|
30
|
+
lambda { @module.nsurl 'http://some.url' }.should_not raise_error(ArgumentError)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should not be able to change nsurl to the value already assigned to some module" do
|
34
|
+
@some_module = Module.new
|
35
|
+
@some_module.nsurl 'http://some.url'
|
36
|
+
lambda { @module.nsurl 'http://some.url' }.should raise_error(ArgumentError)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe Module do
|
42
|
+
|
43
|
+
|
44
|
+
before(:each) do
|
45
|
+
Module.reset_nsurls
|
46
|
+
end
|
47
|
+
|
48
|
+
after(:each) do
|
49
|
+
Module.reset_nsurls
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
it "should have empty nsurl by default" do
|
54
|
+
Module.nsurl.should be_empty
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe StrokeDB do
|
60
|
+
|
61
|
+
before(:each) do
|
62
|
+
Module.reset_nsurls
|
63
|
+
end
|
64
|
+
|
65
|
+
after(:each) do
|
66
|
+
Module.reset_nsurls
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should have #{STROKEDB_NSURL} nsurl by default" do
|
70
|
+
StrokeDB.nsurl.should == STROKEDB_NSURL
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
[ FileStorage, MemoryStorage ].each do |storage|
|
4
|
+
describe "Chained chunk storage (#{storage})" do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@path = TEMP_STORAGES + '/file_chunk_storage_spec'
|
8
|
+
FileUtils.rm_rf @path
|
9
|
+
@storage = storage.new(:path => @path)
|
10
|
+
@storage.clear!
|
11
|
+
@store = mock("Store")
|
12
|
+
@document = Document.new(@store, 'a' => 1, 'b' => 2)
|
13
|
+
|
14
|
+
@target_storage = storage.new(:path => "#{@path}_chained")
|
15
|
+
@target_storage.clear!
|
16
|
+
|
17
|
+
@target_storage1 = storage.new(:path => "#{@path}_chained_1")
|
18
|
+
@target_storage1.clear!
|
19
|
+
|
20
|
+
@counter = LTS.zero
|
21
|
+
end
|
22
|
+
|
23
|
+
after(:each) do
|
24
|
+
@target_storage.close!
|
25
|
+
@target_storage1.close!
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should collect update to target store" do
|
29
|
+
@storage.save!(@document,@counter)
|
30
|
+
@storage.add_chained_storage!(@target_storage)
|
31
|
+
@document1 = Document.new(@store, 'x' => 1, 'y' => 2)
|
32
|
+
@storage.save!(@document1,@counter)
|
33
|
+
@target_storage.should_receive(:save!).with(@document1,@counter,{},@storage)
|
34
|
+
@storage.sync_chained_storage!(@target_storage)
|
35
|
+
@storage.sync_chained_storage!(@target_storage)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
it "should collect update to multiple target store" do
|
40
|
+
@storage.add_chained_storage!(@target_storage)
|
41
|
+
@storage.save!(@document,@counter)
|
42
|
+
@storage.add_chained_storage!(@target_storage1)
|
43
|
+
@document1 = Document.new(@store, 'x' => 1, 'y' => 2)
|
44
|
+
@storage.save!(@document1,@counter)
|
45
|
+
@target_storage.should_receive(:save!).with(@document,@counter,{},@storage).ordered
|
46
|
+
@target_storage.should_receive(:save!).with(@document1,@counter,{},@storage).ordered
|
47
|
+
@target_storage1.should_receive(:save!).with(@document1,@counter,{},@storage)
|
48
|
+
|
49
|
+
@storage.sync_chained_storage!(@target_storage)
|
50
|
+
@storage.sync_chained_storage!(@target_storage1)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should collect update to multiple target store and send them at once" do
|
54
|
+
@storage.add_chained_storage!(@target_storage)
|
55
|
+
@storage.save!(@document,@counter)
|
56
|
+
@storage.add_chained_storage!(@target_storage1)
|
57
|
+
@document1 = Document.new(@store,'x' => 1, 'y' => 2)
|
58
|
+
@storage.save!(@document1,@counter)
|
59
|
+
@target_storage.should_receive(:save!).with(@document,@counter,{},@storage).ordered
|
60
|
+
@target_storage.should_receive(:save!).with(@document1,@counter,{},@storage).ordered
|
61
|
+
@target_storage1.should_receive(:save!).with(@document1,@counter,{},@storage)
|
62
|
+
|
63
|
+
@storage.sync_chained_storages!
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should collect multiple update to target store" do
|
67
|
+
@storage.save!(@document,@counter)
|
68
|
+
@storage.add_chained_storage!(@target_storage)
|
69
|
+
@document1 = Document.new(@store, 'x' => 1, 'y' => 2)
|
70
|
+
@document2 = Document.new(@store, 'v' => 1, 'z' => 2)
|
71
|
+
@storage.save!(@document1,@counter)
|
72
|
+
@storage.save!(@document2,@counter)
|
73
|
+
@target_storage.should_receive(:save!).with(@document1,@counter,{},@storage).ordered
|
74
|
+
@target_storage.should_receive(:save!).with(@document2,@counter,{},@storage).ordered
|
75
|
+
@storage.sync_chained_storage!(@target_storage)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should remove savings sucessfully (current outstanding savings are dropped and new savings are no longer collected)" do
|
79
|
+
@storage.save!(@document,@counter)
|
80
|
+
@storage.add_chained_storage!(@target_storage)
|
81
|
+
@document1 = Document.new(@store,'x' => 1, 'y' => 2)
|
82
|
+
@storage.remove_chained_storage!(@target_storage)
|
83
|
+
@document2 = Document.new(@store,'v' => 1, 'z' => 2)
|
84
|
+
@storage.save!(@document1,@counter)
|
85
|
+
@storage.save!(@document2,@counter)
|
86
|
+
@storage.sync_chained_storage!(@target_storage)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should add reverse chaining to target storage when adding chained storage" do
|
90
|
+
@target_storage.should_receive(:add_chained_storage!).with(@storage)
|
91
|
+
@storage.add_chained_storage!(@target_storage)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should remove reverse chaining from target storage when removing chained storage" do
|
95
|
+
@target_storage.should_receive(:remove_chained_storage!).with(@storage)
|
96
|
+
@storage.add_chained_storage!(@target_storage)
|
97
|
+
@storage.remove_chained_storage!(@target_storage)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not collect savings for target store if these saving where originally from the target store" do
|
101
|
+
@storage.add_chained_storage!(@target_storage)
|
102
|
+
@storage.save!(@document,@counter)
|
103
|
+
@storage.sync_chained_storage!(@target_storage)
|
104
|
+
@storage.should_not_receive(:save!).with(@document,@counter,{},@target_storage)
|
105
|
+
@target_storage.sync_chained_storage!(@storage)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should let next storage to sync on sync_chained_storages! as well" do
|
109
|
+
@storage.add_chained_storage!(@target_storage)
|
110
|
+
@storage.save!(@document,@counter)
|
111
|
+
@target_storage.should_receive(:sync_chained_storages!).once
|
112
|
+
@storage.sync_chained_storages!
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
@@ -0,0 +1,201 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Store", :shared => true do
|
4
|
+
|
5
|
+
it "should increment timestamp when storing a document" do
|
6
|
+
@document = Document.new :stuff => '...'
|
7
|
+
lambda do
|
8
|
+
@store.save!(@document)
|
9
|
+
end.should change(@store,:timestamp)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should store a document" do
|
13
|
+
@document = Document.new :stuff => '...'
|
14
|
+
@store.save!(@document)
|
15
|
+
(doc = @store.find(@document.uuid)).should == @document
|
16
|
+
doc.should_not be_a_kind_of(VersionedDocument)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should store VersionedDocument" do
|
20
|
+
@document = Document.create! :stuff => '...'
|
21
|
+
vd = @document.versions.all.first
|
22
|
+
FileUtils.rm_rf TEMP_STORAGES + '/skiplist_store'
|
23
|
+
another_cfg = StrokeDB::Config.build :base_path => TEMP_STORAGES + '/skiplist_store'
|
24
|
+
another_store = another_cfg.stores[:default]
|
25
|
+
another_store.save!(vd)
|
26
|
+
another_store.find(vd.uuid,vd.version).should == vd
|
27
|
+
another_store.find(vd.uuid).should be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be Enumerable" do
|
31
|
+
@store.should be_a_kind_of(Enumerable)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "New store" do
|
38
|
+
|
39
|
+
before(:each) do
|
40
|
+
@store = setup_default_store
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have its own UUID" do
|
44
|
+
@store.uuid.should match(/^#{UUID_RE}$/)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have 0 timestamp" do
|
48
|
+
@store.timestamp.should == LTS.zero(@store.uuid)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should create corresponding StoreInfo document" do
|
52
|
+
@store.document.should be_a_kind_of(StoreInfo)
|
53
|
+
@store.document.uuid.should == @store.uuid
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
it "should return nil as head_version for unexistent document (well there is no documents at all)" do
|
58
|
+
@store.head_version(Util.random_uuid).should be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it_should_behave_like "Store"
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
describe "Non-empty store" do
|
67
|
+
|
68
|
+
before(:each) do
|
69
|
+
@store = setup_default_store
|
70
|
+
setup_index
|
71
|
+
@documents = []
|
72
|
+
10.times do |i|
|
73
|
+
@documents << Document.create!(:stuff => i)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
it "should report existing document as such" do
|
79
|
+
@store.include?(@documents.first.uuid).should == true
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should report existing versioned document as such" do
|
83
|
+
@store.include?(@documents.first.uuid,@documents.first.version).should == true
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should report versioned document that does not exist as such" do
|
87
|
+
@store.include?(@documents.first.uuid,'ouch, there is no way such version could be generated').should == false
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should report document that does not exist as such" do
|
91
|
+
@store.include?('ouch, there is no way such UUID could be generated').should == false
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should find a document" do
|
95
|
+
(doc = @store.find(@documents.first.uuid)).should == @documents.first
|
96
|
+
doc.should_not be_a_kind_of(VersionedDocument)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should find a versioned document" do
|
100
|
+
(doc = @store.find(@documents.first.uuid,@documents.first.version)).should == @documents.first
|
101
|
+
doc.should be_a_kind_of(VersionedDocument)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should not find a versioned document with version that does not exist" do
|
105
|
+
@store.find(@documents.first.uuid,'absolutely absurd version').should be_nil
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
it "should iterate over all stored documents" do
|
110
|
+
iterated_documents = []
|
111
|
+
@store.each do |doc|
|
112
|
+
iterated_documents << doc
|
113
|
+
end
|
114
|
+
iterated_documents.sort_by {|doc| doc.uuid}.should == @documents.sort_by {|doc| doc.uuid}
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should iterate over all stored documents and their versions if told so" do
|
118
|
+
iterated_documents = []
|
119
|
+
@store.each(:include_versions => true) do |doc|
|
120
|
+
iterated_documents << doc
|
121
|
+
end
|
122
|
+
documents_with_versions = @documents.clone
|
123
|
+
@documents.each do |doc|
|
124
|
+
doc.versions.all.each do |vd|
|
125
|
+
documents_with_versions << vd
|
126
|
+
end
|
127
|
+
end
|
128
|
+
iterated_documents.sort_by {|doc| doc.uuid}.should == documents_with_versions.sort_by {|doc| doc.uuid}
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should iterate over all newly stored documents if told so" do
|
132
|
+
timestamp = @store.timestamp.counter
|
133
|
+
@new_documents = []
|
134
|
+
10.times do |i|
|
135
|
+
@new_documents << Document.create!(:stuff => i)
|
136
|
+
end
|
137
|
+
|
138
|
+
iterated_documents = []
|
139
|
+
@store.each(:after_timestamp => timestamp) do |doc|
|
140
|
+
iterated_documents << doc
|
141
|
+
end
|
142
|
+
iterated_documents.sort_by {|doc| doc.uuid}.should == @new_documents.sort_by {|doc| doc.uuid}
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should iterate over all newly stored versions if told so" do
|
146
|
+
timestamp = @store.timestamp.counter
|
147
|
+
@new_documents = []
|
148
|
+
@documents.each_with_index do |document,i|
|
149
|
+
document.stuff = i+100
|
150
|
+
@new_documents << document.save!
|
151
|
+
end
|
152
|
+
|
153
|
+
iterated_documents = []
|
154
|
+
@store.each(:after_timestamp => timestamp, :include_versions => true) do |doc|
|
155
|
+
iterated_documents << doc
|
156
|
+
end
|
157
|
+
iterated_documents.sort_by {|doc| doc.uuid}.should == (@documents + @new_documents).sort_by {|doc| doc.uuid}
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
it_should_behave_like "Store"
|
162
|
+
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# describe "[Regression] First chunk cut" do
|
168
|
+
#
|
169
|
+
#
|
170
|
+
# before(:all) do
|
171
|
+
# @store = setup_default_store
|
172
|
+
# @doc1 = Document.new(@store,:stuff => 123)
|
173
|
+
# @doc2 = Document.new(@store,:stuff => 123)
|
174
|
+
# @doc3 = Document.new(@store,:stuff => 123)
|
175
|
+
# end
|
176
|
+
#
|
177
|
+
# it "should store a document with big uuid in a first chunk" do
|
178
|
+
# $DEBUG_CHEATERS_LEVEL = 2
|
179
|
+
# @store.save!(@doc3)
|
180
|
+
# @store.find(@doc3.uuid).uuid.should == @doc3.uuid
|
181
|
+
# # end
|
182
|
+
# # it "should store a document with lower uuid in a first chunk" do
|
183
|
+
# $DEBUG_CHEATERS_LEVEL = 2
|
184
|
+
# @store.save!(@doc1)
|
185
|
+
# @store.find(@doc1.uuid).uuid.should == @doc1.uuid
|
186
|
+
# @store.find(@doc3.uuid).uuid.should == @doc3.uuid
|
187
|
+
# # end
|
188
|
+
# # it "should cut a chunk with a document with medium uuid" do
|
189
|
+
# $DEBUG_CHEATERS_LEVEL = 5
|
190
|
+
# @store.save!(@doc2)
|
191
|
+
# @store.find(@doc1.uuid).uuid.should == @doc1.uuid
|
192
|
+
# @store.find(@doc3.uuid).uuid.should == @doc3.uuid
|
193
|
+
# @store.find(@doc2.uuid).uuid.should == @doc2.uuid
|
194
|
+
# end
|
195
|
+
#
|
196
|
+
# after(:each) do
|
197
|
+
# $DEBUG_CHEATERS_LEVEL = nil
|
198
|
+
# end
|
199
|
+
# end
|
200
|
+
|
201
|
+
|