Permalink
Browse files

Use thriftclient.

  • Loading branch information...
1 parent 3225de7 commit ce023bc6781e6ac5a0ad67b4d4ac292d352e356e Evan Weaver committed Oct 14, 2009
Showing with 17 additions and 18 deletions.
  1. +2 −0 CHANGELOG
  2. +11 −14 lib/cassandra/cassandra.rb
  3. +3 −3 test/cassandra_test.rb
  4. +1 −1 test/test_helper.rb
View
@@ -1,4 +1,6 @@
+v0.6. Use thrift_client gem.
+
v0.5.6.2. Release process was busted.
v0.5.6. Real multiget.
View
@@ -52,26 +52,23 @@ module Consistency
:reversed => false,
:consistency => Consistency::ONE
}.freeze
+
+ THRIFT_DEFAULTS = {
+ :transport => Thrift::BufferedTransport
+ }.freeze
- attr_reader :keyspace, :host, :port, :serializer, :transport, :client, :schema
+ attr_reader :keyspace, :servers, :client, :schema, :thrift_client_options
- # Instantiate a new Cassandra and open the connection.
- def initialize(keyspace, host = '127.0.0.1', port = 9160, buffer = true)
+ # Create a new Cassandra instance and open the connection.
+ def initialize(keyspace, servers = "127.0.0.1:9160", thrift_client_options = {})
@is_super = {}
@column_name_class = {}
@sub_column_name_class = {}
+ @thrift_client_options = THRIFT_DEFAULTS.merge(thrift_client_options)
@keyspace = keyspace
- @host = host
- @port = port
-
- transport = Thrift::BufferedTransport.new(Thrift::Socket.new(@host, @port))
- transport.open
-
- @client = CassandraThrift::Cassandra::SafeClient.new(
- CassandraThrift::Cassandra::Client.new(Thrift::BinaryProtocol.new(transport)),
- transport,
- !buffer)
+ @servers = Array(servers)
+ @client = ThriftClient.new(CassandraThrift::Cassandra::Client, @servers, @thrift_client_options)
keyspaces = @client.get_string_list_property("keyspaces")
unless keyspaces.include?(@keyspace)
@@ -84,7 +81,7 @@ def initialize(keyspace, host = '127.0.0.1', port = 9160, buffer = true)
def inspect
"#<Cassandra:#{object_id}, @keyspace=#{keyspace.inspect}, @schema={#{
schema.map {|name, hash| ":#{name} => #{hash['type'].inspect}"}.join(', ')
- }}, @host=#{host.inspect}, @port=#{port}>"
+ }}, @servers=#{servers.inspect}>"
end
### Write
View
@@ -4,13 +4,13 @@ class CassandraTest < Test::Unit::TestCase
include Cassandra::Constants
def setup
- @twitter = Cassandra.new('Twitter', '127.0.0.1')
+ @twitter = Cassandra.new('Twitter', "127.0.0.1:9160", :retries => 2)
@twitter.clear_keyspace!
- @blogs = Cassandra.new('Multiblog', '127.0.0.1')
+ @blogs = Cassandra.new('Multiblog')
@blogs.clear_keyspace!
- @blogs_long = Cassandra.new('MultiblogLong', '127.0.0.1')
+ @blogs_long = Cassandra.new('MultiblogLong')
@blogs_long.clear_keyspace!
@uuids = (0..6).map {|i| UUID.new(Time.at(2**(24+i))) }
View
@@ -4,7 +4,7 @@
begin; require 'ruby-debug'; rescue LoadError; end
begin
- @test_client = Cassandra.new('Twitter', '127.0.0.1')
+ @test_client = Cassandra.new('Twitter')
rescue Thrift::TransportException => e
#FIXME Make server automatically start if not running
if e.message =~ /Could not connect/

0 comments on commit ce023bc

Please sign in to comment.