cequel 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +37 -33
- data/README.md +1 -1
- data/Rakefile +2 -31
- data/Vagrantfile +3 -1
- data/lib/cequel/metal/batch.rb +12 -0
- data/lib/cequel/metal/batch_manager.rb +2 -2
- data/lib/cequel/metal/keyspace.rb +26 -2
- data/lib/cequel/metal/updater.rb +7 -5
- data/lib/cequel/metal/writer.rb +1 -1
- data/lib/cequel/record/persistence.rb +18 -14
- data/lib/cequel/record/timestamps.rb +1 -0
- data/lib/cequel/version.rb +1 -1
- data/spec/examples/metal/keyspace_spec.rb +30 -1
- data/spec/examples/record/persistence_spec.rb +24 -0
- data/spec/support/helpers.rb +9 -0
- data/templates/config/cequel.yml +3 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72e24f9cd8e2717c595a60f3826bf274f50241cb
|
4
|
+
data.tar.gz: e1a9ea1d681b534945d96ab4f0d87af7b7a08ef0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59a1423af086bf7f369f10efa5f37f0fb5c5c0d5c5235d1dfa7aeca84f60ae41712b89da735d5e59b3bdef4f200c8ea1658ba26b4d939dcd399370b4e7004f02
|
7
|
+
data.tar.gz: 8e5cf589b91e25dd6533c06241b862723a81b6a738d6f1df31d4a7fc0d71a9693ef995b08c1d5c27eb80c3b7d6b7c51398f59345286a6a03fb94ccc1140c9d3e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 1.4.2
|
2
|
+
|
3
|
+
* Allow setting a key attribute to what it already is
|
4
|
+
* Don't reset model updater/deleter if save results in an error
|
5
|
+
* Read `:default_consistency` from cequel.yml
|
6
|
+
* `:max_retries` configuration parameter for customization of maximum retries that will be made to reconnect to cassandra
|
7
|
+
|
1
8
|
## 1.4.1
|
2
9
|
|
3
10
|
* Cequel::Record::descendants doesn't return weakrefs
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cequel (1.4.
|
4
|
+
cequel (1.4.2)
|
5
5
|
activemodel (>= 3.1, < 5.0)
|
6
6
|
cql-rb (>= 1.2, < 3.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (4.1.
|
12
|
-
activesupport (= 4.1.
|
11
|
+
activemodel (4.1.6)
|
12
|
+
activesupport (= 4.1.6)
|
13
13
|
builder (~> 3.1)
|
14
|
-
activesupport (4.1.
|
14
|
+
activesupport (4.1.6)
|
15
15
|
i18n (~> 0.6, >= 0.6.9)
|
16
16
|
json (~> 1.7, >= 1.7.7)
|
17
17
|
minitest (~> 5.1)
|
18
18
|
thread_safe (~> 0.1)
|
19
19
|
tzinfo (~> 1.1)
|
20
|
-
appraisal (0.
|
20
|
+
appraisal (1.0.2)
|
21
21
|
bundler
|
22
22
|
rake
|
23
|
+
thor (>= 0.14.0)
|
23
24
|
ast (2.0.0)
|
24
25
|
builder (3.2.2)
|
25
26
|
byebug (2.7.0)
|
@@ -27,55 +28,55 @@ GEM
|
|
27
28
|
debugger-linecache (~> 1.2)
|
28
29
|
coderay (1.1.0)
|
29
30
|
columnize (0.8.9)
|
30
|
-
cql-rb (2.0.
|
31
|
+
cql-rb (2.0.3)
|
31
32
|
ione (~> 1)
|
32
|
-
debugger (1.6.
|
33
|
+
debugger (1.6.8)
|
33
34
|
columnize (>= 0.3.1)
|
34
35
|
debugger-linecache (~> 1.2.0)
|
35
|
-
debugger-ruby_core_source (~> 1.3.
|
36
|
+
debugger-ruby_core_source (~> 1.3.5)
|
36
37
|
debugger-linecache (1.2.0)
|
37
|
-
debugger-ruby_core_source (1.3.
|
38
|
+
debugger-ruby_core_source (1.3.5)
|
38
39
|
diff-lcs (1.2.5)
|
39
|
-
ffi (1.9.
|
40
|
+
ffi (1.9.4-java)
|
40
41
|
ffi2-generators (0.1.1)
|
41
|
-
i18n (0.6.
|
42
|
-
ione (1.1.
|
42
|
+
i18n (0.6.11)
|
43
|
+
ione (1.1.4)
|
43
44
|
json (1.8.1)
|
44
45
|
json (1.8.1-java)
|
45
46
|
method_source (0.8.2)
|
46
|
-
minitest (5.
|
47
|
+
minitest (5.4.1)
|
47
48
|
parser (2.1.9)
|
48
49
|
ast (>= 1.1, < 3.0)
|
49
50
|
slop (~> 3.4, >= 3.4.5)
|
50
51
|
powerpack (0.0.9)
|
51
|
-
pry (0.
|
52
|
-
coderay (~> 1.0)
|
53
|
-
method_source (~> 0.8)
|
52
|
+
pry (0.10.1)
|
53
|
+
coderay (~> 1.1.0)
|
54
|
+
method_source (~> 0.8.1)
|
54
55
|
slop (~> 3.4)
|
55
|
-
pry (0.
|
56
|
-
coderay (~> 1.0)
|
57
|
-
method_source (~> 0.8)
|
56
|
+
pry (0.10.1-java)
|
57
|
+
coderay (~> 1.1.0)
|
58
|
+
method_source (~> 0.8.1)
|
58
59
|
slop (~> 3.4)
|
59
60
|
spoon (~> 0.0)
|
60
|
-
psych (2.0.
|
61
|
-
racc (1.4.
|
61
|
+
psych (2.0.6)
|
62
|
+
racc (1.4.12)
|
62
63
|
rainbow (2.0.0)
|
63
64
|
rake (10.3.2)
|
64
|
-
rspec (2.
|
65
|
-
rspec-core (~> 2.
|
66
|
-
rspec-expectations (~> 2.
|
67
|
-
rspec-mocks (~> 2.
|
68
|
-
rspec-core (2.
|
69
|
-
rspec-expectations (2.
|
65
|
+
rspec (2.99.0)
|
66
|
+
rspec-core (~> 2.99.0)
|
67
|
+
rspec-expectations (~> 2.99.0)
|
68
|
+
rspec-mocks (~> 2.99.0)
|
69
|
+
rspec-core (2.99.2)
|
70
|
+
rspec-expectations (2.99.2)
|
70
71
|
diff-lcs (>= 1.1.3, < 2.0)
|
71
|
-
rspec-mocks (2.
|
72
|
+
rspec-mocks (2.99.2)
|
72
73
|
rubocop (0.19.1)
|
73
74
|
json (>= 1.7.7, < 2)
|
74
75
|
parser (~> 2.1.7)
|
75
76
|
powerpack (~> 0.0.6)
|
76
77
|
rainbow (>= 1.99.1, < 3.0)
|
77
78
|
ruby-progressbar (~> 1.4)
|
78
|
-
ruby-progressbar (1.
|
79
|
+
ruby-progressbar (1.6.0)
|
79
80
|
rubysl (2.0.15)
|
80
81
|
rubysl-abbrev (~> 2.0)
|
81
82
|
rubysl-base64 (~> 2.0)
|
@@ -181,7 +182,7 @@ GEM
|
|
181
182
|
rubysl-csv (2.0.2)
|
182
183
|
rubysl-english (~> 2.0)
|
183
184
|
rubysl-curses (2.0.1)
|
184
|
-
rubysl-date (2.0.
|
185
|
+
rubysl-date (2.0.8)
|
185
186
|
rubysl-delegate (2.0.1)
|
186
187
|
rubysl-digest (2.0.3)
|
187
188
|
rubysl-drb (2.0.1)
|
@@ -278,14 +279,16 @@ GEM
|
|
278
279
|
rubysl-xmlrpc (2.0.0)
|
279
280
|
rubysl-yaml (2.0.4)
|
280
281
|
rubysl-zlib (2.0.1)
|
281
|
-
slop (3.
|
282
|
+
slop (3.6.0)
|
282
283
|
spoon (0.0.4)
|
283
284
|
ffi
|
285
|
+
thor (0.19.1)
|
284
286
|
thread_safe (0.3.4)
|
285
287
|
thread_safe (0.3.4-java)
|
286
288
|
timecop (0.7.1)
|
287
|
-
tzinfo (1.2.
|
289
|
+
tzinfo (1.2.2)
|
288
290
|
thread_safe (~> 0.1)
|
291
|
+
wwtd (0.5.5)
|
289
292
|
yard (0.8.7.4)
|
290
293
|
|
291
294
|
PLATFORMS
|
@@ -293,7 +296,7 @@ PLATFORMS
|
|
293
296
|
ruby
|
294
297
|
|
295
298
|
DEPENDENCIES
|
296
|
-
appraisal (~> 0
|
299
|
+
appraisal (~> 1.0)
|
297
300
|
byebug (~> 2.7)
|
298
301
|
cequel!
|
299
302
|
debugger (~> 1.6)
|
@@ -305,4 +308,5 @@ DEPENDENCIES
|
|
305
308
|
rubocop (~> 0.19.0)
|
306
309
|
rubysl (~> 2.0)
|
307
310
|
timecop (~> 0.7)
|
311
|
+
wwtd (~> 0.5)
|
308
312
|
yard (~> 0.6)
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Cequel is a Ruby ORM for [Cassandra](http://cassandra.apache.org/) using
|
|
7
7
|
[![Build Status](https://travis-ci.org/cequel/cequel.png?branch=master)](https://travis-ci.org/cequel/cequel)
|
8
8
|
[![Dependency Status](https://gemnasium.com/cequel/cequel.png)](https://gemnasium.com/cequel/cequel)
|
9
9
|
[![Code Climate](https://codeclimate.com/github/cequel/cequel.png)](https://codeclimate.com/github/cequel/cequel)
|
10
|
-
[![Inline docs](http://inch-
|
10
|
+
[![Inline docs](http://inch-ci.org/github/cequel/cequel.png)](http://inch-ci.org/github/cequel/cequel)
|
11
11
|
|
12
12
|
`Cequel::Record` is an ActiveRecord-like domain model layer that exposes
|
13
13
|
the robust data modeling capabilities of CQL3, including parent-child
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'yaml'
|
|
2
2
|
require 'bundler/setup'
|
3
3
|
require 'rspec/core/rake_task'
|
4
4
|
require 'rubocop/rake_task'
|
5
|
-
require '
|
5
|
+
require 'wwtd/tasks'
|
6
6
|
require File.expand_path('../lib/cequel/version', __FILE__)
|
7
7
|
|
8
8
|
RUBY_VERSIONS = YAML.load_file(File.expand_path('../.travis.yml', __FILE__))['rvm']
|
@@ -11,7 +11,7 @@ task :default => :release
|
|
11
11
|
task :release => [
|
12
12
|
:verify_changelog,
|
13
13
|
:rubocop,
|
14
|
-
:
|
14
|
+
:wwtd,
|
15
15
|
:build,
|
16
16
|
:tag,
|
17
17
|
:update_stable,
|
@@ -53,23 +53,6 @@ RSpec::Core::RakeTask.new(:test) do |t|
|
|
53
53
|
t.rspec_opts = '-b'
|
54
54
|
end
|
55
55
|
|
56
|
-
namespace :bundle do
|
57
|
-
desc 'Run bundler for all environments'
|
58
|
-
task :all do
|
59
|
-
abort unless all_rubies('bundle')
|
60
|
-
abort unless all_rubies('rake', 'appraisal:install')
|
61
|
-
end
|
62
|
-
|
63
|
-
desc 'Update to latest dependencies on all environments'
|
64
|
-
task :update_all do
|
65
|
-
gemfiles = File.expand_path("../gemfiles", __FILE__)
|
66
|
-
FileUtils.rm_r(gemfiles, :verbose => true) if File.exist?(gemfiles)
|
67
|
-
abort unless system('bundle', 'update')
|
68
|
-
abort unless all_rubies('bundle')
|
69
|
-
abort unless all_rubies('rake', 'appraisal:install')
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
56
|
desc 'Check style with Rubocop'
|
74
57
|
Rubocop::RakeTask.new(:rubocop) do |task|
|
75
58
|
task.patterns = ['lib/**/*.rb']
|
@@ -86,12 +69,6 @@ namespace :test do
|
|
86
69
|
end
|
87
70
|
end
|
88
71
|
|
89
|
-
namespace :test do
|
90
|
-
task :all do
|
91
|
-
abort unless all_rubies('rake', 'appraisal', 'test:concise')
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
72
|
desc 'Update changelog'
|
96
73
|
task :changelog do
|
97
74
|
require './lib/cequel/version.rb'
|
@@ -114,9 +91,3 @@ task :verify_changelog do
|
|
114
91
|
abort "Changelog is not up-to-date."
|
115
92
|
end
|
116
93
|
end
|
117
|
-
|
118
|
-
def all_rubies(*command)
|
119
|
-
!RUBY_VERSIONS.find do |version|
|
120
|
-
!system('rvm', version, 'do', *command)
|
121
|
-
end
|
122
|
-
end
|
data/Vagrantfile
CHANGED
@@ -136,7 +136,9 @@ exec /opt/apache-cassandra-$1/bin/cassandra" > /etc/init/cassandra.conf
|
|
136
136
|
service cassandra start
|
137
137
|
SH
|
138
138
|
|
139
|
-
versions = (0..
|
139
|
+
versions = (0..0).map { |p| "2.1.#{p}" } +
|
140
|
+
(0..10).map { |p| "2.0.#{p}" } +
|
141
|
+
(0..19).map { |p| "1.2.#{p}" }
|
140
142
|
versions.each do |version|
|
141
143
|
java_version = version =~ /^1/ ? '6' : '7'
|
142
144
|
config.vm.define version do |machine|
|
data/lib/cequel/metal/batch.rb
CHANGED
@@ -59,6 +59,11 @@ module Cequel
|
|
59
59
|
end
|
60
60
|
@keyspace.execute_with_consistency(
|
61
61
|
@statement.args.first, @statement.args.drop(1), @consistency)
|
62
|
+
execute_on_complete_hooks
|
63
|
+
end
|
64
|
+
|
65
|
+
def on_complete(&block)
|
66
|
+
on_complete_hooks << block
|
62
67
|
end
|
63
68
|
|
64
69
|
#
|
@@ -91,14 +96,21 @@ module Cequel
|
|
91
96
|
|
92
97
|
private
|
93
98
|
|
99
|
+
attr_reader :on_complete_hooks
|
100
|
+
|
94
101
|
def reset
|
95
102
|
@statement = Statement.new
|
96
103
|
@statement_count = 0
|
104
|
+
@on_complete_hooks = []
|
97
105
|
end
|
98
106
|
|
99
107
|
def begin_statement
|
100
108
|
"BEGIN #{"UNLOGGED " if unlogged?}BATCH\n"
|
101
109
|
end
|
110
|
+
|
111
|
+
def execute_on_complete_hooks
|
112
|
+
on_complete_hooks.each { |hook| hook.call }
|
113
|
+
end
|
102
114
|
end
|
103
115
|
end
|
104
116
|
end
|
@@ -44,12 +44,12 @@ module Cequel
|
|
44
44
|
fail ArgumentError,
|
45
45
|
"Already in an unlogged batch; can't start a logged batch."
|
46
46
|
end
|
47
|
-
return yield
|
47
|
+
return yield(current_batch)
|
48
48
|
end
|
49
49
|
|
50
50
|
begin
|
51
51
|
self.current_batch = new_batch
|
52
|
-
yield.tap { new_batch.apply }
|
52
|
+
yield(new_batch).tap { new_batch.apply }
|
53
53
|
ensure
|
54
54
|
self.current_batch = nil
|
55
55
|
end
|
@@ -21,6 +21,8 @@ module Cequel
|
|
21
21
|
attr_reader :hosts
|
22
22
|
# @return Integer port to connect to Cassandra nodes on
|
23
23
|
attr_reader :port
|
24
|
+
# @return Integer maximum number of retries to reconnect to Cassandra
|
25
|
+
attr_reader :max_retries
|
24
26
|
# @return [Symbol] the default consistency for queries in this keyspace
|
25
27
|
# @since 1.1.0
|
26
28
|
attr_writer :default_consistency
|
@@ -98,6 +100,8 @@ module Cequel
|
|
98
100
|
# single Cassandra instance to connect to
|
99
101
|
# @option configuration [Integer] :port (9042) port on which to connect
|
100
102
|
# to all specified hosts
|
103
|
+
# @option configuration [Integer] :max_retries maximum number of retries
|
104
|
+
# on connection failure
|
101
105
|
# @option configuration [Array<String>] :hosts list of Cassandra
|
102
106
|
# instances to connect to (hostnames only)
|
103
107
|
# @option configuration [String] :username user to auth with (leave blank
|
@@ -115,9 +119,12 @@ module Cequel
|
|
115
119
|
@configuration = configuration
|
116
120
|
|
117
121
|
@hosts, @port = extract_hosts_and_port(configuration)
|
118
|
-
@credentials
|
122
|
+
@credentials = extract_credentials(configuration)
|
123
|
+
@max_retries = extract_max_retries(configuration)
|
119
124
|
|
120
125
|
@name = configuration[:keyspace]
|
126
|
+
@default_consistency = configuration[:default_consistency].try(:to_sym)
|
127
|
+
|
121
128
|
# reset the connections
|
122
129
|
clear_active_connections!
|
123
130
|
end
|
@@ -153,6 +160,10 @@ module Cequel
|
|
153
160
|
#
|
154
161
|
# Execute a CQL query in this keyspace
|
155
162
|
#
|
163
|
+
# If a connection error occurs, will retry a maximum number of
|
164
|
+
# time (default 3) before re-raising the original connection
|
165
|
+
# error.
|
166
|
+
#
|
156
167
|
# @param statement [String] CQL string
|
157
168
|
# @param bind_vars [Object] values for bind variables
|
158
169
|
# @return [Enumerable] the results of the query
|
@@ -160,7 +171,16 @@ module Cequel
|
|
160
171
|
# @see #execute_with_consistency
|
161
172
|
#
|
162
173
|
def execute(statement, *bind_vars)
|
163
|
-
|
174
|
+
retries = max_retries
|
175
|
+
|
176
|
+
begin
|
177
|
+
execute_with_consistency(statement, bind_vars, default_consistency)
|
178
|
+
rescue Cql::NotConnectedError, Ione::Io::ConnectionError
|
179
|
+
clear_active_connections!
|
180
|
+
raise if retries < 0
|
181
|
+
retries -= 1
|
182
|
+
retry
|
183
|
+
end
|
164
184
|
end
|
165
185
|
|
166
186
|
#
|
@@ -269,6 +289,10 @@ module Cequel
|
|
269
289
|
def extract_credentials(configuration)
|
270
290
|
configuration.slice(:username, :password).presence
|
271
291
|
end
|
292
|
+
|
293
|
+
def extract_max_retries(configuration)
|
294
|
+
configuration.fetch(:max_retries, 3)
|
295
|
+
end
|
272
296
|
end
|
273
297
|
end
|
274
298
|
end
|
data/lib/cequel/metal/updater.rb
CHANGED
@@ -144,20 +144,22 @@ module Cequel
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def write_to_statement(statement, options)
|
147
|
-
|
147
|
+
all_statements, all_bind_vars = statements_with_column_updates
|
148
148
|
statement.append("UPDATE #{table_name}")
|
149
149
|
.append(generate_upsert_options(options))
|
150
150
|
.append(" SET ")
|
151
|
-
.append(
|
151
|
+
.append(all_statements.join(', '), *all_bind_vars)
|
152
152
|
end
|
153
153
|
|
154
|
-
def
|
154
|
+
def statements_with_column_updates
|
155
|
+
all_statements, all_bind_vars = statements.dup, bind_vars.dup
|
155
156
|
column_updates.each_pair do |column, value|
|
156
157
|
prepare_upsert_value(value) do |binding, *values|
|
157
|
-
|
158
|
-
|
158
|
+
all_statements << "#{column} = #{binding}"
|
159
|
+
all_bind_vars.concat(values)
|
159
160
|
end
|
160
161
|
end
|
162
|
+
[all_statements, all_bind_vars]
|
161
163
|
end
|
162
164
|
end
|
163
165
|
end
|
data/lib/cequel/metal/writer.rb
CHANGED
@@ -26,7 +26,7 @@ module Cequel
|
|
26
26
|
# Execute the statement as a write operation
|
27
27
|
#
|
28
28
|
# @param options [Options] options
|
29
|
-
# @
|
29
|
+
# @option options [Symbol] :consistency what consistency level to use for
|
30
30
|
# the operation
|
31
31
|
# @option options [Integer] :ttl time-to-live in seconds for the written
|
32
32
|
# data
|
@@ -280,10 +280,10 @@ module Cequel
|
|
280
280
|
|
281
281
|
def update(options = {})
|
282
282
|
assert_keys_present!
|
283
|
-
connection.batch do
|
283
|
+
connection.batch do |batch|
|
284
|
+
batch.on_complete { @updater, @deleter = nil }
|
284
285
|
updater.execute(options)
|
285
286
|
deleter.execute(options.except(:ttl))
|
286
|
-
@updater, @deleter = nil
|
287
287
|
end
|
288
288
|
end
|
289
289
|
|
@@ -312,18 +312,22 @@ module Cequel
|
|
312
312
|
fail UnknownAttributeError, "unknown attribute: #{name}" unless column
|
313
313
|
value = column.cast(value) unless value.nil?
|
314
314
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
315
|
+
if !new_record? && key_attributes.keys.include?(name)
|
316
|
+
if read_attribute(name) != value
|
317
|
+
fail ArgumentError,
|
318
|
+
"Can't update key #{name} on persisted record"
|
319
|
+
end
|
320
|
+
else
|
321
|
+
super.tap { stage_attribute_update(name, value) }
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
def stage_attribute_update(name, value)
|
326
|
+
unless new_record?
|
327
|
+
if value.nil?
|
328
|
+
deleter.delete_columns(name)
|
329
|
+
else
|
330
|
+
updater.set(name => value)
|
327
331
|
end
|
328
332
|
end
|
329
333
|
end
|
data/lib/cequel/version.rb
CHANGED
@@ -82,7 +82,36 @@ describe Cequel::Metal::Keyspace do
|
|
82
82
|
port: Cequel::SpecSupport::Helpers.port,
|
83
83
|
keyspace: "totallymadeup"
|
84
84
|
|
85
|
-
expect(nonexistent_keyspace.exists?).to
|
85
|
+
expect(nonexistent_keyspace.exists?).to be false
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#execute" do
|
90
|
+
let(:statement) { "SELECT id FROM posts" }
|
91
|
+
|
92
|
+
context "without a connection error" do
|
93
|
+
it "executes a CQL query" do
|
94
|
+
expect { cequel.execute(statement) }.not_to raise_error
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "with a connection error" do
|
99
|
+
after(:each) do
|
100
|
+
RSpec::Mocks.proxy_for(cequel).reset
|
101
|
+
end
|
102
|
+
|
103
|
+
it "reconnects to cassandra with a new client after first failed connection" do
|
104
|
+
allow(cequel).to receive(:execute_with_consistency)
|
105
|
+
.with(statement, [], nil)
|
106
|
+
.and_raise(Ione::Io::ConnectionError)
|
107
|
+
.once
|
108
|
+
|
109
|
+
expect(cequel).to receive(:execute_with_consistency)
|
110
|
+
.with(statement, [], :quorum)
|
111
|
+
.once
|
112
|
+
|
113
|
+
expect { cequel.execute(statement) }.not_to raise_error
|
114
|
+
end
|
86
115
|
end
|
87
116
|
end
|
88
117
|
end
|
@@ -103,6 +103,13 @@ describe Cequel::Record::Persistence do
|
|
103
103
|
}.to raise_error(ArgumentError)
|
104
104
|
end
|
105
105
|
|
106
|
+
it 'should allow setting a key value to the same thing it already is' do
|
107
|
+
expect {
|
108
|
+
blog.subdomain = 'cequel'
|
109
|
+
blog.save
|
110
|
+
}.to_not raise_error
|
111
|
+
end
|
112
|
+
|
106
113
|
it 'should save with specified consistency' do
|
107
114
|
expect_query_with_consistency(/UPDATE/, :one) do
|
108
115
|
blog.name = 'Cequel'
|
@@ -125,6 +132,23 @@ describe Cequel::Record::Persistence do
|
|
125
132
|
.to eq((timestamp.to_f * 1_000_000).to_i)
|
126
133
|
Blog.connection.schema.truncate_table(Blog.table_name)
|
127
134
|
end
|
135
|
+
|
136
|
+
it 'should not query database if no attributes have been changed' do
|
137
|
+
disallow_queries!
|
138
|
+
blog.save
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should not mark itself as clean if save failed at Cassandra level' do
|
142
|
+
blog.name = 'Pizza'
|
143
|
+
with_client_error(Cql::QueryError.new(1, 'error')) do
|
144
|
+
begin
|
145
|
+
blog.save
|
146
|
+
rescue Cql::QueryError
|
147
|
+
end
|
148
|
+
end
|
149
|
+
blog.save
|
150
|
+
subject[:name].should == 'Pizza'
|
151
|
+
end
|
128
152
|
end
|
129
153
|
end
|
130
154
|
|
data/spec/support/helpers.rb
CHANGED
@@ -114,6 +114,15 @@ module Cequel
|
|
114
114
|
cequel.client.should_not_receive(:execute)
|
115
115
|
end
|
116
116
|
|
117
|
+
def with_client_error(error)
|
118
|
+
cequel.client.stub(:execute).and_raise(error)
|
119
|
+
begin
|
120
|
+
yield
|
121
|
+
ensure
|
122
|
+
cequel.client.unstub(:execute)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
117
126
|
def expect_query_with_consistency(matcher, consistency)
|
118
127
|
expect(cequel.client).to receive(:execute).with(matcher, consistency)
|
119
128
|
.and_call_original
|
data/templates/config/cequel.yml
CHANGED
@@ -3,11 +3,13 @@ development:
|
|
3
3
|
host: '127.0.0.1'
|
4
4
|
port: 9042
|
5
5
|
keyspace: <%= app_name %>_development
|
6
|
+
max_retries: 3
|
6
7
|
|
7
8
|
test:
|
8
9
|
host: '127.0.0.1'
|
9
10
|
port: 9042
|
10
11
|
keyspace: <%= app_name %>_test
|
12
|
+
max_retries: 3
|
11
13
|
|
12
14
|
production:
|
13
15
|
hosts:
|
@@ -18,3 +20,4 @@ production:
|
|
18
20
|
keyspace: <%= app_name %>_production
|
19
21
|
username: 'myappuser'
|
20
22
|
password: 'password1'
|
23
|
+
max_retries: 3
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat Brown
|
@@ -20,7 +20,7 @@ authors:
|
|
20
20
|
autorequire:
|
21
21
|
bindir: bin
|
22
22
|
cert_chain: []
|
23
|
-
date: 2014-
|
23
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activemodel
|
@@ -64,6 +64,20 @@ dependencies:
|
|
64
64
|
version: '3.0'
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
66
|
name: appraisal
|
67
|
+
requirement: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.0'
|
72
|
+
type: :development
|
73
|
+
prerelease: false
|
74
|
+
version_requirements: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - "~>"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '1.0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: wwtd
|
67
81
|
requirement: !ruby/object:Gem::Requirement
|
68
82
|
requirements:
|
69
83
|
- - "~>"
|