cassandra 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +18 -4
- data/README.rdoc +14 -2
- data/Rakefile +8 -4
- data/cassandra.gemspec +9 -9
- data/conf/cassandra.yaml +113 -0
- data/conf/storage-conf.xml +2 -1
- data/lib/cassandra.rb +22 -5
- data/lib/cassandra/0.6.rb +7 -0
- data/lib/cassandra/0.6/cassandra.rb +63 -0
- data/lib/cassandra/0.6/columns.rb +35 -0
- data/lib/cassandra/{protocol.rb → 0.6/protocol.rb} +2 -2
- data/lib/cassandra/0.7.rb +7 -0
- data/lib/cassandra/0.7/cassandra.rb +195 -0
- data/lib/cassandra/0.7/column_family.rb +3 -0
- data/lib/cassandra/0.7/columns.rb +59 -0
- data/lib/cassandra/0.7/keyspace.rb +3 -0
- data/lib/cassandra/0.7/protocol.rb +95 -0
- data/lib/cassandra/cassandra.rb +35 -72
- data/lib/cassandra/columns.rb +7 -35
- data/lib/cassandra/debug.rb +2 -0
- data/lib/cassandra/ordered_hash.rb +66 -7
- data/test/cassandra_test.rb +60 -4
- data/test/ordered_hash_test.rb +182 -3
- data/vendor/{gen-rb → 0.6/gen-rb}/cassandra.rb +85 -82
- data/vendor/{gen-rb → 0.6/gen-rb}/cassandra_constants.rb +0 -0
- data/vendor/{gen-rb → 0.6/gen-rb}/cassandra_types.rb +48 -45
- data/vendor/0.7/gen-rb/cassandra.rb +1936 -0
- data/vendor/0.7/gen-rb/cassandra_constants.rb +12 -0
- data/vendor/0.7/gen-rb/cassandra_types.rb +679 -0
- metadata +48 -12
data/lib/cassandra/columns.rb
CHANGED
@@ -22,7 +22,7 @@ class Cassandra
|
|
22
22
|
case $1
|
23
23
|
when "LongType" then Long
|
24
24
|
when "LexicalUUIDType", "TimeUUIDType" then SimpleUUID::UUID
|
25
|
-
else
|
25
|
+
else
|
26
26
|
String # UTF8, Ascii, Bytes, anything else
|
27
27
|
end
|
28
28
|
end
|
@@ -41,13 +41,13 @@ class Cassandra
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def multi_columns_to_hash!(column_family, hash)
|
44
|
-
hash.each do |key, columns|
|
44
|
+
hash.each do |key, columns|
|
45
45
|
hash[key] = columns_to_hash(column_family, columns)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
def multi_sub_columns_to_hash!(column_family, hash)
|
50
|
-
hash.each do |key, sub_columns|
|
50
|
+
hash.each do |key, sub_columns|
|
51
51
|
hash[key] = sub_columns_to_hash(column_family, sub_columns)
|
52
52
|
end
|
53
53
|
end
|
@@ -64,43 +64,15 @@ class Cassandra
|
|
64
64
|
hash = OrderedHash.new
|
65
65
|
Array(columns).each do |c|
|
66
66
|
c = c.super_column || c.column if c.is_a?(CassandraThrift::ColumnOrSuperColumn)
|
67
|
-
|
68
|
-
when CassandraThrift::SuperColumn
|
69
|
-
columns_to_hash_for_classes(c.columns, sub_column_name_class) # Pop the class stack, and recurse
|
67
|
+
case c
|
68
|
+
when CassandraThrift::SuperColumn
|
69
|
+
hash.[]=(column_name_class.new(c.name), columns_to_hash_for_classes(c.columns, sub_column_name_class)) # Pop the class stack, and recurse
|
70
70
|
when CassandraThrift::Column
|
71
|
-
c.value
|
71
|
+
hash.[]=(column_name_class.new(c.name), c.value, c.timestamp)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
hash
|
75
75
|
end
|
76
76
|
|
77
|
-
def _standard_insert_mutation(column_family, column_name, value, timestamp)
|
78
|
-
CassandraThrift::Mutation.new(
|
79
|
-
:column_or_supercolumn => CassandraThrift::ColumnOrSuperColumn.new(
|
80
|
-
:column => CassandraThrift::Column.new(
|
81
|
-
:name => column_name_class(column_family).new(column_name).to_s,
|
82
|
-
:value => value,
|
83
|
-
:timestamp => timestamp
|
84
|
-
)
|
85
|
-
)
|
86
|
-
)
|
87
|
-
end
|
88
|
-
|
89
|
-
def _super_insert_mutation(column_family, super_column_name, sub_columns, timestamp)
|
90
|
-
CassandraThrift::Mutation.new(:column_or_supercolumn =>
|
91
|
-
CassandraThrift::ColumnOrSuperColumn.new(
|
92
|
-
:super_column => CassandraThrift::SuperColumn.new(
|
93
|
-
:name => column_name_class(column_family).new(super_column_name).to_s,
|
94
|
-
:columns => sub_columns.collect { |sub_column_name, sub_column_value|
|
95
|
-
CassandraThrift::Column.new(
|
96
|
-
:name => sub_column_name_class(column_family).new(sub_column_name).to_s,
|
97
|
-
:value => sub_column_value.to_s,
|
98
|
-
:timestamp => timestamp
|
99
|
-
)
|
100
|
-
}
|
101
|
-
)
|
102
|
-
)
|
103
|
-
)
|
104
|
-
end
|
105
77
|
end
|
106
78
|
end
|
data/lib/cassandra/debug.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
class Cassandra
|
3
3
|
# Hash is ordered in Ruby 1.9!
|
4
4
|
if RUBY_VERSION >= '1.9'
|
5
|
-
|
5
|
+
OrderedHashInt = ::Hash
|
6
6
|
else
|
7
|
-
class
|
7
|
+
class OrderedHashInt < Hash #:nodoc:
|
8
8
|
def initialize(*args, &block)
|
9
9
|
super
|
10
10
|
@keys = []
|
@@ -52,7 +52,7 @@ class Cassandra
|
|
52
52
|
end
|
53
53
|
super
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def delete_if
|
57
57
|
super
|
58
58
|
sync_keys!
|
@@ -127,10 +127,6 @@ class Cassandra
|
|
127
127
|
self
|
128
128
|
end
|
129
129
|
|
130
|
-
def inspect
|
131
|
-
"#<OrderedHash #{super}>"
|
132
|
-
end
|
133
|
-
|
134
130
|
private
|
135
131
|
|
136
132
|
def sync_keys!
|
@@ -138,4 +134,67 @@ class Cassandra
|
|
138
134
|
end
|
139
135
|
end
|
140
136
|
end
|
137
|
+
|
138
|
+
class OrderedHash < OrderedHashInt #:nodoc:
|
139
|
+
def initialize(*args, &block)
|
140
|
+
@timestamps = Hash.new
|
141
|
+
super
|
142
|
+
end
|
143
|
+
|
144
|
+
def initialize_copy(other)
|
145
|
+
@timestamps = other.timestamps
|
146
|
+
super
|
147
|
+
end
|
148
|
+
|
149
|
+
def []=(key, value, timestamp = nil)
|
150
|
+
@timestamps[key] = timestamp
|
151
|
+
super(key, value)
|
152
|
+
end
|
153
|
+
|
154
|
+
def delete(key)
|
155
|
+
@timestamps.delete(key)
|
156
|
+
super
|
157
|
+
end
|
158
|
+
|
159
|
+
def delete_if
|
160
|
+
@timestamps.delete_if
|
161
|
+
super
|
162
|
+
end
|
163
|
+
|
164
|
+
def reject!
|
165
|
+
@timestamps.reject!
|
166
|
+
super
|
167
|
+
end
|
168
|
+
|
169
|
+
def timestamps
|
170
|
+
@timestamps.dup
|
171
|
+
end
|
172
|
+
|
173
|
+
def clear
|
174
|
+
@timestamps.clear
|
175
|
+
super
|
176
|
+
end
|
177
|
+
|
178
|
+
def shift
|
179
|
+
k, v = super
|
180
|
+
@timestamps.delete(k)
|
181
|
+
[k, v]
|
182
|
+
end
|
183
|
+
|
184
|
+
def replace(other)
|
185
|
+
@timestamps = other.timestamps
|
186
|
+
super
|
187
|
+
end
|
188
|
+
|
189
|
+
def inspect
|
190
|
+
"#<OrderedHash #{super}\n#{@timestamps.inspect}>"
|
191
|
+
end
|
192
|
+
|
193
|
+
private
|
194
|
+
|
195
|
+
def sync_keys!
|
196
|
+
@timestamps.delete_if {|k,v| !has_key?(k)}
|
197
|
+
super
|
198
|
+
end
|
199
|
+
end
|
141
200
|
end
|
data/test/cassandra_test.rb
CHANGED
@@ -27,6 +27,7 @@ class CassandraTest < Test::Unit::TestCase
|
|
27
27
|
def test_get_key
|
28
28
|
@twitter.insert(:Users, key, {'body' => 'v', 'user' => 'v'})
|
29
29
|
assert_equal({'body' => 'v', 'user' => 'v'}, @twitter.get(:Users, key))
|
30
|
+
assert_equal(['body', 'user'].sort, @twitter.get(:Users, key).timestamps.keys.sort)
|
30
31
|
assert_equal({}, @twitter.get(:Users, 'bogus'))
|
31
32
|
end
|
32
33
|
|
@@ -42,13 +43,14 @@ class CassandraTest < Test::Unit::TestCase
|
|
42
43
|
hash = OrderedHash['b', '', 'c', '', 'd', '', 'a', '']
|
43
44
|
@twitter.insert(:Users, key, hash)
|
44
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)
|
45
47
|
assert_not_equal(hash.keys, @twitter.get(:Users, key).keys)
|
46
48
|
end
|
47
49
|
|
48
50
|
def test_get_first_time_uuid_column
|
49
|
-
@blogs.insert(:Blogs, key,
|
51
|
+
@blogs.insert(:Blogs, key,
|
50
52
|
{@uuids[0] => 'I like this cat', @uuids[1] => 'Buttons is cuter', @uuids[2] => 'I disagree'})
|
51
|
-
|
53
|
+
|
52
54
|
assert_equal({@uuids[0] => 'I like this cat'}, @blogs.get(:Blogs, key, :count => 1))
|
53
55
|
assert_equal({@uuids[2] => 'I disagree'}, @blogs.get(:Blogs, key, :count => 1, :reversed => true))
|
54
56
|
assert_equal({}, @blogs.get(:Blogs, 'bogus'))
|
@@ -62,12 +64,15 @@ class CassandraTest < Test::Unit::TestCase
|
|
62
64
|
end
|
63
65
|
|
64
66
|
def test_get_first_long_column
|
65
|
-
@blogs_long.insert(:Blogs, key,
|
67
|
+
@blogs_long.insert(:Blogs, key,
|
66
68
|
{@longs[0] => 'I like this cat', @longs[1] => 'Buttons is cuter', @longs[2] => 'I disagree'})
|
67
69
|
|
68
70
|
assert_equal({@longs[0] => 'I like this cat'}, @blogs_long.get(:Blogs, key, :count => 1))
|
69
71
|
assert_equal({@longs[2] => 'I disagree'}, @blogs_long.get(:Blogs, key, :count => 1, :reversed => true))
|
70
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)
|
71
76
|
end
|
72
77
|
|
73
78
|
def test_long_remove_bug
|
@@ -77,12 +82,15 @@ class CassandraTest < Test::Unit::TestCase
|
|
77
82
|
|
78
83
|
@blogs_long.insert(:Blogs, key, {@longs[0] => 'I really like this cat'})
|
79
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)
|
80
86
|
end
|
81
87
|
|
82
88
|
def test_get_with_count
|
83
89
|
@twitter.insert(:Statuses, key, {'1' => 'v', '2' => 'v', '3' => 'v'})
|
84
90
|
assert_equal 1, @twitter.get(:Statuses, key, :count => 1).size
|
85
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
|
86
94
|
end
|
87
95
|
|
88
96
|
def test_get_value
|
@@ -94,10 +102,16 @@ class CassandraTest < Test::Unit::TestCase
|
|
94
102
|
assert !@twitter.exists?(:Statuses, 'bogus', 'body')
|
95
103
|
end
|
96
104
|
|
105
|
+
def test_exists_with_only_key
|
106
|
+
@twitter.insert(:Statuses, key, {'body' => 'v'})
|
107
|
+
assert @twitter.exists?(:Statuses, key)
|
108
|
+
end
|
109
|
+
|
97
110
|
def test_get_super_key
|
98
111
|
columns = {'user_timelines' => {@uuids[4] => '4', @uuids[5] => '5'}}
|
99
112
|
@twitter.insert(:StatusRelationships, key, columns)
|
100
113
|
assert_equal(columns, @twitter.get(:StatusRelationships, key))
|
114
|
+
assert_equal(columns.keys, @twitter.get(:StatusRelationships, key).timestamps.keys)
|
101
115
|
assert_equal({}, @twitter.get(:StatusRelationships, 'bogus'))
|
102
116
|
end
|
103
117
|
|
@@ -108,6 +122,7 @@ class CassandraTest < Test::Unit::TestCase
|
|
108
122
|
@twitter.insert(:StatusRelationships, key, columns)
|
109
123
|
|
110
124
|
assert_equal(columns, @twitter.get(:StatusRelationships, key))
|
125
|
+
assert_equal(columns.keys, @twitter.get(:StatusRelationships, key).timestamps.keys)
|
111
126
|
assert_equal({}, @twitter.get(:StatusRelationships, 'bogus'))
|
112
127
|
end
|
113
128
|
|
@@ -118,6 +133,10 @@ class CassandraTest < Test::Unit::TestCase
|
|
118
133
|
@twitter.get(:StatusRelationships, key, "user_timelines", :count => 1))
|
119
134
|
assert_equal({@uuids[3] => 'v3'},
|
120
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)
|
121
140
|
end
|
122
141
|
|
123
142
|
def test_get_super_sub_keys_with_ranges
|
@@ -134,12 +153,16 @@ class CassandraTest < Test::Unit::TestCase
|
|
134
153
|
assert_equal({@uuids[1] => 'v1'}, @twitter.get(:StatusRelationships, key, "user_timelines", :finish => @uuids[2], :count => 1))
|
135
154
|
assert_equal({@uuids[2] => 'v2'}, @twitter.get(:StatusRelationships, key, "user_timelines", :start => @uuids[2], :count => 1))
|
136
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
|
137
159
|
end
|
138
160
|
|
139
161
|
def test_get_super_sub_key
|
140
162
|
columns = {@uuids[1] => 'v1', @uuids[2] => 'v2'}
|
141
163
|
@twitter.insert(:StatusRelationships, key, {'user_timelines' => columns})
|
142
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)
|
143
166
|
assert_equal({}, @twitter.get(:StatusRelationships, 'bogus', 'user_timelines'))
|
144
167
|
# FIXME Not sure if this is valid
|
145
168
|
# assert_nil @twitter.exists?(:StatusRelationships, 'bogus', 'user_timelines')
|
@@ -163,6 +186,15 @@ class CassandraTest < Test::Unit::TestCase
|
|
163
186
|
# assert_equal(['3', '4', '5'], @twitter.get_range(:Statuses, :start => '3', :finish => '5'))
|
164
187
|
# end
|
165
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
|
+
|
166
198
|
def test_multi_get
|
167
199
|
@twitter.insert(:Users, key + '1', {'body' => 'v1', 'user' => 'v1'})
|
168
200
|
@twitter.insert(:Users, key + '2', {'body' => 'v2', 'user' => 'v2'})
|
@@ -171,11 +203,13 @@ class CassandraTest < Test::Unit::TestCase
|
|
171
203
|
result = @twitter.multi_get(:Users, [key + '1', key + '2', 'bogus'])
|
172
204
|
assert_equal expected, result
|
173
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
|
174
207
|
|
175
208
|
expected = OrderedHash[key + '2', {'body' => 'v2', 'user' => 'v2'}, 'bogus', {}, key + '1', {'body' => 'v1', 'user' => 'v1'}]
|
176
209
|
result = @twitter.multi_get(:Users, [key + '2', 'bogus', key + '1'])
|
177
210
|
assert_equal expected, result
|
178
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
|
179
213
|
end
|
180
214
|
|
181
215
|
def test_remove_key
|
@@ -190,6 +224,7 @@ class CassandraTest < Test::Unit::TestCase
|
|
190
224
|
@twitter.insert(:Statuses, key, {'body' => 'v'})
|
191
225
|
@twitter.remove(:Statuses, key, 'body')
|
192
226
|
assert_nil @twitter.get(:Statuses, key, 'body')
|
227
|
+
assert_nil @twitter.get(:Statuses, key).timestamps['body']
|
193
228
|
end
|
194
229
|
|
195
230
|
def test_remove_super_key
|
@@ -209,6 +244,7 @@ class CassandraTest < Test::Unit::TestCase
|
|
209
244
|
@twitter.insert(:StatusRelationships, key, {'user_timelines' => columns})
|
210
245
|
@twitter.remove(:StatusRelationships, key, 'user_timelines', columns.keys.first)
|
211
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]
|
212
248
|
end
|
213
249
|
|
214
250
|
def test_clear_column_family
|
@@ -222,12 +258,14 @@ class CassandraTest < Test::Unit::TestCase
|
|
222
258
|
def test_insert_key
|
223
259
|
@twitter.insert(:Statuses, key, {'body' => 'v', 'user' => 'v'})
|
224
260
|
assert_equal({'body' => 'v', 'user' => 'v'}, @twitter.get(:Statuses, key))
|
261
|
+
assert_equal(['body', 'user'], @twitter.get(:Statuses, key).timestamps.keys)
|
225
262
|
end
|
226
263
|
|
227
264
|
def test_insert_super_key
|
228
265
|
columns = {@uuids[1] => 'v1', @uuids[2] => 'v2'}
|
229
266
|
@twitter.insert(:StatusRelationships, key, {'user_timelines' => columns})
|
230
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)
|
231
269
|
end
|
232
270
|
|
233
271
|
def test_get_columns
|
@@ -259,6 +297,12 @@ class CassandraTest < Test::Unit::TestCase
|
|
259
297
|
assert_equal(
|
260
298
|
OrderedHash[key + '2', ['v2', 'v2'], 'bogus', [nil, nil], key + '1', ['v1', 'v1']],
|
261
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)
|
262
306
|
end
|
263
307
|
|
264
308
|
def test_count_keys
|
@@ -324,6 +368,11 @@ class CassandraTest < Test::Unit::TestCase
|
|
324
368
|
assert_equal({'body' => 'v4', 'user' => 'v4'}, @twitter.get(:Users, k + '4')) # Written
|
325
369
|
assert_equal({'body' => 'v'}, @twitter.get(:Statuses, k + '3')) # Written
|
326
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
|
327
376
|
end
|
328
377
|
|
329
378
|
def test_complain_about_nil_key
|
@@ -340,7 +389,7 @@ class CassandraTest < Test::Unit::TestCase
|
|
340
389
|
end
|
341
390
|
|
342
391
|
def test_nil_sub_column_value
|
343
|
-
@twitter.insert(:Index, 'asdf', {"thing" => {'jkl' =>
|
392
|
+
@twitter.insert(:Index, 'asdf', {"thing" => {'jkl' => ''} })
|
344
393
|
end
|
345
394
|
|
346
395
|
def test_disconnect!
|
@@ -348,6 +397,13 @@ class CassandraTest < Test::Unit::TestCase
|
|
348
397
|
assert_nil @twitter.instance_variable_get(:@client)
|
349
398
|
end
|
350
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
|
+
|
351
407
|
private
|
352
408
|
|
353
409
|
def key
|
data/test/ordered_hash_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
2
|
|
3
|
-
class
|
3
|
+
class OrderedHashTestInt < Test::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@keys = %w( blue green red pink orange )
|
6
6
|
@values = %w( 000099 009900 aa0000 cc0066 cc6633 )
|
@@ -152,7 +152,7 @@ class OrderedHashTest < Test::Unit::TestCase
|
|
152
152
|
assert_equal [@keys.first, @values.first], pair
|
153
153
|
assert !@ordered_hash.keys.include?(pair.first)
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
def test_keys
|
157
157
|
original = @ordered_hash.keys.dup
|
158
158
|
@ordered_hash.keys.pop
|
@@ -198,4 +198,183 @@ class OrderedHashTest < Test::Unit::TestCase
|
|
198
198
|
assert_same original, @ordered_hash
|
199
199
|
assert_equal @other_ordered_hash.keys, @ordered_hash.keys
|
200
200
|
end
|
201
|
-
end
|
201
|
+
end
|
202
|
+
|
203
|
+
class OrderedHashTest < Test::Unit::TestCase
|
204
|
+
def setup
|
205
|
+
@keys = %w( blue green red pink orange )
|
206
|
+
@values = %w( 000099 009900 aa0000 cc0066 cc6633 )
|
207
|
+
@timestamps = %w( 12 34 56 78 90 )
|
208
|
+
@hash = Hash.new
|
209
|
+
@timestamps_hash = Hash.new
|
210
|
+
@ordered_hash = Cassandra::OrderedHash.new
|
211
|
+
|
212
|
+
@keys.each_with_index do |key, index|
|
213
|
+
@hash[key] = @values[index]
|
214
|
+
@timestamps_hash[key] = @timestamps[index]
|
215
|
+
@ordered_hash.[]=(key, @values[index], @timestamps[index])
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_order
|
220
|
+
assert_equal @keys, @ordered_hash.keys
|
221
|
+
assert_equal @values, @ordered_hash.values
|
222
|
+
assert_equal @timestamps_hash, @ordered_hash.timestamps
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_access
|
226
|
+
assert @hash.all? { |k, v| @ordered_hash[k] == v }
|
227
|
+
assert @timestamps_hash.all? { |k, v| @ordered_hash.timestamps[k] == v }
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_assignment
|
231
|
+
key, value, timestamp = 'purple', '5422a8', '1234'
|
232
|
+
|
233
|
+
@ordered_hash.[]=(key, value, timestamp)
|
234
|
+
|
235
|
+
assert_equal @keys.length + 1, @ordered_hash.length
|
236
|
+
assert_equal key, @ordered_hash.keys.last
|
237
|
+
assert_equal value, @ordered_hash.values.last
|
238
|
+
assert_equal value, @ordered_hash[key]
|
239
|
+
|
240
|
+
assert_equal @keys.length + 1, @ordered_hash.timestamps.length
|
241
|
+
assert_equal key, @ordered_hash.timestamps.keys.last
|
242
|
+
assert_equal timestamp, @ordered_hash.timestamps.values.last
|
243
|
+
assert_equal timestamp, @ordered_hash.timestamps[key]
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_delete
|
247
|
+
key, value, timestamp = 'white', 'ffffff', '999'
|
248
|
+
bad_key = 'black'
|
249
|
+
|
250
|
+
@ordered_hash.[]=(key, value, timestamp)
|
251
|
+
assert_equal @keys.length + 1, @ordered_hash.length
|
252
|
+
assert_equal @ordered_hash.keys.length, @ordered_hash.length
|
253
|
+
|
254
|
+
assert_equal value, @ordered_hash.delete(key)
|
255
|
+
assert_equal @keys.length, @ordered_hash.length
|
256
|
+
assert_equal @ordered_hash.keys.length, @ordered_hash.length
|
257
|
+
|
258
|
+
assert_nil @ordered_hash.delete(bad_key)
|
259
|
+
|
260
|
+
@ordered_hash.[]=(key, value, timestamp)
|
261
|
+
assert_equal @keys.length + 1, @ordered_hash.timestamps.length
|
262
|
+
assert_equal @ordered_hash.keys.length, @ordered_hash.timestamps.length
|
263
|
+
|
264
|
+
assert_equal value, @ordered_hash.delete(key)
|
265
|
+
assert_equal @keys.length, @ordered_hash.timestamps.length
|
266
|
+
assert_equal @ordered_hash.keys.length, @ordered_hash.timestamps.length
|
267
|
+
|
268
|
+
assert_nil @ordered_hash.delete(bad_key)
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_to_a
|
272
|
+
assert_equal @keys.zip(@timestamps).sort, @ordered_hash.timestamps.sort.to_a
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_has_key
|
276
|
+
assert_equal true, @ordered_hash.timestamps.has_key?('blue')
|
277
|
+
assert_equal true, @ordered_hash.timestamps.key?('blue')
|
278
|
+
assert_equal true, @ordered_hash.timestamps.include?('blue')
|
279
|
+
assert_equal true, @ordered_hash.timestamps.member?('blue')
|
280
|
+
|
281
|
+
assert_equal false, @ordered_hash.timestamps.has_key?('indigo')
|
282
|
+
assert_equal false, @ordered_hash.timestamps.key?('indigo')
|
283
|
+
assert_equal false, @ordered_hash.timestamps.include?('indigo')
|
284
|
+
assert_equal false, @ordered_hash.timestamps.member?('indigo')
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_has_value
|
288
|
+
assert_equal true, @ordered_hash.timestamps.has_value?('12')
|
289
|
+
assert_equal true, @ordered_hash.timestamps.value?('12')
|
290
|
+
assert_equal false, @ordered_hash.timestamps.has_value?('99')
|
291
|
+
assert_equal false, @ordered_hash.timestamps.value?('99')
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_each_key
|
295
|
+
keys = []
|
296
|
+
@ordered_hash.timestamps.each_key { |k| keys << k }
|
297
|
+
assert_equal @keys.sort, keys.sort
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_each_value
|
301
|
+
values = []
|
302
|
+
@ordered_hash.timestamps.each_value { |v| values << v }
|
303
|
+
assert_equal @timestamps.sort, values.sort
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_each
|
307
|
+
values = []
|
308
|
+
@ordered_hash.timestamps.each {|key, value| values << value}
|
309
|
+
assert_equal @timestamps.sort, values.sort
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_delete_if
|
313
|
+
copy = @ordered_hash.dup
|
314
|
+
copy.delete('pink')
|
315
|
+
assert_equal copy, @ordered_hash.delete_if { |k, _| k == 'pink' }
|
316
|
+
assert !@ordered_hash.timestamps.keys.include?('pink')
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_reject!
|
320
|
+
(copy = @ordered_hash.dup).delete('pink')
|
321
|
+
@ordered_hash.reject! { |k, _| k == 'pink' }
|
322
|
+
assert_equal copy, @ordered_hash
|
323
|
+
assert !@ordered_hash.keys.include?('pink')
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_reject
|
327
|
+
copy = @ordered_hash.dup
|
328
|
+
new_ordered_hash = @ordered_hash.reject { |k, _| k == 'pink' }
|
329
|
+
assert_equal copy, @ordered_hash
|
330
|
+
assert !new_ordered_hash.timestamps.keys.include?('pink')
|
331
|
+
assert @ordered_hash.timestamps.keys.include?('pink')
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_clear
|
335
|
+
@ordered_hash.clear
|
336
|
+
assert_equal [], @ordered_hash.timestamps.keys
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_merge
|
340
|
+
other_hash = Cassandra::OrderedHash.new
|
341
|
+
other_hash['purple'] = '800080'
|
342
|
+
other_hash['violet'] = 'ee82ee'
|
343
|
+
merged = @ordered_hash.merge other_hash
|
344
|
+
assert_equal merged.timestamps.length, @ordered_hash.timestamps.length + other_hash.timestamps.length
|
345
|
+
assert_equal (@keys + ['purple', 'violet']).sort, merged.timestamps.keys.sort
|
346
|
+
|
347
|
+
@ordered_hash.merge! other_hash
|
348
|
+
assert_equal @ordered_hash.timestamps, merged.timestamps
|
349
|
+
assert_equal @ordered_hash.timestamps.keys.sort, merged.timestamps.keys.sort
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_shift
|
353
|
+
pair = @ordered_hash.shift
|
354
|
+
assert_equal [@keys.first, @values.first], pair
|
355
|
+
assert !@ordered_hash.timestamps.keys.include?(pair.first)
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_keys
|
359
|
+
original = @ordered_hash.keys.dup
|
360
|
+
@ordered_hash.keys.pop
|
361
|
+
assert_equal original.sort, @ordered_hash.timestamps.keys.sort
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_inspect
|
365
|
+
assert @ordered_hash.timestamps.sort.inspect.include?(@timestamps_hash.sort.inspect)
|
366
|
+
end
|
367
|
+
|
368
|
+
def test_alternate_initialization_with_splat
|
369
|
+
alternate = Cassandra::OrderedHash[1,2,3,4]
|
370
|
+
assert_kind_of Cassandra::OrderedHash, alternate
|
371
|
+
assert_equal [1, 3], alternate.timestamps.keys
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_replace_updates_keys
|
375
|
+
@other_ordered_hash = Cassandra::OrderedHash[:black, '000000', :white, '000000']
|
376
|
+
original = @ordered_hash.replace(@other_ordered_hash)
|
377
|
+
assert_equal original.timestamps, @ordered_hash.timestamps
|
378
|
+
assert_equal @other_ordered_hash.timestamps.keys, @ordered_hash.timestamps.keys
|
379
|
+
end
|
380
|
+
end
|