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.
Files changed (192) hide show
  1. data/README +18 -20
  2. data/bench.html +4001 -0
  3. data/bin/strokedb +14 -0
  4. data/examples/movies.rb +105 -0
  5. data/examples/movies2.rb +97 -0
  6. data/examples/strokewiki/README +28 -0
  7. data/examples/strokewiki/view/edit.xhtml +27 -0
  8. data/examples/strokewiki/view/new.xhtml +26 -0
  9. data/examples/strokewiki/view/pages.xhtml +27 -0
  10. data/examples/strokewiki/view/show.xhtml +40 -0
  11. data/examples/strokewiki/view/versions.xhtml +25 -0
  12. data/examples/strokewiki/wiki.rb +106 -0
  13. data/examples/todo.rb +92 -0
  14. data/lib/strokedb.rb +85 -0
  15. data/lib/{config → strokedb}/config.rb +14 -9
  16. data/lib/strokedb/console.rb +87 -0
  17. data/lib/strokedb/core_ext.rb +10 -0
  18. data/lib/{util/ext → strokedb/core_ext}/blank.rb +1 -1
  19. data/lib/{util/ext → strokedb/core_ext}/enumerable.rb +0 -0
  20. data/lib/{util/ext → strokedb/core_ext}/fixnum.rb +0 -0
  21. data/lib/strokedb/core_ext/float.rb +4 -0
  22. data/lib/{util/ext → strokedb/core_ext}/hash.rb +0 -0
  23. data/lib/strokedb/core_ext/infinity.rb +33 -0
  24. data/lib/strokedb/core_ext/kernel.rb +41 -0
  25. data/lib/strokedb/core_ext/object.rb +16 -0
  26. data/lib/{util/ext → strokedb/core_ext}/string.rb +28 -1
  27. data/lib/strokedb/core_ext/symbol.rb +13 -0
  28. data/lib/strokedb/data_structures.rb +5 -0
  29. data/lib/strokedb/data_structures/chunked_skiplist.rb +123 -0
  30. data/lib/{data_structures → strokedb/data_structures}/inverted_list.rb +0 -0
  31. data/lib/{data_structures → strokedb/data_structures}/point_query.rb +0 -0
  32. data/lib/strokedb/data_structures/simple_skiplist.rb +350 -0
  33. data/lib/{data_structures → strokedb/data_structures}/skiplist.rb +1 -1
  34. data/lib/{document → strokedb}/document.rb +180 -71
  35. data/lib/{document → strokedb/document}/callback.rb +0 -0
  36. data/lib/{document → strokedb/document}/delete.rb +2 -2
  37. data/lib/strokedb/document/dsl.rb +4 -0
  38. data/lib/{document → strokedb/document/dsl}/associations.rb +0 -0
  39. data/lib/{document → strokedb/document/dsl}/coercions.rb +0 -0
  40. data/lib/strokedb/document/dsl/meta_dsl.rb +7 -0
  41. data/lib/{document → strokedb/document/dsl}/validations.rb +26 -21
  42. data/lib/{document → strokedb/document/dsl}/virtualize.rb +0 -0
  43. data/lib/{document → strokedb/document}/meta.rb +92 -29
  44. data/lib/{document → strokedb/document}/slot.rb +17 -5
  45. data/lib/{document → strokedb/document}/util.rb +0 -0
  46. data/lib/{document → strokedb/document}/versions.rb +2 -2
  47. data/lib/strokedb/index.rb +2 -0
  48. data/lib/strokedb/nsurl.rb +24 -0
  49. data/lib/strokedb/store.rb +149 -0
  50. data/lib/strokedb/stores.rb +6 -0
  51. data/lib/{stores → strokedb/stores}/chainable_storage.rb +20 -14
  52. data/lib/strokedb/stores/file_storage.rb +118 -0
  53. data/lib/{stores/inverted_list_index → strokedb/stores}/inverted_list_file_storage.rb +50 -0
  54. data/lib/strokedb/stores/memory_storage.rb +80 -0
  55. data/lib/{stores → strokedb/stores}/remote_store.rb +10 -4
  56. data/lib/strokedb/sync.rb +4 -0
  57. data/lib/{sync → strokedb/sync}/chain_sync.rb +0 -0
  58. data/lib/{sync → strokedb/sync}/diff.rb +12 -1
  59. data/lib/{sync/stroke_diff → strokedb/sync/diff}/array.rb +1 -1
  60. data/lib/{sync/stroke_diff → strokedb/sync/diff}/default.rb +0 -0
  61. data/lib/{sync/stroke_diff → strokedb/sync/diff}/hash.rb +1 -1
  62. data/lib/{sync/stroke_diff → strokedb/sync/diff}/string.rb +1 -1
  63. data/lib/{sync → strokedb/sync}/lamport_timestamp.rb +0 -0
  64. data/lib/{sync → strokedb/sync}/store_sync.rb +15 -7
  65. data/lib/strokedb/transaction.rb +78 -0
  66. data/lib/{util → strokedb}/util.rb +14 -7
  67. data/lib/strokedb/util/attach_dsl.rb +29 -0
  68. data/lib/{util → strokedb/util}/blankslate.rb +0 -0
  69. data/lib/strokedb/util/class_optimization.rb +93 -0
  70. data/lib/{util → strokedb/util}/inflect.rb +0 -0
  71. data/lib/strokedb/util/java_util.rb +13 -0
  72. data/lib/{util → strokedb/util}/lazy_array.rb +0 -0
  73. data/lib/{util → strokedb/util}/lazy_mapping_array.rb +4 -0
  74. data/lib/{util → strokedb/util}/lazy_mapping_hash.rb +0 -0
  75. data/lib/{util → strokedb/util}/serialization.rb +21 -0
  76. data/lib/strokedb/util/uuid.rb +159 -0
  77. data/lib/{util → strokedb/util}/xml.rb +0 -0
  78. data/lib/{view → strokedb}/view.rb +2 -2
  79. data/lib/strokedb/volumes.rb +5 -0
  80. data/lib/strokedb/volumes/archive_volume.rb +165 -0
  81. data/lib/strokedb/volumes/block_volume.rb +169 -0
  82. data/lib/strokedb/volumes/distributed_pointer.rb +43 -0
  83. data/lib/strokedb/volumes/fixed_length_skiplist_volume.rb +109 -0
  84. data/lib/strokedb/volumes/map_volume.rb +268 -0
  85. data/meta/MANIFEST +175 -0
  86. data/script/console +2 -70
  87. data/spec/integration/remote_store_spec.rb +70 -0
  88. data/spec/integration/search_spec.rb +76 -0
  89. data/spec/integration/spec_helper.rb +1 -0
  90. data/spec/lib/spec_helper.rb +1 -0
  91. data/spec/lib/strokedb/config_spec.rb +250 -0
  92. data/spec/lib/strokedb/core_ext/blank_spec.rb +20 -0
  93. data/spec/lib/strokedb/core_ext/extract_spec.rb +42 -0
  94. data/spec/lib/strokedb/core_ext/float_spec.rb +62 -0
  95. data/spec/lib/strokedb/core_ext/infinity_spec.rb +40 -0
  96. data/spec/lib/strokedb/core_ext/spec_helper.rb +1 -0
  97. data/spec/lib/strokedb/core_ext/string_spec.rb +25 -0
  98. data/spec/lib/strokedb/core_ext/symbol_spec.rb +8 -0
  99. data/spec/lib/strokedb/data_structures/chunked_skiplist_spec.rb +144 -0
  100. data/spec/lib/strokedb/data_structures/inverted_list_spec.rb +172 -0
  101. data/spec/lib/strokedb/data_structures/simple_skiplist_spec.rb +200 -0
  102. data/spec/lib/strokedb/data_structures/skiplist_spec.rb +253 -0
  103. data/spec/lib/strokedb/data_structures/spec_helper.rb +1 -0
  104. data/spec/lib/strokedb/document/associations_spec.rb +319 -0
  105. data/spec/lib/strokedb/document/callbacks_spec.rb +134 -0
  106. data/spec/lib/strokedb/document/coercions_spec.rb +110 -0
  107. data/spec/lib/strokedb/document/document_spec.rb +1063 -0
  108. data/spec/lib/strokedb/document/meta_meta_spec.rb +30 -0
  109. data/spec/lib/strokedb/document/meta_spec.rb +435 -0
  110. data/spec/lib/strokedb/document/metaslot_spec.rb +43 -0
  111. data/spec/lib/strokedb/document/slot_spec.rb +130 -0
  112. data/spec/lib/strokedb/document/spec_helper.rb +1 -0
  113. data/spec/lib/strokedb/document/validations_spec.rb +1081 -0
  114. data/spec/lib/strokedb/document/virtualize_spec.rb +80 -0
  115. data/spec/lib/strokedb/nsurl_spec.rb +73 -0
  116. data/spec/lib/strokedb/spec_helper.rb +1 -0
  117. data/spec/lib/strokedb/stores/chained_storages_spec.rb +116 -0
  118. data/spec/lib/strokedb/stores/spec_helper.rb +1 -0
  119. data/spec/lib/strokedb/stores/store_spec.rb +201 -0
  120. data/spec/lib/strokedb/stores/transaction_spec.rb +107 -0
  121. data/spec/lib/strokedb/sync/chain_sync_spec.rb +43 -0
  122. data/spec/lib/strokedb/sync/diff_spec.rb +111 -0
  123. data/spec/lib/strokedb/sync/lamport_timestamp_spec.rb +174 -0
  124. data/spec/lib/strokedb/sync/slot_diff_spec.rb +164 -0
  125. data/spec/lib/strokedb/sync/spec_helper.rb +1 -0
  126. data/spec/lib/strokedb/sync/store_sync_spec.rb +181 -0
  127. data/spec/lib/strokedb/sync/stroke_diff/array_spec.rb +97 -0
  128. data/spec/lib/strokedb/sync/stroke_diff/complex_spec.rb +58 -0
  129. data/spec/lib/strokedb/sync/stroke_diff/hash_spec.rb +144 -0
  130. data/spec/lib/strokedb/sync/stroke_diff/scalar_spec.rb +23 -0
  131. data/spec/lib/strokedb/sync/stroke_diff/spec_helper.rb +25 -0
  132. data/spec/lib/strokedb/sync/stroke_diff/string_spec.rb +61 -0
  133. data/spec/lib/strokedb/util/attach_dsl_spec.rb +45 -0
  134. data/spec/lib/strokedb/util/inflect_spec.rb +14 -0
  135. data/spec/lib/strokedb/util/lazy_array_spec.rb +157 -0
  136. data/spec/lib/strokedb/util/lazy_mapping_array_spec.rb +174 -0
  137. data/spec/lib/strokedb/util/lazy_mapping_hash_spec.rb +92 -0
  138. data/spec/lib/strokedb/util/spec_helper.rb +1 -0
  139. data/spec/lib/strokedb/util/uuid_spec.rb +46 -0
  140. data/spec/lib/strokedb/view_spec.rb +228 -0
  141. data/spec/lib/strokedb/volumes/archive_volume_spec.rb +105 -0
  142. data/spec/lib/strokedb/volumes/block_volume_spec.rb +100 -0
  143. data/spec/lib/strokedb/volumes/distributed_pointer_spec.rb +14 -0
  144. data/spec/lib/strokedb/volumes/fixed_length_skiplist_volume_spec.rb +177 -0
  145. data/spec/lib/strokedb/volumes/map_volume_spec.rb +172 -0
  146. data/spec/lib/strokedb/volumes/spec_helper.rb +1 -0
  147. data/spec/regression/docref_spec.rb +94 -0
  148. data/spec/regression/meta_spec.rb +23 -0
  149. data/spec/regression/spec_helper.rb +1 -0
  150. data/spec/regression/sync_spec.rb +36 -0
  151. data/spec/spec.opts +7 -0
  152. data/spec/spec_helper.rb +37 -0
  153. data/spec/temp/storages/TIMESTAMP +1 -0
  154. data/spec/temp/storages/UUID +1 -0
  155. data/spec/temp/storages/database-sync/TIMESTAMP +1 -0
  156. data/spec/temp/storages/database-sync/UUID +1 -0
  157. data/spec/temp/storages/database-sync/config +1 -0
  158. data/spec/temp/storages/database-sync/file/LAST +1 -0
  159. data/spec/temp/storages/database-sync/file/bd/f6/bdf675e5-8a7b-494e-97f2-f74a14ccd95d.av +0 -0
  160. data/spec/temp/storages/database-sync/file/uindex.wal +0 -0
  161. data/spec/temp/storages/database-sync/inverted_list_file/INVERTED_INDEX +1 -0
  162. data/spec/temp/storages/inverted_list_storage/INVERTED_INDEX +0 -0
  163. data/strokedb.gemspec +120 -0
  164. data/task/benchmark.task +9 -0
  165. data/task/ditz.task +30 -0
  166. data/task/echoe.rb +17 -0
  167. data/task/rcov.task +50 -0
  168. data/task/rdoc.task +10 -0
  169. data/task/rspec.task +0 -0
  170. data/vendor/java_inline.rb +106 -0
  171. data/vendor/rbmodexcl/mrimodexcl.rb +82 -0
  172. data/vendor/rbmodexcl/rbmodexcl.rb +5 -0
  173. data/vendor/rbmodexcl/rbxmodexcl.rb +48 -0
  174. data/vendor/rbmodexcl/spec/unextend_spec.rb +50 -0
  175. data/vendor/rbmodexcl/spec/uninclude_spec.rb +26 -0
  176. metadata +271 -79
  177. data/CONTRIBUTORS +0 -7
  178. data/CREDITS +0 -13
  179. data/bin/sdbc +0 -2
  180. data/lib/init.rb +0 -57
  181. data/lib/stores/inverted_list_index/inverted_list_index.rb +0 -49
  182. data/lib/stores/skiplist_store/chunk.rb +0 -119
  183. data/lib/stores/skiplist_store/chunk_storage.rb +0 -21
  184. data/lib/stores/skiplist_store/file_chunk_storage.rb +0 -44
  185. data/lib/stores/skiplist_store/memory_chunk_storage.rb +0 -37
  186. data/lib/stores/skiplist_store/skiplist_store.rb +0 -217
  187. data/lib/stores/store.rb +0 -5
  188. data/lib/sync/stroke_diff/stroke_diff.rb +0 -9
  189. data/lib/util/ext/object.rb +0 -8
  190. data/lib/util/java_util.rb +0 -9
  191. data/lib/util/trigger_partition.rb +0 -136
  192. data/strokedb.rb +0 -75
