xbar 0.0.1 → 0.4.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.
Files changed (80) hide show
  1. data/Appraisals +25 -0
  2. data/README.mkdn +215 -0
  3. data/Rakefile +337 -1
  4. data/examples/README +5 -0
  5. data/examples/config/simple.json +22 -0
  6. data/examples/example1.rb +34 -0
  7. data/examples/migrations/1_create_users.rb +10 -0
  8. data/examples/setup.rb +43 -0
  9. data/gemfiles/rails3.gemfile +8 -0
  10. data/gemfiles/rails3.gemfile.lock +74 -0
  11. data/gemfiles/rails31.gemfile +8 -0
  12. data/gemfiles/rails31.gemfile.lock +83 -0
  13. data/gemfiles/rails32.gemfile +7 -0
  14. data/gemfiles/rails32.gemfile.lock +117 -0
  15. data/gemfiles/rails4.gemfile +9 -0
  16. data/gemfiles/rails4.gemfile.lock +134 -0
  17. data/lib/migrations/1_create_usage_statistics.rb +23 -0
  18. data/lib/xbar/association.rb +49 -0
  19. data/lib/xbar/association_collection.rb +69 -0
  20. data/lib/xbar/colors.rb +32 -0
  21. data/lib/xbar/has_and_belongs_to_many_association.rb +17 -0
  22. data/lib/xbar/logger.rb +14 -0
  23. data/lib/xbar/mapper.rb +304 -0
  24. data/lib/xbar/migration.rb +76 -0
  25. data/lib/xbar/model.rb +165 -0
  26. data/lib/xbar/proxy.rb +249 -0
  27. data/lib/xbar/rails2/association.rb +133 -0
  28. data/lib/xbar/rails2/persistence.rb +39 -0
  29. data/lib/xbar/rails3/arel.rb +13 -0
  30. data/lib/xbar/rails3/association.rb +112 -0
  31. data/lib/xbar/rails3/persistence.rb +37 -0
  32. data/lib/xbar/rails3.1/singular_association.rb +34 -0
  33. data/lib/xbar/scope_proxy.rb +55 -0
  34. data/lib/xbar/shard.rb +95 -0
  35. data/lib/xbar/version.rb +2 -2
  36. data/lib/xbar.rb +121 -2
  37. data/run +27 -0
  38. data/spec/config/acme.json +53 -0
  39. data/spec/config/connection.rb +2 -0
  40. data/spec/config/default.json +160 -0
  41. data/spec/config/duplicate_shard.json +21 -0
  42. data/spec/config/missing_key.json +20 -0
  43. data/spec/config/new_shards.json +29 -0
  44. data/spec/config/no_master_shard.json +19 -0
  45. data/spec/config/not_entire_sharded.json +23 -0
  46. data/spec/config/octopus.json +27 -0
  47. data/spec/config/octopus_rails.json +25 -0
  48. data/spec/config/production_fully_replicated.json +21 -0
  49. data/spec/config/production_raise_error.json +17 -0
  50. data/spec/config/simple.json +22 -0
  51. data/spec/config/single_adapter.json +20 -0
  52. data/spec/console.rb +15 -0
  53. data/spec/migrations/10_create_users_using_replication.rb +12 -0
  54. data/spec/migrations/11_add_field_in_all_slaves.rb +11 -0
  55. data/spec/migrations/12_create_users_using_block.rb +23 -0
  56. data/spec/migrations/13_create_users_using_block_and_using.rb +15 -0
  57. data/spec/migrations/1_create_users_on_master.rb +9 -0
  58. data/spec/migrations/2_create_users_on_canada.rb +11 -0
  59. data/spec/migrations/3_create_users_on_both_shards.rb +11 -0
  60. data/spec/migrations/4_create_users_on_shards_of_a_group.rb +11 -0
  61. data/spec/migrations/5_create_users_on_multiples_groups.rb +11 -0
  62. data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +11 -0
  63. data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +11 -0
  64. data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +11 -0
  65. data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +11 -0
  66. data/spec/spec_helper.rb +25 -0
  67. data/spec/support/database_models.rb +78 -0
  68. data/spec/support/xbar_helper.rb +42 -0
  69. data/spec/xbar/association_spec.rb +660 -0
  70. data/spec/xbar/controller_spec.rb +40 -0
  71. data/spec/xbar/logger_spec.rb +22 -0
  72. data/spec/xbar/mapper_spec.rb +283 -0
  73. data/spec/xbar/migration_spec.rb +110 -0
  74. data/spec/xbar/model_spec.rb +434 -0
  75. data/spec/xbar/proxy_spec.rb +124 -0
  76. data/spec/xbar/replication_spec.rb +94 -0
  77. data/spec/xbar/scope_proxy_spec.rb +22 -0
  78. data/spec/xbar/shard_spec.rb +36 -0
  79. data/xbar.gemspec +13 -3
  80. metadata +231 -10
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "replication should act correctly with sharding" do
4
+ before(:each) do
5
+ set_xbar_env('default', 'staging')
6
+ end
7
+
8
+ it "should choose master shard correctly for independent databases" do
9
+ User.using(:china).create!(:name => "Thiago")
10
+ using_environment :test do
11
+ XBar.using(:china) do
12
+ User.create!(:name => "Thiago")
13
+ end
14
+ User.count.should == 0 #reads from a slave
15
+ User.using(:china_east).count.should == 2
16
+ User.using(:china_west).count.should == 0
17
+ end
18
+ end
19
+
20
+ it "replication should act correctly with sharding" do
21
+ Cat.create!(:name => "Thiago")
22
+ using_environment :test do
23
+ XBar.using(:canada) do
24
+ Cat.create!(:name => "Thiago")
25
+ # Reads from a replica, assumes replication is fast enough.
26
+ Cat.count.should == 1
27
+ end
28
+ Cat.using(:canada).count.should == 1
29
+ Cat.using(:canada_east).count.should == 1
30
+ Cat.using(:canada_central).count.should == 1
31
+ Cat.using(:canada_west).count.should == 1
32
+ end
33
+ end
34
+
35
+ end
36
+
data/xbar.gemspec CHANGED
@@ -4,12 +4,12 @@ require "xbar/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "xbar"
7
- s.version = Xbar::VERSION
7
+ s.version = XBar::VERSION
8
8
  s.authors = ["Michael Schmitz"]
