adapter-cassanity 0.5.0 → 0.6.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1761583821e237acab173505a0b8a8571ace2eba
4
+ data.tar.gz: d1ef6ff6e5de5259dd88681ff1ab242910d2252e
5
+ SHA512:
6
+ metadata.gz: a8546307ae7a8190cc91609d87159e22ee78d7120a367c758526dbc033b2b32ab41c709c8983c4e94c21792b6d707cb8234784a5c31e799d1e27e0348440d2f0
7
+ data.tar.gz: ac61ef85fd2d3b1e20315922142559847b64ee77b5b5a97d3b99f4f2fe10fa4bf97ff0e2a1854665b3bb7abc29113d9798f7cf47d11a3975b558709c5b3f3abd
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Adapter::Cassanity
1
+ # Adapter::Cassanity [![Build Status](https://secure.travis-ci.org/jnunemaker/adapter-cassanity.png?branch=master)](http://travis-ci.org/jnunemaker/adapter-cassanity)
2
2
 
3
3
  Adapter for Cassanity. Defaults consistency to :quorum.
4
4
 
@@ -7,7 +7,7 @@ Adapter for Cassanity. Defaults consistency to :quorum.
7
7
  ```ruby
8
8
  require 'adapter/cassanity'
9
9
 
10
- client = Cassanity::Client.new('127.0.0.1:9160')
10
+ client = Cassanity::Client.new(['127.0.0.1'], 9160)
11
11
  keyspace = client.keyspace('adapter_cassanity')
12
12
  keyspace.recreate
13
13
 
@@ -27,15 +27,7 @@ client = apps
27
27
  adapter = Adapter[:cassanity].new(client)
28
28
  adapter.clear
29
29
 
30
- # you can also set options for the adapter
31
- using = {using: {consistency: :all}}
32
- adapter = Adapter[:cassanity].new(client, {
33
- read: using, # read using all consistency
34
- write: using, # write using all consistency
35
- delete: using, # delete using all consistency
36
- })
37
-
38
- id = CassandraCQL::UUID.new
30
+ id = Cql::TimeUuid::Generator.new.next
39
31
 
40
32
  adapter.read(id) # => nil
41
33
 
@@ -50,10 +42,6 @@ adapter.read(id) # => {'id' => ..., 'name' => 'GitHub'}
50
42
 
51
43
  adapter.clear
52
44
  adapter.read(id) # => nil
53
-
54
- # You can also override adapter options per method:
55
- # This will perform read with consistency set to ONE.
56
- adapter.read(id, using: {consistency: :one})
57
45
  ```
58
46
 
59
47
  ## Installation
@@ -18,5 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency 'adapter', '~> 0.7.0'
21
- gem.add_dependency 'cassanity', '~> 0.4'
21
+ gem.add_dependency 'cassanity', '< 0.7', '>=0.6.0.beta1' # change to ~>0.6 when 0.6.0 final drops
22
22
  end
@@ -9,7 +9,7 @@ module Adapter
9
9
  # Public
10
10
  def read(key, options = nil)
11
11
  operation_options = {where: where(key)}
12
- adapter_options = with_default_consistency(@options[:read])
12
+ adapter_options = @options[:read]
13
13
  arguments = update_arguments(operation_options, adapter_options, options)
14
14
 
15
15
  rows = @client.select(arguments)
@@ -18,17 +18,17 @@ module Adapter
18
18
 
19
19
  # Public
20
20
  def write(key, attributes, options = nil)
21
- operation_options = {set: attributes, where: where(key)}
22
- adapter_options = with_default_consistency(@options[:write])
21
+ operation, operation_options = prepare_operation(options, :update, set: attributes, where: where(key))
22
+ adapter_options = @options[:write]
23
23
  arguments = update_arguments(operation_options, adapter_options, options)
24
24
 
25
- @client.update(arguments)
25
+ @client.send(operation, arguments)
26
26
  end
27
27
 
28
28
  # Public
29
29
  def delete(key, options = nil)
30
30
  operation_options = {where: where(key)}
31
- adapter_options = with_default_consistency(@options[:delete])
31
+ adapter_options = @options[:delete]
32
32
  arguments = update_arguments(operation_options, adapter_options, options)
33
33
 
34
34
  @client.delete(arguments)
@@ -45,6 +45,15 @@ module Adapter
45
45
  {primary_key => key}
46
46
  end
47
47
 
48
+ # Private.
49
+ def prepare_operation(options, operation, operation_options)
50
+ if options && (modifications = options[:modifications]) && modifications.any?
51
+ operation_options = {modifications: [ [operation, operation_options], *modifications ]}
52
+ operation = :batch
53
+ end
54
+ [ operation, operation_options ]
55
+ end
56
+
48
57
  # Private