@@ -1,70 +1,2 @@
1
- #! /usr/bin/env ruby
2
-
3
- $:.unshift File.dirname(__FILE__)
4
-
5
- require 'irb'
6
- require 'pp'
7
- require "strokedb"
8
- include StrokeDB
9
-
10
- Doc = Document
11
-
12
- def save!
13
- StrokeDB.default_store.chunk_storage.sync_chained_storages!
14
- true
15
- "Database has been saved."
16
- end
17
-
18
- def build_config
19
- StrokeDB::Config.build :default => true, :base_path => '.console.strokedb'
20
- true
21
- end
22
-
23
- def clear!
24
- FileUtils.rm_rf '.console.strokedb'
25
- build_config
26
- "Database has been wiped out."
27
- end
28
-
29
- def find(*args)
30
- StrokeDB.default_store.find(*args)
31
- end
32
-
33
- def store
34
- StrokeDB.default_store
35
- end
36
-
37
- def h(*args)
38
- puts %{
39
- Commands:
40
-
41
- clear! -- Clear the database (will erase all data in console's store)
42
- save! -- Save database (if you will quit without it, your changes will not be recorded)
43
- find <uuid> -- Find document by UUID (example: find "a4430ff1-6cb4-4428-a292-7ab8b77de467")
44
-
45
- Aliases:
46
-
47
- Doc -- StrokeDB::Document
48
- store -- current store
49
- }
50
- end
51
-
52
- def reload!
53
- silence_warnings do
54
- load "strokedb.rb"
55
- end
56
- "Classes reloaded."
57
- end
58
-
59
- if ARGV.last.is_a?(String) && File.exists?(ARGV.last+'/config')
60
- StrokeDB::Config.load(ARGV.last+'/config',true)
61
- puts "# loading #{ARGV.last}"
62
- ARGV.pop
63
- else
64
- build_config
65
- end
66
-
67
- puts "StrokeDB #{StrokeDB::VERSION} Console"
68
- puts "Type 'h' for help"
69
-
70
- IRB.start
1
+ #!/bin/sh
2
+ bin/strokedb $*
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ =begin
3
+ class RemoteStoreContext
4
+ def initialize(store)
5
+ @user = Meta.new store, :name => "User"
6
+ end
7
+ def create_user(*args)
8
+ @user.create!(*args)
9
+ end
10
+ def find_users
11
+ @user.find
12
+ end
13
+ end
14
+
15
+ class ClientScenario < RemoteStoreContext
16
+ def initialize
17
+ @store = StrokeDB::RemoteStore::Client.new('127.0.0.1', 4440)
18
+ super(@store)
19
+ end
20
+ end
21
+
22
+ class ServerScenario < RemoteStoreContext
23
+ def initialize
24
+ StrokeDB::Config.build :default => true, :base_path => '../temp/storages/drb_store'
25
+ StrokeDB.default_store.remote_server("0.0.0.0", 4540).start
26
+ super(StrokeDB.default_store)
27
+ end
28
+ end
29
+ Thread.abort_on_exception = true
30
+ server_thread = Thread.new{ Thread.current['s'] = ServerScenario.new }
31
+ client_thread = Thread.new{ Thread.current['s'] = ClientScenario.new }
32
+
33
+ sleep 2
34
+ p server_thread['s'].create_user(:name => "server guy")
35
+ exit!
36
+
37
+ describe "Database operations thru remote_store" do
38
+
39
+ it "should work perfectly" do
40
+ # Start scenarios
41
+ client = $client
42
+ server = $server
43
+
44
+ # 1. Store document on a server
45
+ server.create_user(:name => "server guy").name.should == 'server guy'
46
+ server.find_users.size.should == 1
47
+ server.find_users[0].name.should == 'server guy'
48
+
49
+ # 2. Find server's documents in a client
50
+ client.find_users.size.should == 1
51
+ server.find_users[0].name.should == 'server guy'
52
+
53
+ # 3. Store document on a client
54
+ client.create_user(:name => "client guy").name.should == 'client guy'
55
+
56
+ # 4. Find all the documents on a server
57
+ server.find_users.size.should == 2
58
+ server.find_users[0].name.should == 'server guy'
59
+ server.find_users[1].name.should == 'client guy'
60
+
61
+ # 5. Find all documents in a client
62
+ client.find_users.size.should == 2
63
+ client.find_users[0].name.should == 'server guy'
64
+ client.find_users[1].name.should == 'client guy'
65
+ end
66
+
67
+ end
68
+
69
+ =end
70
+
@@ -0,0 +1,76 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Database search" do
4
+
5
+ before(:all) do
6
+ @path = File.dirname(__FILE__) + "/../temp/storages/database_search"
7
+ FileUtils.rm_rf @path
8
+ @f_storage = FileStorage.new(:path => @path + "/storage")
9
+ @f_storage.clear!
10
+ @index_storage = InvertedListFileStorage.new(:path => @path+"/index")
11
+ @index_storage.clear!
12
+ @index = InvertedListIndex.new(@index_storage)
13
+ @index2 = InvertedListIndex.new(@index_storage)
14
+
15
+ @f_store = Store.new(:storage => @f_storage, :index => @index, :path => @path + '/store')
16
+ @index.document_store = @f_store
17
+ @index2.document_store = @f_store
18
+
19
+ @profile_meta = Document.create!(@f_store, :name => 'Profile',
20
+ :non_indexable_slots => [ :bio, :version, :previous_version ])
21
+ end
22
+
23
+ # Leave for investigation
24
+ # after(:all) do
25
+ # FileUtils.rm_rf @path
26
+ # end
27
+
28
+ it "should add new doc" do
29
+ doc = Document.create!(@f_store, :name => "Oleg", :state => 'Russia', :age => 21, :meta => @profile_meta)
30
+ doc.uuid.should_not be_nil
31
+ @oleg_uuid = doc.uuid
32
+ results = @index.find(:name => "Oleg")
33
+ results.should_not be_empty
34
+ results[0].uuid.should == @oleg_uuid
35
+ end
36
+
37
+ it "should find doc in a separate index instance" do
38
+ results = @index2.find(:name => "Oleg", :meta => @profile_meta)
39
+ results.should_not be_empty
40
+ results[0]["name"].should == "Oleg"
41
+ end
42
+
43
+ it "should store & find several docs" do
44
+ doc = Document.create!(@f_store, :name => "Yurii", :state => 'Ukraine', :meta => @profile_meta)
45
+ doc.save!
46
+ @yura_uuid = doc.uuid
47
+ results = @index.find(:name => "Yurii")
48
+ results.should_not be_empty
49
+ results[0].uuid.should == @yura_uuid
50
+ end
51
+
52
+ it "should find all profiles" do
53
+ results = @index.find(:meta => @profile_meta)
54
+ results.should_not be_empty
55
+ results.map{|e| e.uuid}.to_set == [ @yura_uuid, @oleg_uuid ].to_set
56
+ end
57
+
58
+ it "should find all profiles from Ukraine" do
59
+ results = @index.find(:meta => @profile_meta, :state => 'Ukraine')
60
+ results.should_not be_empty
61
+ results.map{|e| e.uuid}.to_set == [ @yura_uuid ].to_set
62
+ end
63
+
64
+ it "should remove info from index" do
65
+ results = @index.find(:name => 'Oleg')
66
+ oleg = results[0]
67
+ oleg[:name] = 'Oleganza'
68
+ oleg.save!
69
+ results = @index.find(:name => 'Oleg')
70
+ results.should be_empty
71
+ results = @index.find(:name => 'Oleganza')
72
+ results[0].uuid.should == oleg.uuid
73
+ end
74
+
75
+ end
76
+
@@ -0,0 +1 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
@@ -0,0 +1 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
@@ -0,0 +1,250 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Config" do
4
+
5
+ before(:each) do
6
+ @config = StrokeDB::Config.new
7
+ @root_path = TEMP_STORAGES + '/config/'
8
+ @paths = []
9
+ end
10
+
11
+ it "should be the default config if desired" do
12
+ @config = StrokeDB::Config.new(true)
13
+ ::StrokeDB.default_config.should == @config
14
+ end
15
+
16
+ it "should have no storages or indexes on creation" do
17
+ @config.storages.should be_empty
18
+ @config.indexes.should be_empty
19
+ end
20
+
21
+ it "should add known storages without specific parameters" do
22
+ @config.add_storage :mem, :memory
23
+ @config.storages[:mem].should be_an_instance_of(MemoryStorage)
24
+ end
25
+
26
+ it "should add known storages with specific parameters" do
27
+ @paths << (@root_path + "file_storage")
28
+ @config.add_storage :fs, :file, :path => @paths.last
29
+ @config.storages[:fs].should be_an_instance_of(FileStorage)
30
+ @config.storages[:fs].path.should == @paths.last
31
+ end
32
+
33
+ it "should raise the correct exception when adding an unknown storage" do
34
+ lambda { @config.add_storage :unknown, :unknown_storage_type }.should raise_error(StrokeDB::UnknownStorageTypeError)
35
+ end
36
+
37
+ it "should raise an exception on chain with insufficient storages" do
38
+ lambda { @config.chain }.should raise_error
39
+ @config.add_storage :mem, :memory
40
+ lambda { @config.chain :mem }.should raise_error
41
+ end
42
+
43
+ it "should raise an exception on chain with undefined storages" do
44
+ lambda { @config.chain :not_here }.should raise_error
45
+ end
46
+
47
+ it "should chain storages together" do
48
+ @paths << (@root_path + "file_storage_chain")
49
+ @config.add_storage :mem1, :memory
50
+ @config.add_storage :mem2, :memory
51
+ @config.add_storage :mem3, :memory
52
+ @config.add_storage :fs, :file, :path => @paths.last
53
+ @config.chain :mem1, :mem2, :fs
54
+ @config.chain :mem2, :mem3
55
+ @config.storages[:mem1].should have_chained_storage(@config.storages[:mem2])
56
+ @config.storages[:mem2].should have_chained_storage(@config.storages[:fs])
57
+ @config.storages[:fs].should have_chained_storage(@config.storages[:mem2])
58
+ @config.storages[:mem2].should have_chained_storage(@config.storages[:mem1])
59
+ @config.storages[:mem1].should_not have_chained_storage(@config.storages[:mem1])
60
+ @config.storages[:mem2].should_not have_chained_storage(@config.storages[:mem2])
61
+ @config.storages[:fs].should_not have_chained_storage(@config.storages[:fs])
62
+ @config.storages[:mem1].should_not have_chained_storage(@config.storages[:fs])
63
+ @config.storages[:fs].should_not have_chained_storage(@config.storages[:mem1])
64
+ @config.storages[:mem2].should have_chained_storage(@config.storages[:mem3])
65
+ @config.storages[:mem3].should have_chained_storage(@config.storages[:mem2])
66
+ @config.storages[:mem1].should_not have_chained_storage(@config.storages[:mem3])
67
+ @config.storages[:fs].should_not have_chained_storage(@config.storages[:mem3])
68
+ end
69
+
70
+ it "should add an index" do
71
+ @paths << (@root_path + "file_storage_index")
72
+ @config.add_storage :fs, :file, :path => @paths.last
73
+ @paths << (@root_path + "inverted_list_file_index")
74
+ @config.add_storage :idx_st, :inverted_list_file, :path => @paths.last
75
+ @config.add_index :idx, :inverted_list, :idx_st
76
+ @config.indexes[:idx].should be_an_instance_of(InvertedListIndex)
77
+ end
78
+
79
+ it "should raise the correct exception when adding an unknown index" do
80
+ lambda { @config.add_index :unknown, :unknown_index_type, :idx_st }.should raise_error(StrokeDB::UnknownIndexTypeError)
81
+ end
82
+
83
+ it "should add a store" do
84
+ @paths << (@root_path + "file_storage")
85
+ @config.add_storage :fs, :file, :path => @paths.last
86
+ @config.add_store :store, nil, :storage => :fs, :cut_level => 4, :path => @paths.last
87
+ @config.stores[:store].should be_an_instance_of(Store)
88
+ @config.stores[:store].storage.should == @config.storages[:fs]
89
+ end
90
+
91
+ it "should add a default store with default index" do
92
+ @paths << (@root_path + "file_storage_default_index")
93
+ @config.add_storage :fs, :file, :path => @paths.last
94
+ @paths << (@root_path + "inverted_list_file_default_index")
95
+ @config.add_storage :index_storage, :inverted_list_file, :path => @paths.last
96
+ @config.add_index :default, :inverted_list, :index_storage
97
+ @config.add_store :default, nil, :storage => :fs, :cut_level => 4, :path => @paths.last
98
+ @config.stores[:default].should be_an_instance_of(Store)
99
+ @config.indexes[:default].document_store.should == @config.stores[:default]
100
+ end
101
+
102
+ after(:each) do
103
+ @paths.each {|path| FileUtils.rm_rf path}
104
+ end
105
+
106
+ end
107
+
108
+ describe "Config builder" do
109
+
110
+ before(:each) do
111
+ @base_path = TEMP_STORAGES + '/cfg_builder'
112
+ FileUtils.rm_rf @base_path
113
+ end
114
+
115
+ after(:each) do
116
+ FileUtils.rm_rf @base_path
117
+ end
118
+
119
+ it "should make config default if told so" do
120
+ config = StrokeDB::Config.build :default => true, :base_path => @base_path
121
+ StrokeDB.default_config.should == config
122
+ end
123
+
124
+ it "should not make config default if told so" do
125
+ config = StrokeDB::Config.build :base_path => @base_path
126
+ StrokeDB.default_config.should_not == config
127
+ end
128
+
129
+ it "should use Store by default" do
130
+ config = StrokeDB::Config.build :base_path => @base_path
131
+ config.stores[:default].should be_a_kind_of(Store)
132
+ end
133
+
134
+ it "should use specified store if told so" do
135
+ StrokeDB.send!(:remove_const,'SomeFunnyStore') if defined?(SomeFunnyStore)
136
+ StrokeDB::SomeFunnyStore = Class.new(Store)
137
+ config = StrokeDB::Config.build :store => :some_funny, :base_path => @base_path
138
+ config.stores[:default].should be_a_kind_of(SomeFunnyStore)
139
+ end
140
+
141
+ it "should add storages as he is told to" do
142
+ StrokeDB.send!(:remove_const,'Chunk1Storage') if defined?(Chunk1Storage)
143
+ StrokeDB.send!(:remove_const,'Chunk2Storage') if defined?(Chunk2Storage)
144
+ StrokeDB::Chunk1Storage = Class.new(MemoryStorage)
145
+ StrokeDB::Chunk2Storage = Class.new(MemoryStorage)
146
+ config = StrokeDB::Config.build :storages => [:chunk_1,:chunk_2], :base_path => @base_path
147
+ config.storages[:chunk_1].should be_a_kind_of(Chunk1Storage)
148
+ config.storages[:chunk_2].should be_a_kind_of(Chunk2Storage)
149
+ end
150
+
151
+ it "should initialize all storages with base_path+storage_name" do
152
+ StrokeDB.send!(:remove_const,'Chunk1Storage') if defined?(Chunk1Storage)
153
+ StrokeDB.send!(:remove_const,'Chunk2Storage') if defined?(Chunk2Storage)
154
+ StrokeDB::Chunk1Storage = Class.new(MemoryStorage)
155
+ StrokeDB::Chunk2Storage = Class.new(MemoryStorage)
156
+ Chunk1Storage.should_receive(:new).with(:path => @base_path + '/chunk_1').and_return(MemoryStorage.new)
157
+ Chunk2Storage.should_receive(:new).with(:path => @base_path + '/chunk_2').and_return(MemoryStorage.new)
158
+ config = StrokeDB::Config.build :storages => [:chunk_1,:chunk_2], :base_path => @base_path
159
+ end
160
+
161
+ it "should add :memory and :file by default" do
162
+ config = StrokeDB::Config.build :base_path => @base_path
163
+ config.storages[:memory].should be_a_kind_of(MemoryStorage)
164
+ config.storages[:file].should be_a_kind_of(FileStorage)
165
+ end
166
+
167
+ it "should chain given storages sequentially" do
168
+ StrokeDB.send!(:remove_const,'Chunk1Storage') if defined?(Chunk1Storage)
169
+ StrokeDB.send!(:remove_const,'Chunk2Storage') if defined?(Chunk2Storage)
170
+ StrokeDB.send!(:remove_const,'Chunk3Storage') if defined?(Chunk3Storage)
171
+ StrokeDB::Chunk1Storage = Class.new(MemoryStorage)
172
+ StrokeDB::Chunk2Storage = Class.new(MemoryStorage)
173
+ StrokeDB::Chunk3Storage = Class.new(MemoryStorage)
174
+ config = StrokeDB::Config.build :storages => [:chunk_1,:chunk_2,:chunk_3], :base_path => @base_path
175
+ config.storages[:chunk_1].should have_chained_storage(config[:chunk_2])
176
+ config.storages[:chunk_2].should have_chained_storage(config[:chunk_1])
177
+ config.storages[:chunk_3].should have_chained_storage(config[:chunk_2])
178
+ config.storages[:chunk_2].should have_chained_storage(config[:chunk_3])
179
+ end
180
+
181
+ it "should set authoritative sources for storages sequentially" do
182
+ StrokeDB.send!(:remove_const,'Chunk1Storage') if defined?(Chunk1Storage)
183
+ StrokeDB.send!(:remove_const,'Chunk2Storage') if defined?(Chunk2Storage)
184
+ StrokeDB.send!(:remove_const,'Chunk3Storage') if defined?(Chunk3Storage)
185
+ StrokeDB::Chunk1Storage = Class.new(MemoryStorage)
186
+ StrokeDB::Chunk2Storage = Class.new(MemoryStorage)
187
+ StrokeDB::Chunk3Storage = Class.new(MemoryStorage)
188
+ config = StrokeDB::Config.build :storages => [:chunk_1,:chunk_2,:chunk_3], :base_path => @base_path
189
+ config.storages[:chunk_1].authoritative_source.should == config[:chunk_2]
190
+ config.storages[:chunk_2].authoritative_source.should == config[:chunk_3]
191
+ config.storages[:chunk_3].authoritative_source.should be_nil
192
+ end
193
+
194
+ it "should use InvertedListIndex by default" do
195
+ config = StrokeDB::Config.build :base_path => @base_path
196
+ config.indexes[:default].should be_a_kind_of(InvertedListIndex)
197
+ end
198
+
199
+ it "should use specific index if told so by default" do
200
+ StrokeDB.send!(:remove_const,'SomeFunnyIndex') if defined?(SomeFunnyIndex)
201
+ StrokeDB::SomeFunnyIndex = Class.new(InvertedListIndex)
202
+ config = StrokeDB::Config.build :index => :some_funny, :base_path => @base_path
203
+ config.indexes[:default].should be_a_kind_of(SomeFunnyIndex)
204
+ end
205
+
206
+ it "should use InvertedListFileStorage index storage by default" do
207
+ config = StrokeDB::Config.build :base_path => @base_path
208
+ config.storages[:inverted_list_file].should be_a_kind_of(InvertedListFileStorage)
209
+ end
210
+
211
+ it "should use specific index storage if told so" do
212
+ StrokeDB.send!(:remove_const,'SomeFunnyIndexStorage') if defined?(SomeFunnyIndexStorage)
213
+ StrokeDB::SomeFunnyIndexStorage = Class.new(InvertedListFileStorage)
214
+ config = StrokeDB::Config.build :index_storages => [:some_funny_index], :base_path => @base_path
215
+ config.storages[:some_funny_index].should be_a_kind_of(SomeFunnyIndexStorage)
216
+ end
217
+
218
+ it "should initialize index storage with base_path+storage_name" do
219
+ StrokeDB.send!(:remove_const,'SomeFunnyIndexStorage') if defined?(SomeFunnyIndexStorage)
220
+ StrokeDB::SomeFunnyIndexStorage = Class.new(InvertedListFileStorage)
221
+ index_storage = StrokeDB::SomeFunnyIndexStorage.new(:path => @base_path + '/some_funny_index')
222
+ SomeFunnyIndexStorage.should_receive(:new).with(:path => @base_path + '/some_funny_index').and_return(index_storage)
223
+ config = StrokeDB::Config.build :index_storages => [:some_funny_index], :base_path => @base_path
224
+ end
225
+
226
+ it "should dump config in base_path (except 'default' key)" do
227
+ cfg = StrokeDB::Config.build :default => true, :base_path => @base_path
228
+ config = JSON.parse(IO.read(@base_path + '/config'))
229
+ config.should == cfg.build_config
230
+ end
231
+
232
+ it "should load dumped config" do
233
+ cfg = StrokeDB::Config.build :default => true, :base_path => @base_path
234
+ cfg.storages.values.each {|s| s.close! if s.respond_to?(:close!)}
235
+ config = JSON.parse(IO.read(@base_path + '/config'))
236
+ cfg = StrokeDB::Config.load(@base_path + '/config')
237
+ cfg.build_config.should == config
238
+ cfg.should_not == StrokeDB.default_config
239
+ end
240
+
241
+ it "should load dumped config and make it default if told so" do
242
+ cfg = StrokeDB::Config.build :default => true, :base_path => @base_path
243
+ cfg.storages.values.each {|s| s.close! if s.respond_to?(:close!)}
244
+ config = JSON.parse(IO.read(@base_path + '/config'))
245
+ cfg = StrokeDB::Config.load(@base_path + '/config',true)
246
+ cfg.build_config.should == config
247
+ cfg.should == StrokeDB.default_config
248
+ end
249
+
250
+ end