data_fabric 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/CHANGELOG +1 -0
  2. data/Manifest +79 -0
  3. data/README.rdoc +108 -0
  4. data/Rakefile +69 -0
  5. data/TESTING.rdoc +34 -0
  6. data/TODO +1 -0
  7. data/data_fabric.gemspec +166 -0
  8. data/example/Rakefile +58 -0
  9. data/example/app/controllers/accounts_controller.rb +22 -0
  10. data/example/app/controllers/application.rb +39 -0
  11. data/example/app/controllers/figments_controller.rb +8 -0
  12. data/example/app/helpers/accounts_helper.rb +2 -0
  13. data/example/app/helpers/application_helper.rb +3 -0
  14. data/example/app/helpers/figments_helper.rb +2 -0
  15. data/example/app/models/account.rb +3 -0
  16. data/example/app/models/figment.rb +4 -0
  17. data/example/app/views/accounts/index.html.erb +47 -0
  18. data/example/app/views/layouts/application.html.erb +8 -0
  19. data/example/config/boot.rb +109 -0
  20. data/example/config/database.yml +21 -0
  21. data/example/config/environment.rb +67 -0
  22. data/example/config/environments/development.rb +17 -0
  23. data/example/config/environments/production.rb +22 -0
  24. data/example/config/environments/test.rb +22 -0
  25. data/example/config/initializers/inflections.rb +10 -0
  26. data/example/config/initializers/mime_types.rb +5 -0
  27. data/example/config/initializers/new_rails_defaults.rb +15 -0
  28. data/example/config/routes.rb +45 -0
  29. data/example/db/development.sqlite3 +0 -0
  30. data/example/db/migrate/20080702154628_create_accounts.rb +14 -0
  31. data/example/db/migrate/20080702154820_create_figments.rb +14 -0
  32. data/example/db/s0_development.sqlite3 +0 -0
  33. data/example/db/s0_test.sqlite3 +0 -0
  34. data/example/db/s1_development.sqlite3 +0 -0
  35. data/example/db/s1_test.sqlite3 +0 -0
  36. data/example/db/schema.rb +28 -0
  37. data/example/db/test.sqlite3 +0 -0
  38. data/example/public/404.html +30 -0
  39. data/example/public/422.html +30 -0
  40. data/example/public/500.html +30 -0
  41. data/example/public/dispatch.cgi +10 -0
  42. data/example/public/dispatch.fcgi +24 -0
  43. data/example/public/dispatch.rb +10 -0
  44. data/example/public/favicon.ico +0 -0
  45. data/example/public/images/rails.png +0 -0
  46. data/example/public/javascripts/application.js +2 -0
  47. data/example/public/javascripts/controls.js +963 -0
  48. data/example/public/javascripts/dragdrop.js +972 -0
  49. data/example/public/javascripts/effects.js +1120 -0
  50. data/example/public/javascripts/prototype.js +4225 -0
  51. data/example/public/robots.txt +5 -0
  52. data/example/script/about +3 -0
  53. data/example/script/console +3 -0
  54. data/example/script/dbconsole +3 -0
  55. data/example/script/destroy +3 -0
  56. data/example/script/generate +3 -0
  57. data/example/script/performance/benchmarker +3 -0
  58. data/example/script/performance/profiler +3 -0
  59. data/example/script/performance/request +3 -0
  60. data/example/script/plugin +3 -0
  61. data/example/script/process/inspector +3 -0
  62. data/example/script/process/reaper +3 -0
  63. data/example/script/process/spawner +3 -0
  64. data/example/script/runner +3 -0
  65. data/example/script/server +3 -0
  66. data/example/test/fixtures/accounts.yml +7 -0
  67. data/example/test/functional/accounts_controller_test.rb +12 -0
  68. data/example/test/integration/account_figments_test.rb +95 -0
  69. data/example/test/test_helper.rb +41 -0
  70. data/example/vendor/plugins/data_fabric/init.rb +1 -0
  71. data/example/vendor/plugins/data_fabric/lib/data_fabric.rb +231 -0
  72. data/init.rb +1 -0
  73. data/lib/data_fabric/version.rb +5 -0
  74. data/lib/data_fabric.rb +231 -0
  75. data/test/connection_test.rb +103 -0
  76. data/test/database.yml +27 -0
  77. data/test/database_test.rb +39 -0
  78. data/test/shard_test.rb +24 -0
  79. data/test/test_helper.rb +17 -0
  80. data/test/thread_test.rb +91 -0
  81. metadata +164 -0