49
58
  def update_arguments(operation_options, adapter_options, method_options)
50
59
  keys = operation_options.keys
@@ -61,14 +70,6 @@ module Adapter
61
70
 
62
71
  operation_options
63
72
  end
64
-
65
- # Private
66
- def with_default_consistency(options)
67
- options ||= {}
68
- options[:using] ||= {}
69
- options[:using][:consistency] ||= :quorum
70
- options
71
- end
72
73
  end
73
74
  end
74
75
 
@@ -1,5 +1,5 @@
1
1
  module Adapter
2
2
  module Cassanity
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0.beta1"
4
4
  end
5
5
  end
@@ -16,63 +16,20 @@ describe "Cassanity adapter" do
16
16
  it_behaves_like 'an adapter'
17
17
  end
18
18
 
19
- context "default read consistency" do
20
- it "is :quorum" do
21
- client = COLUMN_FAMILIES[:single]
22
- adapter = Adapter[adapter_name].new(client, primary_key: :some_key,)
23
-
24
- client.should_receive(:select).with({
25
- where: {:some_key => 'foo'},
26
- using: {consistency: :quorum},
27
- }).and_return([])
28
-
29
- adapter.read('foo')
30
- end
31
- end
32
-
33
- context "default write consistency" do
34
- it "is :quorum" do
35
- client = COLUMN_FAMILIES[:single]
36
- adapter = Adapter[adapter_name].new(client, primary_key: :some_key,)
37
-
38
- client.should_receive(:update).with({
39
- set: {'name' => 'New Name'},
40
- where: {:some_key => 'foo'},
41
- using: {consistency: :quorum},
42
- })
43
-
44
- adapter.write('foo', {'name' => 'New Name'})
45
- end
46
- end
47
-
48
- context "default delete consistency" do
49
- it "is :quorum" do
50
- client = COLUMN_FAMILIES[:single]
51
- adapter = Adapter[adapter_name].new(client, primary_key: :some_key)
52
-
53
- client.should_receive(:delete).with({
54
- where: {:some_key => 'foo'},
55
- using: {consistency: :quorum},
56
- })
57
-
58
- adapter.delete('foo')
59
- end
60
- end
61
-
62
19
  context "with adapter read options" do
63
20
  it "uses read options for read method" do
64
21
  client = COLUMN_FAMILIES[:single]
65
22
  options = {
66
23
  primary_key: :some_key,
67
24
  read: {
68
- using: {consistency: :one},
25
+ using: {ttl: 10},
69
26
  },
70
27
  }
71
28
  adapter = Adapter[adapter_name].new(client, options)
72
29
 
73
30
  client.should_receive(:select).with({
74
31
  where: {:some_key => 'foo'},
75
- using: {consistency: :one},
32
+ using: {ttl: 10},
76
33
  }).and_return([])
77
34
 
78
35
  adapter.read('foo')
@@ -84,14 +41,14 @@ describe "Cassanity adapter" do
84
41
  primary_key: :some_key,
85
42
  read: {
86
43
  where: {:some_key => 'bar'},
87
- using: {consistency: :one},
44
+ using: {ttl: 10},
88
45
  },
89
46
  }
90
47
  adapter = Adapter[adapter_name].new(client, options)
91
48
 
92
49
  client.should_receive(:select).with({
93
50
  where: {:some_key => 'foo'},
94
- using: {consistency: :one},
51
+ using: {ttl: 10},
95
52
  }).and_return([])
96
53
 
97
54
  adapter.read('foo')
@@ -102,17 +59,17 @@ describe "Cassanity adapter" do
102
59
  options = {
103
60
  primary_key: :some_key,
104
61
  read: {
105
- using: {consistency: :one},
62
+ using: {ttl: 20},
106
63
  },
107
64
  }
108
65
  adapter = Adapter[adapter_name].new(client, options)
109
66
 
110
67
  client.should_receive(:select).with({
111
68
  where: {:some_key => 'foo'},
112
- using: {consistency: :one},
69
+ using: {ttl: 10},
113
70
  }).and_return([])
114
71
 
115
- adapter.read('foo', using: {consistency: :one})
72
+ adapter.read('foo', using: {ttl: 10})
116
73
  end
117
74
  end
118
75
 
@@ -122,7 +79,7 @@ describe "Cassanity adapter" do
122
79
  options = {
123
80
  primary_key: :some_key,
124
81
  write: {
125
- using: {consistency: :one},
82
+ using: {ttl: 10},
126
83
  },
127
84
  }
128
85
  adapter = Adapter[adapter_name].new(client, options)
