cassandra-mavericks 0.21.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGELOG +150 -0
- data/Gemfile +7 -0
- data/LICENSE +202 -0
- data/Manifest +94 -0
- data/README.md +373 -0
- data/Rakefile +191 -0
- data/bin/cassandra_helper +16 -0
- data/cassandra.gemspec +29 -0
- data/conf/0.6/cassandra.in.sh +47 -0
- data/conf/0.6/log4j.properties +38 -0
- data/conf/0.6/schema.json +57 -0
- data/conf/0.6/storage-conf.xml +352 -0
- data/conf/0.7/cassandra.in.sh +46 -0
- data/conf/0.7/cassandra.yaml +336 -0
- data/conf/0.7/log4j-server.properties +41 -0
- data/conf/0.7/schema.json +57 -0
- data/conf/0.7/schema.txt +45 -0
- data/conf/0.8/cassandra.in.sh +41 -0
- data/conf/0.8/cassandra.yaml +61 -0
- data/conf/0.8/log4j-server.properties +40 -0
- data/conf/0.8/schema.json +72 -0
- data/conf/0.8/schema.txt +57 -0
- data/conf/1.0/cassandra.in.sh +41 -0
- data/conf/1.0/cassandra.yaml +415 -0
- data/conf/1.0/log4j-server.properties +40 -0
- data/conf/1.0/schema.json +72 -0
- data/conf/1.0/schema.txt +57 -0
- data/conf/1.1/cassandra.in.sh +41 -0
- data/conf/1.1/cassandra.yaml +567 -0
- data/conf/1.1/log4j-server.properties +44 -0
- data/conf/1.1/schema.json +72 -0
- data/conf/1.1/schema.txt +57 -0
- data/conf/1.2/cassandra.in.sh +41 -0
- data/conf/1.2/cassandra.yaml +643 -0
- data/conf/1.2/log4j-server.properties +44 -0
- data/conf/1.2/schema.json +72 -0
- data/conf/1.2/schema.txt +57 -0
- data/ext/cassandra_native.c +69 -0
- data/ext/extconf.rb +9 -0
- data/lib/cassandra.rb +47 -0
- data/lib/cassandra/0.6.rb +7 -0
- data/lib/cassandra/0.6/cassandra.rb +113 -0
- data/lib/cassandra/0.6/columns.rb +78 -0
- data/lib/cassandra/0.6/protocol.rb +91 -0
- data/lib/cassandra/0.7.rb +7 -0
- data/lib/cassandra/0.7/cassandra.rb +2 -0
- data/lib/cassandra/0.7/columns.rb +4 -0
- data/lib/cassandra/0.7/protocol.rb +5 -0
- data/lib/cassandra/0.8.rb +7 -0
- data/lib/cassandra/0.8/cassandra.rb +25 -0
- data/lib/cassandra/0.8/columns.rb +28 -0
- data/lib/cassandra/0.8/protocol.rb +10 -0
- data/lib/cassandra/1.0.rb +7 -0
- data/lib/cassandra/1.0/cassandra.rb +1 -0
- data/lib/cassandra/1.0/columns.rb +1 -0
- data/lib/cassandra/1.0/protocol.rb +1 -0
- data/lib/cassandra/1.1.rb +7 -0
- data/lib/cassandra/1.1/cassandra.rb +1 -0
- data/lib/cassandra/1.1/columns.rb +1 -0
- data/lib/cassandra/1.1/protocol.rb +1 -0
- data/lib/cassandra/1.2.rb +7 -0
- data/lib/cassandra/1.2/cassandra.rb +1 -0
- data/lib/cassandra/1.2/columns.rb +1 -0
- data/lib/cassandra/1.2/protocol.rb +1 -0
- data/lib/cassandra/array.rb +8 -0
- data/lib/cassandra/batch.rb +41 -0
- data/lib/cassandra/cassandra.rb +1091 -0
- data/lib/cassandra/column_family.rb +3 -0
- data/lib/cassandra/columns.rb +172 -0
- data/lib/cassandra/comparable.rb +28 -0
- data/lib/cassandra/composite.rb +137 -0
- data/lib/cassandra/constants.rb +11 -0
- data/lib/cassandra/debug.rb +9 -0
- data/lib/cassandra/dynamic_composite.rb +118 -0
- data/lib/cassandra/helpers.rb +41 -0
- data/lib/cassandra/keyspace.rb +3 -0
- data/lib/cassandra/long.rb +58 -0
- data/lib/cassandra/mock.rb +536 -0
- data/lib/cassandra/ordered_hash.rb +195 -0
- data/lib/cassandra/protocol.rb +137 -0
- data/lib/cassandra/time.rb +11 -0
- data/test/cassandra_client_test.rb +20 -0
- data/test/cassandra_mock_test.rb +128 -0
- data/test/cassandra_test.rb +1367 -0
- data/test/comparable_types_test.rb +45 -0
- data/test/composite_type_test.rb +86 -0
- data/test/eventmachine_test.rb +42 -0
- data/test/ordered_hash_test.rb +386 -0
- data/test/test_helper.rb +19 -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 +1936 -0
- data/vendor/0.7/gen-rb/cassandra_constants.rb +12 -0
- data/vendor/0.7/gen-rb/cassandra_types.rb +681 -0
- data/vendor/0.8/gen-rb/cassandra.rb +2215 -0
- data/vendor/0.8/gen-rb/cassandra_constants.rb +12 -0
- data/vendor/0.8/gen-rb/cassandra_types.rb +824 -0
- data/vendor/1.0/gen-rb/cassandra.rb +2215 -0
- data/vendor/1.0/gen-rb/cassandra_constants.rb +12 -0
- data/vendor/1.0/gen-rb/cassandra_types.rb +857 -0
- data/vendor/1.1/gen-rb/cassandra.rb +2571 -0
- data/vendor/1.1/gen-rb/cassandra_constants.rb +12 -0
- data/vendor/1.1/gen-rb/cassandra_types.rb +928 -0
- data/vendor/1.2/gen-rb/cassandra.rb +3013 -0
- data/vendor/1.2/gen-rb/cassandra_constants.rb +13 -0
- data/vendor/1.2/gen-rb/cassandra_types.rb +965 -0
- metadata +288 -0
@@ -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,86 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class CompositeTypesTest < Test::Unit::TestCase
|
4
|
+
include Cassandra::Constants
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@col_parts = [[363].pack('N'), 'extradites-mulling', SimpleUUID::UUID.new().bytes]
|
8
|
+
@col = Cassandra::Composite.new(*@col_parts)
|
9
|
+
|
10
|
+
@part0_length = 2 + 4 + 1 # size + int + end_term
|
11
|
+
@part1_length = 2 + @col_parts[1].length + 1 # size + string_len + end_term
|
12
|
+
@part2_length = 2 + @col_parts[2].length + 1 # size + uuid_bytes + end_term
|
13
|
+
|
14
|
+
@types = ['IntegerType', 'UTF8Type', 'TimeUUIDType']
|
15
|
+
@type_aliaes = ['i', 's', 't']
|
16
|
+
|
17
|
+
@dycol = Cassandra::DynamicComposite.new(*@types.zip(@col_parts))
|
18
|
+
@dycol_alias = Cassandra::DynamicComposite.new(*@type_aliaes.zip(@col_parts))
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_creation_from_parts
|
22
|
+
(0..2).each do |i|
|
23
|
+
assert_equal(@col_parts[i], @col[i])
|
24
|
+
assert_equal(@col_parts[i], @dycol[i])
|
25
|
+
assert_equal(@col_parts[i], @dycol_alias[i])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_packing_and_unpacking
|
30
|
+
assert_equal(@part0_length + @part1_length + @part2_length, @col.pack.length)
|
31
|
+
|
32
|
+
col2 = Cassandra::Composite.new_from_packed(@col.pack)
|
33
|
+
assert_equal(@col_parts[0], col2[0])
|
34
|
+
assert_equal(@col_parts[1], col2[1])
|
35
|
+
assert_equal(@col_parts[2], col2[2])
|
36
|
+
assert_equal(@col, col2)
|
37
|
+
# make sure we set this while we have the packed string handy
|
38
|
+
assert_equal(@col.pack.hash, col2.instance_variable_get(:@hash))
|
39
|
+
|
40
|
+
col2 = Cassandra::Composite.new(@col.pack)
|
41
|
+
assert_equal(@col_parts[0], col2[0])
|
42
|
+
assert_equal(@col_parts[1], col2[1])
|
43
|
+
assert_equal(@col_parts[2], col2[2])
|
44
|
+
assert_equal(@col, col2)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_packing_and_unpacking_dynamic_columns
|
48
|
+
part0_length = @part0_length + 2 + @types[0].length
|
49
|
+
part1_length = @part1_length + 2 + @types[1].length
|
50
|
+
part2_length = @part2_length + 2 + @types[2].length
|
51
|
+
assert_equal(part0_length + part1_length + part2_length, @dycol.pack.length)
|
52
|
+
|
53
|
+
col2 = Cassandra::DynamicComposite.new_from_packed(@dycol.pack)
|
54
|
+
assert_equal(@col_parts[0], col2[0])
|
55
|
+
assert_equal(@col_parts[1], col2[1])
|
56
|
+
assert_equal(@col_parts[2], col2[2])
|
57
|
+
assert_equal(@dycol, col2)
|
58
|
+
# make sure we set this while we have the packed string handy
|
59
|
+
assert_equal(@dycol.pack.hash, col2.instance_variable_get(:@hash))
|
60
|
+
|
61
|
+
col2 = Cassandra::DynamicComposite.new(@dycol.pack)
|
62
|
+
assert_equal(@col_parts[0], col2[0])
|
63
|
+
assert_equal(@col_parts[1], col2[1])
|
64
|
+
assert_equal(@col_parts[2], col2[2])
|
65
|
+
assert_equal(@dycol, col2)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_packing_and_unpacking_dynamic_columns_with_aliases
|
69
|
+
part0_length = @part0_length + 2
|
70
|
+
part1_length = @part1_length + 2
|
71
|
+
part2_length = @part2_length + 2
|
72
|
+
assert_equal(part0_length + part1_length + part2_length, @dycol_alias.pack.length)
|
73
|
+
|
74
|
+
col2 = Cassandra::DynamicComposite.new_from_packed(@dycol_alias.pack)
|
75
|
+
assert_equal(@col_parts[0], col2[0])
|
76
|
+
assert_equal(@col_parts[1], col2[1])
|
77
|
+
assert_equal(@col_parts[2], col2[2])
|
78
|
+
assert_equal(@dycol_alias, col2)
|
79
|
+
|
80
|
+
col2 = Cassandra::DynamicComposite.new(@dycol_alias.pack)
|
81
|
+
assert_equal(@col_parts[0], col2[0])
|
82
|
+
assert_equal(@col_parts[1], col2[1])
|
83
|
+
assert_equal(@col_parts[2], col2[2])
|
84
|
+
assert_equal(@dycol_alias, col2)
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
if RUBY_VERSION < '1.9' || CASSANDRA_VERSION == '0.6'
|
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
|
@@ -0,0 +1,386 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class OrderedHashTestInt < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@keys = %w( blue green red pink orange )
|
6
|
+
@values = %w( 000099 009900 aa0000 cc0066 cc6633 )
|
7
|
+
@hash = Hash.new
|
8
|
+
@ordered_hash = Cassandra::OrderedHash.new
|
9
|
+
|
10
|
+
@keys.each_with_index do |key, index|
|
11
|
+
@hash[key] = @values[index]
|
12
|
+
@ordered_hash[key] = @values[index]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_order
|
17
|
+
assert_equal @keys, @ordered_hash.keys
|
18
|
+
assert_equal @values, @ordered_hash.values
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_access
|
22
|
+
assert @hash.all? { |k, v| @ordered_hash[k] == v }
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_assignment
|
26
|
+
key, value = 'purple', '5422a8'
|
27
|
+
|
28
|
+
@ordered_hash[key] = value
|
29
|
+
assert_equal @keys.length + 1, @ordered_hash.length
|
30
|
+
assert_equal key, @ordered_hash.keys.last
|
31
|
+
assert_equal value, @ordered_hash.values.last
|
32
|
+
assert_equal value, @ordered_hash[key]
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_delete
|
36
|
+
key, value = 'white', 'ffffff'
|
37
|
+
bad_key = 'black'
|
38
|
+
|
39
|
+
@ordered_hash[key] = value
|
40
|
+
assert_equal @keys.length + 1, @ordered_hash.length
|
41
|
+
assert_equal @ordered_hash.keys.length, @ordered_hash.length
|
42
|
+
|
43
|
+
assert_equal value, @ordered_hash.delete(key)
|
44
|
+
assert_equal @keys.length, @ordered_hash.length
|
45
|
+
assert_equal @ordered_hash.keys.length, @ordered_hash.length
|
46
|
+
|
47
|
+
assert_nil @ordered_hash.delete(bad_key)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_to_hash
|
51
|
+
assert_same @ordered_hash, @ordered_hash.to_hash
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_to_a
|
55
|
+
assert_equal @keys.zip(@values), @ordered_hash.to_a
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_has_key
|
59
|
+
assert_equal true, @ordered_hash.has_key?('blue')
|
60
|
+
assert_equal true, @ordered_hash.key?('blue')
|
61
|
+
assert_equal true, @ordered_hash.include?('blue')
|
62
|
+
assert_equal true, @ordered_hash.member?('blue')
|
63
|
+
|
64
|
+
assert_equal false, @ordered_hash.has_key?('indigo')
|
65
|
+
assert_equal false, @ordered_hash.key?('indigo')
|
66
|
+
assert_equal false, @ordered_hash.include?('indigo')
|
67
|
+
assert_equal false, @ordered_hash.member?('indigo')
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_has_value
|
71
|
+
assert_equal true, @ordered_hash.has_value?('000099')
|
72
|
+
assert_equal true, @ordered_hash.value?('000099')
|
73
|
+
assert_equal false, @ordered_hash.has_value?('ABCABC')
|
74
|
+
assert_equal false, @ordered_hash.value?('ABCABC')
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_each_key
|
78
|
+
keys = []
|
79
|
+
@ordered_hash.each_key { |k| keys << k }
|
80
|
+
assert_equal @keys, keys
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_each_value
|
84
|
+
values = []
|
85
|
+
@ordered_hash.each_value { |v| values << v }
|
86
|
+
assert_equal @values, values
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_each
|
90
|
+
values = []
|
91
|
+
@ordered_hash.each {|key, value| values << value}
|
92
|
+
assert_equal @values, values
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_each_with_index
|
96
|
+
@ordered_hash.each_with_index { |pair, index| assert_equal [@keys[index], @values[index]], pair}
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_each_pair
|
100
|
+
values = []
|
101
|
+
keys = []
|
102
|
+
@ordered_hash.each_pair do |key, value|
|
103
|
+
keys << key
|
104
|
+
values << value
|
105
|
+
end
|
106
|
+
assert_equal @values, values
|
107
|
+
assert_equal @keys, keys
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_delete_if
|
111
|
+
copy = @ordered_hash.dup
|
112
|
+
copy.delete('pink')
|
113
|
+
assert_equal copy, @ordered_hash.delete_if { |k, _| k == 'pink' }
|
114
|
+
assert !@ordered_hash.keys.include?('pink')
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_reject!
|
118
|
+
(copy = @ordered_hash.dup).delete('pink')
|
119
|
+
@ordered_hash.reject! { |k, _| k == 'pink' }
|
120
|
+
assert_equal copy, @ordered_hash
|
121
|
+
assert !@ordered_hash.keys.include?('pink')
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_reject
|
125
|
+
copy = @ordered_hash.dup
|
126
|
+
new_ordered_hash = @ordered_hash.reject { |k, _| k == 'pink' }
|
127
|
+
assert_equal copy, @ordered_hash
|
128
|
+
assert !new_ordered_hash.keys.include?('pink')
|
129
|
+
assert @ordered_hash.keys.include?('pink')
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_clear
|
133
|
+
@ordered_hash.clear
|
134
|
+
assert_equal [], @ordered_hash.keys
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_merge
|
138
|
+
other_hash = Cassandra::OrderedHash.new
|
139
|
+
other_hash['purple'] = '800080'
|
140
|
+
other_hash['violet'] = 'ee82ee'
|
141
|
+
merged = @ordered_hash.merge other_hash
|
142
|
+
assert_equal merged.length, @ordered_hash.length + other_hash.length
|
143
|
+
assert_equal @keys + ['purple', 'violet'], merged.keys
|
144
|
+
|
145
|
+
@ordered_hash.merge! other_hash
|
146
|
+
assert_equal @ordered_hash, merged
|
147
|
+
assert_equal @ordered_hash.keys, merged.keys
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_shift
|
151
|
+
pair = @ordered_hash.shift
|
152
|
+
assert_equal [@keys.first, @values.first], pair
|
153
|
+
assert !@ordered_hash.keys.include?(pair.first)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_keys
|
157
|
+
original = @ordered_hash.keys.dup
|
158
|
+
@ordered_hash.keys.pop
|
159
|
+
assert_equal original, @ordered_hash.keys
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_inspect
|
163
|
+
assert @ordered_hash.inspect.include?(@hash.inspect)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_alternate_initialization_with_splat
|
167
|
+
alternate = Cassandra::OrderedHash[1,2,3,4]
|
168
|
+
assert_kind_of Cassandra::OrderedHash, alternate
|
169
|
+
assert_equal [1, 3], alternate.keys
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_alternate_initialization_with_array
|
173
|
+
alternate = Cassandra::OrderedHash[ [
|
174
|
+
[1, 2],
|
175
|
+
[3, 4],
|
176
|
+
"bad key value pair",
|
177
|
+
[ 'missing value' ]
|
178
|
+
]]
|
179
|
+
|
180
|
+
assert_kind_of Cassandra::OrderedHash, alternate
|
181
|
+
assert_equal [1, 3, 'missing value'], alternate.keys
|
182
|
+
assert_equal [2, 4, nil ], alternate.values
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_alternate_initialization_raises_exception_on_odd_length_args
|
186
|
+
begin
|
187
|
+
alternate = Cassandra::OrderedHash[1,2,3,4,5]
|
188
|
+
flunk "Hash::[] should have raised an exception on initialization " +
|
189
|
+
"with an odd number of parameters"
|
190
|
+
rescue
|
191
|
+
assert_equal "odd number of arguments for Hash", $!.message
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_replace_updates_keys
|
196
|
+
@other_ordered_hash = Cassandra::OrderedHash[:black, '000000', :white, '000000']
|
197
|
+
original = @ordered_hash.replace(@other_ordered_hash)
|
198
|
+
assert_same original, @ordered_hash
|
199
|
+
assert_equal @other_ordered_hash.keys, @ordered_hash.keys
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_reverse
|
203
|
+
assert_equal @keys.reverse, @ordered_hash.reverse.keys
|
204
|
+
assert_equal @values.reverse, @ordered_hash.reverse.values
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
class OrderedHashTest < Test::Unit::TestCase
|
209
|
+
def setup
|
210
|
+
@keys = %w( blue green red pink orange )
|
211
|
+
@values = %w( 000099 009900 aa0000 cc0066 cc6633 )
|
212
|
+
@timestamps = %w( 12 34 56 78 90 )
|
213
|
+
@hash = Hash.new
|
214
|
+
@timestamps_hash = Hash.new
|
215
|
+
@ordered_hash = Cassandra::OrderedHash.new
|
216
|
+
|
217
|
+
@keys.each_with_index do |key, index|
|
218
|
+
@hash[key] = @values[index]
|
219
|
+
@timestamps_hash[key] = @timestamps[index]
|
220
|
+
@ordered_hash.[]=(key, @values[index], @timestamps[index])
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_order
|
225
|
+
assert_equal @keys, @ordered_hash.keys
|
226
|
+
assert_equal @values, @ordered_hash.values
|
227
|
+
assert_equal @timestamps_hash, @ordered_hash.timestamps
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_access
|
231
|
+
assert @hash.all? { |k, v| @ordered_hash[k] == v }
|
232
|
+
assert @timestamps_hash.all? { |k, v| @ordered_hash.timestamps[k] == v }
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_assignment
|
236
|
+
key, value, timestamp = 'purple', '5422a8', '1234'
|
237
|
+
|
238
|
+
@ordered_hash.[]=(key, value, timestamp)
|
239
|
+
|
240
|
+
assert_equal @keys.length + 1, @ordered_hash.length
|
241
|
+
assert_equal key, @ordered_hash.keys.last
|
242
|
+
assert_equal value, @ordered_hash.values.last
|
243
|
+
assert_equal value, @ordered_hash[key]
|
244
|
+
|
245
|
+
assert_equal @keys.length + 1, @ordered_hash.timestamps.length
|
246
|
+
assert_equal key, @ordered_hash.timestamps.keys.last
|
247
|
+
assert_equal timestamp, @ordered_hash.timestamps.values.last
|
248
|
+
assert_equal timestamp, @ordered_hash.timestamps[key]
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_delete
|
252
|
+
key, value, timestamp = 'white', 'ffffff', '999'
|
253
|
+
bad_key = 'black'
|
254
|
+
|
255
|
+
@ordered_hash.[]=(key, value, timestamp)
|
256
|
+
assert_equal @keys.length + 1, @ordered_hash.length
|
257
|
+
assert_equal @ordered_hash.keys.length, @ordered_hash.length
|
258
|
+
|
259
|
+
assert_equal value, @ordered_hash.delete(key)
|
260
|
+
assert_equal @keys.length, @ordered_hash.length
|
261
|
+
assert_equal @ordered_hash.keys.length, @ordered_hash.length
|
262
|
+
|
263
|
+
assert_nil @ordered_hash.delete(bad_key)
|
264
|
+
|
265
|
+
@ordered_hash.[]=(key, value, timestamp)
|
266
|
+
assert_equal @keys.length + 1, @ordered_hash.timestamps.length
|
267
|
+
assert_equal @ordered_hash.keys.length, @ordered_hash.timestamps.length
|
268
|
+
|
269
|
+
assert_equal value, @ordered_hash.delete(key)
|
270
|
+
assert_equal @keys.length, @ordered_hash.timestamps.length
|
271
|
+
assert_equal @ordered_hash.keys.length, @ordered_hash.timestamps.length
|
272
|
+
|
273
|
+
assert_nil @ordered_hash.delete(bad_key)
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_to_a
|
277
|
+
assert_equal @keys.zip(@timestamps).sort, @ordered_hash.timestamps.sort.to_a
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_has_key
|
281
|
+
assert_equal true, @ordered_hash.timestamps.has_key?('blue')
|
282
|
+
assert_equal true, @ordered_hash.timestamps.key?('blue')
|
283
|
+
assert_equal true, @ordered_hash.timestamps.include?('blue')
|
284
|
+
assert_equal true, @ordered_hash.timestamps.member?('blue')
|
285
|
+
|
286
|
+
assert_equal false, @ordered_hash.timestamps.has_key?('indigo')
|
287
|
+
assert_equal false, @ordered_hash.timestamps.key?('indigo')
|
288
|
+
assert_equal false, @ordered_hash.timestamps.include?('indigo')
|
289
|
+
assert_equal false, @ordered_hash.timestamps.member?('indigo')
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_has_value
|
293
|
+
assert_equal true, @ordered_hash.timestamps.has_value?('12')
|
294
|
+
assert_equal true, @ordered_hash.timestamps.value?('12')
|
295
|
+
assert_equal false, @ordered_hash.timestamps.has_value?('99')
|
296
|
+
assert_equal false, @ordered_hash.timestamps.value?('99')
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_each_key
|
300
|
+
keys = []
|
301
|
+
@ordered_hash.timestamps.each_key { |k| keys << k }
|
302
|
+
assert_equal @keys.sort, keys.sort
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_each_value
|
306
|
+
values = []
|
307
|
+
@ordered_hash.timestamps.each_value { |v| values << v }
|
308
|
+
assert_equal @timestamps.sort, values.sort
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_each
|
312
|
+
values = []
|
313
|
+
@ordered_hash.timestamps.each {|key, value| values << value}
|
314
|
+
assert_equal @timestamps.sort, values.sort
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_delete_if
|
318
|
+
copy = @ordered_hash.dup
|
319
|
+
copy.delete('pink')
|
320
|
+
assert_equal copy, @ordered_hash.delete_if { |k, _| k == 'pink' }
|
321
|
+
assert !@ordered_hash.timestamps.keys.include?('pink')
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_reject!
|
325
|
+
(copy = @ordered_hash.dup).delete('pink')
|
326
|
+
@ordered_hash.reject! { |k, _| k == 'pink' }
|
327
|
+
assert_equal copy, @ordered_hash
|
328
|
+
assert !@ordered_hash.keys.include?('pink')
|
329
|
+
assert !@ordered_hash.timestamps.keys.include?('pink')
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_reject
|
333
|
+
copy = @ordered_hash.dup
|
334
|
+
new_ordered_hash = @ordered_hash.reject { |k, _| k == 'pink' }
|
335
|
+
assert_equal copy, @ordered_hash
|
336
|
+
assert !new_ordered_hash.timestamps.keys.include?('pink')
|
337
|
+
assert @ordered_hash.timestamps.keys.include?('pink')
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_clear
|
341
|
+
@ordered_hash.clear
|
342
|
+
assert_equal [], @ordered_hash.timestamps.keys
|
343
|
+
end
|
344
|
+
|
345
|
+
def test_merge
|
346
|
+
other_hash = Cassandra::OrderedHash.new
|
347
|
+
other_hash['purple'] = '800080'
|
348
|
+
other_hash['violet'] = 'ee82ee'
|
349
|
+
merged = @ordered_hash.merge other_hash
|
350
|
+
assert_equal merged.timestamps.length, @ordered_hash.timestamps.length + other_hash.timestamps.length
|
351
|
+
assert_equal (@keys + ['purple', 'violet']).sort, merged.timestamps.keys.sort
|
352
|
+
|
353
|
+
@ordered_hash.merge! other_hash
|
354
|
+
assert_equal @ordered_hash.timestamps, merged.timestamps
|
355
|
+
assert_equal @ordered_hash.timestamps.keys.sort, merged.timestamps.keys.sort
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_shift
|
359
|
+
pair = @ordered_hash.shift
|
360
|
+
assert_equal [@keys.first, @values.first], pair
|
361
|
+
assert !@ordered_hash.timestamps.keys.include?(pair.first)
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_keys
|
365
|
+
original = @ordered_hash.keys.dup
|
366
|
+
@ordered_hash.keys.pop
|
367
|
+
assert_equal original.sort, @ordered_hash.timestamps.keys.sort
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_inspect
|
371
|
+
assert @ordered_hash.timestamps.sort.inspect.include?(@timestamps_hash.sort.inspect)
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_alternate_initialization_with_splat
|
375
|
+
alternate = Cassandra::OrderedHash[1,2,3,4]
|
376
|
+
assert_kind_of Cassandra::OrderedHash, alternate
|
377
|
+
assert_equal [1, 3], alternate.timestamps.keys
|
378
|
+
end
|
379
|
+
|
380
|
+
def test_replace_updates_keys
|
381
|
+
@other_ordered_hash = Cassandra::OrderedHash[:black, '000000', :white, '000000']
|
382
|
+
original = @ordered_hash.replace(@other_ordered_hash)
|
383
|
+
assert_equal original.timestamps, @ordered_hash.timestamps
|
384
|
+
assert_equal @other_ordered_hash.timestamps.keys, @ordered_hash.timestamps.keys
|
385
|
+
end
|
386
|
+
end
|