@@ -0,0 +1,91 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require 'erb'
3
+
4
+ class ThreadTest < Test::Unit::TestCase
5
+
6
+ MUTEX = Mutex.new
7
+
8
+ def test_concurrency_not_allowed
9
+ assert_raise ArgumentError do
10
+ Object.class_eval %{
11
+ class ThreadedEnchilada < ActiveRecord::Base
12
+ self.allow_concurrency = true
13
+ set_table_name :enchiladas
14
+ connection_topology :prefix => 'fiveruns', :replicated => true, :shard_by => :city
15
+ end
16
+ }
17
+ end
18
+ end
19
+
20
+ def xtest_class_and_instance_connections
21
+ filename = File.join(File.dirname(__FILE__), "database.yml")
22
+ ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(filename)).result)
23
+
24
+ cconn = ThreadedEnchilada.connection
25
+ iconn = ThreadedEnchilada.new.connection
26
+ assert_equal cconn, iconn
27
+ end
28
+
29
+ def xtest_threaded_access
30
+ clear_databases
31
+
32
+ filename = File.join(File.dirname(__FILE__), "database.yml")
33
+ ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(filename)).result)
34
+
35
+ counts = {:austin => 0, :dallas => 0}
36
+ threads = []
37
+ 10.times do
38
+ threads << Thread.new do
39
+ begin
40
+ 200.times do
41
+ city = rand(1_000_000) % 2 == 0 ? :austin : :dallas
42
+ DataFabric.activate_shard :city => city do
43
+ #puts Enchilada.connection.to_s
44
+ #assert_equal "fiveruns_city_#{city}_test_slave", Enchilada.connection.connection_name
45
+ ThreadedEnchilada.create!(:name => "#{city}")
46
+ MUTEX.synchronize do
47
+ counts[city] += 1
48
+ end
49
+ end
50
+ end
51
+ rescue => e
52
+ puts e.message
53
+ puts e.backtrace.join("\n\t")
54
+ end
55
+ end
56
+ end
57
+ threads.each { |thread| thread.join }
58
+
59
+ counts.each_pair do |city, count|
60
+ DataFabric.activate_shard(:city => city) do
61
+ # slave should be empty
62
+ #assert_equal "fiveruns_city_#{city}_test_slave", ThreadedEnchilada.connection.connection_name
63
+ assert_equal 0, ThreadedEnchilada.count
64
+ ThreadedEnchilada.transaction do
65
+ #assert_equal "fiveruns_city_#{city}_test_master", Enchilada.connection.connection_name
66
+ # master should have the counts we expect
67
+ assert_equal count, ThreadedEnchilada.count
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def clear_databases
76
+ ActiveRecord::Base.configurations = { 'test' => { :adapter => 'mysql', :host => 'localhost', :database => 'mysql' } }
77
+ ActiveRecord::Base.establish_connection 'test'
78
+ databases = %w( vr_austin_master vr_austin_slave vr_dallas_master vr_dallas_slave )
79
+ databases.each do |db|
80
+ using_connection do
81
+ execute "use #{db}"
82
+ execute "delete from the_whole_burritos"
83
+ end
84
+ end
85
+ ActiveRecord::Base.clear_active_connections!
86
+ end
87
+
88
+ def using_connection(&block)
89
+ ActiveRecord::Base.connection.instance_eval(&block)
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: data_fabric
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Perham
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-08 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: echoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Sharding and replication support for ActiveRecord 2.x
36
+ email: mperham@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - CHANGELOG
43
+ - lib/data_fabric/version.rb
44
+ - lib/data_fabric.rb
45
+ - README.rdoc
46
+ - TODO
47
+ files:
48
+ - CHANGELOG
49
+ - example/app/controllers/accounts_controller.rb
50
+ - example/app/controllers/application.rb
51
+ - example/app/controllers/figments_controller.rb
52
+ - example/app/helpers/accounts_helper.rb
53
+ - example/app/helpers/application_helper.rb
54
+ - example/app/helpers/figments_helper.rb
55
+ - example/app/models/account.rb
56
+ - example/app/models/figment.rb
57
+ - example/app/views/accounts/index.html.erb
58
+ - example/app/views/layouts/application.html.erb
59
+ - example/config/boot.rb
60
+ - example/config/database.yml
61
+ - example/config/environment.rb
62
+ - example/config/environments/development.rb
63
+ - example/config/environments/production.rb
64
+ - example/config/environments/test.rb
65
+ - example/config/initializers/inflections.rb
66
+ - example/config/initializers/mime_types.rb
67
+ - example/config/initializers/new_rails_defaults.rb
68
+ - example/config/routes.rb
69
+ - example/db/development.sqlite3
70
+ - example/db/migrate/20080702154628_create_accounts.rb
71
+ - example/db/migrate/20080702154820_create_figments.rb
72
+ - example/db/s0_development.sqlite3
73
+ - example/db/s0_test.sqlite3
74
+ - example/db/s1_development.sqlite3
75
+ - example/db/s1_test.sqlite3
76
+ - example/db/schema.rb
77
+ - example/db/test.sqlite3
78
+ - example/public/404.html
79
+ - example/public/422.html
80
+ - example/public/500.html
81
+ - example/public/dispatch.cgi
82
+ - example/public/dispatch.fcgi
83
+ - example/public/dispatch.rb
84
+ - example/public/favicon.ico
85
+ - example/public/images/rails.png
86
+ - example/public/javascripts/application.js
87
+ - example/public/javascripts/controls.js
88
+ - example/public/javascripts/dragdrop.js
89
+ - example/public/javascripts/effects.js
90
+ - example/public/javascripts/prototype.js
91
+ - example/public/robots.txt
92
+ - example/Rakefile
93
+ - example/script/about
94
+ - example/script/console
95
+ - example/script/dbconsole
96
+ - example/script/destroy
97
+ - example/script/generate
98
+ - example/script/performance/benchmarker
99
+ - example/script/performance/profiler
100
+ - example/script/performance/request
101
+ - example/script/plugin
102
+ - example/script/process/inspector
103
+ - example/script/process/reaper
104
+ - example/script/process/spawner
105
+ - example/script/runner
106
+ - example/script/server
107
+ - example/test/fixtures/accounts.yml
108
+ - example/test/functional/accounts_controller_test.rb
109
+ - example/test/integration/account_figments_test.rb
110
+ - example/test/test_helper.rb
111
+ - example/vendor/plugins/data_fabric/init.rb
112
+ - example/vendor/plugins/data_fabric/lib/data_fabric.rb
113
+ - init.rb
114
+ - lib/data_fabric/version.rb
115
+ - lib/data_fabric.rb
116
+ - Rakefile
117
+ - README.rdoc
118
+ - test/connection_test.rb
119
+ - test/database.yml
120
+ - test/database_test.rb
121
+ - test/shard_test.rb
122
+ - test/test_helper.rb
123
+ - test/thread_test.rb
124
+ - TESTING.rdoc
125
+ - TODO
126
+ - Manifest
127
+ - data_fabric.gemspec
128
+ has_rdoc: true
129
+ homepage: http://github.com/fiveruns/data_fabric
130
+ post_install_message:
131
+ rdoc_options:
132
+ - --line-numbers
133
+ - --inline-source
134
+ - --title
135
+ - Data_fabric
136
+ - --main
137
+ - README.rdoc
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: "0"
145
+ version:
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "="
149
+ - !ruby/object:Gem::Version
150
+ version: "1.2"
151
+ version:
152
+ requirements: []
153
+
154
+ rubyforge_project: fiveruns
155
+ rubygems_version: 1.2.0
156
+ signing_key:
157
+ specification_version: 2
158
+ summary: Sharding and replication support for ActiveRecord 2.x
159
+ test_files:
160
+ - test/connection_test.rb
161
+ - test/database_test.rb
162
+ - test/shard_test.rb
163
+ - test/test_helper.rb
164
+ - test/thread_test.rb