Permalink
Browse files

some refactoring and bugfixing to make the mock work with the twitter…

… codebase
  • Loading branch information...
1 parent c2dc984 commit 1d5a44f7769f476773b2631be1d51f9f10b1cddb @ryanking ryanking committed Mar 1, 2010
Showing with 31 additions and 12 deletions.
  1. +28 −9 lib/cassandra/mock.rb
  2. +3 −3 test/cassandra_mock_test.rb
View
@@ -132,15 +132,16 @@ def exists?(column_family, key, column=nil)
!!get(column_family, key, column)
end
- def multi_get(column_family, keys, options)
+ def multi_get(column_family, keys, *columns_and_options)
+ column_family, column, sub_column, options = extract_and_validate_params_for_real(column_family, keys, columns_and_options, READ_DEFAULTS)
keys.inject(OrderedHash.new) do |hash, key|
hash[key] = get(column_family, key)
hash
end
end
def remove(column_family, key, *columns_and_options)
- column_family, column, sub_column, options = extract_and_validate_params(column_family, key, columns_and_options, WRITE_DEFAULTS)
+ column_family, column, sub_column, options = extract_and_validate_params_for_real(column_family, key, columns_and_options, WRITE_DEFAULTS)
if @batch
@batch << [:remove, column_family, key, column]
else
@@ -156,10 +157,19 @@ def remove(column_family, key, *columns_and_options)
end
end
- def get_columns(column_family, key, columns)
+ def get_columns(column_family, key, *columns_and_options)
+ column_family, columns, sub_columns, options = extract_and_validate_params_for_real(column_family, key, columns_and_options, READ_DEFAULTS)
d = get(column_family, key)
- columns.collect do |column|
- d[column]
+
+
+ if sub_columns
+ sub_columns.collect do |sub_column|
+ d[columns][sub_column]
+ end
+ else
+ columns.collect do |column|
+ d[column]
+ end
end
end
@@ -182,8 +192,7 @@ def multi_count_columns(column_family, keys)
end
def get_range(column_family, options = {})
- column_family, _, _, options =
- extract_and_validate_params_for_real(column_family, "", [options], READ_DEFAULTS)
+ column_family, _, _, options = extract_and_validate_params_for_real(column_family, "", [options], READ_DEFAULTS)
_get_range(column_family, options[:start], options[:finish], options[:count]).keys
end
@@ -246,10 +255,20 @@ def read_storage_xml
end
def extract_and_validate_params_for_real(column_family, keys, args, options)
- column_family, column, sub_column, options = extract_and_validate_params(column_family, keys, args, options)
+ column_family, columns, sub_column, options = extract_and_validate_params(column_family, keys, args, options)
options[:start] = nil if options[:start] == ''
options[:finish] = nil if options[:finish] == ''
- [column_family, to_compare_with_type(column, column_family), to_compare_with_type(sub_column, column_family, false), options]
+ [column_family, to_compare_with_types(columns, column_family), to_compare_with_types(sub_column, column_family, false), options]
+ end
+
+ def to_compare_with_types(column_names, column_family, standard=true)
+ if column_names.is_a?(Array)
+ column_names.collect do |name|
+ to_compare_with_type(name, column_family, standard)
+ end
+ else
+ to_compare_with_type(column_names, column_family, standard)
+ end
end
def to_compare_with_type(column_name, column_family, standard=true)
@@ -7,13 +7,13 @@ class CassandraMockTest < CassandraTest
def setup
storage_xml_path = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'conf', 'storage-conf.xml'))
- @twitter = Cassandra::Mock.new('Twitter', nil, :storage_xml => storage_xml_path)
+ @twitter = Cassandra::Mock.new('Twitter', storage_xml_path)
@twitter.clear_keyspace!
- @blogs = Cassandra::Mock.new('Multiblog', nil, :storage_xml => storage_xml_path)
+ @blogs = Cassandra::Mock.new('Multiblog', storage_xml_path)
@blogs.clear_keyspace!
- @blogs_long = Cassandra::Mock.new('MultiblogLong', nil, :storage_xml => storage_xml_path)
+ @blogs_long = Cassandra::Mock.new('MultiblogLong', storage_xml_path)
@blogs_long.clear_keyspace!
@uuids = (0..6).map {|i| UUID.new(Time.at(2**(24+i))) }

0 comments on commit 1d5a44f

Please sign in to comment.