Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

… codebase
  • Loading branch information...
commit 1d5a44f7769f476773b2631be1d51f9f10b1cddb 1 parent c2dc984
Ryan King ryanking authored

Showing 2 changed files with 31 additions and 12 deletions. Show diff stats Hide diff stats

  1. +28 9 lib/cassandra/mock.rb
  2. +3 3 test/cassandra_mock_test.rb
37 lib/cassandra/mock.rb
@@ -132,7 +132,8 @@ def exists?(column_family, key, column=nil)
132 132 !!get(column_family, key, column)
133 133 end
134 134
135   - def multi_get(column_family, keys, options)
  135 + def multi_get(column_family, keys, *columns_and_options)
  136 + column_family, column, sub_column, options = extract_and_validate_params_for_real(column_family, keys, columns_and_options, READ_DEFAULTS)
136 137 keys.inject(OrderedHash.new) do |hash, key|
137 138 hash[key] = get(column_family, key)
138 139 hash
@@ -140,7 +141,7 @@ def multi_get(column_family, keys, options)
140 141 end
141 142
142 143 def remove(column_family, key, *columns_and_options)
143   - column_family, column, sub_column, options = extract_and_validate_params(column_family, key, columns_and_options, WRITE_DEFAULTS)
  144 + column_family, column, sub_column, options = extract_and_validate_params_for_real(column_family, key, columns_and_options, WRITE_DEFAULTS)
144 145 if @batch
145 146 @batch << [:remove, column_family, key, column]
146 147 else
@@ -156,10 +157,19 @@ def remove(column_family, key, *columns_and_options)
156 157 end
157 158 end
158 159
159   - def get_columns(column_family, key, columns)
  160 + def get_columns(column_family, key, *columns_and_options)
  161 + column_family, columns, sub_columns, options = extract_and_validate_params_for_real(column_family, key, columns_and_options, READ_DEFAULTS)
160 162 d = get(column_family, key)
161   - columns.collect do |column|
162   - d[column]
  163 +
  164 +
  165 + if sub_columns
  166 + sub_columns.collect do |sub_column|
  167 + d[columns][sub_column]
  168 + end
  169 + else
  170 + columns.collect do |column|
  171 + d[column]
  172 + end
163 173 end
164 174 end
165 175
@@ -182,8 +192,7 @@ def multi_count_columns(column_family, keys)
182 192 end
183 193
184 194 def get_range(column_family, options = {})
185   - column_family, _, _, options =
186   - extract_and_validate_params_for_real(column_family, "", [options], READ_DEFAULTS)
  195 + column_family, _, _, options = extract_and_validate_params_for_real(column_family, "", [options], READ_DEFAULTS)
187 196 _get_range(column_family, options[:start], options[:finish], options[:count]).keys
188 197 end
189 198
@@ -246,10 +255,20 @@ def read_storage_xml
246 255 end
247 256
248 257 def extract_and_validate_params_for_real(column_family, keys, args, options)
249   - column_family, column, sub_column, options = extract_and_validate_params(column_family, keys, args, options)
  258 + column_family, columns, sub_column, options = extract_and_validate_params(column_family, keys, args, options)
250 259 options[:start] = nil if options[:start] == ''
251 260 options[:finish] = nil if options[:finish] == ''
252   - [column_family, to_compare_with_type(column, column_family), to_compare_with_type(sub_column, column_family, false), options]
  261 + [column_family, to_compare_with_types(columns, column_family), to_compare_with_types(sub_column, column_family, false), options]
  262 + end
  263 +
  264 + def to_compare_with_types(column_names, column_family, standard=true)
  265 + if column_names.is_a?(Array)
  266 + column_names.collect do |name|
  267 + to_compare_with_type(name, column_family, standard)
  268 + end
  269 + else
  270 + to_compare_with_type(column_names, column_family, standard)
  271 + end
253 272 end
254 273
255 274 def to_compare_with_type(column_name, column_family, standard=true)
6 test/cassandra_mock_test.rb
@@ -7,13 +7,13 @@ class CassandraMockTest < CassandraTest
7 7
8 8 def setup
9 9 storage_xml_path = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'conf', 'storage-conf.xml'))
10   - @twitter = Cassandra::Mock.new('Twitter', nil, :storage_xml => storage_xml_path)
  10 + @twitter = Cassandra::Mock.new('Twitter', storage_xml_path)
11 11 @twitter.clear_keyspace!
12 12
13   - @blogs = Cassandra::Mock.new('Multiblog', nil, :storage_xml => storage_xml_path)
  13 + @blogs = Cassandra::Mock.new('Multiblog', storage_xml_path)
14 14 @blogs.clear_keyspace!
15 15
16   - @blogs_long = Cassandra::Mock.new('MultiblogLong', nil, :storage_xml => storage_xml_path)
  16 + @blogs_long = Cassandra::Mock.new('MultiblogLong', storage_xml_path)
17 17 @blogs_long.clear_keyspace!
18 18
19 19 @uuids = (0..6).map {|i| UUID.new(Time.at(2**(24+i))) }

0 comments on commit 1d5a44f

Please sign in to comment.
Something went wrong with that request. Please try again.