eurydice 1.1.0.b4-java → 1.1.1.b1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -3
- data/Gemfile.lock +12 -13
- data/eurydice.gemspec +1 -1
- data/examples/01_connect.rb +1 -1
- data/lib/eurydice/pelops/column_family.rb +62 -24
- data/lib/eurydice/version.rb +1 -1
- data/spec/eurydice/pelops/cluster_spec.rb +2 -27
- data/spec/eurydice/pelops/column_family_spec.rb +3 -560
- data/spec/eurydice/pelops/keyspace_spec.rb +4 -76
- data/spec/eurydice/support/cluster.rb +35 -0
- data/spec/eurydice/support/column_family.rb +593 -0
- data/spec/eurydice/support/keyspace.rb +80 -0
- data/spec/spec_helper.rb +5 -1
- metadata +6 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
eurydice (1.1.0.
|
5
|
-
pelops-jars (>= 1.
|
4
|
+
eurydice (1.1.0.b4-java)
|
5
|
+
pelops-jars (>= 1.3.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
bouncy-castle-java (1.5.0146.1)
|
11
11
|
cassandra-jars (1.0.0-java)
|
12
|
-
diff-lcs (1.1.
|
12
|
+
diff-lcs (1.1.3)
|
13
13
|
jruby-openssl (0.7.4)
|
14
14
|
bouncy-castle-java
|
15
|
-
pelops-jars (1.3.0
|
15
|
+
pelops-jars (1.3.0-java)
|
16
16
|
cassandra-jars (~> 1.0.0)
|
17
17
|
rake (0.9.2)
|
18
|
-
rspec (2.
|
19
|
-
rspec-core (~> 2.
|
20
|
-
rspec-expectations (~> 2.
|
21
|
-
rspec-mocks (~> 2.
|
22
|
-
rspec-core (2.
|
23
|
-
rspec-expectations (2.
|
18
|
+
rspec (2.7.0)
|
19
|
+
rspec-core (~> 2.7.0)
|
20
|
+
rspec-expectations (~> 2.7.0)
|
21
|
+
rspec-mocks (~> 2.7.0)
|
22
|
+
rspec-core (2.7.1)
|
23
|
+
rspec-expectations (2.7.0)
|
24
24
|
diff-lcs (~> 1.1.2)
|
25
|
-
rspec-mocks (2.
|
25
|
+
rspec-mocks (2.7.0)
|
26
26
|
|
27
27
|
PLATFORMS
|
28
28
|
java
|
@@ -30,6 +30,5 @@ PLATFORMS
|
|
30
30
|
DEPENDENCIES
|
31
31
|
eurydice!
|
32
32
|
jruby-openssl
|
33
|
-
pelops-jars (= 1.3.0.b3)
|
34
33
|
rake
|
35
|
-
rspec
|
34
|
+
rspec (= 2.7.0)
|
data/eurydice.gemspec
CHANGED
data/examples/01_connect.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative 'common'
|
|
5
5
|
|
6
6
|
# Connect to the default host (localhost) and port (9160), these can be
|
7
7
|
# overridden by passing then :host and :port options.
|
8
|
-
cluster = Eurydice.connect
|
8
|
+
cluster = Eurydice.connect
|
9
9
|
|
10
10
|
# Get a reference to a keyspace, it will be created if it does not exist
|
11
11
|
# (pass the option :create => false to not automatically create the keyspace).
|
@@ -47,34 +47,20 @@ module Eurydice
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def delete_column(row_key, column_key, options={})
|
50
|
-
|
51
|
-
|
52
|
-
mutator.delete_column(@name, row_key, to_pelops_bytes(column_key))
|
53
|
-
mutator.execute(get_cl(options))
|
50
|
+
batch(options) do |b|
|
51
|
+
b.delete_column(row_key, column_key)
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
55
|
def delete_columns(row_key, column_keys, options={})
|
58
|
-
|
59
|
-
|
60
|
-
mutator.delete_columns(@name, row_key, column_keys.map { |k| to_pelops_bytes(k) })
|
61
|
-
mutator.execute(get_cl(options))
|
56
|
+
batch(options) do |b|
|
57
|
+
b.delete_columns(row_key, column_keys)
|
62
58
|
end
|
63
59
|
end
|
64
60
|
|
65
61
|
def update(row_key, properties, options={})
|
66
|
-
|
67
|
-
|
68
|
-
key_type = options[:comparator]
|
69
|
-
mutator = @keyspace.create_mutator
|
70
|
-
columns = properties.map do |k, v|
|
71
|
-
key = to_pelops_bytes(k, key_type)
|
72
|
-
value = to_pelops_bytes(v, types[k])
|
73
|
-
ttl = options.fetch(:ttl, mutator.class::NO_TTL)
|
74
|
-
mutator.new_column(key, value, ttl)
|
75
|
-
end
|
76
|
-
mutator.write_columns(@name, row_key, columns)
|
77
|
-
mutator.execute(get_cl(options))
|
62
|
+
batch(options) do |b|
|
63
|
+
b.update(row_key, properties, options)
|
78
64
|
end
|
79
65
|
end
|
80
66
|
alias_method :insert, :update
|
@@ -170,6 +156,15 @@ module Eurydice
|
|
170
156
|
end
|
171
157
|
end
|
172
158
|
|
159
|
+
def batch(options={})
|
160
|
+
batch = Batch.new(@name, @keyspace)
|
161
|
+
if block_given?
|
162
|
+
yield batch
|
163
|
+
batch.execute!(options)
|
164
|
+
end
|
165
|
+
nil
|
166
|
+
end
|
167
|
+
|
173
168
|
private
|
174
169
|
|
175
170
|
EMPTY_STRING = ''.freeze
|
@@ -252,10 +247,53 @@ module Eurydice
|
|
252
247
|
end
|
253
248
|
return key, value
|
254
249
|
end
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
250
|
+
|
251
|
+
module ConsistencyLevelHelpers
|
252
|
+
def get_cl(options)
|
253
|
+
cl = options.fetch(:consistency_level, options.fetch(:cl, :one))
|
254
|
+
Cassandra::CONSISTENCY_LEVELS[cl]
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
include ConsistencyLevelHelpers
|
259
|
+
|
260
|
+
class Batch
|
261
|
+
include ExceptionHelpers
|
262
|
+
include ByteHelpers
|
263
|
+
include ConsistencyLevelHelpers
|
264
|
+
|
265
|
+
def initialize(name, keyspace)
|
266
|
+
@name = name
|
267
|
+
@keyspace = keyspace
|
268
|
+
@mutator = @keyspace.create_mutator
|
269
|
+
end
|
270
|
+
|
271
|
+
def delete_column(row_key, column_key)
|
272
|
+
@mutator.delete_column(@name, row_key, to_pelops_bytes(column_key))
|
273
|
+
end
|
274
|
+
|
275
|
+
def delete_columns(row_key, column_keys)
|
276
|
+
@mutator.delete_columns(@name, row_key, column_keys.map { |k| to_pelops_bytes(k) })
|
277
|
+
end
|
278
|
+
|
279
|
+
def update(row_key, properties, options={})
|
280
|
+
types = options[:validations] || {}
|
281
|
+
key_type = options[:comparator]
|
282
|
+
columns = properties.map do |k, v|
|
283
|
+
key = to_pelops_bytes(k, key_type)
|
284
|
+
value = to_pelops_bytes(v, types[k])
|
285
|
+
ttl = options.fetch(:ttl, @mutator.class::NO_TTL)
|
286
|
+
@mutator.new_column(key, value, ttl)
|
287
|
+
end
|
288
|
+
@mutator.write_columns(@name, row_key, columns)
|
289
|
+
end
|
290
|
+
alias_method :insert, :update
|
291
|
+
|
292
|
+
def execute!(options={})
|
293
|
+
thrift_exception_handler do
|
294
|
+
@mutator.execute(get_cl(options))
|
295
|
+
end
|
296
|
+
end
|
259
297
|
end
|
260
298
|
end
|
261
299
|
end
|
data/lib/eurydice/version.rb
CHANGED
@@ -4,36 +4,11 @@ require_relative '../../spec_helper'
|
|
4
4
|
module Eurydice
|
5
5
|
module Pelops
|
6
6
|
describe Cluster do
|
7
|
-
|
7
|
+
before :all do
|
8
8
|
@cluster = Eurydice.connect
|
9
|
-
@cluster.should be_connected
|
10
9
|
end
|
11
|
-
|
12
|
-
describe '#keyspace' do
|
13
|
-
before do
|
14
|
-
@cluster = Eurydice.connect
|
15
|
-
@keyspace_name = "eurydice_test_space_#{rand(1000)}"
|
16
|
-
if @cluster.keyspaces.include?(@keyspace_name)
|
17
|
-
@cluster.keyspace(@keyspace_name).drop!
|
18
|
-
end
|
19
|
-
end
|
20
10
|
|
21
|
-
|
22
|
-
@keyspace.drop! rescue nil
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'creates a keyspace' do
|
26
|
-
@keyspace = @cluster.keyspace(@keyspace_name)
|
27
|
-
@keyspace.exists?.should be_true
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'defers the creation of a keyspace with :create => false' do
|
31
|
-
@keyspace = @cluster.keyspace(@keyspace_name, :create => false)
|
32
|
-
@keyspace.exists?.should be_false
|
33
|
-
@keyspace.create!
|
34
|
-
@keyspace.exists?.should be_true
|
35
|
-
end
|
36
|
-
end
|
11
|
+
it_behaves_like 'Cluster', @cluster
|
37
12
|
end
|
38
13
|
end
|
39
14
|
end
|