9
9
  s.email = ["lydianblues@gmail.com"]
10
10
  s.homepage = ""
11
- s.summary = %q{Dymanic connection router}
12
- s.description = %q{Manage connection pools to implement shards and mirrors}
11
+ s.summary = %q{Dymanic connection pool manager for ActiveRecord}
12
+ s.description = %q{Supports MongoDB style sharding and mirroring}
13
13
 
14
14
  s.rubyforge_project = "xbar"
15
15
 
@@ -20,4 +20,14 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_development_dependency "rspec"
22
22
  s.add_runtime_dependency "mysql2"
23
+ s.add_dependency 'activerecord'
24
+ s.add_development_dependency 'rake'
25
+ s.add_development_dependency 'actionpack'
26
+ s.add_development_dependency 'appraisal'
27
+ s.add_development_dependency 'rspec', '2.8.0'
28
+ s.add_development_dependency 'mysql2'
29
+ s.add_development_dependency 'pg'
30
+ s.add_development_dependency 'sqlite3'
31
+ s.add_development_dependency 'syntax'
32
+ # s.add_development_dependency 'metric_fu'
23
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-26 00:00:00.000000000 Z
12
+ date: 2012-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70355009959100 !ruby/object:Gem::Requirement
16
+ requirement: &70299244954380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70355009959100
24
+ version_requirements: *70299244954380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mysql2
27
- requirement: &70355009958360 !ruby/object:Gem::Requirement
27
+ requirement: &70299244952740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,8 +32,107 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70355009958360
36
- description: Manage connection pools to implement shards and mirrors
35
+ version_requirements: *70299244952740
36
+ - !ruby/object:Gem::Dependency
37
+ name: activerecord
38
+ requirement: &70299244951780 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70299244951780
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &70299244965880 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70299244965880
58
+ - !ruby/object:Gem::Dependency
59
+ name: actionpack
60
+ requirement: &70299244961660 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70299244961660
69
+ - !ruby/object:Gem::Dependency
70
+ name: appraisal
71
+ requirement: &70299244971220 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70299244971220
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec
82
+ requirement: &70299244983260 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - =
86
+ - !ruby/object:Gem::Version
87
+ version: 2.8.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70299244983260
91
+ - !ruby/object:Gem::Dependency
92
+ name: mysql2
93
+ requirement: &70299244979900 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70299244979900
102
+ - !ruby/object:Gem::Dependency
103
+ name: pg
104
+ requirement: &70299244977220 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70299244977220
113
+ - !ruby/object:Gem::Dependency
114
+ name: sqlite3
115
+ requirement: &70299244991040 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *70299244991040
124
+ - !ruby/object:Gem::Dependency
125
+ name: syntax
126
+ requirement: &70299244989980 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *70299244989980
135
+ description: Supports MongoDB style sharding and mirroring
37
136
  email:
38
137
  - lydianblues@gmail.com
39
138
  executables: []
@@ -41,10 +140,85 @@ extensions: []
41
140
  extra_rdoc_files: []
42
141
  files:
43
142
  - .gitignore
143
+ - Appraisals
44
144
  - Gemfile
145
+ - README.mkdn
45
146
  - Rakefile
147
+ - examples/README
148
+ - examples/config/simple.json
149
+ - examples/example1.rb
150
+ - examples/migrations/1_create_users.rb
151
+ - examples/setup.rb
152
+ - gemfiles/rails3.gemfile
153
+ - gemfiles/rails3.gemfile.lock
154
+ - gemfiles/rails31.gemfile
155
+ - gemfiles/rails31.gemfile.lock
156
+ - gemfiles/rails32.gemfile
157
+ - gemfiles/rails32.gemfile.lock
158
+ - gemfiles/rails4.gemfile
159
+ - gemfiles/rails4.gemfile.lock
160
+ - lib/migrations/1_create_usage_statistics.rb
46
161
  - lib/xbar.rb
162
+ - lib/xbar/association.rb
163
+ - lib/xbar/association_collection.rb
164
+ - lib/xbar/colors.rb
165
+ - lib/xbar/has_and_belongs_to_many_association.rb
166
+ - lib/xbar/logger.rb
167
+ - lib/xbar/mapper.rb
168
+ - lib/xbar/migration.rb
169
+ - lib/xbar/model.rb
170
+ - lib/xbar/proxy.rb
171
+ - lib/xbar/rails2/association.rb
172
+ - lib/xbar/rails2/persistence.rb
173
+ - lib/xbar/rails3.1/singular_association.rb
174
+ - lib/xbar/rails3/arel.rb
175
+ - lib/xbar/rails3/association.rb
176
+ - lib/xbar/rails3/persistence.rb
177
+ - lib/xbar/scope_proxy.rb
178
+ - lib/xbar/shard.rb
47
179
  - lib/xbar/version.rb
180
+ - run
181
+ - spec/config/acme.json
182
+ - spec/config/connection.rb
183
+ - spec/config/default.json
184
+ - spec/config/duplicate_shard.json
185
+ - spec/config/missing_key.json
186
+ - spec/config/new_shards.json
187
+ - spec/config/no_master_shard.json
188
+ - spec/config/not_entire_sharded.json
189
+ - spec/config/octopus.json
190
+ - spec/config/octopus_rails.json
191
+ - spec/config/production_fully_replicated.json
192
+ - spec/config/production_raise_error.json
193
+ - spec/config/simple.json
194
+ - spec/config/single_adapter.json
195
+ - spec/console.rb
196
+ - spec/migrations/10_create_users_using_replication.rb
197
+ - spec/migrations/11_add_field_in_all_slaves.rb
198
+ - spec/migrations/12_create_users_using_block.rb
199
+ - spec/migrations/13_create_users_using_block_and_using.rb
200
+ - spec/migrations/1_create_users_on_master.rb
201
+ - spec/migrations/2_create_users_on_canada.rb
202
+ - spec/migrations/3_create_users_on_both_shards.rb
203
+ - spec/migrations/4_create_users_on_shards_of_a_group.rb
204
+ - spec/migrations/5_create_users_on_multiples_groups.rb
205
+ - spec/migrations/6_raise_exception_with_invalid_shard_name.rb
206
+ - spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb
207
+ - spec/migrations/8_raise_exception_with_invalid_group_name.rb
208
+ - spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb
209
+ - spec/spec_helper.rb
210
+ - spec/support/database_models.rb
211
+ - spec/support/xbar_helper.rb
212
+ - spec/xbar/association_spec.rb
213
+ - spec/xbar/controller_spec.rb
214
+ - spec/xbar/logger_spec.rb
215
+ - spec/xbar/mapper_spec.rb
216
+ - spec/xbar/migration_spec.rb
217
+ - spec/xbar/model_spec.rb
218
+ - spec/xbar/proxy_spec.rb
219
+ - spec/xbar/replication_spec.rb
220
+ - spec/xbar/scope_proxy_spec.rb
221
+ - spec/xbar/shard_spec.rb
48
222
  - xbar.gemspec
