cassanity 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/.gitignore +2 -1
  2. data/.travis.yml +1 -0
  3. data/Gemfile +3 -0
  4. data/Guardfile +0 -2
  5. data/README.md +11 -0
  6. data/doc/Instrumentation.md +40 -0
  7. data/doc/Migrations.md +132 -0
  8. data/examples/keyspaces.rb +11 -7
  9. data/lib/cassanity/argument_generators/column_family_delete.rb +1 -1
  10. data/lib/cassanity/argument_generators/columns.rb +33 -0
  11. data/lib/cassanity/argument_generators/where_clause.rb +1 -1
  12. data/lib/cassanity/client.rb +3 -1
  13. data/lib/cassanity/column.rb +48 -0
  14. data/lib/cassanity/column_family.rb +21 -2
  15. data/lib/cassanity/connection.rb +4 -8
  16. data/lib/cassanity/error.rb +18 -11
  17. data/lib/cassanity/executors/cassandra_cql.rb +79 -50
  18. data/lib/cassanity/instrumentation/log_subscriber.rb +4 -5
  19. data/lib/cassanity/instrumentation/metriks.rb +6 -0
  20. data/lib/cassanity/instrumentation/metriks_subscriber.rb +16 -0
  21. data/lib/cassanity/instrumentation/statsd.rb +6 -0
  22. data/lib/cassanity/instrumentation/statsd_subscriber.rb +22 -0
  23. data/lib/cassanity/instrumentation/subscriber.rb +58 -0
  24. data/lib/cassanity/instrumenters/memory.rb +0 -1
  25. data/lib/cassanity/keyspace.rb +10 -8
  26. data/lib/cassanity/migration.rb +125 -0
  27. data/lib/cassanity/migration_proxy.rb +76 -0
  28. data/lib/cassanity/migrator.rb +154 -0
  29. data/lib/cassanity/result_transformers/column_families.rb +20 -0
  30. data/lib/cassanity/result_transformers/columns.rb +21 -0
  31. data/lib/cassanity/result_transformers/keyspaces.rb +21 -0
  32. data/lib/cassanity/result_transformers/mirror.rb +1 -1
  33. data/lib/cassanity/result_transformers/result_to_array.rb +1 -1
  34. data/lib/cassanity/retry_strategies/exponential_backoff.rb +43 -0
  35. data/lib/cassanity/retry_strategies/retry_n_times.rb +29 -0
  36. data/lib/cassanity/retry_strategies/retry_strategy.rb +35 -0
  37. data/lib/cassanity/version.rb +1 -1
  38. data/spec/helper.rb +8 -0
  39. data/spec/integration/cassanity/column_family_spec.rb +36 -25
  40. data/spec/integration/cassanity/connection_spec.rb +11 -11
  41. data/spec/integration/cassanity/fixtures/migrations/20130224135000_create_users.rb +17 -0
  42. data/spec/integration/cassanity/fixtures/migrations/20130225135002_create_apps.rb +15 -0
  43. data/spec/integration/cassanity/fixtures/migrations/20130226135004_add_username_to_users.rb +9 -0
  44. data/spec/integration/cassanity/instrumentation/log_subscriber_spec.rb +71 -0
  45. data/spec/integration/cassanity/instrumentation/metriks_subscriber_spec.rb +48 -0
  46. data/spec/integration/cassanity/instrumentation/statsd_subscriber_spec.rb +58 -0
  47. data/spec/integration/cassanity/keyspace_spec.rb +21 -21
  48. data/spec/integration/cassanity/migration_spec.rb +157 -0
  49. data/spec/integration/cassanity/migrator_spec.rb +212 -0
  50. data/spec/support/cassanity_helpers.rb +21 -17
  51. data/spec/support/fake_udp_socket.rb +27 -0
  52. data/spec/unit/cassanity/argument_generators/batch_spec.rb +5 -5
  53. data/spec/unit/cassanity/argument_generators/column_family_delete_spec.rb +20 -6
  54. data/spec/unit/cassanity/argument_generators/column_family_update_spec.rb +6 -6
  55. data/spec/unit/cassanity/argument_generators/columns_spec.rb +45 -0
  56. data/spec/unit/cassanity/argument_generators/keyspace_create_spec.rb +1 -1
  57. data/spec/unit/cassanity/argument_generators/keyspace_drop_spec.rb +1 -1
  58. data/spec/unit/cassanity/argument_generators/keyspace_use_spec.rb +1 -1
  59. data/spec/unit/cassanity/argument_generators/where_clause_spec.rb +2 -2
  60. data/spec/unit/cassanity/client_spec.rb +10 -3
  61. data/spec/unit/cassanity/column_family_spec.rb +20 -3
  62. data/spec/unit/cassanity/column_spec.rb +76 -0
  63. data/spec/unit/cassanity/connection_spec.rb +1 -1
  64. data/spec/unit/cassanity/error_spec.rb +7 -2
  65. data/spec/unit/cassanity/executors/cassandra_cql_spec.rb +76 -23
  66. data/spec/unit/cassanity/keyspace_spec.rb +38 -13
  67. data/spec/unit/cassanity/migration_proxy_spec.rb +81 -0
  68. data/spec/unit/cassanity/migration_spec.rb +12 -0
  69. data/spec/unit/cassanity/migrator_spec.rb +20 -0
  70. data/spec/unit/cassanity/retry_strategies/exponential_backoff_spec.rb +37 -0
  71. data/spec/unit/cassanity/retry_strategies/retry_n_times_spec.rb +47 -0
  72. data/spec/unit/cassanity/retry_strategies/retry_strategy_spec.rb +27 -0
  73. metadata +56 -4
