cassanity 0.6.0.beta2 → 0.6.0.beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aee509bb367d05f910d105796eeb15a6a9d3e3ec
4
- data.tar.gz: f25ef46dc1e27af16144642fdf9e50e43a2a717e
3
+ metadata.gz: f55c2651855af2b3beae8140f050e24ffce99b92
4
+ data.tar.gz: 03ebc3e813d4e4b5875516fbb2dba386d965a1b6
5
5
  SHA512:
6
- metadata.gz: b4a973ccb47b4a3e244ab33fcd4ca2bceffeada294ad865a92c6fb850065d5466de26a3067b01dd6328ca867c034040697d1f7c15bdf3af95b576c42a7c0b04c
7
- data.tar.gz: 63750d81f4656e692606d9b81d4504341cccfa626d7a637a15446a1768327f52b2e8d846fedd35ef1bae81b5851b395b909e5905a7b443d818d7b1505199ad2c
6
+ metadata.gz: a53e35e81287014b86092ae6269ba89929610d3234194cf1c9d42d1af9a7d0ea99370a7022eab777c0bfb89f2541fe3e910482afad2a4f8dbe086393b35d9959
7
+ data.tar.gz: b4aee0161df84024daff56121d12aa67810a08aa66f535ca79447bbb49dc11789d8d9b4181d93add6aed69d60701d8988139e2e826208e5288bd3d9999d1e599
@@ -1,5 +1,6 @@
1
1
  require 'forwardable'
2
2
  require 'cql'
3
+ require 'cassanity/cql/reconnectable_driver'
3
4
  require 'cassanity/executors/cql_rb'
4
5
  require 'cassanity/connection'
5
6
 
@@ -35,14 +36,7 @@ module Cassanity
35
36
  @instrumenter = @options.delete(:instrumenter)
36
37
  @retry_strategy = @options.delete(:retry_strategy)
37
38
 
38
- connect
39
- end
40
-
41
- # Connect or reconnect to cassandra
42
- def connect
43
- disconnect
44
-
45
- @driver = Cql::Client.connect(@options)
39
+ @driver = Cassanity::Cql::ReconnectableDriver.connect(@options)
46
40
  @executor = Cassanity::Executors::CqlRb.new({
47
41
  driver: @driver,
48
42
  instrumenter: @instrumenter,
@@ -53,9 +47,14 @@ module Cassanity
53
47
  })
54
48
  end
55
49
 
50
+ # Reconnect to cassandra.
51
+ def connect
52
+ @driver.connect
53
+ end
54
+
56
55
  # Disconnect from cassandra.
57
56
  def disconnect
58
- @driver.close if @driver
57
+ @driver.disconnect
59
58
  end
60
59
 
61
60
  # Methods on client that should be delegated to connection.
@@ -0,0 +1,34 @@
1
+ require 'delegate'
2
+
3
+ module Cassanity
4
+ module Cql
5
+ # Internal: An intermediate driver for cql-rb that supports reconnecting
6
+ # by recycling the underlying Cql::Client instance.
7
+ #
8
+ # Reconnecting is important when using a forking web server like unicorn,
9
+ # but cql-rb does not allow a Cql::Client instances that has been
10
+ # disconnected to be reconnected.
11
+ class ReconnectableDriver
12
+ extend Forwardable
13
+ def_delegators :@driver, :use, :execute, :keyspace
14
+
15
+ def self.connect(cql_options = {})
16
+ new(cql_options).tap(&:connect)
17
+ end
18
+
19
+ # cql_options: Options for constructing a Cql::Client
20
+ def initialize(cql_options = {})
21
+ @cql_options = cql_options
22
+ end
23
+
24
+ def connect
25
+ disconnect
26
+ @driver = ::Cql::Client.connect(@cql_options)
27
+ end
28
+
29
+ def disconnect
30
+ @driver.close if @driver
31
+ end
32
+ end
33
+ end
34
+ end
@@ -25,7 +25,7 @@ module Cassanity
25
25
  begin
26
26
  payload[:attempts] = attempt unless payload.nil?
27
27
  return yield
28
- rescue Cql::CqlError => e
28
+ rescue ::Cql::CqlError => e
29
29
  fail(attempt, e)
30
30
  end
31
31
  end
@@ -1,3 +1,3 @@
1
1
  module Cassanity
2
- VERSION = "0.6.0.beta2"
2
+ VERSION = "0.6.0.beta3"
3
3
  end
@@ -36,6 +36,6 @@ module CassanityHelpers
36
36
  end
37
37
 
38
38
  def cassandra_error(err)
39
- Cql::CqlError.new(err)
39
+ ::Cql::CqlError.new(err)
40
40
  end
41
41
  end
@@ -6,26 +6,26 @@ describe Cassanity::Client do
6
6
 
7
7
  before do
8
8
  # Ensure that we never hit cassandra for real here.
9
- Cql::Client.stub(:connect => driver)
9
+ Cassanity::Cql::ReconnectableDriver.stub(:connect => driver)
10
10
  end
11
11
 
12
12
  describe "#initialize" do
13
13
  it "passes arguments to cassandra cql database instance" do
