Skip to content
This repository has been archived by the owner on May 29, 2020. It is now read-only.

Commit

Permalink
Merge 315158b into ff3ad20
Browse files Browse the repository at this point in the history
  • Loading branch information
ottbot committed Aug 1, 2013
2 parents ff3ad20 + 315158b commit 33c9caf
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -3,6 +3,6 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in virsandra.gemspec

gem 'coveralls', require: false
gem "cassandra-cql", :git => "git://github.com/ottbot/cassandra-cql", :branch => "1.2-set-consistency"


gemspec
3 changes: 2 additions & 1 deletion lib/virsandra.rb
@@ -1,5 +1,6 @@
require "virtus"
require "cassandra-cql/1.2"
require "cql"
require "simple_uuid"

require "virsandra/version"
require "virsandra/configuration"
Expand Down
4 changes: 0 additions & 4 deletions lib/virsandra/configuration.rb
Expand Up @@ -6,9 +6,7 @@ module Configuration
OPTIONS = [
:keyspace,
:servers,
:thrift_options,
:consistency,
:cql_version
]

attr_accessor *OPTIONS
Expand All @@ -19,9 +17,7 @@ def self.extended(base)

def reset!
self.servers = '127.0.0.1:9160'
self.cql_version = '3.0.0'
self.consistency = :quorum
self.thrift_options = {retries: 5, connect_timeout: 10, timeout: 10}
self.keyspace = nil
end

Expand Down
10 changes: 6 additions & 4 deletions lib/virsandra/connection.rb
Expand Up @@ -13,11 +13,13 @@ def initialize(options)
end

def connect!
cql_options = @options.select {|k| [:keyspace, :cql_version, :consistency].include?(k) }
@handle = Cql::Client.connect(hosts: @options[:servers])
@handle.use(@options[:keyspace])
@handle
end

@handle = CassandraCQL::Database.new(@options[:servers],
cql_options,
@options[:thrift_options])
def disconnect!
@handle.close
end

# Delegate to CassandraCQL::Database handle
Expand Down
2 changes: 1 addition & 1 deletion lib/virsandra/query.rb
Expand Up @@ -72,7 +72,7 @@ def raw_query
end

def fetch_with_symbolized_keys
row_hash = @row && @row.fetch_hash
row_hash = @row && @row.first
return {} unless row_hash

Hash[row_hash.map{|(k,v)| [k.to_sym,v]}]
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/virsandra/connection_spec.rb
Expand Up @@ -11,7 +11,7 @@
end

it "obtains a db connection" do
connection.handle.should be_a CassandraCQL::Database
connection.handle.should be_a Cql::Client::SynchronousClient
end

it "delegates to the cassandra handle" do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/virsandra/query_spec.rb
Expand Up @@ -9,7 +9,7 @@
end

it "should return empty hash when can't fetch hash from results" do
Virsandra.stub(:execute => double("row", :fetch_hash => nil))
Virsandra.stub(:execute => double("row", :first => nil))
described_class.new.fetch.should eq({})
end

Expand Down
6 changes: 1 addition & 5 deletions spec/lib/virsandra_spec.rb
Expand Up @@ -43,9 +43,7 @@

defaults = {
servers: '127.0.0.1:9160',
cql_version: '3.0.0',
consistency: :quorum,
thrift_options: {retries: 5, connect_timeout: 10, timeout: 10},
keyspace: nil
}

Expand All @@ -65,12 +63,10 @@
end

it "reconnects if dirty" do
CassandraCQL::Database.stub(:new)

Virsandra::Connection.should_receive(:new).twice.and_call_original
Virsandra.connection

Virsandra.keyspace = 'foo'
Virsandra.keyspace = 'system'
Virsandra.connection
Virsandra.connection
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -42,7 +42,7 @@ def build_up
begin
create_keyspace
create_companies_table
rescue CassandraCQL::Error::InvalidRequestException
rescue Cql::QueryError
drop_keyspace

if defined?(retried)
Expand Down
1 change: 1 addition & 0 deletions virsandra.gemspec
Expand Up @@ -20,6 +20,7 @@ Gem::Specification.new do |gem|

#gem.add_dependency "cassandra-cql", #WHEN IT SUPPORTS CQL3
gem.add_dependency "virtus", ">= 0.5.4"
gem.add_dependency "cql-rb", ">= 1.0.2"
gem.add_dependency "simple_uuid", ">= 0.3.0"

gem.add_development_dependency "rake", ">= 0.9.2"
Expand Down

0 comments on commit 33c9caf

Please sign in to comment.