adapter-cassanity 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -9
- data/adapter-cassanity.gemspec +1 -1
- data/examples/adapter_options.rb +1 -1
- data/examples/method_options.rb +2 -2
- data/examples/shared_setup.rb +2 -4
- data/lib/adapter/cassanity.rb +11 -3
- data/lib/adapter/cassanity/version.rb +1 -1
- data/spec/cassanity_spec.rb +58 -15
- metadata +6 -6
data/README.md
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
# Adapter::Cassanity
|
2
2
|
|
3
|
-
Adapter for Cassanity.
|
3
|
+
Adapter for Cassanity. Defaults consistency to :quorum.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
7
|
```ruby
|
8
8
|
require 'adapter/cassanity'
|
9
9
|
|
10
|
-
client =
|
11
|
-
|
12
|
-
connection = Cassanity::Connection.new(executor: executor)
|
13
|
-
keyspace = connection.keyspace('adapter_cassanity')
|
10
|
+
client = Cassanity::Client.new('127.0.0.1:9160')
|
11
|
+
keyspace = client.keyspace('adapter_cassanity')
|
14
12
|
keyspace.recreate
|
15
13
|
|
16
14
|
apps = keyspace.column_family(:apps, {
|
@@ -30,11 +28,11 @@ adapter = Adapter[:cassanity].new(client)
|
|
30
28
|
adapter.clear
|
31
29
|
|
32
30
|
# you can also set options for the adapter
|
33
|
-
using = {using: {consistency: :
|
31
|
+
using = {using: {consistency: :all}}
|
34
32
|
adapter = Adapter[:cassanity].new(client, {
|
35
|
-
read: using, # read using
|
36
|
-
write: using, # write using
|
37
|
-
delete: using, # delete using
|
33
|
+
read: using, # read using all consistency
|
34
|
+
write: using, # write using all consistency
|
35
|
+
delete: using, # delete using all consistency
|
38
36
|
})
|
39
37
|
|
40
38
|
id = CassandraCQL::UUID.new
|
data/adapter-cassanity.gemspec
CHANGED
data/examples/adapter_options.rb
CHANGED
data/examples/method_options.rb
CHANGED
@@ -6,6 +6,6 @@ adapter.clear
|
|
6
6
|
|
7
7
|
id = CassandraCQL::UUID.new
|
8
8
|
|
9
|
-
adapter.write(id, {name: 'GitHub'}, using: {consistency: :
|
10
|
-
pp adapter.read(id, using: {consistency: :
|
9
|
+
adapter.write(id, {name: 'GitHub'}, using: {consistency: :one})
|
10
|
+
pp adapter.read(id, using: {consistency: :one})
|
11
11
|
adapter.delete(id)
|
data/examples/shared_setup.rb
CHANGED
@@ -8,10 +8,8 @@ $:.unshift(lib_path)
|
|
8
8
|
|
9
9
|
require 'adapter/cassanity'
|
10
10
|
|
11
|
-
client =
|
12
|
-
|
13
|
-
connection = Cassanity::Connection.new(executor: executor)
|
14
|
-
keyspace = connection.keyspace('adapter_cassanity')
|
11
|
+
client = Cassanity::Client.new('127.0.0.1:9160')
|
12
|
+
keyspace = client.keyspace(:adapter_cassanity)
|
15
13
|
keyspace.recreate
|
16
14
|
|
17
15
|
AppsCF = keyspace.column_family(:apps, {
|
data/lib/adapter/cassanity.rb
CHANGED
@@ -11,7 +11,7 @@ module Adapter
|
|
11
11
|
# Public
|
12
12
|
def read(key, options = nil)
|
13
13
|
operation_options = {where: where(key)}
|
14
|
-
adapter_options = @options[:read]
|
14
|
+
adapter_options = with_default_consistency(@options[:read])
|
15
15
|
arguments = update_arguments(operation_options, adapter_options, options)
|
16
16
|
|
17
17
|
rows = @client.select(arguments)
|
@@ -21,7 +21,7 @@ module Adapter
|
|
21
21
|
# Public
|
22
22
|
def write(key, attributes, options = nil)
|
23
23
|
operation_options = {set: attributes, where: where(key)}
|
24
|
-
adapter_options = @options[:write]
|
24
|
+
adapter_options = with_default_consistency(@options[:write])
|
25
25
|
arguments = update_arguments(operation_options, adapter_options, options)
|
26
26
|
|
27
27
|
@client.update(arguments)
|
@@ -30,7 +30,7 @@ module Adapter
|
|
30
30
|
# Public
|
31
31
|
def delete(key, options = nil)
|
32
32
|
operation_options = {where: where(key)}
|
33
|
-
adapter_options = @options[:delete]
|
33
|
+
adapter_options = with_default_consistency(@options[:delete])
|
34
34
|
arguments = update_arguments(operation_options, adapter_options, options)
|
35
35
|
|
36
36
|
@client.delete(arguments)
|
@@ -67,6 +67,14 @@ module Adapter
|
|
67
67
|
|
68
68
|
operation_options
|
69
69
|
end
|
70
|
+
|
71
|
+
# Private
|
72
|
+
def with_default_consistency(options)
|
73
|
+
options ||= {}
|
74
|
+
options[:using] ||= {}
|
75
|
+
options[:using][:consistency] ||= :quorum
|
76
|
+
options
|
77
|
+
end
|
70
78
|
end
|
71
79
|
end
|
72
80
|
|
data/spec/cassanity_spec.rb
CHANGED
@@ -16,17 +16,60 @@ 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)
|
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)
|
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)
|
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
|
+
|
19
62
|
context "with adapter read options" do
|
20
63
|
it "uses read options for read method" do
|
21
64
|
client = COLUMN_FAMILIES[:single]
|
22
65
|
options = {read: {
|
23
|
-
using: {consistency: :
|
66
|
+
using: {consistency: :one},
|
24
67
|
}}
|
25
68
|
adapter = Adapter[adapter_name].new(client, options)
|
26
69
|
|
27
70
|
client.should_receive(:select).with({
|
28
71
|
where: {:some_key => 'foo'},
|
29
|
-
using: {consistency: :
|
72
|
+
using: {consistency: :one},
|
30
73
|
}).and_return([])
|
31
74
|
|
32
75
|
adapter.read('foo')
|
@@ -36,13 +79,13 @@ describe "Cassanity adapter" do
|
|
36
79
|
client = COLUMN_FAMILIES[:single]
|
37
80
|
options = {read: {
|
38
81
|
where: {:some_key => 'bar'},
|
39
|
-
using: {consistency: :
|
82
|
+
using: {consistency: :one},
|
40
83
|
}}
|
41
84
|
adapter = Adapter[adapter_name].new(client, options)
|
42
85
|
|
43
86
|
client.should_receive(:select).with({
|
44
87
|
where: {:some_key => 'foo'},
|
45
|
-
using: {consistency: :
|
88
|
+
using: {consistency: :one},
|
46
89
|
}).and_return([])
|
47
90
|
|
48
91
|
adapter.read('foo')
|
@@ -51,7 +94,7 @@ describe "Cassanity adapter" do
|
|
51
94
|
it "can be overriden by read method options" do
|
52
95
|
client = COLUMN_FAMILIES[:single]
|
53
96
|
options = {read: {
|
54
|
-
using: {consistency: :
|
97
|
+
using: {consistency: :one},
|
55
98
|
}}
|
56
99
|
adapter = Adapter[adapter_name].new(client, options)
|
57
100
|
|
@@ -68,14 +111,14 @@ describe "Cassanity adapter" do
|
|
68
111
|
it "uses write options for write method" do
|
69
112
|
client = COLUMN_FAMILIES[:single]
|
70
113
|
options = {write: {
|
71
|
-
using: {consistency: :
|
114
|
+
using: {consistency: :one},
|
72
115
|
}}
|
73
116
|
adapter = Adapter[adapter_name].new(client, options)
|
74
117
|
|
75
118
|
client.should_receive(:update).with({
|
76
119
|
set: {'name' => 'New Name'},
|
77
120
|
where: {:some_key => 'foo'},
|
78
|
-
using: {consistency: :
|
121
|
+
using: {consistency: :one},
|
79
122
|
})
|
80
123
|
|
81
124
|
adapter.write('foo', {'name' => 'New Name'})
|
@@ -86,14 +129,14 @@ describe "Cassanity adapter" do
|
|
86
129
|
options = {write: {
|
87
130
|
where: {:some_key => 'should not use this'},
|
88
131
|
set: {'name' => 'should not use this'},
|
89
|
-
using: {consistency: :
|
132
|
+
using: {consistency: :one,
|
90
133
|
}}}
|
91
134
|
adapter = Adapter[adapter_name].new(client, options)
|
92
135
|
|
93
136
|
client.should_receive(:update).with({
|
94
137
|
set: {'name' => 'New Name'},
|
95
138
|
where: {:some_key => 'foo'},
|
96
|
-
using: {consistency: :
|
139
|
+
using: {consistency: :one},
|
97
140
|
})
|
98
141
|
|
99
142
|
adapter.write('foo', {'name' => 'New Name'})
|
@@ -102,7 +145,7 @@ describe "Cassanity adapter" do
|
|
102
145
|
it "can be overriden by write method options" do
|
103
146
|
client = COLUMN_FAMILIES[:single]
|
104
147
|
options = {write: {
|
105
|
-
using: {consistency: :
|
148
|
+
using: {consistency: :one},
|
106
149
|
}}
|
107
150
|
adapter = Adapter[adapter_name].new(client, options)
|
108
151
|
|
@@ -120,13 +163,13 @@ describe "Cassanity adapter" do
|
|
120
163
|
it "uses delete options for delete method" do
|
121
164
|
client = COLUMN_FAMILIES[:single]
|
122
165
|
options = {delete: {
|
123
|
-
using: {consistency: :
|
166
|
+
using: {consistency: :one},
|
124
167
|
}}
|
125
168
|
adapter = Adapter[adapter_name].new(client, options)
|
126
169
|
|
127
170
|
client.should_receive(:delete).with({
|
128
171
|
where: {:some_key => 'foo'},
|
129
|
-
using: {consistency: :
|
172
|
+
using: {consistency: :one},
|
130
173
|
})
|
131
174
|
|
132
175
|
adapter.delete('foo')
|
@@ -136,13 +179,13 @@ describe "Cassanity adapter" do
|
|
136
179
|
client = COLUMN_FAMILIES[:single]
|
137
180
|
options = {delete: {
|
138
181
|
where: {:some_key => 'bar'},
|
139
|
-
using: {consistency: :
|
182
|
+
using: {consistency: :one},
|
140
183
|
}}
|
141
184
|
adapter = Adapter[adapter_name].new(client, options)
|
142
185
|
|
143
186
|
client.should_receive(:delete).with({
|
144
187
|
where: {:some_key => 'foo'},
|
145
|
-
using: {consistency: :
|
188
|
+
using: {consistency: :one},
|
146
189
|
})
|
147
190
|
|
148
191
|
adapter.delete('foo')
|
@@ -151,7 +194,7 @@ describe "Cassanity adapter" do
|
|
151
194
|
it "can be overriden by delete method options" do
|
152
195
|
client = COLUMN_FAMILIES[:single]
|
153
196
|
options = {delete: {
|
154
|
-
using: {consistency: :
|
197
|
+
using: {consistency: :one},
|
155
198
|
}}
|
156
199
|
adapter = Adapter[adapter_name].new(client, options)
|
157
200
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adapter-cassanity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.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:
|
12
|
+
date: 2013-01-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: adapter
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
37
|
+
version: '0.4'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
45
|
+
version: '0.4'
|
46
46
|
description: Adapter for Cassanity
|
47
47
|
email:
|
48
48
|
- nunemaker@gmail.com
|
@@ -83,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
segments:
|
85
85
|
- 0
|
86
|
-
hash: -
|
86
|
+
hash: -1292988058434292696
|
87
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
88
|
none: false
|
89
89
|
requirements:
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
segments:
|
94
94
|
- 0
|
95
|
-
hash: -
|
95
|
+
hash: -1292988058434292696
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
98
|
rubygems_version: 1.8.23
|