14
- Cql::Client.should_receive(:connect).
14
+ Cassanity::Cql::ReconnectableDriver.should_receive(:connect).
15
15
  with(hash_including(hosts: ['localhost'], port: 1234, some: 'option'))
16
16
 
17
17
  described_class.new(['localhost'], 1234, some: 'option')
18
18
  end
19
19
 
20
20
  it "defaults servers if not present" do
21
- Cql::Client.should_receive(:connect).
21
+ Cassanity::Cql::ReconnectableDriver.should_receive(:connect).
22
22
  with(hash_including(hosts: ['127.0.0.1'], port: 9042))
23
23
 
24
24
  described_class.new
25
25
  end
26
26
 
27
27
  it "defaults servers if nil" do
28
- Cql::Client.should_receive(:connect).
28
+ Cassanity::Cql::ReconnectableDriver.should_receive(:connect).
29
29
  with(hash_including(hosts: ['127.0.0.1'], port: 9042))
30
30
 
31
31
  described_class.new(nil)
@@ -36,7 +36,7 @@ describe Cassanity::Client do
36
36
  driver = double('Driver')
37
37
  executor = double('Executor')
38
38
 
39
- Cql::Client.should_receive(:connect).
39
+ Cassanity::Cql::ReconnectableDriver.should_receive(:connect).
40
40
  with(hash_not_including(instrumenter: instrumenter)).
41
41
  and_return(driver)
42
42
 
@@ -57,7 +57,7 @@ describe Cassanity::Client do
57
57
  executor = double('Executor')
58
58
  connection = double('Connection')
59
59
 
60
- Cql::Client.should_receive(:connect).and_return(driver)
60
+ Cassanity::Cql::ReconnectableDriver.should_receive(:connect).and_return(driver)
61
61
 
62
62
  Cassanity::Executors::CqlRb.should_receive(:new).
63
63
  with(hash_including(driver: driver)).
@@ -118,7 +118,7 @@ describe Cassanity::Client do
118
118
 
119
119
  describe "#disconnect" do
120
120
  it "allows the connection to be terminated" do
121
- driver.should_receive(:close)
121
+ driver.should_receive(:disconnect)
122
122
 
123
123
  client = described_class.new
124
124
  client.disconnect
@@ -0,0 +1,42 @@
1
+ require 'helper'
2
+
3
+ describe Cassanity::Cql::ReconnectableDriver do
4
+ let(:client) { double('Cql::Client') }
5
+
6
+ describe '.connect' do
7
+ it 'constructs a CQL client using the provided options' do
8
+ Cql::Client.should_receive(:connect).with(:foo => "bar") { client }
9
+ driver = described_class.connect(:foo => "bar")
10
+ end
11
+ end
12
+
13
+ describe '#disconnect' do
14
+ it 'closes the underlying driver' do
15
+ Cql::Client.stub(:connect => client)
16
+ driver = described_class.connect(:foo => "bar")
17
+
18
+ client.should_receive(:close)
19
+ driver.disconnect
20
+ end
21
+ end
22
+
23
+ describe '#use' do
24
+ it 'forwards the message to the underlying driver' do
25
+ Cql::Client.stub(:connect => client)
26
+ driver = described_class.connect(:foo => "bar")
27
+
28
+ client.should_receive(:use).with("keyspace")
29
+ driver.use("keyspace")
30
+ end
31
+ end
32
+
33
+ describe '#execute' do
34
+ it 'forwards the message to the underlying driver' do
35
+ Cql::Client.stub(:connect => client)
36
+ driver = described_class.connect(:foo => "bar")
37
+
38
+ client.should_receive(:execute).with("query")
39
+ driver.execute("query")
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.beta2
4
+ version: 0.6.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -98,6 +98,7 @@ files:
98
98
  - lib/cassanity/column.rb
99
99
  - lib/cassanity/column_family.rb
100
100
  - lib/cassanity/connection.rb
101
+ - lib/cassanity/cql/reconnectable_driver.rb
101
102
  - lib/cassanity/decrement.rb
102
103
  - lib/cassanity/error.rb
103
104
  - lib/cassanity/executors/cql_rb.rb
@@ -173,6 +174,7 @@ files:
173
174
  - spec/unit/cassanity/column_family_spec.rb
174
175
  - spec/unit/cassanity/column_spec.rb
175
176
  - spec/unit/cassanity/connection_spec.rb
177
+ - spec/unit/cassanity/cql/reconnectable_driver_spec.rb
176
178
  - spec/unit/cassanity/decrement_spec.rb
177
179
  - spec/unit/cassanity/error_spec.rb
178
180
  - spec/unit/cassanity/increment_spec.rb
@@ -262,6 +264,7 @@ test_files:
262
264
  - spec/unit/cassanity/column_family_spec.rb
263
265
  - spec/unit/cassanity/column_spec.rb
264
266
  - spec/unit/cassanity/connection_spec.rb
267
+ - spec/unit/cassanity/cql/reconnectable_driver_spec.rb
265
268
  - spec/unit/cassanity/decrement_spec.rb
266
269
  - spec/unit/cassanity/error_spec.rb
267
270
  - spec/unit/cassanity/increment_spec.rb