diff --git a/ext/cassandra_native.c b/ext/cassandra_native.c index aa33d3c..741a3bc 100755 --- a/ext/cassandra_native.c +++ b/ext/cassandra_native.c @@ -56,7 +56,7 @@ VALUE rb_cassandra_dynamic_composite_fast_unpack(VALUE self, VALUE packed_string } void Init_cassandra_native(void) { - VALUE cassandra_module = rb_const_get(rb_cObject, rb_intern("Cassandra")); + VALUE cassandra_module = rb_const_get(rb_cObject, rb_intern("CassandraOld")); VALUE cassandra_composite_class = rb_define_class_under(cassandra_module, "Composite", rb_cObject); rb_define_method(cassandra_composite_class, "fast_unpack", rb_cassandra_composite_fast_unpack, 1); diff --git a/lib/cassandra.rb b/lib/cassandra.rb deleted file mode 100755 index 5d536f4..0000000 --- a/lib/cassandra.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'rubygems' -gem 'thrift_client', '~> 0.7' -require 'thrift_client' -gem 'simple_uuid' , '~> 0.3' -require 'simple_uuid' - -require 'json' unless defined?(JSON) - -here = File.expand_path(File.dirname(__FILE__)) - -class Cassandra ; end -unless Cassandra.respond_to?(:VERSION) - require "#{here}/cassandra/0.8" -end - -$LOAD_PATH << "#{here}/../vendor/#{Cassandra.VERSION}/gen-rb" -require "#{here}/../vendor/#{Cassandra.VERSION}/gen-rb/cassandra" - -$LOAD_PATH << "#{here}" - -require 'cassandra/helpers' -require 'cassandra/array' -require 'cassandra/time' -require 'cassandra/comparable' -require 'cassandra/long' -require 'cassandra/composite' -require 'cassandra/dynamic_composite' -require 'cassandra/ordered_hash' -require 'cassandra/columns' -require 'cassandra/protocol' -require 'cassandra/batch' -require "cassandra/#{Cassandra.VERSION}/columns" -require "cassandra/#{Cassandra.VERSION}/protocol" -require "cassandra/cassandra" -require "cassandra/#{Cassandra.VERSION}/cassandra" -unless Cassandra.VERSION.eql?("0.6") - require "cassandra/column_family" - require "cassandra/keyspace" -end -require 'cassandra/constants' -require 'cassandra/debug' if ENV['DEBUG'] - -begin - require "cassandra_native" -rescue LoadError - puts "Unable to load cassandra_native extension. Defaulting to pure Ruby libraries." -end diff --git a/lib/cassandra/0.7/cassandra.rb b/lib/cassandra/0.7/cassandra.rb deleted file mode 100755 index b023017..0000000 --- a/lib/cassandra/0.7/cassandra.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Cassandra -end diff --git a/lib/cassandra/constants.rb b/lib/cassandra/constants.rb deleted file mode 100755 index 6e816df..0000000 --- a/lib/cassandra/constants.rb +++ /dev/null @@ -1,11 +0,0 @@ - -class Cassandra - # A helper module you can include in your own class. Makes it easier - # to work with Cassandra subclasses. - module Constants - include Cassandra::Consistency - - Long = Cassandra::Long - OrderedHash = Cassandra::OrderedHash - end -end diff --git a/lib/cassandra_old.rb b/lib/cassandra_old.rb new file mode 100755 index 0000000..38eff4e --- /dev/null +++ b/lib/cassandra_old.rb @@ -0,0 +1,47 @@ +require 'rubygems' +gem 'thrift_client', '~> 0.7' +require 'thrift_client' +gem 'simple_uuid' , '~> 0.3' +require 'simple_uuid' + +require 'json' unless defined?(JSON) + +here = File.expand_path(File.dirname(__FILE__)) + +class CassandraOld ; end +unless CassandraOld.respond_to?(:VERSION) + require "#{here}/cassandra_old/0.8" +end + +$LOAD_PATH << "#{here}/../vendor/#{CassandraOld.VERSION}/gen-rb" +require "#{here}/../vendor/#{CassandraOld.VERSION}/gen-rb/cassandra" + +$LOAD_PATH << "#{here}" + +require 'cassandra_old/helpers' +require 'cassandra_old/array' +require 'cassandra_old/time' +require 'cassandra_old/comparable' +require 'cassandra_old/long' +require 'cassandra_old/composite' +require 'cassandra_old/dynamic_composite' +require 'cassandra_old/ordered_hash' +require 'cassandra_old/columns' +require 'cassandra_old/protocol' +require 'cassandra_old/batch' +require "cassandra_old/#{CassandraOld.VERSION}/columns" +require "cassandra_old/#{CassandraOld.VERSION}/protocol" +require "cassandra_old/cassandra" +require "cassandra_old/#{CassandraOld.VERSION}/cassandra" +unless CassandraOld.VERSION.eql?("0.6") + require "cassandra_old/column_family" + require "cassandra_old/keyspace" +end +require 'cassandra_old/constants' +require 'cassandra_old/debug' if ENV['DEBUG'] + +begin + require "cassandra_native" +rescue LoadError + puts "Unable to load cassandra_native extension. Defaulting to pure Ruby libraries." +end diff --git a/lib/cassandra/0.6.rb b/lib/cassandra_old/0.6.rb similarity index 80% rename from lib/cassandra/0.6.rb rename to lib/cassandra_old/0.6.rb index 6911f2a..bac5644 100755 --- a/lib/cassandra/0.6.rb +++ b/lib/cassandra_old/0.6.rb @@ -1,7 +1,7 @@ -class Cassandra +class CassandraOld def self.VERSION "0.6" end end -require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra" \ No newline at end of file +require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra_old" diff --git a/lib/cassandra/0.6/cassandra.rb b/lib/cassandra_old/0.6/cassandra.rb similarity index 93% rename from lib/cassandra/0.6/cassandra.rb rename to lib/cassandra_old/0.6/cassandra.rb index 586ce79..c3737f2 100755 --- a/lib/cassandra/0.6/cassandra.rb +++ b/lib/cassandra_old/0.6/cassandra.rb @@ -1,4 +1,4 @@ -class Cassandra +class CassandraOld def self.DEFAULT_TRANSPORT_WRAPPER Thrift::BufferedTransport end @@ -16,7 +16,7 @@ def login!(username, password) end def inspect - "# #{hash['type'].inspect}"}.join(', ') }}, @servers=#{servers.inspect}>" end @@ -56,16 +56,16 @@ def clear_keyspace!(options = {}) # the :consistency option, which overrides the consistency set in # the individual commands. def batch(options = {}) - _, _, _, options = + _, _, _, options = extract_and_validate_params(schema.keys.first, "", [options], WRITE_DEFAULTS) @batch = [] yield(self) compacted_map,seen_clevels = compact_mutations! - clevel = if options[:consistency] != nil # Override any clevel from individual mutations if + clevel = if options[:consistency] != nil # Override any clevel from individual mutations if options[:consistency] elsif seen_clevels.length > 1 # Cannot choose which CLevel to use if there are several ones - raise "Multiple consistency levels used in the batch, and no override...cannot pick one" + raise "Multiple consistency levels used in the batch, and no override...cannot pick one" else # if no consistency override has been provided but all the clevels in the batch are the same: use that one seen_clevels.first end @@ -102,7 +102,7 @@ def all_nodes ips = ::JSON.parse(temp_client.get_string_property('token map')).values port = @servers.first.split(':').last ips.map{|ip| "#{ip}:#{port}" } - ensure + ensure temp_client.disconnect! end else diff --git a/lib/cassandra/0.6/columns.rb b/lib/cassandra_old/0.6/columns.rb similarity index 94% rename from lib/cassandra/0.6/columns.rb rename to lib/cassandra_old/0.6/columns.rb index 082b729..35a90c7 100755 --- a/lib/cassandra/0.6/columns.rb +++ b/lib/cassandra_old/0.6/columns.rb @@ -1,4 +1,4 @@ -class Cassandra +class CassandraOld # A bunch of crap, mostly related to introspecting on column types module Columns #:nodoc: private @@ -35,7 +35,7 @@ def _standard_insert_mutation(column_family, column_name, value, timestamp, _=ni end def _super_insert_mutation(column_family, super_column_name, sub_columns, timestamp, _=nil) - CassandraThrift::Mutation.new(:column_or_supercolumn => + CassandraThrift::Mutation.new(:column_or_supercolumn => CassandraThrift::ColumnOrSuperColumn.new( :super_column => CassandraThrift::SuperColumn.new( :name => column_name_class(column_family).new(super_column_name).to_s, @@ -53,12 +53,12 @@ def _super_insert_mutation(column_family, super_column_name, sub_columns, timest # General info about a deletion object within a mutation # timestamp - required. If this is the only param, it will cause deletion of the whole key at that TS - # supercolumn - opt. If passed, the deletes will only occur within that supercolumn (only subcolumns + # supercolumn - opt. If passed, the deletes will only occur within that supercolumn (only subcolumns # will be deleted). Otherwise the normal columns will be deleted. - # predicate - opt. Defines how to match the columns to delete. if supercolumn passed, the slice will + # predicate - opt. Defines how to match the columns to delete. if supercolumn passed, the slice will # be scoped to subcolumns of that supercolumn. - - # Deletes a single column from the containing key/CF (and possibly supercolumn), at a given timestamp. + + # Deletes a single column from the containing key/CF (and possibly supercolumn), at a given timestamp. # Although mutations (as opposed to 'remove' calls) support deleting slices and lists of columns in one shot, this is not implemented here. # The main reason being that the batch function takes removes, but removes don't have that capability...so we'd need to change the remove # methods to use delete mutation calls...although that might have performance implications. We'll leave that refactoring for later. diff --git a/lib/cassandra/0.6/protocol.rb b/lib/cassandra_old/0.6/protocol.rb similarity index 99% rename from lib/cassandra/0.6/protocol.rb rename to lib/cassandra_old/0.6/protocol.rb index 1b97f8e..3c97adf 100755 --- a/lib/cassandra/0.6/protocol.rb +++ b/lib/cassandra_old/0.6/protocol.rb @@ -1,5 +1,5 @@ -class Cassandra +class CassandraOld # Inner methods for actually doing the Thrift calls module Protocol #:nodoc: private diff --git a/lib/cassandra/0.7.rb b/lib/cassandra_old/0.7.rb similarity index 80% rename from lib/cassandra/0.7.rb rename to lib/cassandra_old/0.7.rb index fc2734a..b35821a 100755 --- a/lib/cassandra/0.7.rb +++ b/lib/cassandra_old/0.7.rb @@ -1,7 +1,7 @@ -class Cassandra +class CassandraOld def self.VERSION "0.7" end end -require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra" \ No newline at end of file +require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra_old" diff --git a/lib/cassandra_old/0.7/cassandra.rb b/lib/cassandra_old/0.7/cassandra.rb new file mode 100755 index 0000000..0b94488 --- /dev/null +++ b/lib/cassandra_old/0.7/cassandra.rb @@ -0,0 +1,2 @@ +class CassandraOld +end diff --git a/lib/cassandra/0.7/columns.rb b/lib/cassandra_old/0.7/columns.rb similarity index 65% rename from lib/cassandra/0.7/columns.rb rename to lib/cassandra_old/0.7/columns.rb index d62c187..73d7719 100755 --- a/lib/cassandra/0.7/columns.rb +++ b/lib/cassandra_old/0.7/columns.rb @@ -1,4 +1,4 @@ -class Cassandra +class CassandraOld module Columns #:nodoc: end end diff --git a/lib/cassandra/0.7/protocol.rb b/lib/cassandra_old/0.7/protocol.rb similarity index 82% rename from lib/cassandra/0.7/protocol.rb rename to lib/cassandra_old/0.7/protocol.rb index 438585a..c20816a 100755 --- a/lib/cassandra/0.7/protocol.rb +++ b/lib/cassandra_old/0.7/protocol.rb @@ -1,4 +1,4 @@ -class Cassandra +class CassandraOld # Inner methods for actually doing the Thrift calls module Protocol #:nodoc: end diff --git a/lib/cassandra/0.8.rb b/lib/cassandra_old/0.8.rb similarity index 80% rename from lib/cassandra/0.8.rb rename to lib/cassandra_old/0.8.rb index e1c9fc0..bcac7b6 100755 --- a/lib/cassandra/0.8.rb +++ b/lib/cassandra_old/0.8.rb @@ -1,7 +1,7 @@ -class Cassandra +class CassandraOld def self.VERSION "0.8" end end -require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra" +require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra_old" diff --git a/lib/cassandra/0.8/cassandra.rb b/lib/cassandra_old/0.8/cassandra.rb similarity index 97% rename from lib/cassandra/0.8/cassandra.rb rename to lib/cassandra_old/0.8/cassandra.rb index 9fd3236..b0370c7 100755 --- a/lib/cassandra/0.8/cassandra.rb +++ b/lib/cassandra_old/0.8/cassandra.rb @@ -1,4 +1,4 @@ -class Cassandra +class CassandraOld ## Counters diff --git a/lib/cassandra/0.8/columns.rb b/lib/cassandra_old/0.8/columns.rb similarity index 98% rename from lib/cassandra/0.8/columns.rb rename to lib/cassandra_old/0.8/columns.rb index 385d37f..8a8352f 100755 --- a/lib/cassandra/0.8/columns.rb +++ b/lib/cassandra_old/0.8/columns.rb @@ -1,4 +1,4 @@ -class Cassandra +class CassandraOld module Columns #:nodoc: def _standard_counter_mutation(column_family, column_name, value) CassandraThrift::Mutation.new( diff --git a/lib/cassandra/0.8/protocol.rb b/lib/cassandra_old/0.8/protocol.rb similarity index 92% rename from lib/cassandra/0.8/protocol.rb rename to lib/cassandra_old/0.8/protocol.rb index 18cc811..68fe75d 100755 --- a/lib/cassandra/0.8/protocol.rb +++ b/lib/cassandra_old/0.8/protocol.rb @@ -1,4 +1,4 @@ -class Cassandra +class CassandraOld # Inner methods for actually doing the Thrift calls module Protocol #:nodoc: private diff --git a/lib/cassandra/1.0.rb b/lib/cassandra_old/1.0.rb similarity index 80% rename from lib/cassandra/1.0.rb rename to lib/cassandra_old/1.0.rb index a23f572..9c9b1f0 100755 --- a/lib/cassandra/1.0.rb +++ b/lib/cassandra_old/1.0.rb @@ -1,7 +1,7 @@ -class Cassandra +class CassandraOld def self.VERSION "1.0" end end -require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra" +require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra_old" diff --git a/lib/cassandra/1.0/cassandra.rb b/lib/cassandra_old/1.0/cassandra.rb similarity index 100% rename from lib/cassandra/1.0/cassandra.rb rename to lib/cassandra_old/1.0/cassandra.rb diff --git a/lib/cassandra/1.0/columns.rb b/lib/cassandra_old/1.0/columns.rb similarity index 100% rename from lib/cassandra/1.0/columns.rb rename to lib/cassandra_old/1.0/columns.rb diff --git a/lib/cassandra/1.0/protocol.rb b/lib/cassandra_old/1.0/protocol.rb similarity index 100% rename from lib/cassandra/1.0/protocol.rb rename to lib/cassandra_old/1.0/protocol.rb diff --git a/lib/cassandra/1.1.rb b/lib/cassandra_old/1.1.rb similarity index 80% rename from lib/cassandra/1.1.rb rename to lib/cassandra_old/1.1.rb index ffe1760..ba86c23 100755 --- a/lib/cassandra/1.1.rb +++ b/lib/cassandra_old/1.1.rb @@ -1,7 +1,7 @@ -class Cassandra +class CassandraOld def self.VERSION "1.1" end end -require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra" +require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra_old" diff --git a/lib/cassandra/1.1/cassandra.rb b/lib/cassandra_old/1.1/cassandra.rb similarity index 100% rename from lib/cassandra/1.1/cassandra.rb rename to lib/cassandra_old/1.1/cassandra.rb diff --git a/lib/cassandra/1.1/columns.rb b/lib/cassandra_old/1.1/columns.rb similarity index 100% rename from lib/cassandra/1.1/columns.rb rename to lib/cassandra_old/1.1/columns.rb diff --git a/lib/cassandra/1.1/protocol.rb b/lib/cassandra_old/1.1/protocol.rb similarity index 100% rename from lib/cassandra/1.1/protocol.rb rename to lib/cassandra_old/1.1/protocol.rb diff --git a/lib/cassandra/1.2.rb b/lib/cassandra_old/1.2.rb similarity index 80% rename from lib/cassandra/1.2.rb rename to lib/cassandra_old/1.2.rb index bb9c62d..545e346 100755 --- a/lib/cassandra/1.2.rb +++ b/lib/cassandra_old/1.2.rb @@ -1,7 +1,7 @@ -class Cassandra +class CassandraOld def self.VERSION "1.2" end end -require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra" +require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra_old" diff --git a/lib/cassandra/1.2/cassandra.rb b/lib/cassandra_old/1.2/cassandra.rb similarity index 100% rename from lib/cassandra/1.2/cassandra.rb rename to lib/cassandra_old/1.2/cassandra.rb diff --git a/lib/cassandra/1.2/columns.rb b/lib/cassandra_old/1.2/columns.rb similarity index 100% rename from lib/cassandra/1.2/columns.rb rename to lib/cassandra_old/1.2/columns.rb diff --git a/lib/cassandra/1.2/protocol.rb b/lib/cassandra_old/1.2/protocol.rb similarity index 100% rename from lib/cassandra/1.2/protocol.rb rename to lib/cassandra_old/1.2/protocol.rb diff --git a/lib/cassandra/array.rb b/lib/cassandra_old/array.rb similarity index 100% rename from lib/cassandra/array.rb rename to lib/cassandra_old/array.rb diff --git a/lib/cassandra/batch.rb b/lib/cassandra_old/batch.rb similarity index 92% rename from lib/cassandra/batch.rb rename to lib/cassandra_old/batch.rb index 9137b3a..7d667a9 100644 --- a/lib/cassandra/batch.rb +++ b/lib/cassandra_old/batch.rb @@ -1,8 +1,8 @@ -class Cassandra +class CassandraOld class Batch include Enumerable - def initialize(cassandra, options) + def initialize(cassandra, options) @queue_size = options.delete(:queue_size) || 0 @cassandra = cassandra @options = options diff --git a/lib/cassandra/cassandra.rb b/lib/cassandra_old/cassandra.rb similarity index 96% rename from lib/cassandra/cassandra.rb rename to lib/cassandra_old/cassandra.rb index 6555a78..2dbb7c4 100755 --- a/lib/cassandra/cassandra.rb +++ b/lib/cassandra_old/cassandra.rb @@ -31,7 +31,7 @@ =end -class Cassandra +class CassandraOld include Columns include Protocol include Helpers @@ -79,7 +79,7 @@ def initialize(keyspace, servers = "127.0.0.1:9160", thrift_client_options = {}) @column_name_maker = {} @sub_column_name_maker = {} @auto_discover_nodes = true - thrift_client_options[:transport_wrapper] ||= Cassandra.DEFAULT_TRANSPORT_WRAPPER + thrift_client_options[:transport_wrapper] ||= CassandraOld.DEFAULT_TRANSPORT_WRAPPER @thrift_client_options = THRIFT_DEFAULTS.merge(thrift_client_options) @thrift_client_class = @thrift_client_options[:thrift_client_class] @keyspace = keyspace @@ -131,7 +131,7 @@ def login!(username, password) end def inspect - "# #{cfdef.column_type}"}.join(', ') }}, @servers=#{servers.inspect}>" end @@ -141,7 +141,7 @@ def inspect # # Please note that this only works on version 0.7.0 and higher. def keyspace=(ks) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 client.set_keyspace(ks) @schema = nil; @keyspace = ks @@ -152,7 +152,7 @@ def keyspace=(ks) # # Please note that this only works on version 0.7.0 and higher. def keyspaces - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 client.describe_keyspaces.to_a.collect {|ksdef| ksdef.name } end @@ -161,7 +161,7 @@ def keyspaces # Return a hash of column_family definitions indexed by their # names def column_families - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 schema.cf_defs.inject(Hash.new){|memo, cf_def| memo[cf_def.name] = cf_def; memo;} end @@ -172,10 +172,10 @@ def column_families # # Please note that this only works on version 0.7.0 and higher. def schema(load=true) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 if !load && !@schema - Cassandra::Keyspace.new + CassandraOld::Keyspace.new else @schema ||= client.describe_keyspace(@keyspace) end @@ -186,7 +186,7 @@ def schema(load=true) # # Please note that this only works on version 0.7.0 and higher. def schema_agreement? - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 client.describe_schema_versions().length == 1 end @@ -196,7 +196,7 @@ def schema_agreement? # # Please note that this only works on version 0.7.0 and higher. def version - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 client.describe_version() end @@ -206,7 +206,7 @@ def version # # Please note that this only works on version 0.7.0 and higher. def cluster_name - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 @cluster_name ||= client.describe_cluster_name() end @@ -218,7 +218,7 @@ def cluster_name # # Please note that this only works on version 0.7.0 and higher. def ring - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 client.describe_ring(@keyspace) end @@ -230,7 +230,7 @@ def ring # # Please note that this only works on version 0.7.0 and higher. def partitioner - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 client.describe_partitioner() end @@ -257,7 +257,7 @@ def truncate!(column_family) # Please note that this only works on version 0.7.0 and higher. # def clear_keyspace! - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 schema.cf_defs.each { |cfdef| truncate!(cfdef.name) } end @@ -267,7 +267,7 @@ def clear_keyspace! # Cassandra::ColumnFamily instance, and returns the schema id. # def add_column_family(cf_def) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 @schema = nil return client.system_add_column_family(cf_def) @@ -279,7 +279,7 @@ def add_column_family(cf_def) # * column_family - The column_family name to drop. # def drop_column_family(column_family) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 @schema = nil return client.system_drop_column_family(column_family) @@ -292,7 +292,7 @@ def drop_column_family(column_family) # * new_name - The desired column_family name. # def rename_column_family(old_name, new_name) - return false if Cassandra.VERSION.to_f != 0.7 + return false if CassandraOld.VERSION.to_f != 0.7 @schema = nil return client.system_rename_column_family(old_name, new_name) @@ -302,7 +302,7 @@ def rename_column_family(old_name, new_name) # Update the column family based on the passed in definition. # def update_column_family(cf_def) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 @schema = nil return client.system_update_column_family(cf_def) @@ -314,7 +314,7 @@ def update_column_family(cf_def) # Returns the new schema id. # def add_keyspace(ks_def) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 @keyspaces = nil return client.system_add_keyspace(ks_def) @@ -326,7 +326,7 @@ def add_keyspace(ks_def) # Returns the new schema id. # def drop_keyspace(keyspace=@keyspace) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 @keyspaces = nil ret = client.system_drop_keyspace(keyspace) @@ -342,7 +342,7 @@ def drop_keyspace(keyspace=@keyspace) # # Returns the new schema id def rename_keyspace(old_name, new_name) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 @keyspaces = nil ret = client.system_rename_keyspace(old_name, new_name) @@ -354,7 +354,7 @@ def rename_keyspace(old_name, new_name) # Update the keyspace using the passed in keyspace definition. # def update_keyspace(ks_def) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 @keyspaces = nil return client.system_update_keyspace(ks_def) @@ -804,7 +804,7 @@ def each(column_family, options = {}) # the individual commands. # def batch(options = {}) - @batch = Cassandra::Batch.new(self, options) + @batch = CassandraOld::Batch.new(self, options) _, _, _, options = extract_and_validate_params(schema.cf_defs.first.name, "", [options], WRITE_DEFAULTS) @@ -841,7 +841,7 @@ def flush_batch(options={}) # * validation_class # def create_index(keyspace, column_family, column_name, validation_class) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 cf_def = client.describe_keyspace(keyspace).cf_defs.find{|x| x.name == column_family} if !cf_def.nil? and !cf_def.column_metadata.find{|x| x.name == column_name} @@ -863,7 +863,7 @@ def create_index(keyspace, column_family, column_name, validation_class) # * column_name # def drop_index(keyspace, column_family, column_name) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 cf_def = client.describe_keyspace(keyspace).cf_defs.find{|x| x.name == column_family} if !cf_def.nil? and cf_def.column_metadata.find{|x| x.name == column_name} @@ -881,7 +881,7 @@ def drop_index(keyspace, column_family, column_name) # * comparison - Type of comparison to do. # def create_index_expression(column_name, value, comparison) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 CassandraThrift::IndexExpression.new( :column_name => column_name, @@ -911,7 +911,7 @@ def create_index_expression(column_name, value, comparison) # * count - The count of items to be returned # def create_index_clause(index_expressions, start = "", count = 100) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 CassandraThrift::IndexClause.new( :start_key => start, @@ -940,7 +940,7 @@ def create_index_clause(index_expressions, start = "", count = 100) # # TODO: Supercolumn support. def get_indexed_slices(column_family, index_clause, *columns_and_options) - return false if Cassandra.VERSION.to_f < 0.7 + return false if CassandraOld.VERSION.to_f < 0.7 column_family, columns, _, options = extract_and_validate_params(column_family, [], columns_and_options, diff --git a/lib/cassandra/column_family.rb b/lib/cassandra_old/column_family.rb similarity index 69% rename from lib/cassandra/column_family.rb rename to lib/cassandra_old/column_family.rb index 6b0e810..6767136 100755 --- a/lib/cassandra/column_family.rb +++ b/lib/cassandra_old/column_family.rb @@ -1,3 +1,3 @@ -class Cassandra +class CassandraOld class ColumnFamily < CassandraThrift::CfDef ; end -end \ No newline at end of file +end diff --git a/lib/cassandra/columns.rb b/lib/cassandra_old/columns.rb similarity index 99% rename from lib/cassandra/columns.rb rename to lib/cassandra_old/columns.rb index d6b6971..2fc3204 100755 --- a/lib/cassandra/columns.rb +++ b/lib/cassandra_old/columns.rb @@ -1,5 +1,5 @@ -class Cassandra +class CassandraOld # A bunch of crap, mostly related to introspecting on column types module Columns #:nodoc: private diff --git a/lib/cassandra/comparable.rb b/lib/cassandra_old/comparable.rb similarity index 89% rename from lib/cassandra/comparable.rb rename to lib/cassandra_old/comparable.rb index a6aa6dc..a6c92e3 100755 --- a/lib/cassandra/comparable.rb +++ b/lib/cassandra_old/comparable.rb @@ -1,26 +1,26 @@ -class Cassandra +class CassandraOld # Abstract base class for comparable numeric column name types class Comparable class TypeError < ::TypeError #:nodoc: end - + def <=>(other) self.to_i <=> other.to_i end - + def hash @bytes.hash end - + def eql?(other) other.is_a?(Comparable) and @bytes == other.to_s - end - + end + def ==(other) other.respond_to?(:to_i) && self.to_i == other.to_i end - + def to_s @bytes end diff --git a/lib/cassandra/composite.rb b/lib/cassandra_old/composite.rb similarity index 99% rename from lib/cassandra/composite.rb rename to lib/cassandra_old/composite.rb index 9da9945..380d17c 100755 --- a/lib/cassandra/composite.rb +++ b/lib/cassandra_old/composite.rb @@ -1,4 +1,4 @@ -class Cassandra +class CassandraOld class Composite include ::Comparable attr_reader :parts diff --git a/lib/cassandra_old/constants.rb b/lib/cassandra_old/constants.rb new file mode 100755 index 0000000..92fcde8 --- /dev/null +++ b/lib/cassandra_old/constants.rb @@ -0,0 +1,11 @@ + +class CassandraOld + # A helper module you can include in your own class. Makes it easier + # to work with Cassandra subclasses. + module Constants + include CassandraOld::Consistency + + Long = CassandraOld::Long + OrderedHash = CassandraOld::OrderedHash + end +end diff --git a/lib/cassandra/debug.rb b/lib/cassandra_old/debug.rb similarity index 100% rename from lib/cassandra/debug.rb rename to lib/cassandra_old/debug.rb diff --git a/lib/cassandra/dynamic_composite.rb b/lib/cassandra_old/dynamic_composite.rb similarity index 99% rename from lib/cassandra/dynamic_composite.rb rename to lib/cassandra_old/dynamic_composite.rb index 6f77074..d1a3076 100755 --- a/lib/cassandra/dynamic_composite.rb +++ b/lib/cassandra_old/dynamic_composite.rb @@ -1,4 +1,4 @@ -class Cassandra +class CassandraOld class DynamicComposite < Composite attr_accessor :types diff --git a/lib/cassandra/helpers.rb b/lib/cassandra_old/helpers.rb similarity index 94% rename from lib/cassandra/helpers.rb rename to lib/cassandra_old/helpers.rb index 0e0c228..2c21c43 100755 --- a/lib/cassandra/helpers.rb +++ b/lib/cassandra_old/helpers.rb @@ -1,4 +1,4 @@ -class Cassandra +class CassandraOld module Helpers def extract_and_validate_params(column_family, keys, args, options) options = options.dup @@ -12,12 +12,12 @@ def extract_and_validate_params(column_family, keys, args, options) if args.last.is_a?(Hash) extras = args.last.keys - options.keys raise ArgumentError, "Invalid options #{extras.inspect[1..-2]} for #{caller[1]}" if extras.any? - options.merge!(args.pop) + options.merge!(args.pop) end # Ranges column, sub_column = args[0], args[1] - raise ArgumentError, "Invalid arguments: subcolumns specified for a non-supercolumn family" if sub_column && !is_super(column_family) + raise ArgumentError, "Invalid arguments: subcolumns specified for a non-supercolumn family" if sub_column && !is_super(column_family) klass, sub_klass = column_name_class(column_family), sub_column_name_class(column_family) range_class = column ? sub_klass : klass diff --git a/lib/cassandra/keyspace.rb b/lib/cassandra_old/keyspace.rb similarity index 67% rename from lib/cassandra/keyspace.rb rename to lib/cassandra_old/keyspace.rb index 4125f3a..867f076 100755 --- a/lib/cassandra/keyspace.rb +++ b/lib/cassandra_old/keyspace.rb @@ -1,3 +1,3 @@ -class Cassandra +class CassandraOld class Keyspace < CassandraThrift::KsDef ; end -end \ No newline at end of file +end diff --git a/lib/cassandra/long.rb b/lib/cassandra_old/long.rb similarity index 95% rename from lib/cassandra/long.rb rename to lib/cassandra_old/long.rb index 84c3ab7..7007e97 100755 --- a/lib/cassandra/long.rb +++ b/lib/cassandra_old/long.rb @@ -1,5 +1,5 @@ -class Cassandra +class CassandraOld # A temporally-ordered Long class for use in Cassandra column names class Long < Comparable @@ -41,10 +41,10 @@ def to_i def to_guid "%08x-%04x-%04x" % @bytes.unpack("Nnn") - end + end def inspect - "> 12) / 1_000_000).utc.inspect }, usecs: #{ (to_i >> 12) % 1_000_000 diff --git a/lib/cassandra/mock.rb b/lib/cassandra_old/mock.rb similarity index 97% rename from lib/cassandra/mock.rb rename to lib/cassandra_old/mock.rb index 570d8e8..026b414 100755 --- a/lib/cassandra/mock.rb +++ b/lib/cassandra_old/mock.rb @@ -8,10 +8,10 @@ def <=(other) end end -class Cassandra +class CassandraOld class Mock - include ::Cassandra::Helpers - include ::Cassandra::Columns + include ::CassandraOld::Helpers + include ::CassandraOld::Columns attr_reader :keyspace @@ -75,7 +75,7 @@ def insert_super(column_family, key, hash) end def batch(options={}) - @batch = Cassandra::Batch.new(self, options) + @batch = CassandraOld::Batch.new(self, options) yield flush_batch(options) ensure @@ -363,7 +363,7 @@ def add(column_family, key, value, *columns_and_options) def column_families cf_defs = {} schema.each do |key, value| - cf_def = Cassandra::ColumnFamily.new + cf_def = CassandraOld::ColumnFamily.new value.each do |property, property_value| cf_def.send(:"#{property}=", property_value) @@ -490,16 +490,16 @@ def columns_to_hash(column_family, columns) columns.each do |column_name, value| timestamp = columns.timestamps[column_name] - column = column_class.new(column_name) + column = column_class.new(column_name.dup) if [Hash, OrderedHash].include?(value.class) output[column] ||= OrderedHash.new value.each do |sub_column, sub_column_value| timestamp = value.timestamps[sub_column] - output[column].[]=(sub_column_class.new(sub_column), sub_column_value, timestamp) + output[column].[]=(sub_column_class.new(sub_column.dup), sub_column_value, timestamp) end else - output.[]=(column_class.new(column_name), value, timestamp) + output.[]=(column_class.new(column_name.dup), value, timestamp) end end diff --git a/lib/cassandra/ordered_hash.rb b/lib/cassandra_old/ordered_hash.rb similarity index 99% rename from lib/cassandra/ordered_hash.rb rename to lib/cassandra_old/ordered_hash.rb index 0b496c0..6b708f9 100755 --- a/lib/cassandra/ordered_hash.rb +++ b/lib/cassandra_old/ordered_hash.rb @@ -1,5 +1,5 @@ # OrderedHash is namespaced to prevent conflicts with other implementations -class Cassandra +class CassandraOld class OrderedHashInt < Hash #:nodoc: def initialize(*args, &block) super @@ -125,7 +125,7 @@ def replace(other) @keys = other.keys self end - + def reverse OrderedHashInt[self.to_a.reverse] end diff --git a/lib/cassandra/protocol.rb b/lib/cassandra_old/protocol.rb similarity index 97% rename from lib/cassandra/protocol.rb rename to lib/cassandra_old/protocol.rb index 8aaf190..08ad852 100755 --- a/lib/cassandra/protocol.rb +++ b/lib/cassandra_old/protocol.rb @@ -1,4 +1,4 @@ -class Cassandra +class CassandraOld # Inner methods for actually doing the Thrift calls module Protocol #:nodoc: private @@ -48,20 +48,20 @@ def _get_columns(column_family, key, columns, sub_columns, consistency) klass = column_name_class(column_family) (sub_columns || columns).map { |name| result[klass.new(name)] } end - + def _multi_get_columns(column_family, keys, columns, sub_columns, consistency) result = if is_super(column_family) and sub_columns predicate = CassandraThrift::SlicePredicate.new(:column_names => sub_columns) column_parent = CassandraThrift::ColumnParent.new( - :column_family => column_family, + :column_family => column_family, :super_column => columns.kind_of?(Array) ? columns[0] : columns ) multi_sub_columns_to_hash!(column_family, client.multiget_slice(keys, column_parent, predicate, consistency)) else predicate = CassandraThrift::SlicePredicate.new(:column_names => columns) column_parent = CassandraThrift::ColumnParent.new(:column_family => column_family) multi_columns_to_hash!(column_family, client.multiget_slice(keys, column_parent, predicate, consistency)) - end - + end + klass = column_name_class(column_family) OrderedHash[result.keys.map { |key| [key, (sub_columns || columns).map { |column| result[key][klass.new(column)] }] }] end @@ -107,9 +107,9 @@ def _get_range(column_family, start_key, finish_key, key_count, columns, start, predicate = if columns CassandraThrift::SlicePredicate.new(:column_names => columns) else - CassandraThrift::SlicePredicate.new(:slice_range => + CassandraThrift::SlicePredicate.new(:slice_range => CassandraThrift::SliceRange.new( - :start => start, + :start => start, :finish => finish, :count => count, :reversed => reversed)) diff --git a/lib/cassandra/time.rb b/lib/cassandra_old/time.rb similarity index 100% rename from lib/cassandra/time.rb rename to lib/cassandra_old/time.rb diff --git a/test/cassandra_client_test.rb b/test/cassandra_client_test.rb index d3864da..36c4cb4 100755 --- a/test/cassandra_client_test.rb +++ b/test/cassandra_client_test.rb @@ -1,20 +1,20 @@ require File.expand_path(File.dirname(__FILE__) + '/test_helper') class CassandraClientTest < Test::Unit::TestCase - include Cassandra::Constants - + include CassandraOld::Constants + def setup - @twitter = Cassandra.new('Twitter', "127.0.0.1:9160", :retries => 2, :exception_classes => []) + @twitter = CassandraOld.new('Twitter', "127.0.0.1:9160", :retries => 2, :exception_classes => []) end - + def test_client_method_is_called assert_nil @twitter.instance_variable_get(:@client) @twitter.insert(:Statuses, key, {'1' => 'v', '2' => 'v', '3' => 'v'}) assert_not_nil @twitter.instance_variable_get(:@client) end - + def key caller.first[/`(.*?)'/, 1] end - -end \ No newline at end of file + +end diff --git a/test/cassandra_mock_test.rb b/test/cassandra_mock_test.rb index b81e7ce..503088c 100755 --- a/test/cassandra_mock_test.rb +++ b/test/cassandra_mock_test.rb @@ -1,38 +1,38 @@ require File.expand_path(File.dirname(__FILE__) + '/test_helper') require File.expand_path(File.dirname(__FILE__) + '/cassandra_test') -require 'cassandra/mock' +require 'cassandra_old/mock' require 'json' class CassandraMockTest < CassandraTest - include Cassandra::Constants + include CassandraOld::Constants def setup @test_schema = JSON.parse(File.read(File.join(File.expand_path(File.dirname(__FILE__)), '..','conf', CASSANDRA_VERSION, 'schema.json'))) - @twitter = Cassandra::Mock.new('Twitter', @test_schema) + @twitter = CassandraOld::Mock.new('Twitter', @test_schema) @twitter.clear_keyspace! - @blogs = Cassandra::Mock.new('Multiblog', @test_schema) + @blogs = CassandraOld::Mock.new('Multiblog', @test_schema) @blogs.clear_keyspace! - @blogs_long = Cassandra::Mock.new('MultiblogLong', @test_schema) + @blogs_long = CassandraOld::Mock.new('MultiblogLong', @test_schema) @blogs_long.clear_keyspace! - @type_conversions = Cassandra::Mock.new('TypeConversions', @test_schema) + @type_conversions = CassandraOld::Mock.new('TypeConversions', @test_schema) @type_conversions.clear_keyspace! @uuids = (0..6).map {|i| SimpleUUID::UUID.new(Time.at(2**(24+i))) } @longs = (0..6).map {|i| Long.new(Time.at(2**(24+i))) } @composites = [ - Cassandra::Composite.new([5].pack('N'), "zebra"), - Cassandra::Composite.new([5].pack('N'), "aardvark"), - Cassandra::Composite.new([1].pack('N'), "elephant"), - Cassandra::Composite.new([10].pack('N'), "kangaroo"), + CassandraOld::Composite.new([5].pack('N'), "zebra"), + CassandraOld::Composite.new([5].pack('N'), "aardvark"), + CassandraOld::Composite.new([1].pack('N'), "elephant"), + CassandraOld::Composite.new([10].pack('N'), "kangaroo"), ] @dynamic_composites = [ - Cassandra::DynamicComposite.new(['i', [5].pack('N')], ['UTF8Type', "zebra"]), - Cassandra::DynamicComposite.new(['i', [5].pack('N')], ['UTF8Type', "aardvark"]), - Cassandra::DynamicComposite.new(['IntegerType', [1].pack('N')], ['s', "elephant"]), - Cassandra::DynamicComposite.new(['IntegerType', [10].pack('N')], ['s', "kangaroo"]), + CassandraOld::DynamicComposite.new(['i', [5].pack('N')], ['UTF8Type', "zebra"]), + CassandraOld::DynamicComposite.new(['i', [5].pack('N')], ['UTF8Type', "aardvark"]), + CassandraOld::DynamicComposite.new(['IntegerType', [1].pack('N')], ['s', "elephant"]), + CassandraOld::DynamicComposite.new(['IntegerType', [10].pack('N')], ['s', "kangaroo"]), ] end @@ -41,7 +41,7 @@ def test_setup assert @blogs assert @blogs_long end - + def test_schema_for_keyspace data = @test_schema['Twitter'] stuff = @twitter.send(:schema_for_keyspace, 'Twitter') @@ -55,44 +55,44 @@ def test_sorting_row_keys @twitter.insert(:Statuses, 'a', {:text => 'foo'}) assert_equal ['a'], @twitter.get_range(:Statuses, :key_count => 1).keys end - + def test_get_range_reversed data = 3.times.map { |i| ["body-#{i.to_s}", "v"] } - hash = Cassandra::OrderedHash[data] - reversed_hash = Cassandra::OrderedHash[data.reverse] - + hash = CassandraOld::OrderedHash[data] + reversed_hash = CassandraOld::OrderedHash[data.reverse] + @twitter.insert(:Statuses, "all-keys", hash) - + columns = @twitter.get_range(:Statuses, :reversed => true)["all-keys"] columns.each do |column| assert_equal reversed_hash.shift, column end end - + def test_get_range_reversed_slice data = 4.times.map { |i| ["body-#{i.to_s}", "v"] } - hash = Cassandra::OrderedHash[data] - sliced_hash = Cassandra::OrderedHash[data.reverse[1..-1]] - + hash = CassandraOld::OrderedHash[data] + sliced_hash = CassandraOld::OrderedHash[data.reverse[1..-1]] + @twitter.insert(:Statuses, "all-keys", hash) - + columns = @twitter.get_range( :Statuses, :start => sliced_hash.keys.first, :reversed => true )["all-keys"] - + columns.each do |column| assert_equal sliced_hash.shift, column end end - + def test_get_range_count data = 3.times.map { |i| ["body-#{i.to_s}", "v"] } - hash = Cassandra::OrderedHash[data] - + hash = CassandraOld::OrderedHash[data] + @twitter.insert(:Statuses, "all-keys", hash) - + columns = @twitter.get_range(:Statuses, :count => 2)["all-keys"] assert_equal 2, columns.count end @@ -106,7 +106,7 @@ def test_inserting_array_for_indices @twitter.insert(:UserRelationships, 'a', ['u1','u2']) } end - + def test_column_timestamps base_time = Time.now @twitter.insert(:Statuses, "time-key", { "body" => "value" }) @@ -114,14 +114,14 @@ def test_column_timestamps results = @twitter.get(:Statuses, "time-key") assert(results.timestamps["body"] / 1000000 >= base_time.to_i) end - + def test_supercolumn_timestamps base_time = Time.now @twitter.insert(:StatusRelationships, "time-key", { "super" => { @uuids[1] => "value" }}) results = @twitter.get(:StatusRelationships, "time-key") assert_nil(results.timestamps["super"]) - + columns = results["super"] assert(columns.timestamps[@uuids[1]] / 1000000 >= base_time.to_i) end diff --git a/test/cassandra_test.rb b/test/cassandra_test.rb index 6f3a247..a06ec8e 100755 --- a/test/cassandra_test.rb +++ b/test/cassandra_test.rb @@ -1,41 +1,41 @@ require File.expand_path(File.dirname(__FILE__) + '/test_helper') class CassandraTest < Test::Unit::TestCase - include Cassandra::Constants + include CassandraOld::Constants def assert_has_keys(keys, hash) assert_equal Set.new(keys), Set.new(hash.keys) end def setup - @twitter = Cassandra.new('Twitter', "127.0.0.1:9160", :retries => 2, :connect_timeout => 1, :timeout => 5, :exception_classes => []) + @twitter = CassandraOld.new('Twitter', "127.0.0.1:9160", :retries => 2, :connect_timeout => 1, :timeout => 5, :exception_classes => []) @twitter.clear_keyspace! - @blogs = Cassandra.new('Multiblog', "127.0.0.1:9160", :retries => 2, :connect_timeout => 1, :timeout => 5, :exception_classes => []) + @blogs = CassandraOld.new('Multiblog', "127.0.0.1:9160", :retries => 2, :connect_timeout => 1, :timeout => 5, :exception_classes => []) @blogs.clear_keyspace! - @blogs_long = Cassandra.new('MultiblogLong', "127.0.0.1:9160", :retries => 2, :connect_timeout => 1, :timeout => 5, :exception_classes => []) + @blogs_long = CassandraOld.new('MultiblogLong', "127.0.0.1:9160", :retries => 2, :connect_timeout => 1, :timeout => 5, :exception_classes => []) @blogs_long.clear_keyspace! - @type_conversions = Cassandra.new('TypeConversions', "127.0.0.1:9160", :retries => 2, :connect_timeout => 1, :timeout => 5, :exception_classes => []) + @type_conversions = CassandraOld.new('TypeConversions', "127.0.0.1:9160", :retries => 2, :connect_timeout => 1, :timeout => 5, :exception_classes => []) @type_conversions.clear_keyspace! - Cassandra::WRITE_DEFAULTS[:consistency] = Cassandra::Consistency::ONE - Cassandra::READ_DEFAULTS[:consistency] = Cassandra::Consistency::ONE + CassandraOld::WRITE_DEFAULTS[:consistency] = CassandraOld::Consistency::ONE + CassandraOld::READ_DEFAULTS[:consistency] = CassandraOld::Consistency::ONE @uuids = (0..6).map {|i| SimpleUUID::UUID.new(Time.at(2**(24+i))) } @longs = (0..6).map {|i| Long.new(Time.at(2**(24+i))) } @composites = [ - Cassandra::Composite.new([5].pack('N'), "zebra"), - Cassandra::Composite.new([5].pack('N'), "aardvark"), - Cassandra::Composite.new([1].pack('N'), "elephant"), - Cassandra::Composite.new([10].pack('N'), "kangaroo"), + CassandraOld::Composite.new([5].pack('N'), "zebra"), + CassandraOld::Composite.new([5].pack('N'), "aardvark"), + CassandraOld::Composite.new([1].pack('N'), "elephant"), + CassandraOld::Composite.new([10].pack('N'), "kangaroo"), ] @dynamic_composites = [ - Cassandra::DynamicComposite.new(['i', [5].pack('N')], ['UTF8Type', "zebra"]), - Cassandra::DynamicComposite.new(['i', [5].pack('N')], ['UTF8Type', "aardvark"]), - Cassandra::DynamicComposite.new(['IntegerType', [1].pack('N')], ['s', "elephant"]), - Cassandra::DynamicComposite.new(['IntegerType', [10].pack('N')], ['s', "kangaroo"]), + CassandraOld::DynamicComposite.new(['i', [5].pack('N')], ['UTF8Type', "zebra"]), + CassandraOld::DynamicComposite.new(['i', [5].pack('N')], ['UTF8Type', "aardvark"]), + CassandraOld::DynamicComposite.new(['IntegerType', [1].pack('N')], ['s', "elephant"]), + CassandraOld::DynamicComposite.new(['IntegerType', [10].pack('N')], ['s', "kangaroo"]), ] end @@ -48,14 +48,14 @@ def test_inspect def test_setting_default_consistency assert_nothing_raised do - @twitter.default_read_consistency = Cassandra::Consistency::ALL + @twitter.default_read_consistency = CassandraOld::Consistency::ALL end - assert_equal(Cassandra::READ_DEFAULTS[:consistency], Cassandra::Consistency::ALL) + assert_equal(CassandraOld::READ_DEFAULTS[:consistency], CassandraOld::Consistency::ALL) assert_nothing_raised do - @twitter.default_write_consistency = Cassandra::Consistency::ALL + @twitter.default_write_consistency = CassandraOld::Consistency::ALL end - assert_equal(Cassandra::WRITE_DEFAULTS[:consistency], Cassandra::Consistency::ALL) + assert_equal(CassandraOld::WRITE_DEFAULTS[:consistency], CassandraOld::Consistency::ALL) end def test_get_key @@ -322,8 +322,8 @@ def test_get_range_block def test_get_range_reversed data = 3.times.map { |i| ["body-#{i.to_s}", "v"] } - hash = Cassandra::OrderedHash[data] - reversed_hash = Cassandra::OrderedHash[data.reverse] + hash = CassandraOld::OrderedHash[data] + reversed_hash = CassandraOld::OrderedHash[data.reverse] @twitter.insert(:Statuses, "all-keys", hash) @@ -718,7 +718,7 @@ def test_disconnect! def test_disconnect_when_not_connected! assert_nothing_raised do - @twitter = Cassandra.new('Twitter', "127.0.0.1:9160", :retries => 2, :exception_classes => []) + @twitter = CassandraOld.new('Twitter', "127.0.0.1:9160", :retries => 2, :exception_classes => []) @twitter.disconnect! end end @@ -1176,7 +1176,7 @@ def test_column_family_mutation # Verify add_column_family works as desired. @twitter.add_column_family( - Cassandra::ColumnFamily.new( + CassandraOld::ColumnFamily.new( :keyspace => 'Twitter', :name => k ) @@ -1245,40 +1245,40 @@ def test_reading_rows_with_super_column_counter def test_composite_column_type_conversion columns = {} @composites.push( - Cassandra::Composite.new_from_parts([[20].pack('N'), "meerkat"]) + CassandraOld::Composite.new_from_parts([[20].pack('N'), "meerkat"]) ) @composites.each_with_index do |c, index| columns[c] = "value-#{index}" end @type_conversions.insert(:CompositeColumnConversion, key, columns) columns_in_order = [ - Cassandra::Composite.new([1].pack('N'), "elephant"), - Cassandra::Composite.new([5].pack('N'), "aardvark"), - Cassandra::Composite.new([5].pack('N'), "zebra"), - Cassandra::Composite.new([10].pack('N'), "kangaroo"), - Cassandra::Composite.new([20].pack('N'), "meerkat"), + CassandraOld::Composite.new([1].pack('N'), "elephant"), + CassandraOld::Composite.new([5].pack('N'), "aardvark"), + CassandraOld::Composite.new([5].pack('N'), "zebra"), + CassandraOld::Composite.new([10].pack('N'), "kangaroo"), + CassandraOld::Composite.new([20].pack('N'), "meerkat"), ] assert_equal(columns_in_order, @type_conversions.get(:CompositeColumnConversion, key).keys) column_slice = @type_conversions.get(:CompositeColumnConversion, key, - :start => Cassandra::Composite.new([1].pack('N')), - :finish => Cassandra::Composite.new([20].pack('N')) + :start => CassandraOld::Composite.new([1].pack('N')), + :finish => CassandraOld::Composite.new([20].pack('N')) ).keys assert_equal(columns_in_order[0..-2], column_slice) column_slice = @type_conversions.get(:CompositeColumnConversion, key, - :start => Cassandra::Composite.new([5].pack('N')), - :finish => Cassandra::Composite.new([5].pack('N'), :slice => :after) + :start => CassandraOld::Composite.new([5].pack('N')), + :finish => CassandraOld::Composite.new([5].pack('N'), :slice => :after) ).keys assert_equal(columns_in_order[1..2], column_slice) column_slice = @type_conversions.get(:CompositeColumnConversion, key, - :start => Cassandra::Composite.new([5].pack('N'), :slice => :after).to_s + :start => CassandraOld::Composite.new([5].pack('N'), :slice => :after).to_s ).keys assert_equal(columns_in_order[-2..-1], column_slice) column_slice = @type_conversions.get(:CompositeColumnConversion, key, - :finish => Cassandra::Composite.new([10].pack('N'), :slice => :before).to_s + :finish => CassandraOld::Composite.new([10].pack('N'), :slice => :before).to_s ).keys assert_equal(columns_in_order[0..-3], column_slice) @@ -1293,32 +1293,32 @@ def test_dynamic_composite_column_type_conversion @type_conversions.insert(:DynamicComposite, key, columns) columns_in_order = [ - Cassandra::DynamicComposite.new(['IntegerType', [1].pack('N')], ['s', "elephant"]), - Cassandra::DynamicComposite.new(['i', [5].pack('N')], ['UTF8Type', "aardvark"]), - Cassandra::DynamicComposite.new(['i', [5].pack('N')], ['UTF8Type', "zebra"]), - Cassandra::DynamicComposite.new(['IntegerType', [10].pack('N')], ['s', "kangaroo"]), + CassandraOld::DynamicComposite.new(['IntegerType', [1].pack('N')], ['s', "elephant"]), + CassandraOld::DynamicComposite.new(['i', [5].pack('N')], ['UTF8Type', "aardvark"]), + CassandraOld::DynamicComposite.new(['i', [5].pack('N')], ['UTF8Type', "zebra"]), + CassandraOld::DynamicComposite.new(['IntegerType', [10].pack('N')], ['s', "kangaroo"]), ] assert_equal(columns_in_order, @type_conversions.get(:DynamicComposite, key).keys) column_slice = @type_conversions.get(:DynamicComposite, key, - :start => Cassandra::DynamicComposite.new(['i', [1].pack('N')]), - :finish => Cassandra::DynamicComposite.new(['i', [10].pack('N')]) + :start => CassandraOld::DynamicComposite.new(['i', [1].pack('N')]), + :finish => CassandraOld::DynamicComposite.new(['i', [10].pack('N')]) ).keys assert_equal(columns_in_order[0..-2], column_slice) column_slice = @type_conversions.get(:DynamicComposite, key, - :start => Cassandra::DynamicComposite.new(['IntegerType', [5].pack('N')]), - :finish => Cassandra::DynamicComposite.new(['IntegerType', [5].pack('N')], :slice => :after) + :start => CassandraOld::DynamicComposite.new(['IntegerType', [5].pack('N')]), + :finish => CassandraOld::DynamicComposite.new(['IntegerType', [5].pack('N')], :slice => :after) ).keys assert_equal(columns_in_order[1..2], column_slice) column_slice = @type_conversions.get(:DynamicComposite, key, - :start => Cassandra::DynamicComposite.new(['i', [5].pack('N')], :slice => :after).to_s + :start => CassandraOld::DynamicComposite.new(['i', [5].pack('N')], :slice => :after).to_s ).keys assert_equal([columns_in_order[-1]], column_slice) column_slice = @type_conversions.get(:DynamicComposite, key, - :finish => Cassandra::DynamicComposite.new(['i', [10].pack('N')], :slice => :before).to_s + :finish => CassandraOld::DynamicComposite.new(['i', [10].pack('N')], :slice => :before).to_s ).keys assert_equal(columns_in_order[0..-2], column_slice) @@ -1346,9 +1346,9 @@ def test_supercolumn_timestamps end def test_keyspace_operations - system = Cassandra.new 'system' + system = CassandraOld.new 'system' keyspace_name = 'robots' - keyspace_definition = Cassandra::Keyspace.new :name => keyspace_name, + keyspace_definition = CassandraOld::Keyspace.new :name => keyspace_name, :strategy_class => 'SimpleStrategy', :strategy_options => { 'replication_factor' => '2' }, :cf_defs => [] @@ -1359,7 +1359,7 @@ def test_keyspace_operations assert system.keyspaces.none? {|it| it == keyspace_name } system.add_keyspace keyspace_definition - Cassandra.new(keyspace_name).drop_keyspace + CassandraOld.new(keyspace_name).drop_keyspace assert system.keyspaces.none? {|it| it == keyspace_name } end diff --git a/test/comparable_types_test.rb b/test/comparable_types_test.rb index 421a9a0..6856f91 100755 --- a/test/comparable_types_test.rb +++ b/test/comparable_types_test.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__) + '/test_helper') class ComparableTypesTest < Test::Unit::TestCase - include Cassandra::Constants + include CassandraOld::Constants def test_long_sort ary = [] @@ -18,7 +18,7 @@ def test_long_equality end def test_long_error - assert_raises(Cassandra::Comparable::TypeError) do + assert_raises(CassandraOld::Comparable::TypeError) do Long.new("bogus") end end @@ -28,18 +28,18 @@ def test_types_behave_well end def test_casting_unknown_class - assert_raises(Cassandra::Comparable::TypeError) do - Cassandra::Long.new({}) + assert_raises(CassandraOld::Comparable::TypeError) do + CassandraOld::Long.new({}) end end def test_long_inspect obj = Long.new("\000\000\000\000\000\000\000\000") if RUBY_VERSION < '1.9' - assert_equal "", obj.inspect + assert_equal "", obj.inspect else - assert_equal "", obj.inspect + assert_equal "", obj.inspect end end -end \ No newline at end of file +end diff --git a/test/composite_type_test.rb b/test/composite_type_test.rb index 01a9f3a..d5f7519 100755 --- a/test/composite_type_test.rb +++ b/test/composite_type_test.rb @@ -1,11 +1,11 @@ require File.expand_path(File.dirname(__FILE__) + '/test_helper') class CompositeTypesTest < Test::Unit::TestCase - include Cassandra::Constants + include CassandraOld::Constants def setup @col_parts = [[363].pack('N'), 'extradites-mulling', SimpleUUID::UUID.new().bytes] - @col = Cassandra::Composite.new(*@col_parts) + @col = CassandraOld::Composite.new(*@col_parts) @part0_length = 2 + 4 + 1 # size + int + end_term @part1_length = 2 + @col_parts[1].length + 1 # size + string_len + end_term @@ -14,8 +14,8 @@ def setup @types = ['IntegerType', 'UTF8Type', 'TimeUUIDType'] @type_aliaes = ['i', 's', 't'] - @dycol = Cassandra::DynamicComposite.new(*@types.zip(@col_parts)) - @dycol_alias = Cassandra::DynamicComposite.new(*@type_aliaes.zip(@col_parts)) + @dycol = CassandraOld::DynamicComposite.new(*@types.zip(@col_parts)) + @dycol_alias = CassandraOld::DynamicComposite.new(*@type_aliaes.zip(@col_parts)) end def test_creation_from_parts @@ -25,7 +25,7 @@ def test_creation_from_parts assert_equal(@col_parts[i], @dycol_alias[i]) end - col2 = Cassandra::Composite.new_from_parts(@col_parts) + col2 = CassandraOld::Composite.new_from_parts(@col_parts) (0..2).each do |i| assert_equal(@col_parts[i], col2[i].to_s) end @@ -34,7 +34,7 @@ def test_creation_from_parts def test_packing_and_unpacking assert_equal(@part0_length + @part1_length + @part2_length, @col.pack.length) - col2 = Cassandra::Composite.new_from_packed(@col.pack) + col2 = CassandraOld::Composite.new_from_packed(@col.pack) assert_equal(@col_parts[0], col2[0]) assert_equal(@col_parts[1], col2[1]) assert_equal(@col_parts[2], col2[2]) @@ -42,7 +42,7 @@ def test_packing_and_unpacking # make sure we set this while we have the packed string handy assert_equal(@col.pack.hash, col2.instance_variable_get(:@hash)) - col2 = Cassandra::Composite.new(@col.pack) + col2 = CassandraOld::Composite.new(@col.pack) assert_equal(@col_parts[0], col2[0]) assert_equal(@col_parts[1], col2[1]) assert_equal(@col_parts[2], col2[2]) @@ -55,7 +55,7 @@ def test_packing_and_unpacking_dynamic_columns part2_length = @part2_length + 2 + @types[2].length assert_equal(part0_length + part1_length + part2_length, @dycol.pack.length) - col2 = Cassandra::DynamicComposite.new_from_packed(@dycol.pack) + col2 = CassandraOld::DynamicComposite.new_from_packed(@dycol.pack) assert_equal(@col_parts[0], col2[0]) assert_equal(@col_parts[1], col2[1]) assert_equal(@col_parts[2], col2[2]) @@ -63,7 +63,7 @@ def test_packing_and_unpacking_dynamic_columns # make sure we set this while we have the packed string handy assert_equal(@dycol.pack.hash, col2.instance_variable_get(:@hash)) - col2 = Cassandra::DynamicComposite.new(@dycol.pack) + col2 = CassandraOld::DynamicComposite.new(@dycol.pack) assert_equal(@col_parts[0], col2[0]) assert_equal(@col_parts[1], col2[1]) assert_equal(@col_parts[2], col2[2]) @@ -76,13 +76,13 @@ def test_packing_and_unpacking_dynamic_columns_with_aliases part2_length = @part2_length + 2 assert_equal(part0_length + part1_length + part2_length, @dycol_alias.pack.length) - col2 = Cassandra::DynamicComposite.new_from_packed(@dycol_alias.pack) + col2 = CassandraOld::DynamicComposite.new_from_packed(@dycol_alias.pack) assert_equal(@col_parts[0], col2[0]) assert_equal(@col_parts[1], col2[1]) assert_equal(@col_parts[2], col2[2]) assert_equal(@dycol_alias, col2) - col2 = Cassandra::DynamicComposite.new(@dycol_alias.pack) + col2 = CassandraOld::DynamicComposite.new(@dycol_alias.pack) assert_equal(@col_parts[0], col2[0]) assert_equal(@col_parts[1], col2[1]) assert_equal(@col_parts[2], col2[2]) diff --git a/test/eventmachine_test.rb b/test/eventmachine_test.rb index 0c4f48f..8f220f7 100755 --- a/test/eventmachine_test.rb +++ b/test/eventmachine_test.rb @@ -9,7 +9,7 @@ class EventmachineTest < Test::Unit::TestCase def test_twitter - @twitter = Cassandra.new('Twitter', "127.0.0.1:9160", :retries => 2, :exception_classes => [], :transport => Thrift::EventMachineTransport, :transport_wrapper => nil) + @twitter = CassandraOld.new('Twitter', "127.0.0.1:9160", :retries => 2, :exception_classes => [], :transport => Thrift::EventMachineTransport, :transport_wrapper => nil) @twitter.clear_keyspace! end diff --git a/test/ordered_hash_test.rb b/test/ordered_hash_test.rb index 56aab43..d9a036b 100755 --- a/test/ordered_hash_test.rb +++ b/test/ordered_hash_test.rb @@ -5,7 +5,7 @@ def setup @keys = %w( blue green red pink orange ) @values = %w( 000099 009900 aa0000 cc0066 cc6633 ) @hash = Hash.new - @ordered_hash = Cassandra::OrderedHash.new + @ordered_hash = CassandraOld::OrderedHash.new @keys.each_with_index do |key, index| @hash[key] = @values[index] @@ -135,7 +135,7 @@ def test_clear end def test_merge - other_hash = Cassandra::OrderedHash.new + other_hash = CassandraOld::OrderedHash.new other_hash['purple'] = '800080' other_hash['violet'] = 'ee82ee' merged = @ordered_hash.merge other_hash @@ -164,27 +164,27 @@ def test_inspect end def test_alternate_initialization_with_splat - alternate = Cassandra::OrderedHash[1,2,3,4] - assert_kind_of Cassandra::OrderedHash, alternate + alternate = CassandraOld::OrderedHash[1,2,3,4] + assert_kind_of CassandraOld::OrderedHash, alternate assert_equal [1, 3], alternate.keys end def test_alternate_initialization_with_array - alternate = Cassandra::OrderedHash[ [ + alternate = CassandraOld::OrderedHash[ [ [1, 2], [3, 4], "bad key value pair", [ 'missing value' ] ]] - assert_kind_of Cassandra::OrderedHash, alternate + assert_kind_of CassandraOld::OrderedHash, alternate assert_equal [1, 3, 'missing value'], alternate.keys assert_equal [2, 4, nil ], alternate.values end def test_alternate_initialization_raises_exception_on_odd_length_args begin - alternate = Cassandra::OrderedHash[1,2,3,4,5] + alternate = CassandraOld::OrderedHash[1,2,3,4,5] flunk "Hash::[] should have raised an exception on initialization " + "with an odd number of parameters" rescue @@ -193,12 +193,12 @@ def test_alternate_initialization_raises_exception_on_odd_length_args end def test_replace_updates_keys - @other_ordered_hash = Cassandra::OrderedHash[:black, '000000', :white, '000000'] + @other_ordered_hash = CassandraOld::OrderedHash[:black, '000000', :white, '000000'] original = @ordered_hash.replace(@other_ordered_hash) assert_same original, @ordered_hash assert_equal @other_ordered_hash.keys, @ordered_hash.keys end - + def test_reverse assert_equal @keys.reverse, @ordered_hash.reverse.keys assert_equal @values.reverse, @ordered_hash.reverse.values @@ -212,7 +212,7 @@ def setup @timestamps = %w( 12 34 56 78 90 ) @hash = Hash.new @timestamps_hash = Hash.new - @ordered_hash = Cassandra::OrderedHash.new + @ordered_hash = CassandraOld::OrderedHash.new @keys.each_with_index do |key, index| @hash[key] = @values[index] @@ -343,7 +343,7 @@ def test_clear end def test_merge - other_hash = Cassandra::OrderedHash.new + other_hash = CassandraOld::OrderedHash.new other_hash['purple'] = '800080' other_hash['violet'] = 'ee82ee' merged = @ordered_hash.merge other_hash @@ -372,13 +372,13 @@ def test_inspect end def test_alternate_initialization_with_splat - alternate = Cassandra::OrderedHash[1,2,3,4] - assert_kind_of Cassandra::OrderedHash, alternate + alternate = CassandraOld::OrderedHash[1,2,3,4] + assert_kind_of CassandraOld::OrderedHash, alternate assert_equal [1, 3], alternate.timestamps.keys end def test_replace_updates_keys - @other_ordered_hash = Cassandra::OrderedHash[:black, '000000', :white, '000000'] + @other_ordered_hash = CassandraOld::OrderedHash[:black, '000000', :white, '000000'] original = @ordered_hash.replace(@other_ordered_hash) assert_equal original.timestamps, @ordered_hash.timestamps assert_equal @other_ordered_hash.timestamps.keys, @ordered_hash.timestamps.keys diff --git a/test/test_helper.rb b/test/test_helper.rb index 8cbd6d7..e7030f3 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,11 +1,11 @@ CASSANDRA_VERSION = ENV['CASSANDRA_VERSION'] || '0.8' unless defined?(CASSANDRA_VERSION) require 'test/unit' -require "#{File.expand_path(File.dirname(__FILE__))}/../lib/cassandra/#{CASSANDRA_VERSION}" +require "#{File.expand_path(File.dirname(__FILE__))}/../lib/cassandra_old/#{CASSANDRA_VERSION}" begin; require 'ruby-debug'; rescue LoadError; end begin - @test_client = Cassandra.new('Twitter', 'localhost:9160', :thrift_client_options => { + @test_client = CassandraOld.new('Twitter', 'localhost:9160', :thrift_client_options => { :retries => 3, :timeout => 5, :connect_timeout => 1