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.
@@ -5,8 +5,9 @@ module Eurydice
5
5
  module Pelops
6
6
  describe ColumnFamily do
7
7
  before :all do
8
- @cluster = Eurydice.connect
9
8
  @keyspace_name = "eurydice_test_space_#{rand(1000)}"
9
+ @cf_name = "column_family_#{rand(1000)}"
10
+ @cluster = Eurydice.connect
10
11
  @keyspace = @cluster.keyspace(@keyspace_name, :create => false)
11
12
  @keyspace.drop! rescue nil
12
13
  @keyspace.create!
@@ -16,565 +17,7 @@ module Eurydice
16
17
  @keyspace.drop! rescue nil
17
18
  end
18
19
 
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
- before do
186
- @counter_cf = @keyspace.column_family('counter_family', :create => false)
187
- @counter_cf.create!(:default_validation_class => :counter) unless @counter_cf.exists?
188
- @counter_cf.truncate!
189
- end
190
-
191
- describe '#update/#insert' do
192
- it 'writes a column' do
193
- @cf.insert('ABC', 'xyz' => 'abc')
194
- @cf.get('ABC').should == {'xyz' => 'abc'}
195
- end
196
-
197
- it '#update and #insert are synonyms' do
198
- @cf.update('ABC', 'foo' => 'bar')
199
- @cf.insert('ABC', 'xyz' => 'abc')
200
- @cf.get('ABC').should == {'xyz' => 'abc', 'foo' => 'bar'}
201
- end
202
-
203
- it 'writes many columns' do
204
- @cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
205
- @cf.get('ABC').should == {'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar'}
206
- end
207
-
208
- it 'writes with a custom consistency level' do
209
- # TODO: not sure how to test, this just tests that no error is raised
210
- @cf.insert('ABC', {'xyz' => 'abc'}, {:consistency_level => :quorum})
211
- @cf.get('ABC').should == {'xyz' => 'abc'}
212
- end
213
-
214
- it 'writes with a custom consistency level (:cl is an alias for :consistency_level)' do
215
- # TODO: not sure how to test, this just tests that no error is raised
216
- @cf.insert('ABC', {'xyz' => 'abc'}, {:cl => :one})
217
- @cf.get('ABC').should == {'xyz' => 'abc'}
218
- end
219
-
220
- it 'writes a column with a TTL' do
221
- # TODO: not sure how to test without actually waiting for the TTL to expire
222
- @cf.insert('ABC', {'xyz' => 'abc'}, {:ttl => 1})
223
- sleep(1.5)
224
- @cf.get('ABC').should be_nil
225
- end
226
-
227
- context 'with explicit column data types' do
228
- it 'writes integer columns keys as longs' do
229
- @cf.insert('ABC', {42 => 'foo'}, :comparator => :long)
230
- @cf.get('ABC', :comparator => :long).should == {42 => 'foo'}
231
- end
232
-
233
- it 'writes integer values as longs' do
234
- @cf.insert('ABC', {'xyz' => 3}, :validations => {'xyz' => :long})
235
- @cf.get('ABC', :validations => {'xyz' => :long}).should == {'xyz' => 3}
236
- end
237
- end
238
- end
239
-
240
- describe '#increment' do
241
- it 'can increment a counter column' do
242
- @cf.increment('ABC', 'count')
243
- @cf.get_column('ABC', 'count').should == 1
244
- end
245
-
246
- it 'can increment a counter column by the specified amount' do
247
- @cf.increment('ABC', 'count', 3)
248
- @cf.increment('ABC', 'count', 2)
249
- @cf.get_column('ABC', 'count').should == 5
250
- end
251
-
252
- [:inc, :incr, :increment_column].each do |name|
253
- it "is aliased as #{name}" do
254
- @cf.send(name, 'ABC', 'count')
255
- @cf.get_column('ABC', 'count').should == 1
256
- end
257
- end
258
- end
259
-
260
- describe '#get' do
261
- context 'with a single row key' do
262
- it 'loads a row' do
263
- @cf.insert('ABC', 'xyz' => 'abc')
264
- @cf.get('ABC').should == {'xyz' => 'abc'}
265
- end
266
-
267
- it 'loads all columns for a row by default' do
268
- @cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
269
- @cf.get('ABC').should == {'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar'}
270
- end
271
-
272
- it 'loads the specified columns' do
273
- @cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
274
- @cf.get('ABC', :columns => %w(hello foo)).should == {'hello' => 'world', 'foo' => 'bar'}
275
- end
276
-
277
- it 'loads the specified range of columns' do
278
- @cf.insert('ABC', 'a' => 'A', 'd' => 'D', 'f' => 'F', 'g' => 'G', 'b' => 'B', 'x' => 'X')
279
- @cf.get('ABC', :columns => 'b'...'f').should == {'b' => 'B', 'd' => 'D', 'f' => 'F'}
280
- end
281
-
282
- it 'loads a max number of columns' do
283
- @cf.insert('ABC', Hash[('a'..'z').map { |a| [a, a.upcase] }.shuffle])
284
- @cf.get('ABC', :max_column_count => 10).should == Hash[('a'..'z').take(10).map { |a| [a, a.upcase] }]
285
- end
286
-
287
- it 'loads a page of columns' do
288
- @cf.insert('ABC', Hash[('a'..'z').map { |a| [a, a.upcase] }.shuffle])
289
- @cf.get('ABC', :from_column => 'm', :max_column_count => 10).should == Hash[('m'..'z').take(10).map { |a| [a, a.upcase] }]
290
- end
291
-
292
- it 'raises an error if both :columns and :from_column are given' do
293
- expect { @cf.get('ABC', :columns => 'a'..'z', :from_column => 'm') }.to raise_error(ArgumentError)
294
- end
295
-
296
- it 'loads columns in reverse order with :reversed => true' do
297
- @cf.insert('ABC', Hash[('a'..'f').map { |a| [a, a.upcase] }.shuffle])
298
- @cf.get('ABC', :reversed => true).keys.should == ('a'..'f').to_a.reverse
299
- end
300
-
301
- it 'returns nil if no row was found' do
302
- @cf.get('XYZ').should be_nil
303
- end
304
-
305
- it 'loads the value of counter columns' do
306
- @counter_cf.increment('ABC', 'a', 1)
307
- @counter_cf.increment('ABC', 'b', 2)
308
- @counter_cf.increment('ABC', 'c', 4)
309
- @counter_cf.increment('ABC', 'd', 8)
310
- @counter_cf.get('ABC', :columns => %w(a b c d)).should == {'a' => 1, 'b' => 2, 'c' => 4, 'd' => 8}
311
- end
312
- end
313
-
314
- context 'with multiple row keys' do
315
- it 'loads multiple rows' do
316
- @cf.insert('ABC', 'xyz' => 'abc', 'foo' => 'bar')
317
- @cf.insert('DEF', 'xyz' => 'def', 'hello' => 'world')
318
- @cf.insert('GHI', 'xyz' => 'ghi', 'foo' => 'oof')
319
- @cf.get(%w(ABC GHI)).should == {
320
- 'ABC' => {'xyz' => 'abc', 'foo' => 'bar'},
321
- 'GHI' => {'xyz' => 'ghi', 'foo' => 'oof'}
322
- }
323
- end
324
-
325
- it 'does not include rows that do not exist in the result' do
326
- @cf.insert('ABC', 'xyz' => 'abc', 'foo' => 'bar')
327
- @cf.insert('DEF', 'xyz' => 'def', 'hello' => 'world')
328
- @cf.insert('GHI', 'xyz' => 'ghi', 'foo' => 'oof')
329
- @cf.get(%w(ABC GHI XYZ)).should == {
330
- 'ABC' => {'xyz' => 'abc', 'foo' => 'bar'},
331
- 'GHI' => {'xyz' => 'ghi', 'foo' => 'oof'}
332
- }
333
- end
334
-
335
- it 'loads columns for multiple rows' do
336
- @cf.insert('ABC', 'xyz' => 'abc', 'foo' => 'bar')
337
- @cf.insert('DEF', 'xyz' => 'def', 'hello' => 'world')
338
- @cf.insert('GHI', 'xyz' => 'ghi', 'foo' => 'oof')
339
- @cf.get(%w(ABC GHI), :columns => %w(xyz foo)).should == {'ABC' => {'xyz' => 'abc', 'foo' => 'bar'}, 'GHI' => {'xyz' => 'ghi', 'foo' => 'oof'}}
340
- end
341
-
342
- it 'does not include rows that do not have the specified column' do
343
- @cf.insert('ABC', 'foo' => 'bar')
344
- @cf.insert('DEF', 'xyz' => 'def', 'hello' => 'world')
345
- @cf.insert('GHI', 'xyz' => 'ghi', 'foo' => 'oof', 'abc' => '123')
346
- @cf.get(%w(ABC GHI), :columns => %w(xyz abc)).should == {'GHI' => {'xyz' => 'ghi', 'abc' => '123'}}
347
- end
348
-
349
- it 'does not include rows that do not exist in the results' do
350
- @cf.insert('DEF', 'xyz' => 'def', 'hello' => 'world')
351
- @cf.insert('GHI', 'xyz' => 'ghi', 'foo' => 'oof')
352
- @cf.get(%w(ABC GHI), :columns => %w(xyz foo)).should == {'GHI' => {'xyz' => 'ghi', 'foo' => 'oof'}}
353
- end
354
-
355
- it 'loads all columns in a range from multiple rows' do
356
- @cf.insert('ABC', 'a' => 'A', 'b' => 'B', 'c' => 'C', 'd' => 'D')
357
- @cf.insert('DEF', 'a' => 'A', 'b' => 'B', 'c' => 'C', 'd' => 'D', 'f' => 'F')
358
- @cf.insert('GHI', 'a' => 'A', 'b' => 'B', 'd' => 'D')
359
- @cf.get(%w(ABC GHI), :columns => 'b'...'d').should == {
360
- 'ABC' => {'b' => 'B', 'c' => 'C', 'd' => 'D'},
361
- 'GHI' => {'b' => 'B', 'd' => 'D'}
362
- }
363
- end
364
-
365
- it 'returns an empty hash if no rows exist' do
366
- @cf.get(%w(ABC GHI)).should == {}
367
- end
368
-
369
- it 'loads the value of counter columns' do
370
- @counter_cf.increment('ABC', 'a', 1)
371
- @counter_cf.increment('ABC', 'b', 2)
372
- @counter_cf.increment('DEF', 'c', 4)
373
- @counter_cf.increment('DEF', 'd', 8)
374
- @counter_cf.get(%w(ABC DEF), :columns => %w(a b c d)).should == {
375
- 'ABC' => {'a' => 1, 'b' => 2},
376
- 'DEF' => {'c' => 4, 'd' => 8}
377
- }
378
- end
379
- end
380
-
381
- context 'with options' do
382
- it 'loads with a custom consistency level' do
383
- # TODO: not sure how to test, this just tests that no error is raised
384
- @cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
385
- @cf.get('ABC', :consistency_level => :quorum).should == {'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar'}
386
- end
387
-
388
- it 'loads with a custom consistency level (:cl is an alias for :consistency_level)' do
389
- @cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
390
- @cf.get('ABC', :cl => :one).should == {'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar'}
391
- end
392
- end
393
- end
394
-
395
- describe '#get_column' do
396
- it 'loads a single column for a row' do
397
- @cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
398
- @cf.get_column('ABC', 'hello').should == 'world'
399
- end
400
-
401
- it 'loads with a custom consistency level' do
402
- # TODO: not sure how to test, this just tests that no error is raised
403
- @cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
404
- @cf.get_column('ABC', 'hello', :consistency_level => :quorum).should == 'world'
405
- end
406
-
407
- it 'loads with a custom consistency level (:cl is an alias for :consistency_level)' do
408
- @cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
409
- @cf.get_column('ABC', 'hello', :cl => :one).should == 'world'
410
- end
411
-
412
- it 'returns nil if no row was found' do
413
- @cf.get_column('XYZ', 'abc').should be_nil
414
- end
415
-
416
- it 'returns nil if no column was found' do
417
- @cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
418
- @cf.get_column('XYZ', 'abc').should be_nil
419
- end
420
-
421
- it 'returns the value of a counter column' do
422
- @counter_cf.increment('ABC', 'x', 8)
423
- @counter_cf.get_column('ABC', 'x').should == 8
424
- end
425
- end
426
-
427
- describe '#get_column_count' do
428
- it 'returns the number of columns in the specified row' do
429
- @cf.insert('ABC', Hash[('a'..'z').zip(0..100)])
430
- @cf.get_column_count('ABC').should == 26
431
- end
432
-
433
- it 'returns zero if the row does not exist' do
434
- @cf.get_column_count('X').should == 0
435
- end
436
-
437
- it 'returns the number of columns in the specified range' do
438
- @cf.insert('ABC', Hash[('a'..'z').zip(0..100)])
439
- @cf.get_column_count('ABC', :columns => 'm'..'q').should == 5
440
- end
441
-
442
- it 'returns the number of columns after the specified column' do
443
- @cf.insert('ABC', Hash[('a'..'z').zip(0..100)])
444
- @cf.get_column_count('ABC', :from_column => 's').should == 8
445
- end
446
- end
447
-
448
- describe '#each_column' do
449
- before do
450
- @cf.insert('ABC', Hash[('a'..'z').map { |a| [a, a.upcase] }.shuffle])
451
- end
452
-
453
- it 'yields each column in a row' do
454
- row = {}
455
- @cf.each_column('ABC') do |k, v|
456
- row[k] = v
457
- end
458
- row.should == Hash[('a'..'z').map { |a| [a, a.upcase] }]
459
- end
460
-
461
- it 'returns an Enumerator that yields each column in a row' do
462
- row = {}
463
- enum = @cf.each_column('ABC')
464
- enum.each do |pair|
465
- k, v = *pair # JRuby 1.6.4 Enumerator#each does not splat the arguments
466
- row[k] = v
467
- end
468
- row.should == Hash[('a'..'z').map { |a| [a, a.upcase] }]
469
- end
470
-
471
- it 'yields each column in reverse order with :reversed => true' do
472
- column_keys = []
473
- @cf.each_column('ABC', :reversed => true) do |k, v|
474
- column_keys << k
475
- end
476
- column_keys.should == ('a'..'z').to_a.reverse
477
- end
478
-
479
- it 'can start after a specified key' do
480
- column_keys = []
481
- @cf.each_column('ABC', :start_beyond => 'w') do |k, v|
482
- column_keys << k
483
- end
484
- column_keys.should == ('x'..'z').to_a
485
- end
486
-
487
- it 'can use a custom batch size' do
488
- # TODO: not sure how to test, this just tests that no error is raised
489
- row = {}
490
- @cf.each_column('ABC', :batch_size => 2) do |k, v|
491
- row[k] = v
492
- end
493
- row.should == Hash[('a'..'z').map { |a| [a, a.upcase] }]
494
- end
495
-
496
- it 'loads with a custom consistency level' do
497
- # TODO: not sure how to test, this just tests that no error is raised
498
- @cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
499
- @cf.each_column('ABC', :consistency_level => :quorum) do |k, v|
500
- end
501
- end
502
-
503
- it 'loads with a custom consistency level (:cl is an alias for :consistency_level)' do
504
- @cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
505
- @cf.each_column('ABC', :cl => :one) do |k, v|
506
- end
507
- end
508
- end
509
-
510
- describe '#get_indexed' do
511
- before do
512
- @cf = @keyspace.column_family('indexed_test_family', :create => false)
513
- @cf.drop! rescue nil
514
- @cf.create!(:column_metadata => {
515
- 'name' => {
516
- :validation_class => :ascii,
517
- :index_name => 'name_index',
518
- :index_type => :keys
519
- },
520
- 'age' => {
521
- :validation_class => :long,
522
- :index_name => 'age_index',
523
- :index_type => :keys
524
- }
525
- })
526
- end
527
-
528
- it 'loads rows by index' do
529
- @cf.insert('user1', {'name' => 'sue'})
530
- @cf.insert('user2', {'name' => 'phil'})
531
- @cf.get_indexed('name', :==, 'sue').should == {'user1' => {'name' => 'sue'}}
532
- end
533
-
534
- it 'loads rows by index (using :eq instead of :==)' do
535
- @cf.insert('user1', {'name' => 'sue'})
536
- @cf.insert('user2', {'name' => 'phil'})
537
- @cf.get_indexed('name', :eq, 'sue').should == {'user1' => {'name' => 'sue'}}
538
- end
539
-
540
- it 'limits the number of returned rows' do
541
- names = %w(sue phil sam jim)
542
- 100.times do |i|
543
- row = {'name' => names[i % names.size], 'age' => i % names.size}
544
- @cf.insert("user:#{i}", row, :validations => {'age' => :long})
545
- end
546
- @cf.get_indexed('age', :==, 3, :max_row_count => 3, :validations => {'age' => :long}).should have(3).items
547
- end
548
-
549
- it 'raises an error if the index operator is not supported' do
550
- expect { @cf.get_indexed('name', :%, 'me') }.to raise_error(ArgumentError)
551
- end
552
- end
553
-
554
- describe '#delete' do
555
- it 'removes a row' do
556
- @cf.insert('ABC', 'xyz' => 'abc')
557
- @cf.delete('ABC')
558
- @cf.get('ABC').should == nil
559
- end
560
- end
561
-
562
- describe '#delete_column' do
563
- it 'removes a single column' do
564
- @cf.insert('ABC', 'xyz' => 'abc', 'foo' => 'bar')
565
- @cf.delete_column('ABC', 'foo')
566
- @cf.get('ABC').should == {'xyz' => 'abc'}
567
- end
568
- end
569
-
570
- describe '#delete_columns' do
571
- it 'removes multiple columns' do
572
- @cf.insert('ABC', 'xyz' => 'abc', 'foo' => 'bar', 'hello' => 'world')
573
- @cf.delete_columns('ABC', %w(foo xyz))
574
- @cf.get('ABC').should == {'hello' => 'world'}
575
- end
576
- end
577
- end
20
+ it_behaves_like 'ColumnFamily'
578
21
  end
579
22
  end
580
23
  end
@@ -4,88 +4,16 @@ require_relative '../../spec_helper'
4
4
  module Eurydice
5
5
  module Pelops
6
6
  describe Keyspace do
7
- before do
8
- @cluster = Eurydice.connect
7
+ before :all do
9
8
  @keyspace_name = "eurydice_test_space_#{rand(1000)}"
9
+ @cluster = Eurydice.connect
10
10
  if @cluster.keyspaces.include?(@keyspace_name)
11
11
  @cluster.keyspace(@keyspace_name).drop!
12
12
  end
13
+ @cluster
13
14
  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
15
 
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 => {:dc1 => 1, :dc2 => 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 == {:dc1 => 1, :dc2 => 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.SimpleStrategy'
86
- definition[:strategy_options].should == {:replication_factor => 1}
87
- end
88
- end
16
+ it_behaves_like 'Keyspace'
89
17
  end
90
18
  end
91
19
  end