@@ -130,7 +87,7 @@ describe "Cassanity adapter" do
130
87
  client.should_receive(:update).with({
131
88
  set: {'name' => 'New Name'},
132
89
  where: {:some_key => 'foo'},
133
- using: {consistency: :one},
90
+ using: {ttl: 10},
134
91
  })
135
92
 
136
93
  adapter.write('foo', {'name' => 'New Name'})
@@ -143,7 +100,7 @@ describe "Cassanity adapter" do
143
100
  write: {
144
101
  where: {:some_key => 'should not use this'},
145
102
  set: {'name' => 'should not use this'},
146
- using: {consistency: :one}
103
+ using: {ttl: 10}
147
104
  },
148
105
  }
149
106
  adapter = Adapter[adapter_name].new(client, options)
@@ -151,7 +108,7 @@ describe "Cassanity adapter" do
151
108
  client.should_receive(:update).with({
152
109
  set: {'name' => 'New Name'},
153
110
  where: {:some_key => 'foo'},
154
- using: {consistency: :one},
111
+ using: {ttl: 10},
155
112
  })
156
113
 
157
114
  adapter.write('foo', {'name' => 'New Name'})
@@ -162,7 +119,7 @@ describe "Cassanity adapter" do
162
119
  options = {
163
120
  primary_key: :some_key,
164
121
  write: {
165
- using: {consistency: :one},
122
+ using: {ttl: 10},
166
123
  },
167
124
  }
168
125
  adapter = Adapter[adapter_name].new(client, options)
@@ -170,10 +127,32 @@ describe "Cassanity adapter" do
170
127
  client.should_receive(:update).with({
171
128
  set: {'name' => 'New Name'},
172
129
  where: {:some_key => 'foo'},
173
- using: {consistency: :one},
130
+ using: {ttl: 20},
131
+ })
132
+
133
+ adapter.write('foo', {'name' => 'New Name'}, using: {ttl: 20})
134
+ end
135
+
136
+ it "accepts other batch operations" do
137
+ client = COLUMN_FAMILIES[:single]
138
+ options = {
139
+ primary_key: :some_key,
140
+ write: {
141
+ using: {ttl: 10},
142
+ },
143
+ }
144
+ adapter = Adapter[adapter_name].new(client, options)
145
+
146
+ client.should_receive(:batch).with({
147
+ modifications: [
148
+ [:update, set: {'name' => 'New Name'}, where: {:some_key => 'foo'}],
149
+ [:other],
150
+ ],
151
+ using: {ttl: 10},
174
152
  })
153
+ client.should_not_receive(:update)
175
154
 
176
- adapter.write('foo', {'name' => 'New Name'}, using: {consistency: :one})
155
+ adapter.write('foo', {'name' => 'New Name'}, using: {ttl: 10}, modifications: [ [:other] ])
177
156
  end
178
157
  end
179
158
 
@@ -183,14 +162,14 @@ describe "Cassanity adapter" do
183
162
  options = {
184
163
  primary_key: :some_key,
185
164
  delete: {
186
- using: {consistency: :one},
165
+ using: {ttl: 10},
187
166
  },
188
167
  }
189
168
  adapter = Adapter[adapter_name].new(client, options)
190
169
 
191
170
  client.should_receive(:delete).with({
192
171
  where: {:some_key => 'foo'},
193
- using: {consistency: :one},
172
+ using: {ttl: 10},
194
173
  })
195
174
 
196
175
  adapter.delete('foo')
@@ -202,14 +181,14 @@ describe "Cassanity adapter" do
202
181
  primary_key: :some_key,
203
182
  delete: {
204
183
  where: {:some_key => 'bar'},
205
- using: {consistency: :one},
184
+ using: {ttl: 10},
206
185
  },
207
186
  }
208
187
  adapter = Adapter[adapter_name].new(client, options)
209
188
 
210
189
  client.should_receive(:delete).with({
211
190
  where: {:some_key => 'foo'},
212
- using: {consistency: :one},
191
+ using: {ttl: 10},
213
192
  })
214
193
 
215
194
  adapter.delete('foo')
@@ -220,17 +199,17 @@ describe "Cassanity adapter" do
220
199
  options = {
221
200
  primary_key: :some_key,
222
201
  delete: {
223
- using: {consistency: :one},
202
+ using: {ttl: 10},
224
203
  },
225
204
  }
226
205
  adapter = Adapter[adapter_name].new(client, options)
227
206
 
228
207
  client.should_receive(:delete).with({
229
208
  where: {:some_key => 'foo'},
230
- using: {consistency: :one},
209
+ using: {ttl: 20},
231
210
  })
232
211
 
233
- adapter.delete('foo', using: {consistency: :one})
212
+ adapter.delete('foo', using: {ttl: 20})
234
213
  end
235
214
  end
236
215
  end