@@ -0,0 +1,12 @@
1
+ require 'helper'
2
+ require 'cassanity/migration'
3
+
4
+ describe Cassanity::Migration do
5
+ describe "#initialize" do
6
+ it "sets migrator" do
7
+ migrator = double('Migrator')
8
+ instance = described_class.new(migrator)
9
+ instance.migrator.should be(migrator)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+ require 'cassanity/migrator'
3
+
4
+ describe Cassanity::Migrator do
5
+ describe "#initialize" do
6
+ let(:keyspace) { double('Keyspace') }
7
+
8
+ before do
9
+ @result = described_class.new(keyspace, '/foo/bar')
10
+ end
11
+
12
+ it "sets keyspace" do
13
+ @result.keyspace.should eq(keyspace)
14
+ end
15
+
16
+ it "sets migration path" do
17
+ @result.migrations_path.should eq(Pathname('/foo/bar'))
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,37 @@
1
+ require 'helper'
2
+ require 'cassanity/retry_strategies/exponential_backoff'
3
+
4
+ describe Cassanity::RetryStrategies::ExponentialBackoff do
5
+ subject { described_class.new }
6
+
7
+ describe "#execute" do
8
+ it "sleeps after a failure" do
9
+ subject.should_receive(:sleep).once.and_raise 'Stop!'
10
+
11
+ lambda { subject.execute { raise cassandra_error('An error!') } }.should raise_error(RuntimeError, 'Stop!')
12
+ end
13
+
14
+ it "retries unsuccessful calls up to :retries times, stopping on success" do
15
+ executor = double('Executor')
16
+
17
+ i = 0
18
+ retries = 5
19
+
20
+ # Raise errors for a bit, then succeed.
21
+ executor.stub(:execute) {
22
+ i += 1
23
+ if i <= retries
24
+ raise cassandra_error('An error!')
25
+ else
26
+ :return
27
+ end
28
+ }
29
+
30
+ executor.should_receive(:execute).exactly(retries + 1).times.with('arg')
31
+
32
+ instance = described_class.new(:retries => retries)
33
+ instance.should_receive(:sleep).exactly(retries).times
34
+ instance.execute { executor.execute('arg') }.should eq(:return)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,47 @@
1
+ require 'helper'
2
+ require 'cassanity/retry_strategies/retry_n_times'
3
+
4
+ describe Cassanity::RetryStrategies::RetryNTimes do
5
+ subject { described_class.new }
6
+
7
+ describe "#initialize" do
8
+ it "defaults :retries to none" do
9
+ subject.retries.should eq(0)
10
+ end
11
+ end
12
+
13
+ describe "#execute" do
14
+ it "retries unsuccessful calls up to :retries times, stopping on success" do
15
+ executor = double('Executor')
16
+
17
+ i = 0
18
+ retries = 5
19
+
20
+ # Raise errors for a bit, then succeed.
21
+ executor.stub(:execute) {
22
+ i += 1
23
+ if i <= retries
24
+ raise cassandra_error('An error!')
25
+ else
26
+ :return
27
+ end
28
+ }
29
+
30
+ executor.should_receive(:execute).exactly(retries + 1).times.with('arg')
31
+
32
+ instance = described_class.new(:retries => retries)
33
+ instance.execute { executor.execute('arg') }.should eq(:return)
34
+ end
35
+
36
+ it "returns the last error raised when retries are exhausted" do
37
+ executor = double('Executor')
38
+ retries = 5
39
+ error = cassandra_error('An error!')
40
+
41
+ executor.should_receive(:execute).exactly(retries + 1).times.with('arg').and_raise error
42
+
43
+ instance = described_class.new(:retries => retries)
44
+ lambda { instance.execute { executor.execute('arg') } }.should raise_error(error)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,27 @@
1
+ require 'helper'
2
+ require 'cassanity/retry_strategies/retry_strategy'
3
+
4
+ describe Cassanity::RetryStrategies::RetryStrategy do
5
+ subject { described_class.new }
6
+
7
+ describe "#execute" do
8
+ it "yields to the passed block with the last error raised" do
9
+ error = cassandra_error('An error!')
10
+ subject.should_receive(:fail).with(1, error).and_raise 'Stop!'
11
+
12
+ lambda { subject.execute { raise error } }.should raise_error(RuntimeError, 'Stop!')
13
+ end
14
+
15
+ it "only applies retry logic to CassandraCQL::Error::InvalidRequestException" do
16
+ subject.should_not_receive(:fail)
17
+
18
+ lambda { subject.execute { raise 'An error!' } }.should raise_error(RuntimeError, 'An error!')
19
+ end
20
+
21
+ it "returns the value the block returns when successful" do
22
+ subject.should_not_receive(:fail)
23
+
24
+ subject.execute { 1 }.should eq(1)
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-22 00:00:00.000000000 Z
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cassandra-cql
@@ -45,6 +45,8 @@ files:
45
45
  - README.md
