eurydice 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/.rvmrc +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +34 -0
- data/README.mdown +25 -0
- data/eurydice.gemspec +24 -0
- data/examples/01_connect.rb +18 -0
- data/examples/02_create_keyspace.rb +19 -0
- data/examples/03_create_column_family.rb +28 -0
- data/examples/04_storing_data.rb +37 -0
- data/examples/05_loading_data.rb +86 -0
- data/examples/06_cluster_info.rb +20 -0
- data/examples/common.rb +5 -0
- data/lib/cassandra.rb +158 -0
- data/lib/eurydice/pelops/cluster.rb +42 -0
- data/lib/eurydice/pelops/column_family.rb +217 -0
- data/lib/eurydice/pelops/keyspace.rb +75 -0
- data/lib/eurydice/pelops.rb +124 -0
- data/lib/eurydice/version.rb +6 -0
- data/lib/eurydice.rb +12 -0
- data/spec/eurydice/pelops/cluster_spec.rb +39 -0
- data/spec/eurydice/pelops/column_family_spec.rb +499 -0
- data/spec/eurydice/pelops/keyspace_spec.rb +91 -0
- data/spec/spec_helper.rb +4 -0
- metadata +99 -0
@@ -0,0 +1,499 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
module Eurydice
|
5
|
+
module Pelops
|
6
|
+
describe ColumnFamily do
|
7
|
+
before :all do
|
8
|
+
@cluster = Eurydice.connect
|
9
|
+
@keyspace_name = "eurydice_test_space_#{rand(1000)}"
|
10
|
+
@keyspace = @cluster.keyspace(@keyspace_name, :create => false)
|
11
|
+
@keyspace.drop! rescue nil
|
12
|
+
@keyspace.create!
|
13
|
+
end
|
14
|
+
|
15
|
+
after :all do
|
16
|
+
@keyspace.drop! rescue nil
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#create!' do
|
20
|
+
before do
|
21
|
+
@cf_name = "test_family_#{rand(1000)}"
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
@cf.drop! rescue nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'can create a column family' do
|
29
|
+
@cf = @keyspace.column_family(@cf_name)
|
30
|
+
@cf.exists?.should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'defers the creation of a keyspace with :create => false' do
|
34
|
+
@cf = @keyspace.column_family(@cf_name, :create => false)
|
35
|
+
@cf.exists?.should be_false
|
36
|
+
@cf.create!
|
37
|
+
@cf.exists?.should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
marshal_types = {
|
41
|
+
'a fully qualified name' => 'org.apache.cassandra.db.marshal.UTF8Type',
|
42
|
+
'the package name omitted' => 'UTF8Type',
|
43
|
+
'an alias' => :utf8
|
44
|
+
}
|
45
|
+
|
46
|
+
context 'creating a column family with a specific comparator type' do
|
47
|
+
marshal_types.each do |desc, type|
|
48
|
+
it "with #{desc}" do
|
49
|
+
@cf = @keyspace.column_family(@cf_name, :create => false)
|
50
|
+
@cf.create!(:comparator_type => type)
|
51
|
+
@cf.definition(true)[:comparator_type].should == 'org.apache.cassandra.db.marshal.UTF8Type'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'creating a column family with a specific subcomparator type' do
|
57
|
+
marshal_types.each do |desc, type|
|
58
|
+
it "with #{desc}" do
|
59
|
+
@cf = @keyspace.column_family(@cf_name, :create => false)
|
60
|
+
@cf.create!(:column_type => :super, :subcomparator_type => type)
|
61
|
+
@cf.definition(true)[:subcomparator_type].should == 'org.apache.cassandra.db.marshal.UTF8Type'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'creating a column family with a specific default validation class' do
|
67
|
+
marshal_types.each do |desc, type|
|
68
|
+
it "with #{desc}" do
|
69
|
+
@cf = @keyspace.column_family(@cf_name, :create => false)
|
70
|
+
@cf.create!(:default_validation_class => type)
|
71
|
+
@cf.definition(true)[:default_validation_class].should == 'org.apache.cassandra.db.marshal.UTF8Type'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'creating a column family with a specific validation class for a column' do
|
77
|
+
marshal_types.each do |desc, type|
|
78
|
+
it "with #{desc}" do
|
79
|
+
@cf = @keyspace.column_family(@cf_name, :create => false)
|
80
|
+
@cf.create!(:column_metadata => {'xyz' => {:validation_class => type}})
|
81
|
+
@cf.definition(true)[:column_metadata]['xyz'][:validation_class].should == 'org.apache.cassandra.db.marshal.UTF8Type'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'creates a column family with an index' do
|
87
|
+
@cf = @keyspace.column_family(@cf_name, :create => false)
|
88
|
+
@cf.create!(:column_metadata => {'xyz' => {:index_name => 'abc', :index_type => :keys, :validation_class => :ascii}})
|
89
|
+
@cf.definition(true)[:column_metadata]['xyz'][:index_name].should == 'abc'
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'creates a column family with a specific column type' do
|
93
|
+
@cf = @keyspace.column_family(@cf_name, :create => false)
|
94
|
+
@cf.create!(:column_type => :super)
|
95
|
+
@cf.definition(true)[:column_type].should == :super
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#drop!' do
|
100
|
+
it 'drops the column family' do
|
101
|
+
cf = @keyspace.column_family('test_family')
|
102
|
+
cf.drop!
|
103
|
+
cf.exists?.should_not be_true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#truncate!' do
|
108
|
+
before do
|
109
|
+
@cf = @keyspace.column_family('test_family', :create => false)
|
110
|
+
@cf.drop! rescue nil
|
111
|
+
@cf.create!
|
112
|
+
end
|
113
|
+
|
114
|
+
after do
|
115
|
+
@cf.drop!
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'removes all rows' do
|
119
|
+
@cf.insert('ABC', {'test' => 'abc'})
|
120
|
+
@cf.insert('DEF', {'test' => 'def'})
|
121
|
+
@cf.insert('GHI', {'test' => 'ghi'})
|
122
|
+
@cf.truncate!
|
123
|
+
@cf.get('ABC').should be_nil
|
124
|
+
@cf.get('DEF').should be_nil
|
125
|
+
@cf.get('GHI').should be_nil
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#definition' do
|
130
|
+
before do
|
131
|
+
@cf = @keyspace.column_family('test_family', :create => false)
|
132
|
+
@cf.drop! rescue nil
|
133
|
+
@cf.create!
|
134
|
+
end
|
135
|
+
|
136
|
+
after do
|
137
|
+
@cf.drop!
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'returns column family metadata' do
|
141
|
+
definition = @cf.definition
|
142
|
+
definition[:name].should == 'test_family'
|
143
|
+
definition[:default_validation_class].should == 'org.apache.cassandra.db.marshal.BytesType'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe '#key?' do
|
148
|
+
before do
|
149
|
+
@cf = @keyspace.column_family('test_family', :create => false)
|
150
|
+
@cf.drop! rescue nil
|
151
|
+
@cf.create!
|
152
|
+
end
|
153
|
+
|
154
|
+
after do
|
155
|
+
@cf.drop!
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'returns true if a row with the specified key exists' do
|
159
|
+
@cf.insert('ABC', 'xyz' => 'def')
|
160
|
+
@cf.key?('ABC').should be_true
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'returns false if a row with the specified key does not exist' do
|
164
|
+
@cf.key?('XYZ').should be_false
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'returns false if a row has no columns' do
|
168
|
+
@cf.insert('ABC', 'xyz' => 'def')
|
169
|
+
@cf.delete_column('ABC', 'xyz')
|
170
|
+
@cf.key?('ABC').should be_false
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'is aliased as #row_exists?' do
|
174
|
+
@cf.insert('ABC', 'xyz' => 'def')
|
175
|
+
@cf.row_exists?('ABC').should be_true
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'loading, storing and removing' do
|
180
|
+
before do
|
181
|
+
@cf = @keyspace.column_family('test_family')
|
182
|
+
@cf.truncate!
|
183
|
+
end
|
184
|
+
|
185
|
+
describe '#update/#insert' do
|
186
|
+
it 'writes a column' do
|
187
|
+
@cf.insert('ABC', 'xyz' => 'abc')
|
188
|
+
@cf.get('ABC').should == {'xyz' => 'abc'}
|
189
|
+
end
|
190
|
+
|
191
|
+
it '#update and #insert are synonyms' do
|
192
|
+
@cf.update('ABC', 'foo' => 'bar')
|
193
|
+
@cf.insert('ABC', 'xyz' => 'abc')
|
194
|
+
@cf.get('ABC').should == {'xyz' => 'abc', 'foo' => 'bar'}
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'writes many columns' do
|
198
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
|
199
|
+
@cf.get('ABC').should == {'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar'}
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'writes with a custom consistency level' do
|
203
|
+
# TODO: not sure how to test, this just tests that no error is raised
|
204
|
+
@cf.insert('ABC', {'xyz' => 'abc'}, {:consistency_level => :quorum})
|
205
|
+
@cf.get('ABC').should == {'xyz' => 'abc'}
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'writes with a custom consistency level (:cl is an alias for :consistency_level)' do
|
209
|
+
# TODO: not sure how to test, this just tests that no error is raised
|
210
|
+
@cf.insert('ABC', {'xyz' => 'abc'}, {:cl => :one})
|
211
|
+
@cf.get('ABC').should == {'xyz' => 'abc'}
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'writes a column with a TTL' do
|
215
|
+
# TODO: not sure how to test without actually waiting for the TTL to expire
|
216
|
+
@cf.insert('ABC', {'xyz' => 'abc'}, {:ttl => 1})
|
217
|
+
sleep(1.5)
|
218
|
+
@cf.get('ABC').should be_nil
|
219
|
+
end
|
220
|
+
|
221
|
+
context 'with explicit column data types' do
|
222
|
+
it 'writes integer columns keys as longs' do
|
223
|
+
@cf.insert('ABC', {42 => 'foo'}, :comparator => :long)
|
224
|
+
@cf.get('ABC', :comparator => :long).should == {42 => 'foo'}
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'writes integer values as longs' do
|
228
|
+
@cf.insert('ABC', {'xyz' => 3}, :validations => {'xyz' => :long})
|
229
|
+
@cf.get('ABC', :validations => {'xyz' => :long}).should == {'xyz' => 3}
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe '#get' do
|
235
|
+
context 'with a single row key' do
|
236
|
+
it 'loads a row' do
|
237
|
+
@cf.insert('ABC', 'xyz' => 'abc')
|
238
|
+
@cf.get('ABC').should == {'xyz' => 'abc'}
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'loads all columns for a row by default' do
|
242
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
|
243
|
+
@cf.get('ABC').should == {'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar'}
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'loads the specified columns' do
|
247
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
|
248
|
+
@cf.get('ABC', :columns => %w(hello foo)).should == {'hello' => 'world', 'foo' => 'bar'}
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'loads the specified range of columns' do
|
252
|
+
@cf.insert('ABC', 'a' => 'A', 'd' => 'D', 'f' => 'F', 'g' => 'G', 'b' => 'B', 'x' => 'X')
|
253
|
+
@cf.get('ABC', :columns => 'b'...'f').should == {'b' => 'B', 'd' => 'D', 'f' => 'F'}
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'loads a max number of columns' do
|
257
|
+
@cf.insert('ABC', Hash[('a'..'z').map { |a| [a, a.upcase] }.shuffle])
|
258
|
+
@cf.get('ABC', :max_column_count => 10).should == Hash[('a'..'z').take(10).map { |a| [a, a.upcase] }]
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'loads columns in reverse order with :reversed => true' do
|
262
|
+
@cf.insert('ABC', Hash[('a'..'f').map { |a| [a, a.upcase] }.shuffle])
|
263
|
+
@cf.get('ABC', :reversed => true).keys.should == ('a'..'f').to_a.reverse
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'returns nil if no row was found' do
|
267
|
+
@cf.get('XYZ').should be_nil
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
context 'with multiple row keys' do
|
272
|
+
it 'loads multiple rows' do
|
273
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'foo' => 'bar')
|
274
|
+
@cf.insert('DEF', 'xyz' => 'def', 'hello' => 'world')
|
275
|
+
@cf.insert('GHI', 'xyz' => 'ghi', 'foo' => 'oof')
|
276
|
+
@cf.get(%w(ABC GHI)).should == {
|
277
|
+
'ABC' => {'xyz' => 'abc', 'foo' => 'bar'},
|
278
|
+
'GHI' => {'xyz' => 'ghi', 'foo' => 'oof'}
|
279
|
+
}
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'does not include rows that do not exist in the result' do
|
283
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'foo' => 'bar')
|
284
|
+
@cf.insert('DEF', 'xyz' => 'def', 'hello' => 'world')
|
285
|
+
@cf.insert('GHI', 'xyz' => 'ghi', 'foo' => 'oof')
|
286
|
+
@cf.get(%w(ABC GHI XYZ)).should == {
|
287
|
+
'ABC' => {'xyz' => 'abc', 'foo' => 'bar'},
|
288
|
+
'GHI' => {'xyz' => 'ghi', 'foo' => 'oof'}
|
289
|
+
}
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'loads columns for multiple rows' do
|
293
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'foo' => 'bar')
|
294
|
+
@cf.insert('DEF', 'xyz' => 'def', 'hello' => 'world')
|
295
|
+
@cf.insert('GHI', 'xyz' => 'ghi', 'foo' => 'oof')
|
296
|
+
@cf.get(%w(ABC GHI), :columns => %w(xyz foo)).should == {'ABC' => {'xyz' => 'abc', 'foo' => 'bar'}, 'GHI' => {'xyz' => 'ghi', 'foo' => 'oof'}}
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'does not include rows that do not have the specified column' do
|
300
|
+
@cf.insert('ABC', 'foo' => 'bar')
|
301
|
+
@cf.insert('DEF', 'xyz' => 'def', 'hello' => 'world')
|
302
|
+
@cf.insert('GHI', 'xyz' => 'ghi', 'foo' => 'oof', 'abc' => '123')
|
303
|
+
@cf.get(%w(ABC GHI), :columns => %w(xyz abc)).should == {'GHI' => {'xyz' => 'ghi', 'abc' => '123'}}
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'does not include rows that do not exist in the results' do
|
307
|
+
@cf.insert('DEF', 'xyz' => 'def', 'hello' => 'world')
|
308
|
+
@cf.insert('GHI', 'xyz' => 'ghi', 'foo' => 'oof')
|
309
|
+
@cf.get(%w(ABC GHI), :columns => %w(xyz foo)).should == {'GHI' => {'xyz' => 'ghi', 'foo' => 'oof'}}
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'loads all columns in a range from multiple rows' do
|
313
|
+
@cf.insert('ABC', 'a' => 'A', 'b' => 'B', 'c' => 'C', 'd' => 'D')
|
314
|
+
@cf.insert('DEF', 'a' => 'A', 'b' => 'B', 'c' => 'C', 'd' => 'D', 'f' => 'F')
|
315
|
+
@cf.insert('GHI', 'a' => 'A', 'b' => 'B', 'd' => 'D')
|
316
|
+
@cf.get(%w(ABC GHI), :columns => 'b'...'d').should == {
|
317
|
+
'ABC' => {'b' => 'B', 'c' => 'C', 'd' => 'D'},
|
318
|
+
'GHI' => {'b' => 'B', 'd' => 'D'}
|
319
|
+
}
|
320
|
+
end
|
321
|
+
|
322
|
+
it 'returns an empty hash if no rows exist' do
|
323
|
+
@cf.get(%w(ABC GHI)).should == {}
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
context 'with options' do
|
328
|
+
it 'loads with a custom consistency level' do
|
329
|
+
# TODO: not sure how to test, this just tests that no error is raised
|
330
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
|
331
|
+
@cf.get('ABC', :consistency_level => :quorum).should == {'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar'}
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'loads with a custom consistency level (:cl is an alias for :consistency_level)' do
|
335
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
|
336
|
+
@cf.get('ABC', :cl => :one).should == {'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar'}
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
describe '#get_column' do
|
342
|
+
it 'loads a single column for a row' do
|
343
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
|
344
|
+
@cf.get_column('ABC', 'hello').should == 'world'
|
345
|
+
end
|
346
|
+
|
347
|
+
it 'loads with a custom consistency level' do
|
348
|
+
# TODO: not sure how to test, this just tests that no error is raised
|
349
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
|
350
|
+
@cf.get_column('ABC', 'hello', :consistency_level => :quorum).should == 'world'
|
351
|
+
end
|
352
|
+
|
353
|
+
it 'loads with a custom consistency level (:cl is an alias for :consistency_level)' do
|
354
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
|
355
|
+
@cf.get_column('ABC', 'hello', :cl => :one).should == 'world'
|
356
|
+
end
|
357
|
+
|
358
|
+
it 'returns nil if no row was found' do
|
359
|
+
@cf.get_column('XYZ', 'abc').should be_nil
|
360
|
+
end
|
361
|
+
|
362
|
+
it 'returns nil if no column was found' do
|
363
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
|
364
|
+
@cf.get_column('XYZ', 'abc').should be_nil
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
describe '#each_column' do
|
369
|
+
before do
|
370
|
+
@cf.insert('ABC', Hash[('a'..'z').map { |a| [a, a.upcase] }.shuffle])
|
371
|
+
end
|
372
|
+
|
373
|
+
it 'yields each column in a row' do
|
374
|
+
row = {}
|
375
|
+
@cf.each_column('ABC') do |k, v|
|
376
|
+
row[k] = v
|
377
|
+
end
|
378
|
+
row.should == Hash[('a'..'z').map { |a| [a, a.upcase] }]
|
379
|
+
end
|
380
|
+
|
381
|
+
it 'returns an Enumerator that yields each column in a row' do
|
382
|
+
row = {}
|
383
|
+
enum = @cf.each_column('ABC')
|
384
|
+
enum.each do |k, v|
|
385
|
+
row[k] = v
|
386
|
+
end
|
387
|
+
row.should == Hash[('a'..'z').map { |a| [a, a.upcase] }]
|
388
|
+
end
|
389
|
+
|
390
|
+
it 'yields each column in reverse order with :reversed => true' do
|
391
|
+
column_keys = []
|
392
|
+
@cf.each_column('ABC', :reversed => true) do |k, v|
|
393
|
+
column_keys << k
|
394
|
+
end
|
395
|
+
column_keys.should == ('a'..'z').to_a.reverse
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'can start after a specified key' do
|
399
|
+
column_keys = []
|
400
|
+
@cf.each_column('ABC', :start_beyond => 'w') do |k, v|
|
401
|
+
column_keys << k
|
402
|
+
end
|
403
|
+
column_keys.should == ('x'..'z').to_a
|
404
|
+
end
|
405
|
+
|
406
|
+
it 'can use a custom batch size' do
|
407
|
+
# TODO: not sure how to test, this just tests that no error is raised
|
408
|
+
row = {}
|
409
|
+
@cf.each_column('ABC', :batch_size => 2) do |k, v|
|
410
|
+
row[k] = v
|
411
|
+
end
|
412
|
+
row.should == Hash[('a'..'z').map { |a| [a, a.upcase] }]
|
413
|
+
end
|
414
|
+
|
415
|
+
it 'loads with a custom consistency level' do
|
416
|
+
# TODO: not sure how to test, this just tests that no error is raised
|
417
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
|
418
|
+
@cf.each_column('ABC', :consistency_level => :quorum) do |k, v|
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
it 'loads with a custom consistency level (:cl is an alias for :consistency_level)' do
|
423
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
|
424
|
+
@cf.each_column('ABC', :cl => :one) do |k, v|
|
425
|
+
end
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
describe '#get_indexed' do
|
430
|
+
before do
|
431
|
+
@cf = @keyspace.column_family('indexed_test_family', :create => false)
|
432
|
+
@cf.drop! rescue nil
|
433
|
+
@cf.create!(:column_metadata => {
|
434
|
+
'name' => {
|
435
|
+
:validation_class => :ascii,
|
436
|
+
:index_name => 'name_index',
|
437
|
+
:index_type => :keys
|
438
|
+
},
|
439
|
+
'age' => {
|
440
|
+
:validation_class => :long,
|
441
|
+
:index_name => 'age_index',
|
442
|
+
:index_type => :keys
|
443
|
+
}
|
444
|
+
})
|
445
|
+
end
|
446
|
+
|
447
|
+
it 'loads rows by index' do
|
448
|
+
@cf.insert('user1', {'name' => 'sue'})
|
449
|
+
@cf.insert('user2', {'name' => 'phil'})
|
450
|
+
@cf.get_indexed('name', :==, 'sue').should == {'user1' => {'name' => 'sue'}}
|
451
|
+
end
|
452
|
+
|
453
|
+
it 'loads rows by index (using :eq instead of :==)' do
|
454
|
+
@cf.insert('user1', {'name' => 'sue'})
|
455
|
+
@cf.insert('user2', {'name' => 'phil'})
|
456
|
+
@cf.get_indexed('name', :eq, 'sue').should == {'user1' => {'name' => 'sue'}}
|
457
|
+
end
|
458
|
+
|
459
|
+
it 'limits the number of returned rows' do
|
460
|
+
names = %w(sue phil sam jim)
|
461
|
+
100.times do |i|
|
462
|
+
row = {'name' => names[i % names.size], 'age' => i % names.size}
|
463
|
+
@cf.insert("user:#{i}", row, :validations => {'age' => :long})
|
464
|
+
end
|
465
|
+
@cf.get_indexed('age', :==, 3, :max_row_count => 3, :validations => {'age' => :long}).should have(3).items
|
466
|
+
end
|
467
|
+
|
468
|
+
it 'raises an error if the index operator is not supported' do
|
469
|
+
expect { @cf.get_indexed('name', :%, 'me') }.to raise_error(ArgumentError)
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
describe '#delete' do
|
474
|
+
it 'removes a row' do
|
475
|
+
@cf.insert('ABC', 'xyz' => 'abc')
|
476
|
+
@cf.delete('ABC')
|
477
|
+
@cf.get('ABC').should == nil
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
describe '#delete_column' do
|
482
|
+
it 'removes a single column' do
|
483
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'foo' => 'bar')
|
484
|
+
@cf.delete_column('ABC', 'foo')
|
485
|
+
@cf.get('ABC').should == {'xyz' => 'abc'}
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
describe '#delete_columns' do
|
490
|
+
it 'removes multiple columns' do
|
491
|
+
@cf.insert('ABC', 'xyz' => 'abc', 'foo' => 'bar', 'hello' => 'world')
|
492
|
+
@cf.delete_columns('ABC', %w(foo xyz))
|
493
|
+
@cf.get('ABC').should == {'hello' => 'world'}
|
494
|
+
end
|
495
|
+
end
|
496
|
+
end
|
497
|
+
end
|
498
|
+
end
|
499
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
module Eurydice
|
5
|
+
module Pelops
|
6
|
+
describe Keyspace do
|
7
|
+
before do
|
8
|
+
@cluster = Eurydice.connect
|
9
|
+
@keyspace_name = "eurydice_test_space_#{rand(1000)}"
|
10
|
+
if @cluster.keyspaces.include?(@keyspace_name)
|
11
|
+
@cluster.keyspace(@keyspace_name).drop!
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
@keyspace.drop! rescue nil
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#create!' do
|
20
|
+
it 'creates a keyspace with a specific strategy class' do
|
21
|
+
@keyspace = @cluster.keyspace(@keyspace_name, :create => false)
|
22
|
+
@keyspace.create!(:strategy_class => 'org.apache.cassandra.locator.NetworkTopologyStrategy')
|
23
|
+
@keyspace.definition(true)[:strategy_class].should == 'org.apache.cassandra.locator.NetworkTopologyStrategy'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'creates a keyspace with specific strategy options' do
|
27
|
+
@keyspace = @cluster.keyspace(@keyspace_name, :create => false)
|
28
|
+
@keyspace.create!(:strategy_options => {:replication_factor => 2})
|
29
|
+
@keyspace.definition(true)[:strategy_options][:replication_factor].should == '2'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'creates a whole schema' do
|
33
|
+
@keyspace = @cluster.keyspace(@keyspace_name, :create => false)
|
34
|
+
@keyspace.create!(
|
35
|
+
:strategy_class => 'org.apache.cassandra.locator.NetworkTopologyStrategy',
|
36
|
+
:strategy_options => {:replication_factor => 2},
|
37
|
+
:column_families => {
|
38
|
+
'some_family' => {
|
39
|
+
:comparator_type => :ascii,
|
40
|
+
:comment => 'This is some family'
|
41
|
+
},
|
42
|
+
'another_family' => {
|
43
|
+
:comparator_type => :utf8,
|
44
|
+
:comment => 'This is another family',
|
45
|
+
:column_metadata => {
|
46
|
+
'first_col' => {
|
47
|
+
:validation_class => :ascii,
|
48
|
+
:index_name => 'first_index',
|
49
|
+
:index_type => :keys
|
50
|
+
},
|
51
|
+
'second_col' => {
|
52
|
+
:validation_class => :time_uuid
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
)
|
58
|
+
definition = @keyspace.definition(true)
|
59
|
+
definition[:strategy_class].should == 'org.apache.cassandra.locator.NetworkTopologyStrategy'
|
60
|
+
definition[:strategy_options].should == {:replication_factor => '2'}
|
61
|
+
definition[:column_families]['some_family'][:comparator_type].should == 'org.apache.cassandra.db.marshal.AsciiType'
|
62
|
+
definition[:column_families]['some_family'][:comment].should == 'This is some family'
|
63
|
+
definition[:column_families]['another_family'][:comment].should == 'This is another family'
|
64
|
+
definition[:column_families]['another_family'][:column_metadata]['first_col'][:validation_class].should == 'org.apache.cassandra.db.marshal.AsciiType'
|
65
|
+
definition[:column_families]['another_family'][:column_metadata]['first_col'][:index_name].should == 'first_index'
|
66
|
+
definition[:column_families]['another_family'][:column_metadata]['second_col'][:validation_class].should == 'org.apache.cassandra.db.marshal.TimeUUIDType'
|
67
|
+
@keyspace.column_family('some_family', :create => false).should exist
|
68
|
+
@keyspace.column_family('another_family', :create => false).should exist
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#drop!' do
|
73
|
+
it 'drops a keyspace' do
|
74
|
+
@keyspace = @cluster.keyspace(@keyspace_name)
|
75
|
+
@keyspace.drop!
|
76
|
+
@keyspace.exists?.should be_false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#definition' do
|
81
|
+
it 'returns keyspace metadata' do
|
82
|
+
@keyspace = @cluster.keyspace(@keyspace_name)
|
83
|
+
definition = @keyspace.definition
|
84
|
+
definition[:name].should == @keyspace_name
|
85
|
+
definition[:strategy_class].should == 'org.apache.cassandra.locator.LocalStrategy'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
data/spec/spec_helper.rb
ADDED