data/spec/helper.rb CHANGED
@@ -19,15 +19,11 @@ logger = Logger.new(log_path.join('test.log'))
19
19
  COLUMN_FAMILIES = {}
20
20
 
21
21
  cassandra_setup = lambda { |args|
22
- host = ENV.fetch('CASSANDRA_HOST', '127.0.0.1:9160')
22
+ host = ENV.fetch('CASSANDRA_HOST', '127.0.0.1')
23
+ port = ENV.fetch('CASSANDRA_PORT', '9042').to_i
23
24
  keyspace_name = ENV.fetch('CASSANDRA_KEYSPACE_NAME', 'adapter_cassanity')
24
- client = CassandraCQL::Database.new(host, cql_version: '3.0.0')
25
- executor = Cassanity::Executors::CassandraCql.new({
26
- client: client,
27
- logger: logger,
28
- })
29
- connection = Cassanity::Connection.new(executor: executor)
30
- keyspace = connection.keyspace(keyspace_name)
25
+ client = Cassanity::Client.new([host], port)
26
+ keyspace = client.keyspace(keyspace_name)
31
27
  keyspace.recreate
32
28
 
33
29
  COLUMN_FAMILIES[:single] = keyspace.column_family(:single, {
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adapter-cassanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
5
- prerelease:
4
+ version: 0.6.0.beta1
6
5
  platform: ruby
7
6
  authors:
8
7
  - John Nunemaker
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-27 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: adapter
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,19 +27,23 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: cassanity
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - <
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ - - '>='
36
35
  - !ruby/object:Gem::Version
37
- version: '0.4'
36
+ version: 0.6.0.beta1
38
37
  type: :runtime
39
38
  prerelease: false
40
39
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
40
  requirements:
43
- - - ~>
41
+ - - <
44
42
  - !ruby/object:Gem::Version
45
- version: '0.4'
43
+ version: '0.7'
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.6.0.beta1
46
47
  description: Adapter for Cassanity
47
48
  email:
48
49
  - nunemaker@gmail.com
@@ -60,9 +61,7 @@ files:
60
61
  - README.md
61
62
  - Rakefile
62
63
  - adapter-cassanity.gemspec
63
- - examples/adapter_options.rb
64
64
  - examples/cassanity.rb
65
- - examples/method_options.rb
66
65
  - examples/shared_setup.rb
67
66
  - lib/adapter-cassanity.rb
68
67
  - lib/adapter/cassanity.rb
@@ -71,33 +70,26 @@ files:
71
70
  - spec/helper.rb
72
71
  homepage: ''
73
72
  licenses: []
73
+ metadata: {}
74
74
  post_install_message:
75
75
  rdoc_options: []
76
76
  require_paths:
77
77
  - lib
78
78
  required_ruby_version: !ruby/object:Gem::Requirement
79
- none: false
80
79
  requirements:
81
- - - ! '>='
80
+ - - '>='
82
81
  - !ruby/object:Gem::Version
83
82
  version: '0'
84
- segments:
85
- - 0
86
- hash: 242222650800770136
87
83
  required_rubygems_version: !ruby/object:Gem::Requirement
88
- none: false
89
84
  requirements:
90
- - - ! '>='
85
+ - - '>'
91
86
  - !ruby/object:Gem::Version
92
- version: '0'
93
- segments:
94
- - 0
95
- hash: 242222650800770136
87
+ version: 1.3.1
96
88
  requirements: []
97
89
  rubyforge_project:
98
- rubygems_version: 1.8.23
90
+ rubygems_version: 2.0.3
99
91
  signing_key:
100
- specification_version: 3
92
+ specification_version: 4
101
93
  summary: Adapter for Cassanity
102
94
  test_files:
103
95
  - spec/cassanity_spec.rb
@@ -1,16 +0,0 @@
1
- require_relative 'shared_setup'
2
-
3
- client = AppsCF
4
- using = {using: {consistency: :one}}
5
- adapter = Adapter[:cassanity].new(client, {
6
- read: using,
7
- write: using,
8
- delete: using,
9
- })
10
- adapter.clear
11
-
12
- id = CassandraCQL::UUID.new
13
-
14
- adapter.write(id, {name: 'GitHub'})
15
- pp adapter.read(id)
16
- adapter.delete(id)
@@ -1,11 +0,0 @@
1
- require_relative 'shared_setup'
2
-
3
- client = AppsCF
4
- adapter = Adapter[:cassanity].new(client)
5
- adapter.clear
6
-
7
- id = CassandraCQL::UUID.new
8
-
9
- adapter.write(id, {name: 'GitHub'}, using: {consistency: :one})
10
- pp adapter.read(id, using: {consistency: :one})
11
- adapter.delete(id)