46
46
  - Rakefile
47
47
  - cassanity.gemspec
48
+ - doc/Instrumentation.md
49
+ - doc/Migrations.md
48
50
  - examples/_shared.rb
49
51
  - examples/batch.rb
50
52
  - examples/column_families.rb
@@ -62,6 +64,7 @@ files:
62
64
  - lib/cassanity/argument_generators/column_family_select.rb
63
65
  - lib/cassanity/argument_generators/column_family_truncate.rb
64
66
  - lib/cassanity/argument_generators/column_family_update.rb
67
+ - lib/cassanity/argument_generators/columns.rb
65
68
  - lib/cassanity/argument_generators/index_create.rb
66
69
  - lib/cassanity/argument_generators/index_drop.rb
67
70
  - lib/cassanity/argument_generators/keyspace_create.rb
@@ -75,6 +78,7 @@ files:
75
78
  - lib/cassanity/argument_generators/where_clause.rb
76
79
  - lib/cassanity/argument_generators/with_clause.rb
77
80
  - lib/cassanity/client.rb
81
+ - lib/cassanity/column.rb
78
82
  - lib/cassanity/column_family.rb
79
83
  - lib/cassanity/connection.rb
80
84
  - lib/cassanity/decrement.rb
@@ -82,9 +86,17 @@ files:
82
86
  - lib/cassanity/executors/cassandra_cql.rb
83
87
  - lib/cassanity/increment.rb
84
88
  - lib/cassanity/instrumentation/log_subscriber.rb
89
+ - lib/cassanity/instrumentation/metriks.rb
90
+ - lib/cassanity/instrumentation/metriks_subscriber.rb
91
+ - lib/cassanity/instrumentation/statsd.rb
92
+ - lib/cassanity/instrumentation/statsd_subscriber.rb
93
+ - lib/cassanity/instrumentation/subscriber.rb
85
94
  - lib/cassanity/instrumenters/memory.rb
86
95
  - lib/cassanity/instrumenters/noop.rb
87
96
  - lib/cassanity/keyspace.rb
97
+ - lib/cassanity/migration.rb
98
+ - lib/cassanity/migration_proxy.rb
99
+ - lib/cassanity/migrator.rb
88
100
  - lib/cassanity/operator.rb
89
101
  - lib/cassanity/operators/eq.rb
90
102
  - lib/cassanity/operators/gt.rb
@@ -92,15 +104,30 @@ files:
92
104
  - lib/cassanity/operators/lt.rb
93
105
  - lib/cassanity/operators/lte.rb
94
106
  - lib/cassanity/range.rb
107
+ - lib/cassanity/result_transformers/column_families.rb
108
+ - lib/cassanity/result_transformers/columns.rb
109
+ - lib/cassanity/result_transformers/keyspaces.rb
95
110
  - lib/cassanity/result_transformers/mirror.rb