49
223
  homepage: ''
50
224
  licenses: []
@@ -58,16 +232,63 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
232
  - - ! '>='
59
233
  - !ruby/object:Gem::Version
60
234
  version: '0'
235
+ segments:
236
+ - 0
237
+ hash: -1412410971893777561
61
238
  required_rubygems_version: !ruby/object:Gem::Requirement
62
239
  none: false
63
240
  requirements:
64
241
  - - ! '>='
65
242
  - !ruby/object:Gem::Version
66
243
  version: '0'
244
+ segments:
245
+ - 0
246
+ hash: -1412410971893777561
67
247
  requirements: []
68
248
  rubyforge_project: xbar
69
- rubygems_version: 1.8.10
249
+ rubygems_version: 1.8.15
70
250
  signing_key:
71
251
  specification_version: 3
72
- summary: Dymanic connection router
73
- test_files: []
252
+ summary: Dymanic connection pool manager for ActiveRecord
253
+ test_files:
254
+ - spec/config/acme.json
255
+ - spec/config/connection.rb
256
+ - spec/config/default.json
257
+ - spec/config/duplicate_shard.json
258
+ - spec/config/missing_key.json
259
+ - spec/config/new_shards.json
260
+ - spec/config/no_master_shard.json
261
+ - spec/config/not_entire_sharded.json
262
+ - spec/config/octopus.json
263
+ - spec/config/octopus_rails.json
264
+ - spec/config/production_fully_replicated.json
265
+ - spec/config/production_raise_error.json
266
+ - spec/config/simple.json
267
+ - spec/config/single_adapter.json
268
+ - spec/console.rb
269
+ - spec/migrations/10_create_users_using_replication.rb
270
+ - spec/migrations/11_add_field_in_all_slaves.rb
271
+ - spec/migrations/12_create_users_using_block.rb
272
+ - spec/migrations/13_create_users_using_block_and_using.rb
273
+ - spec/migrations/1_create_users_on_master.rb
274
+ - spec/migrations/2_create_users_on_canada.rb
275
+ - spec/migrations/3_create_users_on_both_shards.rb
276
+ - spec/migrations/4_create_users_on_shards_of_a_group.rb
277
+ - spec/migrations/5_create_users_on_multiples_groups.rb
278
+ - spec/migrations/6_raise_exception_with_invalid_shard_name.rb
279
+ - spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb
280
+ - spec/migrations/8_raise_exception_with_invalid_group_name.rb
281
+ - spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb
282
+ - spec/spec_helper.rb
283
+ - spec/support/database_models.rb
284
+ - spec/support/xbar_helper.rb
285
+ - spec/xbar/association_spec.rb
286
+ - spec/xbar/controller_spec.rb
287
+ - spec/xbar/logger_spec.rb
288
+ - spec/xbar/mapper_spec.rb
289
+ - spec/xbar/migration_spec.rb
290
+ - spec/xbar/model_spec.rb
291
+ - spec/xbar/proxy_spec.rb
292
+ - spec/xbar/replication_spec.rb
293
+ - spec/xbar/scope_proxy_spec.rb
294
+ - spec/xbar/shard_spec.rb