cassilds 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +53 -0
- data/LICENSE +202 -0
- data/Manifest +45 -0
- data/README.rdoc +83 -0
- data/Rakefile +9 -0
- data/bin/cassandra_helper +16 -0
- data/cassandra.gemspec +46 -0
- data/conf/cassandra.in.sh +47 -0
- data/conf/cassandra.yaml +113 -0
- data/conf/log4j.properties +38 -0
- data/conf/storage-conf.xml +342 -0
- data/lib/cassandra/0.6/cassandra.rb +68 -0
- data/lib/cassandra/0.6/columns.rb +35 -0
- data/lib/cassandra/0.6/protocol.rb +92 -0
- data/lib/cassandra/0.6.rb +7 -0
- data/lib/cassandra/0.7/cassandra.rb +272 -0
- data/lib/cassandra/0.7/column_family.rb +3 -0
- data/lib/cassandra/0.7/columns.rb +67 -0
- data/lib/cassandra/0.7/keyspace.rb +3 -0
- data/lib/cassandra/0.7/protocol.rb +139 -0
- data/lib/cassandra/0.7.rb +7 -0
- data/lib/cassandra/array.rb +8 -0
- data/lib/cassandra/cassandra.rb +302 -0
- data/lib/cassandra/columns.rb +79 -0
- data/lib/cassandra/comparable.rb +28 -0
- data/lib/cassandra/constants.rb +11 -0
- data/lib/cassandra/debug.rb +9 -0
- data/lib/cassandra/helpers.rb +40 -0
- data/lib/cassandra/long.rb +58 -0
- data/lib/cassandra/mock.rb +326 -0
- data/lib/cassandra/ordered_hash.rb +200 -0
- data/lib/cassandra/time.rb +11 -0
- data/lib/cassandra.rb +39 -0
- data/test/cassandra_client_test.rb +20 -0
- data/test/cassandra_mock_test.rb +73 -0
- data/test/cassandra_test.rb +412 -0
- data/test/comparable_types_test.rb +45 -0
- data/test/eventmachine_test.rb +42 -0
- data/test/ordered_hash_test.rb +380 -0
- data/test/test_helper.rb +14 -0
- data/vendor/0.6/gen-rb/cassandra.rb +1481 -0
- data/vendor/0.6/gen-rb/cassandra_constants.rb +12 -0
- data/vendor/0.6/gen-rb/cassandra_types.rb +482 -0
- data/vendor/0.7/gen-rb/cassandra.rb +1937 -0
- data/vendor/0.7/gen-rb/cassandra_constants.rb +12 -0
- data/vendor/0.7/gen-rb/cassandra_types.rb +679 -0
- metadata +176 -0
@@ -0,0 +1,412 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class CassandraTest < Test::Unit::TestCase
|
4
|
+
include Cassandra::Constants
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@twitter = Cassandra.new('Twitter', "127.0.0.1:9160", :retries => 2, :exception_classes => [])
|
8
|
+
@twitter.clear_keyspace!
|
9
|
+
|
10
|
+
@blogs = Cassandra.new('Multiblog')
|
11
|
+
@blogs.clear_keyspace!
|
12
|
+
|
13
|
+
@blogs_long = Cassandra.new('MultiblogLong')
|
14
|
+
@blogs_long.clear_keyspace!
|
15
|
+
|
16
|
+
@uuids = (0..6).map {|i| SimpleUUID::UUID.new(Time.at(2**(24+i))) }
|
17
|
+
@longs = (0..6).map {|i| Long.new(Time.at(2**(24+i))) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_inspect
|
21
|
+
assert_nothing_raised do
|
22
|
+
@blogs.inspect
|
23
|
+
@twitter.inspect
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_key
|
28
|
+
@twitter.insert(:Users, key, {'body' => 'v', 'user' => 'v'})
|
29
|
+
assert_equal({'body' => 'v', 'user' => 'v'}, @twitter.get(:Users, key))
|
30
|
+
assert_equal(['body', 'user'].sort, @twitter.get(:Users, key).timestamps.keys.sort)
|
31
|
+
assert_equal({}, @twitter.get(:Users, 'bogus'))
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_get_key_preserving_order
|
35
|
+
# In-order hash is preserved
|
36
|
+
hash = OrderedHash['a', '', 'b', '', 'c', '', 'd', '',]
|
37
|
+
@twitter.insert(:Users, key, hash)
|
38
|
+
assert_equal(hash.keys, @twitter.get(:Users, key).keys)
|
39
|
+
|
40
|
+
@twitter.remove(:Users, key)
|
41
|
+
|
42
|
+
# Out-of-order hash is returned sorted
|
43
|
+
hash = OrderedHash['b', '', 'c', '', 'd', '', 'a', '']
|
44
|
+
@twitter.insert(:Users, key, hash)
|
45
|
+
assert_equal(hash.keys.sort, @twitter.get(:Users, key).keys)
|
46
|
+
assert_equal(hash.timestamps.keys.sort, @twitter.get(:Users, key).timestamps.keys.sort)
|
47
|
+
assert_not_equal(hash.keys, @twitter.get(:Users, key).keys)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_get_first_time_uuid_column
|
51
|
+
@blogs.insert(:Blogs, key,
|
52
|
+
{@uuids[0] => 'I like this cat', @uuids[1] => 'Buttons is cuter', @uuids[2] => 'I disagree'})
|
53
|
+
|
54
|
+
assert_equal({@uuids[0] => 'I like this cat'}, @blogs.get(:Blogs, key, :count => 1))
|
55
|
+
assert_equal({@uuids[2] => 'I disagree'}, @blogs.get(:Blogs, key, :count => 1, :reversed => true))
|
56
|
+
assert_equal({}, @blogs.get(:Blogs, 'bogus'))
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_get_multiple_time_uuid_columns
|
60
|
+
@blogs.insert(:Blogs, key,
|
61
|
+
{@uuids[0] => 'I like this cat', @uuids[1] => 'Buttons is cuter', @uuids[2] => 'I disagree'})
|
62
|
+
|
63
|
+
assert_equal(['I like this cat', 'Buttons is cuter'], @blogs.get_columns(:Blogs, key, @uuids[0..1]))
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_get_first_long_column
|
67
|
+
@blogs_long.insert(:Blogs, key,
|
68
|
+
{@longs[0] => 'I like this cat', @longs[1] => 'Buttons is cuter', @longs[2] => 'I disagree'})
|
69
|
+
|
70
|
+
assert_equal({@longs[0] => 'I like this cat'}, @blogs_long.get(:Blogs, key, :count => 1))
|
71
|
+
assert_equal({@longs[2] => 'I disagree'}, @blogs_long.get(:Blogs, key, :count => 1, :reversed => true))
|
72
|
+
assert_equal({}, @blogs_long.get(:Blogs, 'bogus'))
|
73
|
+
|
74
|
+
assert_equal([@longs[0]], @blogs_long.get(:Blogs, key, :count => 1).timestamps.keys)
|
75
|
+
assert_equal([@longs[2]], @blogs_long.get(:Blogs, key, :count => 1, :reversed => true).timestamps.keys)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_long_remove_bug
|
79
|
+
@blogs_long.insert(:Blogs, key, {@longs[0] => 'I like this cat'})
|
80
|
+
@blogs_long.remove(:Blogs, key)
|
81
|
+
assert_equal({}, @blogs_long.get(:Blogs, key, :count => 1))
|
82
|
+
|
83
|
+
@blogs_long.insert(:Blogs, key, {@longs[0] => 'I really like this cat'})
|
84
|
+
assert_equal({@longs[0] => 'I really like this cat'}, @blogs_long.get(:Blogs, key, :count => 1))
|
85
|
+
assert_equal([@longs[0]], @blogs_long.get(:Blogs, key, :count => 1).timestamps.keys)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_get_with_count
|
89
|
+
@twitter.insert(:Statuses, key, {'1' => 'v', '2' => 'v', '3' => 'v'})
|
90
|
+
assert_equal 1, @twitter.get(:Statuses, key, :count => 1).size
|
91
|
+
assert_equal 2, @twitter.get(:Statuses, key, :count => 2).size
|
92
|
+
assert_equal 1, @twitter.get(:Statuses, key, :count => 1).timestamps.size
|
93
|
+
assert_equal 2, @twitter.get(:Statuses, key, :count => 2).timestamps.size
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_get_value
|
97
|
+
@twitter.insert(:Statuses, key, {'body' => 'v'})
|
98
|
+
assert_equal 'v', @twitter.get(:Statuses, key, 'body')
|
99
|
+
assert_nil @twitter.get(:Statuses, 'bogus', 'body')
|
100
|
+
|
101
|
+
assert @twitter.exists?(:Statuses, key, 'body')
|
102
|
+
assert !@twitter.exists?(:Statuses, 'bogus', 'body')
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_exists_with_only_key
|
106
|
+
@twitter.insert(:Statuses, key, {'body' => 'v'})
|
107
|
+
assert @twitter.exists?(:Statuses, key)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_get_super_key
|
111
|
+
columns = {'user_timelines' => {@uuids[4] => '4', @uuids[5] => '5'}}
|
112
|
+
@twitter.insert(:StatusRelationships, key, columns)
|
113
|
+
assert_equal(columns, @twitter.get(:StatusRelationships, key))
|
114
|
+
assert_equal(columns.keys, @twitter.get(:StatusRelationships, key).timestamps.keys)
|
115
|
+
assert_equal({}, @twitter.get(:StatusRelationships, 'bogus'))
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_get_several_super_keys
|
119
|
+
columns = {
|
120
|
+
'user_timelines' => {@uuids[1] => 'v1'},
|
121
|
+
'mentions_timelines' => {@uuids[2] => 'v2'}}
|
122
|
+
@twitter.insert(:StatusRelationships, key, columns)
|
123
|
+
|
124
|
+
assert_equal(columns, @twitter.get(:StatusRelationships, key))
|
125
|
+
assert_equal(columns.keys, @twitter.get(:StatusRelationships, key).timestamps.keys)
|
126
|
+
assert_equal({}, @twitter.get(:StatusRelationships, 'bogus'))
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_get_super_sub_keys_with_count
|
130
|
+
@twitter.insert(:StatusRelationships, key,
|
131
|
+
{'user_timelines' => {@uuids[1] => 'v1', @uuids[2] => 'v2', @uuids[3] => 'v3'}})
|
132
|
+
assert_equal({@uuids[1] => 'v1'},
|
133
|
+
@twitter.get(:StatusRelationships, key, "user_timelines", :count => 1))
|
134
|
+
assert_equal({@uuids[3] => 'v3'},
|
135
|
+
@twitter.get(:StatusRelationships, key, "user_timelines", :count => 1, :reversed => true))
|
136
|
+
assert_equal([@uuids[1]],
|
137
|
+
@twitter.get(:StatusRelationships, key, "user_timelines", :count => 1).timestamps.keys)
|
138
|
+
assert_equal([@uuids[3]],
|
139
|
+
@twitter.get(:StatusRelationships, key, "user_timelines", :count => 1, :reversed => true).timestamps.keys)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_get_super_sub_keys_with_ranges
|
143
|
+
@twitter.insert(:StatusRelationships, key,
|
144
|
+
{'user_timelines' => {
|
145
|
+
@uuids[1] => 'v1',
|
146
|
+
@uuids[2] => 'v2',
|
147
|
+
@uuids[3] => 'v3',
|
148
|
+
@uuids[4] => 'v4',
|
149
|
+
@uuids[5] => 'v5'}})
|
150
|
+
|
151
|
+
keys = @twitter.get(:StatusRelationships, key, "user_timelines").keys
|
152
|
+
assert_equal keys.sort, keys
|
153
|
+
assert_equal({@uuids[1] => 'v1'}, @twitter.get(:StatusRelationships, key, "user_timelines", :finish => @uuids[2], :count => 1))
|
154
|
+
assert_equal({@uuids[2] => 'v2'}, @twitter.get(:StatusRelationships, key, "user_timelines", :start => @uuids[2], :count => 1))
|
155
|
+
assert_equal 4, @twitter.get(:StatusRelationships, key, "user_timelines", :start => @uuids[2], :finish => @uuids[5]).size
|
156
|
+
assert_equal([@uuids[1]], @twitter.get(:StatusRelationships, key, "user_timelines", :finish => @uuids[2], :count => 1).timestamps.keys)
|
157
|
+
assert_equal([@uuids[2]], @twitter.get(:StatusRelationships, key, "user_timelines", :start => @uuids[2], :count => 1).timestamps.keys)
|
158
|
+
assert_equal 4, @twitter.get(:StatusRelationships, key, "user_timelines", :start => @uuids[2], :finish => @uuids[5]).timestamps.size
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_get_super_sub_key
|
162
|
+
columns = {@uuids[1] => 'v1', @uuids[2] => 'v2'}
|
163
|
+
@twitter.insert(:StatusRelationships, key, {'user_timelines' => columns})
|
164
|
+
assert_equal(columns, @twitter.get(:StatusRelationships, key, 'user_timelines'))
|
165
|
+
assert_equal(columns.keys.sort, @twitter.get(:StatusRelationships, key, 'user_timelines').timestamps.keys.sort)
|
166
|
+
assert_equal({}, @twitter.get(:StatusRelationships, 'bogus', 'user_timelines'))
|
167
|
+
# FIXME Not sure if this is valid
|
168
|
+
# assert_nil @twitter.exists?(:StatusRelationships, 'bogus', 'user_timelines')
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_get_super_value
|
172
|
+
columns = {@uuids[1] => 'v1'}
|
173
|
+
@twitter.insert(:StatusRelationships, key, {'user_timelines' => columns})
|
174
|
+
assert_equal('v1', @twitter.get(:StatusRelationships, key, 'user_timelines', columns.keys.first))
|
175
|
+
assert_nil @twitter.get(:StatusRelationships, 'bogus', 'user_timelines', columns.keys.first)
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
#TODO: add a OPP keyspace for this
|
180
|
+
# def test_get_range
|
181
|
+
# @twitter.insert(:Statuses, '2', {'body' => '1'})
|
182
|
+
# @twitter.insert(:Statuses, '3', {'body' => '1'})
|
183
|
+
# @twitter.insert(:Statuses, '4', {'body' => '1'})
|
184
|
+
# @twitter.insert(:Statuses, '5', {'body' => '1'})
|
185
|
+
# @twitter.insert(:Statuses, '6', {'body' => '1'})
|
186
|
+
# assert_equal(['3', '4', '5'], @twitter.get_range(:Statuses, :start => '3', :finish => '5'))
|
187
|
+
# end
|
188
|
+
|
189
|
+
def test_get_range_count
|
190
|
+
@twitter.insert(:Statuses, '2', {'body' => '1'})
|
191
|
+
@twitter.insert(:Statuses, '3', {'body' => '1'})
|
192
|
+
@twitter.insert(:Statuses, '4', {'body' => '1'})
|
193
|
+
@twitter.insert(:Statuses, '5', {'body' => '1'})
|
194
|
+
@twitter.insert(:Statuses, '6', {'body' => '1'})
|
195
|
+
assert_equal(3, @twitter.get_range(:Statuses, :count => 3).size)
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_multi_get
|
199
|
+
@twitter.insert(:Users, key + '1', {'body' => 'v1', 'user' => 'v1'})
|
200
|
+
@twitter.insert(:Users, key + '2', {'body' => 'v2', 'user' => 'v2'})
|
201
|
+
|
202
|
+
expected = OrderedHash[key + '1', {'body' => 'v1', 'user' => 'v1'}, key + '2', {'body' => 'v2', 'user' => 'v2'}, 'bogus', {}]
|
203
|
+
result = @twitter.multi_get(:Users, [key + '1', key + '2', 'bogus'])
|
204
|
+
assert_equal expected, result
|
205
|
+
assert_equal expected.keys, result.keys
|
206
|
+
assert_equal expected.keys.sort, @twitter.multi_get(:Users, [key + '1', key + '2', 'bogus']).timestamps.keys.sort
|
207
|
+
|
208
|
+
expected = OrderedHash[key + '2', {'body' => 'v2', 'user' => 'v2'}, 'bogus', {}, key + '1', {'body' => 'v1', 'user' => 'v1'}]
|
209
|
+
result = @twitter.multi_get(:Users, [key + '2', 'bogus', key + '1'])
|
210
|
+
assert_equal expected, result
|
211
|
+
assert_equal expected.keys, result.keys
|
212
|
+
assert_equal expected.keys.sort, @twitter.multi_get(:Users, [key + '2', 'bogus', key + '1']).timestamps.keys.sort
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_remove_key
|
216
|
+
@twitter.insert(:Statuses, key, {'body' => 'v'})
|
217
|
+
assert_equal({'body' => 'v'}, @twitter.get(:Statuses, key))
|
218
|
+
|
219
|
+
@twitter.remove(:Statuses, key)
|
220
|
+
assert_equal({}, @twitter.get(:Statuses, key))
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_remove_value
|
224
|
+
@twitter.insert(:Statuses, key, {'body' => 'v'})
|
225
|
+
@twitter.remove(:Statuses, key, 'body')
|
226
|
+
assert_nil @twitter.get(:Statuses, key, 'body')
|
227
|
+
assert_nil @twitter.get(:Statuses, key).timestamps['body']
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_remove_super_key
|
231
|
+
@twitter.insert(:StatusRelationships, key, {'user_timelines' => {@uuids[1] => 'v1'}})
|
232
|
+
@twitter.remove(:StatusRelationships, key)
|
233
|
+
assert_equal({}, @twitter.get(:StatusRelationships, key))
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_remove_super_sub_key
|
237
|
+
@twitter.insert(:StatusRelationships, key, {'user_timelines' => {@uuids[1] => 'v1'}})
|
238
|
+
@twitter.remove(:StatusRelationships, key, 'user_timelines')
|
239
|
+
assert_equal({}, @twitter.get(:StatusRelationships, key, 'user_timelines'))
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_remove_super_value
|
243
|
+
columns = {@uuids[1] => 'v1'}
|
244
|
+
@twitter.insert(:StatusRelationships, key, {'user_timelines' => columns})
|
245
|
+
@twitter.remove(:StatusRelationships, key, 'user_timelines', columns.keys.first)
|
246
|
+
assert_nil @twitter.get(:StatusRelationships, key, 'user_timelines', columns.keys.first)
|
247
|
+
assert_nil @twitter.get(:StatusRelationships, key, 'user_timelines').timestamps[columns.keys.first]
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_clear_column_family
|
251
|
+
@twitter.insert(:Statuses, key + "1", {'body' => '1'})
|
252
|
+
@twitter.insert(:Statuses, key + "2", {'body' => '2'})
|
253
|
+
@twitter.insert(:Statuses, key + "3", {'body' => '3'})
|
254
|
+
@twitter.clear_column_family!(:Statuses)
|
255
|
+
assert_equal 0, @twitter.count_range(:Statuses)
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_insert_key
|
259
|
+
@twitter.insert(:Statuses, key, {'body' => 'v', 'user' => 'v'})
|
260
|
+
assert_equal({'body' => 'v', 'user' => 'v'}, @twitter.get(:Statuses, key))
|
261
|
+
assert_equal(['body', 'user'], @twitter.get(:Statuses, key).timestamps.keys)
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_insert_super_key
|
265
|
+
columns = {@uuids[1] => 'v1', @uuids[2] => 'v2'}
|
266
|
+
@twitter.insert(:StatusRelationships, key, {'user_timelines' => columns})
|
267
|
+
assert_equal(columns, @twitter.get(:StatusRelationships, key, 'user_timelines'))
|
268
|
+
assert_equal(columns.keys.sort, @twitter.get(:StatusRelationships, key, 'user_timelines').timestamps.keys.sort)
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_get_columns
|
272
|
+
@twitter.insert(:Statuses, key, {'body' => 'v1', 'user' => 'v2'})
|
273
|
+
assert_equal(['v1' , 'v2'], @twitter.get_columns(:Statuses, key, ['body', 'user']))
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_get_column_values_super
|
277
|
+
user_columns, mentions_columns = {@uuids[1] => 'v1'}, {@uuids[2] => 'v2'}
|
278
|
+
@twitter.insert(:StatusRelationships, key,
|
279
|
+
{'user_timelines' => user_columns, 'mentions_timelines' => mentions_columns})
|
280
|
+
assert_equal [user_columns, mentions_columns],
|
281
|
+
@twitter.get_columns(:StatusRelationships, key, ['user_timelines', 'mentions_timelines'])
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_get_sub_column_values_super
|
285
|
+
user_columns = {@uuids[1] => 'v1', @uuids[2] => 'v2'}
|
286
|
+
@twitter.insert(:StatusRelationships, key, {'user_timelines' => user_columns})
|
287
|
+
assert_equal ['v1', 'v2'],
|
288
|
+
@twitter.get_columns(:StatusRelationships, key, 'user_timelines', @uuids[1..2])
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_multi_get_columns
|
292
|
+
@twitter.insert(:Users, key + '1', {'body' => 'v1', 'user' => 'v1'})
|
293
|
+
@twitter.insert(:Users, key + '2', {'body' => 'v2', 'user' => 'v2'})
|
294
|
+
assert_equal(
|
295
|
+
OrderedHash[key + '1', ['v1', 'v1'], key + '2', ['v2', 'v2'], 'bogus', [nil, nil]],
|
296
|
+
@twitter.multi_get_columns(:Users, [key + '1', key + '2', 'bogus'], ['body', 'user']))
|
297
|
+
assert_equal(
|
298
|
+
OrderedHash[key + '2', ['v2', 'v2'], 'bogus', [nil, nil], key + '1', ['v1', 'v1']],
|
299
|
+
@twitter.multi_get_columns(:Users, [key + '2', 'bogus', key + '1'], ['body', 'user']))
|
300
|
+
assert_equal(
|
301
|
+
OrderedHash[key + '1', ['v1', 'v1'], key + '2', ['v2', 'v2'], 'bogus', [nil, nil]].keys.sort,
|
302
|
+
@twitter.multi_get_columns(:Users, [key + '1', key + '2', 'bogus'], ['body', 'user']).timestamps.keys.sort)
|
303
|
+
assert_equal(
|
304
|
+
OrderedHash[key + '2', ['v2', 'v2'], 'bogus', [nil, nil], key + '1', ['v1', 'v1']].keys.sort,
|
305
|
+
@twitter.multi_get_columns(:Users, [key + '2', 'bogus', key + '1'], ['body', 'user']).timestamps.keys.sort)
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_count_keys
|
309
|
+
@twitter.insert(:Statuses, key + "1", {'body' => '1'})
|
310
|
+
@twitter.insert(:Statuses, key + "2", {'body' => '2'})
|
311
|
+
@twitter.insert(:Statuses, key + "3", {'body' => '3'})
|
312
|
+
assert_equal 3, @twitter.count_range(:Statuses)
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_count_columns
|
316
|
+
@twitter.insert(:Statuses, key, {'body' => 'v1', 'user' => 'v2'})
|
317
|
+
assert_equal 2, @twitter.count_columns(:Statuses, key)
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_count_super_columns
|
321
|
+
@twitter.insert(:StatusRelationships, key, {
|
322
|
+
'user_timelines' => {@uuids[1] => 'v1'},
|
323
|
+
'mentions_timelines' => {@uuids[2] => 'v2'}})
|
324
|
+
assert_equal 2, @twitter.count_columns(:StatusRelationships, key)
|
325
|
+
end
|
326
|
+
|
327
|
+
def test_count_super_sub_columns
|
328
|
+
@twitter.insert(:StatusRelationships, key, {'user_timelines' => {@uuids[1] => 'v1', @uuids[2] => 'v2'}})
|
329
|
+
assert_equal 2, @twitter.count_columns(:StatusRelationships, key, 'user_timelines')
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_multi_count_columns
|
333
|
+
@twitter.insert(:Users, key + '1', {'body' => 'v1', 'user' => 'v1'})
|
334
|
+
@twitter.insert(:Users, key + '2', {'body' => 'v2', 'user' => 'v2'})
|
335
|
+
assert_equal(
|
336
|
+
OrderedHash[key + '1', 2, key + '2', 2, 'bogus', 0],
|
337
|
+
@twitter.multi_count_columns(:Users, [key + '1', key + '2', 'bogus']))
|
338
|
+
assert_equal(
|
339
|
+
OrderedHash[key + '2', 2, 'bogus', 0, key + '1', 2],
|
340
|
+
@twitter.multi_count_columns(:Users, [key + '2', 'bogus', key + '1']))
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_batch_mutate
|
344
|
+
k = key
|
345
|
+
|
346
|
+
@twitter.insert(:Users, k + '1', {'body' => 'v1', 'user' => 'v1'})
|
347
|
+
|
348
|
+
@twitter.batch do
|
349
|
+
@twitter.insert(:Users, k + '2', {'body' => 'v2', 'user' => 'v2'})
|
350
|
+
@twitter.insert(:Users, k + '3', {'body' => 'bogus', 'user' => 'v3'})
|
351
|
+
@twitter.insert(:Users, k + '3', {'body' => 'v3', 'location' => 'v3'})
|
352
|
+
@twitter.insert(:Statuses, k + '3', {'body' => 'v'})
|
353
|
+
|
354
|
+
assert_equal({'body' => 'v1', 'user' => 'v1'}, @twitter.get(:Users, k + '1')) # Written
|
355
|
+
assert_equal({}, @twitter.get(:Users, k + '2')) # Not yet written
|
356
|
+
assert_equal({}, @twitter.get(:Statuses, k + '3')) # Not yet written
|
357
|
+
|
358
|
+
@twitter.remove(:Users, k + '1')
|
359
|
+
assert_equal({'body' => 'v1', 'user' => 'v1'}, @twitter.get(:Users, k + '1')) # Not yet removed
|
360
|
+
|
361
|
+
@twitter.remove(:Users, k + '4')
|
362
|
+
@twitter.insert(:Users, k + '4', {'body' => 'v4', 'user' => 'v4'})
|
363
|
+
assert_equal({}, @twitter.get(:Users, k + '4')) # Not yet written
|
364
|
+
end
|
365
|
+
|
366
|
+
assert_equal({'body' => 'v2', 'user' => 'v2'}, @twitter.get(:Users, k + '2')) # Written
|
367
|
+
assert_equal({'body' => 'v3', 'user' => 'v3', 'location' => 'v3'}, @twitter.get(:Users, k + '3')) # Written and compacted
|
368
|
+
assert_equal({'body' => 'v4', 'user' => 'v4'}, @twitter.get(:Users, k + '4')) # Written
|
369
|
+
assert_equal({'body' => 'v'}, @twitter.get(:Statuses, k + '3')) # Written
|
370
|
+
assert_equal({}, @twitter.get(:Users, k + '1')) # Removed
|
371
|
+
|
372
|
+
assert_equal({'body' => 'v2', 'user' => 'v2'}.keys.sort, @twitter.get(:Users, k + '2').timestamps.keys.sort) # Written
|
373
|
+
assert_equal({'body' => 'v3', 'user' => 'v3', 'location' => 'v3'}.keys.sort, @twitter.get(:Users, k + '3').timestamps.keys.sort) # Written and compacted
|
374
|
+
assert_equal({'body' => 'v4', 'user' => 'v4'}.keys.sort, @twitter.get(:Users, k + '4').timestamps.keys.sort) # Written
|
375
|
+
assert_equal({'body' => 'v'}.keys.sort, @twitter.get(:Statuses, k + '3').timestamps.keys.sort) # Written
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_complain_about_nil_key
|
379
|
+
assert_raises(ArgumentError) do
|
380
|
+
@twitter.insert(:Statuses, nil, {'text' => 'crap'})
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
def test_raise_access_error_on_nonexistent_keyspace
|
385
|
+
nonexistent = Cassandra.new('Nonexistent')
|
386
|
+
assert_raises(Cassandra::AccessError) do
|
387
|
+
nonexistent.get "foo", "bar"
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
def test_nil_sub_column_value
|
392
|
+
@twitter.insert(:Index, 'asdf', {"thing" => {'jkl' => ''} })
|
393
|
+
end
|
394
|
+
|
395
|
+
def test_disconnect!
|
396
|
+
@twitter.disconnect!
|
397
|
+
assert_nil @twitter.instance_variable_get(:@client)
|
398
|
+
end
|
399
|
+
|
400
|
+
def test_super_allows_for_non_string_values_while_normal_does_not
|
401
|
+
columns = {'user_timelines' => {@uuids[4] => '4', @uuids[5] => '5'}}
|
402
|
+
|
403
|
+
@twitter.insert(:StatusRelationships, key, columns)
|
404
|
+
@twitter.insert(:Statuses, key, { 'body' => '1' })
|
405
|
+
end
|
406
|
+
|
407
|
+
private
|
408
|
+
|
409
|
+
def key
|
410
|
+
caller.first[/`(.*?)'/, 1]
|
411
|
+
end
|
412
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class ComparableTypesTest < Test::Unit::TestCase
|
4
|
+
include Cassandra::Constants
|
5
|
+
|
6
|
+
def test_long_sort
|
7
|
+
ary = []
|
8
|
+
10.times { ary << Long.new }
|
9
|
+
assert_equal ary.sort, ary
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_long_equality
|
13
|
+
long = Long.new
|
14
|
+
assert_equal long, Long.new(long)
|
15
|
+
assert_equal long, Long.new(long.to_s)
|
16
|
+
assert_equal long, Long.new(long.to_i)
|
17
|
+
assert_equal long, Long.new(long.to_guid)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_long_error
|
21
|
+
assert_raises(Cassandra::Comparable::TypeError) do
|
22
|
+
Long.new("bogus")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_types_behave_well
|
27
|
+
assert !(Long.new() == false)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_casting_unknown_class
|
31
|
+
assert_raises(Cassandra::Comparable::TypeError) do
|
32
|
+
Cassandra::Long.new({})
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_long_inspect
|
37
|
+
obj = Long.new("\000\000\000\000\000\000\000\000")
|
38
|
+
if RUBY_VERSION < '1.9'
|
39
|
+
assert_equal "<Cassandra::Long##{obj.object_id} time: Thu Jan 01 00:00:00 UTC 1970, usecs: 0, jitter: 0, guid: 00000000-0000-0000>", obj.inspect
|
40
|
+
else
|
41
|
+
assert_equal "<Cassandra::Long##{obj.object_id} time: 1970-01-01 00:00:00 UTC, usecs: 0, jitter: 0, guid: 00000000-0000-0000>", obj.inspect
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
if RUBY_VERSION < '1.9'
|
4
|
+
puts "Skipping EventMachine test"
|
5
|
+
else
|
6
|
+
|
7
|
+
require 'thrift_client/event_machine'
|
8
|
+
|
9
|
+
class EventmachineTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_twitter
|
12
|
+
@twitter = Cassandra.new('Twitter', "127.0.0.1:9160", :retries => 2, :exception_classes => [], :transport => Thrift::EventMachineTransport, :transport_wrapper => nil)
|
13
|
+
@twitter.clear_keyspace!
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def em_test(name)
|
19
|
+
EM.run do
|
20
|
+
Fiber.new do
|
21
|
+
begin
|
22
|
+
send("raw_#{name}".to_sym)
|
23
|
+
ensure
|
24
|
+
EM.stop
|
25
|
+
end
|
26
|
+
end.resume
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.wrap_tests
|
31
|
+
self.public_instance_methods.select { |m| m =~ /^test_/ }.each do |meth|
|
32
|
+
alias_method :"raw_#{meth}", meth
|
33
|
+
define_method(meth) do
|
34
|
+
em_test(meth)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
wrap_tests
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|