96
111
  - lib/cassanity/result_transformers/result_to_array.rb
112
+ - lib/cassanity/retry_strategies/exponential_backoff.rb
113
+ - lib/cassanity/retry_strategies/retry_n_times.rb
114
+ - lib/cassanity/retry_strategies/retry_strategy.rb
97
115
  - lib/cassanity/schema.rb
98
116
  - lib/cassanity/version.rb
99
117
  - spec/helper.rb
100
118
  - spec/integration/cassanity/column_family_spec.rb
101
119
  - spec/integration/cassanity/connection_spec.rb
120
+ - spec/integration/cassanity/fixtures/migrations/20130224135000_create_users.rb
121
+ - spec/integration/cassanity/fixtures/migrations/20130225135002_create_apps.rb
122
+ - spec/integration/cassanity/fixtures/migrations/20130226135004_add_username_to_users.rb
123
+ - spec/integration/cassanity/instrumentation/log_subscriber_spec.rb
124
+ - spec/integration/cassanity/instrumentation/metriks_subscriber_spec.rb
125
+ - spec/integration/cassanity/instrumentation/statsd_subscriber_spec.rb
102
126
  - spec/integration/cassanity/keyspace_spec.rb
127
+ - spec/integration/cassanity/migration_spec.rb
128
+ - spec/integration/cassanity/migrator_spec.rb
103
129
  - spec/support/cassanity_helpers.rb
130
+ - spec/support/fake_udp_socket.rb
104
131
  - spec/unit/cassanity/argument_generators/batch_spec.rb
105
132
  - spec/unit/cassanity/argument_generators/column_families_spec.rb
106
133
  - spec/unit/cassanity/argument_generators/column_family_alter_spec.rb
@@ -111,6 +138,7 @@ files:
111
138
  - spec/unit/cassanity/argument_generators/column_family_select_spec.rb
112
139
  - spec/unit/cassanity/argument_generators/column_family_truncate_spec.rb
113
140
  - spec/unit/cassanity/argument_generators/column_family_update_spec.rb
141
+ - spec/unit/cassanity/argument_generators/columns_spec.rb
114
142
  - spec/unit/cassanity/argument_generators/index_create_spec.rb
115
143
  - spec/unit/cassanity/argument_generators/index_drop_spec.rb
116
144
  - spec/unit/cassanity/argument_generators/keyspace_create_spec.rb
@@ -125,6 +153,7 @@ files:
125
153
  - spec/unit/cassanity/argument_generators/with_clause_spec.rb
126
154
  - spec/unit/cassanity/client_spec.rb
127
155
  - spec/unit/cassanity/column_family_spec.rb
156
+ - spec/unit/cassanity/column_spec.rb
128
157
  - spec/unit/cassanity/connection_spec.rb
129
158
  - spec/unit/cassanity/decrement_spec.rb
130
159
  - spec/unit/cassanity/error_spec.rb
@@ -133,6 +162,9 @@ files:
133
162
  - spec/unit/cassanity/instrumentors/memory_spec.rb
134
163
  - spec/unit/cassanity/instrumentors/noop_spec.rb
135
164
  - spec/unit/cassanity/keyspace_spec.rb
165
+ - spec/unit/cassanity/migration_proxy_spec.rb
166
+ - spec/unit/cassanity/migration_spec.rb
167
+ - spec/unit/cassanity/migrator_spec.rb
136
168
  - spec/unit/cassanity/operator_spec.rb
137
169
  - spec/unit/cassanity/operators/eq_spec.rb
138
170
  - spec/unit/cassanity/operators/gt_spec.rb
@@ -141,6 +173,9 @@ files:
141
173
  - spec/unit/cassanity/operators/lte_spec.rb
142
174
  - spec/unit/cassanity/result_transformers/mirror_spec.rb
143
175
  - spec/unit/cassanity/result_transformers/result_to_array_spec.rb
176
+ - spec/unit/cassanity/retry_strategies/exponential_backoff_spec.rb
177
+ - spec/unit/cassanity/retry_strategies/retry_n_times_spec.rb
178
+ - spec/unit/cassanity/retry_strategies/retry_strategy_spec.rb
144
179
  - spec/unit/cassanity/schema_spec.rb
145
180
  - spec/unit/cassanity_spec.rb
146
181
  homepage: http://johnnunemaker.com/cassanity/
@@ -157,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
192
  version: '0'
158
193
  segments:
159
194
  - 0
160
- hash: 3992273312347222416
195
+ hash: 2363501885824826450
161
196
  required_rubygems_version: !ruby/object:Gem::Requirement
162
197
  none: false
163
198
  requirements:
@@ -166,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
201
  version: '0'
167
202
  segments:
168
203
  - 0
169
- hash: 3992273312347222416
204
+ hash: 2363501885824826450
170
205
  requirements: []
171
206
  rubyforge_project:
172
207
  rubygems_version: 1.8.23
@@ -178,8 +213,17 @@ test_files:
178
213
  - spec/helper.rb
179
214
  - spec/integration/cassanity/column_family_spec.rb
180
215
  - spec/integration/cassanity/connection_spec.rb
216
+ - spec/integration/cassanity/fixtures/migrations/20130224135000_create_users.rb
217
+ - spec/integration/cassanity/fixtures/migrations/20130225135002_create_apps.rb
218
+ - spec/integration/cassanity/fixtures/migrations/20130226135004_add_username_to_users.rb
219
+ - spec/integration/cassanity/instrumentation/log_subscriber_spec.rb
220
+ - spec/integration/cassanity/instrumentation/metriks_subscriber_spec.rb
221
+ - spec/integration/cassanity/instrumentation/statsd_subscriber_spec.rb
181
222
  - spec/integration/cassanity/keyspace_spec.rb
223
+ - spec/integration/cassanity/migration_spec.rb
224
+ - spec/integration/cassanity/migrator_spec.rb
182
225
  - spec/support/cassanity_helpers.rb
226
+ - spec/support/fake_udp_socket.rb
183
227
  - spec/unit/cassanity/argument_generators/batch_spec.rb
184
228
  - spec/unit/cassanity/argument_generators/column_families_spec.rb
185
229
  - spec/unit/cassanity/argument_generators/column_family_alter_spec.rb
@@ -190,6 +234,7 @@ test_files:
190
234
  - spec/unit/cassanity/argument_generators/column_family_select_spec.rb
191
235
  - spec/unit/cassanity/argument_generators/column_family_truncate_spec.rb
192
236
  - spec/unit/cassanity/argument_generators/column_family_update_spec.rb
237
+ - spec/unit/cassanity/argument_generators/columns_spec.rb
193
238
  - spec/unit/cassanity/argument_generators/index_create_spec.rb
194
239
  - spec/unit/cassanity/argument_generators/index_drop_spec.rb
195
240
  - spec/unit/cassanity/argument_generators/keyspace_create_spec.rb
@@ -204,6 +249,7 @@ test_files:
204
249
  - spec/unit/cassanity/argument_generators/with_clause_spec.rb
205
250
  - spec/unit/cassanity/client_spec.rb
206
251
  - spec/unit/cassanity/column_family_spec.rb
252
+ - spec/unit/cassanity/column_spec.rb
207
253
  - spec/unit/cassanity/connection_spec.rb
208
254
  - spec/unit/cassanity/decrement_spec.rb
209
255
  - spec/unit/cassanity/error_spec.rb
@@ -212,6 +258,9 @@ test_files:
212
258
  - spec/unit/cassanity/instrumentors/memory_spec.rb
213
259
  - spec/unit/cassanity/instrumentors/noop_spec.rb
214
260
  - spec/unit/cassanity/keyspace_spec.rb
261
+ - spec/unit/cassanity/migration_proxy_spec.rb
262
+ - spec/unit/cassanity/migration_spec.rb
263
+ - spec/unit/cassanity/migrator_spec.rb
215
264
  - spec/unit/cassanity/operator_spec.rb
216
265
  - spec/unit/cassanity/operators/eq_spec.rb
217
266
  - spec/unit/cassanity/operators/gt_spec.rb
@@ -220,5 +269,8 @@ test_files:
220
269
  - spec/unit/cassanity/operators/lte_spec.rb
221
270
  - spec/unit/cassanity/result_transformers/mirror_spec.rb
222
271
  - spec/unit/cassanity/result_transformers/result_to_array_spec.rb
272
+ - spec/unit/cassanity/retry_strategies/exponential_backoff_spec.rb
273
+ - spec/unit/cassanity/retry_strategies/retry_n_times_spec.rb
274
+ - spec/unit/cassanity/retry_strategies/retry_strategy_spec.rb
223
275
  - spec/unit/cassanity/schema_spec.rb
224
276
  - spec/unit/cassanity_spec.rb