cql-rb 2.0.0.pre0 → 2.0.0.pre1
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 +4 -4
- data/README.md +14 -2
- data/lib/cql.rb +8 -3
- data/lib/cql/client.rb +21 -356
- data/lib/cql/client/authenticators.rb +70 -0
- data/lib/cql/client/batch.rb +54 -0
- data/lib/cql/client/{asynchronous_client.rb → client.rb} +241 -6
- data/lib/cql/client/connector.rb +3 -2
- data/lib/cql/client/{asynchronous_prepared_statement.rb → prepared_statement.rb} +103 -0
- data/lib/cql/protocol.rb +1 -2
- data/lib/cql/protocol/cql_byte_buffer.rb +285 -0
- data/lib/cql/protocol/cql_protocol_handler.rb +3 -3
- data/lib/cql/protocol/frame_decoder.rb +3 -3
- data/lib/cql/protocol/frame_encoder.rb +2 -2
- data/lib/cql/protocol/request.rb +0 -2
- data/lib/cql/protocol/requests/auth_response_request.rb +2 -2
- data/lib/cql/protocol/requests/batch_request.rb +10 -10
- data/lib/cql/protocol/requests/credentials_request.rb +2 -2
- data/lib/cql/protocol/requests/execute_request.rb +13 -13
- data/lib/cql/protocol/requests/options_request.rb +2 -2
- data/lib/cql/protocol/requests/prepare_request.rb +2 -2
- data/lib/cql/protocol/requests/query_request.rb +13 -13
- data/lib/cql/protocol/requests/register_request.rb +2 -2
- data/lib/cql/protocol/requests/startup_request.rb +2 -2
- data/lib/cql/protocol/response.rb +2 -4
- data/lib/cql/protocol/responses/auth_challenge_response.rb +2 -2
- data/lib/cql/protocol/responses/auth_success_response.rb +2 -2
- data/lib/cql/protocol/responses/authenticate_response.rb +2 -2
- data/lib/cql/protocol/responses/detailed_error_response.rb +15 -15
- data/lib/cql/protocol/responses/error_response.rb +4 -4
- data/lib/cql/protocol/responses/event_response.rb +3 -3
- data/lib/cql/protocol/responses/prepared_result_response.rb +4 -4
- data/lib/cql/protocol/responses/raw_rows_result_response.rb +1 -1
- data/lib/cql/protocol/responses/ready_response.rb +1 -1
- data/lib/cql/protocol/responses/result_response.rb +3 -3
- data/lib/cql/protocol/responses/rows_result_response.rb +22 -22
- data/lib/cql/protocol/responses/schema_change_event_response.rb +2 -2
- data/lib/cql/protocol/responses/schema_change_result_response.rb +2 -2
- data/lib/cql/protocol/responses/set_keyspace_result_response.rb +2 -2
- data/lib/cql/protocol/responses/status_change_event_response.rb +2 -2
- data/lib/cql/protocol/responses/supported_response.rb +2 -2
- data/lib/cql/protocol/responses/void_result_response.rb +1 -1
- data/lib/cql/protocol/type_converter.rb +78 -81
- data/lib/cql/time_uuid.rb +6 -0
- data/lib/cql/uuid.rb +2 -1
- data/lib/cql/version.rb +1 -1
- data/spec/cql/client/batch_spec.rb +8 -8
- data/spec/cql/client/{asynchronous_client_spec.rb → client_spec.rb} +162 -0
- data/spec/cql/client/connector_spec.rb +13 -3
- data/spec/cql/client/{asynchronous_prepared_statement_spec.rb → prepared_statement_spec.rb} +148 -1
- data/spec/cql/client/request_runner_spec.rb +2 -2
- data/spec/cql/protocol/cql_byte_buffer_spec.rb +895 -0
- data/spec/cql/protocol/cql_protocol_handler_spec.rb +1 -1
- data/spec/cql/protocol/frame_decoder_spec.rb +14 -14
- data/spec/cql/protocol/frame_encoder_spec.rb +7 -7
- data/spec/cql/protocol/requests/auth_response_request_spec.rb +4 -4
- data/spec/cql/protocol/requests/batch_request_spec.rb +21 -21
- data/spec/cql/protocol/requests/credentials_request_spec.rb +2 -2
- data/spec/cql/protocol/requests/execute_request_spec.rb +13 -13
- data/spec/cql/protocol/requests/options_request_spec.rb +1 -1
- data/spec/cql/protocol/requests/prepare_request_spec.rb +2 -2
- data/spec/cql/protocol/requests/query_request_spec.rb +13 -13
- data/spec/cql/protocol/requests/register_request_spec.rb +2 -2
- data/spec/cql/protocol/requests/startup_request_spec.rb +4 -4
- data/spec/cql/protocol/responses/auth_challenge_response_spec.rb +5 -5
- data/spec/cql/protocol/responses/auth_success_response_spec.rb +5 -5
- data/spec/cql/protocol/responses/authenticate_response_spec.rb +3 -3
- data/spec/cql/protocol/responses/detailed_error_response_spec.rb +15 -15
- data/spec/cql/protocol/responses/error_response_spec.rb +5 -5
- data/spec/cql/protocol/responses/event_response_spec.rb +8 -8
- data/spec/cql/protocol/responses/prepared_result_response_spec.rb +7 -7
- data/spec/cql/protocol/responses/raw_rows_result_response_spec.rb +1 -1
- data/spec/cql/protocol/responses/ready_response_spec.rb +2 -2
- data/spec/cql/protocol/responses/result_response_spec.rb +16 -16
- data/spec/cql/protocol/responses/rows_result_response_spec.rb +21 -21
- data/spec/cql/protocol/responses/schema_change_event_response_spec.rb +3 -3
- data/spec/cql/protocol/responses/schema_change_result_response_spec.rb +3 -3
- data/spec/cql/protocol/responses/set_keyspace_result_response_spec.rb +2 -2
- data/spec/cql/protocol/responses/status_change_event_response_spec.rb +3 -3
- data/spec/cql/protocol/responses/supported_response_spec.rb +3 -3
- data/spec/cql/protocol/responses/topology_change_event_response_spec.rb +3 -3
- data/spec/cql/protocol/responses/void_result_response_spec.rb +2 -2
- data/spec/cql/protocol/type_converter_spec.rb +25 -13
- data/spec/cql/time_uuid_spec.rb +17 -4
- data/spec/cql/uuid_spec.rb +5 -1
- data/spec/integration/protocol_spec.rb +48 -42
- data/spec/spec_helper.rb +0 -1
- metadata +27 -39
- data/lib/cql/byte_buffer.rb +0 -177
- data/lib/cql/client/synchronous_client.rb +0 -79
- data/lib/cql/client/synchronous_prepared_statement.rb +0 -63
- data/lib/cql/future.rb +0 -515
- data/lib/cql/io.rb +0 -15
- data/lib/cql/io/connection.rb +0 -220
- data/lib/cql/io/io_reactor.rb +0 -349
- data/lib/cql/protocol/decoding.rb +0 -187
- data/lib/cql/protocol/encoding.rb +0 -114
- data/spec/cql/byte_buffer_spec.rb +0 -337
- data/spec/cql/client/synchronous_client_spec.rb +0 -170
- data/spec/cql/client/synchronous_prepared_statement_spec.rb +0 -155
- data/spec/cql/future_spec.rb +0 -737
- data/spec/cql/io/connection_spec.rb +0 -484
- data/spec/cql/io/io_reactor_spec.rb +0 -402
- data/spec/cql/protocol/decoding_spec.rb +0 -547
- data/spec/cql/protocol/encoding_spec.rb +0 -386
- data/spec/integration/io_spec.rb +0 -283
- data/spec/support/fake_server.rb +0 -106
@@ -6,10 +6,10 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe SchemaChangeEventResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
let :response do
|
11
|
-
buffer =
|
12
|
-
described_class.decode
|
11
|
+
buffer = CqlByteBuffer.new("\x00\aDROPPED\x00\ncql_rb_609\x00\x05users")
|
12
|
+
described_class.decode(1, buffer, buffer.length)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'decodes the change' do
|
@@ -6,10 +6,10 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe SchemaChangeResultResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
let :response do
|
11
|
-
buffer =
|
12
|
-
described_class.decode
|
11
|
+
buffer = CqlByteBuffer.new("\x00\aUPDATED\x00\ncql_rb_973\x00\x05users")
|
12
|
+
described_class.decode(1, buffer, buffer.length)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'decodes the description' do
|
@@ -6,9 +6,9 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe SetKeyspaceResultResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
let :response do
|
11
|
-
described_class.decode
|
11
|
+
described_class.decode(1, CqlByteBuffer.new("\x00\x06system"), 8)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'decodes the keyspace' do
|
@@ -6,10 +6,10 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe StatusChangeEventResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
let :response do
|
11
|
-
buffer =
|
12
|
-
described_class.decode
|
11
|
+
buffer = CqlByteBuffer.new("\x00\x04DOWN\x04\x00\x00\x00\x00\x00\x00#R")
|
12
|
+
described_class.decode(1, buffer, buffer.length)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'decodes the change' do
|
@@ -6,10 +6,10 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe SupportedResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
let :response do
|
11
|
-
buffer =
|
12
|
-
described_class.decode
|
11
|
+
buffer = CqlByteBuffer.new("\x00\x02\x00\x0bCQL_VERSION\x00\x01\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x00")
|
12
|
+
described_class.decode(1, buffer, buffer.length)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'decodes the options' do
|
@@ -6,10 +6,10 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe TopologyChangeEventResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
let :response do
|
11
|
-
buffer =
|
12
|
-
described_class.decode
|
11
|
+
buffer = CqlByteBuffer.new("\x00\fREMOVED_NODE\x04\x00\x00\x00\x00\x00\x00#R")
|
12
|
+
described_class.decode(1, buffer, buffer.length)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'decodes the change' do
|
@@ -6,10 +6,10 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe VoidResultResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
it 'returns a new instance' do
|
11
11
|
unused_byte_buffer = nil
|
12
|
-
described_class.decode
|
12
|
+
described_class.decode(1, unused_byte_buffer, 0).should be_a(described_class)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -11,55 +11,67 @@ module Cql
|
|
11
11
|
end
|
12
12
|
|
13
13
|
let :buffer do
|
14
|
-
|
14
|
+
CqlByteBuffer.new
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#to_bytes' do
|
18
|
-
|
19
|
-
:ascii,
|
18
|
+
numeric_types = [
|
20
19
|
:bigint,
|
21
|
-
:blob,
|
22
|
-
:boolean,
|
23
20
|
:counter,
|
24
21
|
:decimal,
|
25
22
|
:double,
|
26
23
|
:float,
|
27
|
-
:inet,
|
28
24
|
:int,
|
25
|
+
:varint,
|
26
|
+
]
|
27
|
+
|
28
|
+
types = numeric_types + [
|
29
|
+
:ascii,
|
30
|
+
:blob,
|
31
|
+
:boolean,
|
32
|
+
:inet,
|
29
33
|
:text,
|
30
34
|
:varchar,
|
31
35
|
:timestamp,
|
32
36
|
:timeuuid,
|
33
37
|
:uuid,
|
34
|
-
:varint
|
35
38
|
]
|
36
39
|
|
37
40
|
context 'when encoding normal value' do
|
38
41
|
types.each do |type|
|
39
42
|
it "encodes a null #{type.upcase}" do
|
40
|
-
converter.to_bytes(buffer, type, nil, 4).should
|
43
|
+
converter.to_bytes(buffer, type, nil, 4).should eql_bytes("\xff\xff\xff\xff")
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
44
47
|
it 'encodes a null LIST' do
|
45
|
-
converter.to_bytes(buffer, [:list, :int], nil, 4).should
|
48
|
+
converter.to_bytes(buffer, [:list, :int], nil, 4).should eql_bytes("\xff\xff\xff\xff")
|
46
49
|
end
|
47
50
|
|
48
51
|
it 'encodes a null MAP' do
|
49
|
-
converter.to_bytes(buffer, [:map, :text, :text], nil, 4).should
|
52
|
+
converter.to_bytes(buffer, [:map, :text, :text], nil, 4).should eql_bytes("\xff\xff\xff\xff")
|
50
53
|
|
51
54
|
end
|
52
55
|
|
53
56
|
it 'encodes a null SET' do
|
54
|
-
converter.to_bytes(buffer, [:set, :uuid], nil, 4).should
|
55
|
-
|
57
|
+
converter.to_bytes(buffer, [:set, :uuid], nil, 4).should eql_bytes("\xff\xff\xff\xff")
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
59
61
|
context 'when encoding collection values' do
|
60
62
|
types.each do |type|
|
61
63
|
it "encodes a null #{type.upcase}" do
|
62
|
-
converter.to_bytes(buffer, type, nil, 2).should
|
64
|
+
converter.to_bytes(buffer, type, nil, 2).should eql_bytes("\xff\xff")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when encoding and decoding negative numbers' do
|
70
|
+
numeric_types.each do |type|
|
71
|
+
it "encodes and decodes a -1 #{type.upcase}" do
|
72
|
+
value = type == :decimal ? BigDecimal.new('-1') : -1
|
73
|
+
encoded = converter.to_bytes(buffer, type, value, 4)
|
74
|
+
converter.from_bytes(encoded, type, 4).should == value
|
63
75
|
end
|
64
76
|
end
|
65
77
|
end
|
data/spec/cql/time_uuid_spec.rb
CHANGED
@@ -5,10 +5,6 @@ require 'spec_helper'
|
|
5
5
|
|
6
6
|
module Cql
|
7
7
|
describe TimeUuid do
|
8
|
-
let :time do
|
9
|
-
Time.utc(2013, 6, 7, 8, 9, 10)
|
10
|
-
end
|
11
|
-
|
12
8
|
describe '#to_time' do
|
13
9
|
it 'returns a Time' do
|
14
10
|
x = TimeUuid.new('00b69180-d0e1-11e2-8b8b-0800200c9a66')
|
@@ -16,6 +12,23 @@ module Cql
|
|
16
12
|
x.to_time.should be < Time.utc(2013, 6, 9, 8, 45, 58)
|
17
13
|
end
|
18
14
|
end
|
15
|
+
|
16
|
+
describe '#<=>' do
|
17
|
+
let :uuids do
|
18
|
+
[
|
19
|
+
TimeUuid.new(175821750227570343682790694234162314858),
|
20
|
+
TimeUuid.new(179047849699804924671695969702288932458),
|
21
|
+
TimeUuid.new(179548637446269962124687370109891231338),
|
22
|
+
TimeUuid.new(180030188594876536196511058046351949418),
|
23
|
+
TimeUuid.new(180518394909134308472692603674640891498),
|
24
|
+
TimeUuid.new(183319310901264713895398493985212841578),
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sorts by the time component' do
|
29
|
+
uuids.shuffle.sort.should == uuids
|
30
|
+
end
|
31
|
+
end
|
19
32
|
end
|
20
33
|
|
21
34
|
describe TimeUuid::Generator do
|
data/spec/cql/uuid_spec.rb
CHANGED
@@ -60,7 +60,7 @@ module Cql
|
|
60
60
|
|
61
61
|
describe '#hash' do
|
62
62
|
it 'calculates a 64 bit hash of the UUID' do
|
63
|
-
h = Uuid.new(
|
63
|
+
h = Uuid.new(162917432198567078063626261009205865234).hash
|
64
64
|
h.should be < 2**63
|
65
65
|
h.should be > -2**63
|
66
66
|
end
|
@@ -82,6 +82,10 @@ module Cql
|
|
82
82
|
it 'returns the numeric value' do
|
83
83
|
Uuid.new('cfd66ccc-d857-4e90-b1e5-df98a3d40cd6').value.should == 276263553384940695775376958868900023510
|
84
84
|
end
|
85
|
+
|
86
|
+
it 'is aliased as #to_i' do
|
87
|
+
Uuid.new('cfd66ccc-d857-4e90-b1e5-df98a3d40cd6').to_i.should == 276263553384940695775376958868900023510
|
88
|
+
end
|
85
89
|
end
|
86
90
|
end
|
87
91
|
end
|
@@ -8,21 +8,41 @@ describe 'Protocol parsing and communication' do
|
|
8
8
|
2
|
9
9
|
end
|
10
10
|
|
11
|
-
let
|
12
|
-
|
13
|
-
ir.start
|
14
|
-
connections << ir.connect(ENV['CASSANDRA_HOST'], 9042, 5).value
|
15
|
-
ir
|
11
|
+
let :io_reactor do
|
12
|
+
Cql::Io::IoReactor.new.start.value
|
16
13
|
end
|
17
14
|
|
18
|
-
let :
|
19
|
-
[]
|
15
|
+
let :connection do
|
16
|
+
io_reactor.connect(ENV['CASSANDRA_HOST'], 9042, 5, &protocol_handler_factory).value
|
17
|
+
end
|
18
|
+
|
19
|
+
let :protocol_handler_factory do
|
20
|
+
lambda { |connection| Cql::Protocol::CqlProtocolHandler.new(connection, io_reactor, protocol_version) }
|
20
21
|
end
|
21
22
|
|
22
23
|
let :keyspace_name do
|
23
24
|
"cql_rb_#{rand(1000)}"
|
24
25
|
end
|
25
26
|
|
27
|
+
before :all do
|
28
|
+
ir = Cql::Io::IoReactor.new
|
29
|
+
protocol_handler_factory = lambda { |connection| Cql::Protocol::CqlProtocolHandler.new(connection, ir, 2) }
|
30
|
+
f = ir.start
|
31
|
+
f = f.flat_map do |reactor|
|
32
|
+
reactor.connect(ENV['CASSANDRA_HOST'], 9042, 5, &protocol_handler_factory)
|
33
|
+
end
|
34
|
+
f = f.flat_map do |connection|
|
35
|
+
connection.send_request(Cql::Protocol::StartupRequest.new('3.1.0'))
|
36
|
+
end
|
37
|
+
f = f.map do |response|
|
38
|
+
response.is_a?(Cql::Protocol::AuthenticateResponse)
|
39
|
+
end
|
40
|
+
f = f.flat_map do |authentication_required|
|
41
|
+
ir.stop.map(authentication_required)
|
42
|
+
end
|
43
|
+
@authentication_enabled = f.value
|
44
|
+
end
|
45
|
+
|
26
46
|
after do
|
27
47
|
if io_reactor.running?
|
28
48
|
drop_keyspace! rescue nil
|
@@ -30,22 +50,7 @@ describe 'Protocol parsing and communication' do
|
|
30
50
|
end
|
31
51
|
end
|
32
52
|
|
33
|
-
def authentication_enabled?
|
34
|
-
ir = Cql::Io::IoReactor.new(lambda { |*args| Cql::Protocol::CqlProtocolHandler.new(*args, protocol_version) })
|
35
|
-
ir.start
|
36
|
-
connected = ir.connect(ENV['CASSANDRA_HOST'], 9042, 5)
|
37
|
-
started = connected.flat_map do |connection|
|
38
|
-
connection.send_request(Cql::Protocol::StartupRequest.new('3.1.0'))
|
39
|
-
end
|
40
|
-
response = started.value
|
41
|
-
required = response.is_a?(Cql::Protocol::AuthenticateResponse)
|
42
|
-
ir.stop.value
|
43
|
-
required
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
53
|
def raw_execute_request(request)
|
48
|
-
connection = connections.first
|
49
54
|
connection.send_request(request).value
|
50
55
|
end
|
51
56
|
|
@@ -133,7 +138,7 @@ describe 'Protocol parsing and communication' do
|
|
133
138
|
|
134
139
|
context 'when authentication is not required' do
|
135
140
|
it 'sends STARTUP and receives READY' do
|
136
|
-
pending('authentication required', if: authentication_enabled
|
141
|
+
pending('authentication required', if: @authentication_enabled) do
|
137
142
|
response = execute_request(Cql::Protocol::StartupRequest.new('3.1.0'), false)
|
138
143
|
response.should be_a(Cql::Protocol::ReadyResponse)
|
139
144
|
end
|
@@ -147,14 +152,14 @@ describe 'Protocol parsing and communication' do
|
|
147
152
|
end
|
148
153
|
|
149
154
|
it 'sends STARTUP and receives AUTHENTICATE' do
|
150
|
-
pending('authentication not configured', unless: authentication_enabled
|
155
|
+
pending('authentication not configured', unless: @authentication_enabled) do
|
151
156
|
response = raw_execute_request(Cql::Protocol::StartupRequest.new('3.1.0'))
|
152
157
|
response.should be_a(Cql::Protocol::AuthenticateResponse)
|
153
158
|
end
|
154
159
|
end
|
155
160
|
|
156
161
|
it 'ignores the AUTHENTICATE response and receives ERROR' do
|
157
|
-
pending('authentication not configured', unless: authentication_enabled
|
162
|
+
pending('authentication not configured', unless: @authentication_enabled) do
|
158
163
|
raw_execute_request(Cql::Protocol::StartupRequest.new('3.1.0'))
|
159
164
|
response = raw_execute_request(Cql::Protocol::RegisterRequest.new('TOPOLOGY_CHANGE'))
|
160
165
|
response.code.should == 10
|
@@ -168,7 +173,7 @@ describe 'Protocol parsing and communication' do
|
|
168
173
|
end
|
169
174
|
|
170
175
|
it 'sends bad username and password in CREDENTIALS and receives ERROR' do
|
171
|
-
pending('authentication not configured', unless: authentication_enabled
|
176
|
+
pending('authentication not configured', unless: @authentication_enabled) do
|
172
177
|
raw_execute_request(Cql::Protocol::StartupRequest.new('3.1.0'))
|
173
178
|
response = raw_execute_request(Cql::Protocol::CredentialsRequest.new('username' => 'foo', 'password' => 'bar'))
|
174
179
|
response.code.should == 0x100
|
@@ -178,14 +183,14 @@ describe 'Protocol parsing and communication' do
|
|
178
183
|
|
179
184
|
context 'and the protocol version is 2' do
|
180
185
|
it 'sends STARTUP and receives AUTHENTICATE' do
|
181
|
-
pending('authentication not configured', unless: authentication_enabled
|
186
|
+
pending('authentication not configured', unless: @authentication_enabled) do
|
182
187
|
response = raw_execute_request(Cql::Protocol::StartupRequest.new('3.1.0'))
|
183
188
|
response.should be_a(Cql::Protocol::AuthenticateResponse)
|
184
189
|
end
|
185
190
|
end
|
186
191
|
|
187
192
|
it 'ignores the AUTHENTICATE response and receives ERROR' do
|
188
|
-
pending('authentication not configured', unless: authentication_enabled
|
193
|
+
pending('authentication not configured', unless: @authentication_enabled) do
|
189
194
|
raw_execute_request(Cql::Protocol::StartupRequest.new('3.1.0'))
|
190
195
|
response = raw_execute_request(Cql::Protocol::RegisterRequest.new('TOPOLOGY_CHANGE'))
|
191
196
|
response.code.should == 10
|
@@ -193,7 +198,7 @@ describe 'Protocol parsing and communication' do
|
|
193
198
|
end
|
194
199
|
|
195
200
|
it 'sends STARTUP followed by AUTH_RESPONSE and receives AUTH_SUCCESS' do
|
196
|
-
pending('authentication not configured', unless: authentication_enabled
|
201
|
+
pending('authentication not configured', unless: @authentication_enabled) do
|
197
202
|
raw_execute_request(Cql::Protocol::StartupRequest.new('3.1.0'))
|
198
203
|
response = raw_execute_request(Cql::Protocol::AuthResponseRequest.new("\x00cassandra\x00cassandra"))
|
199
204
|
response.should be_a(Cql::Protocol::AuthSuccessResponse)
|
@@ -201,7 +206,7 @@ describe 'Protocol parsing and communication' do
|
|
201
206
|
end
|
202
207
|
|
203
208
|
it 'sends bad username and password in AUTH_RESPONSE and receives ERROR' do
|
204
|
-
pending('authentication not configured', unless: authentication_enabled
|
209
|
+
pending('authentication not configured', unless: @authentication_enabled) do
|
205
210
|
raw_execute_request(Cql::Protocol::StartupRequest.new('3.1.0'))
|
206
211
|
response = raw_execute_request(Cql::Protocol::AuthResponseRequest.new("\x00cassandra\x00ardnassac"))
|
207
212
|
response.code.should == 0x100
|
@@ -227,7 +232,7 @@ describe 'Protocol parsing and communication' do
|
|
227
232
|
semaphore = Queue.new
|
228
233
|
event = nil
|
229
234
|
execute_request(Cql::Protocol::RegisterRequest.new('SCHEMA_CHANGE'))
|
230
|
-
|
235
|
+
connection.on_event do |event_response|
|
231
236
|
event = event_response
|
232
237
|
semaphore << :ping
|
233
238
|
end
|
@@ -524,13 +529,17 @@ describe 'Protocol parsing and communication' do
|
|
524
529
|
Cql::Compression::SnappyCompressor.new(0)
|
525
530
|
end
|
526
531
|
|
532
|
+
let :protocol_handler_factory do
|
533
|
+
lambda { |connection| Cql::Protocol::CqlProtocolHandler.new(connection, io_reactor, protocol_version, compressor) }
|
534
|
+
end
|
535
|
+
|
527
536
|
it 'sends a compressed request and receives a compressed response' do
|
528
537
|
compressor.stub(:compress).and_call_original
|
529
538
|
compressor.stub(:decompress).and_call_original
|
530
|
-
io_reactor = Cql::Io::IoReactor.new
|
539
|
+
io_reactor = Cql::Io::IoReactor.new
|
531
540
|
io_reactor.start.value
|
532
541
|
begin
|
533
|
-
connection = io_reactor.connect(ENV['CASSANDRA_HOST'], 9042, 0.1).value
|
542
|
+
connection = io_reactor.connect(ENV['CASSANDRA_HOST'], 9042, 0.1, &protocol_handler_factory).value
|
534
543
|
connection.send_request(Cql::Protocol::StartupRequest.new('3.1.0', 'snappy')).value
|
535
544
|
connection.send_request(Cql::Protocol::PrepareRequest.new('SELECT * FROM system.peers')).value
|
536
545
|
compressor.should have_received(:compress).at_least(1).times
|
@@ -542,10 +551,6 @@ describe 'Protocol parsing and communication' do
|
|
542
551
|
end
|
543
552
|
|
544
553
|
context 'with pipelining' do
|
545
|
-
let :connection do
|
546
|
-
connections.first
|
547
|
-
end
|
548
|
-
|
549
554
|
it 'handles multiple concurrent requests' do
|
550
555
|
in_keyspace_with_table do
|
551
556
|
futures = 10.times.map do
|
@@ -577,17 +582,18 @@ describe 'Protocol parsing and communication' do
|
|
577
582
|
|
578
583
|
context 'in special circumstances' do
|
579
584
|
it 'raises an exception when it cannot connect to Cassandra' do
|
580
|
-
io_reactor = Cql::Io::IoReactor.new
|
585
|
+
io_reactor = Cql::Io::IoReactor.new
|
581
586
|
io_reactor.start.value
|
582
|
-
expect { io_reactor.connect('example.com', 9042, 0.1).value }.to raise_error(Cql::Io::ConnectionError)
|
583
|
-
expect { io_reactor.connect('blackhole', 9042, 0.1).value }.to raise_error(Cql::Io::ConnectionError)
|
587
|
+
expect { io_reactor.connect('example.com', 9042, 0.1, &protocol_handler_factory).value }.to raise_error(Cql::Io::ConnectionError)
|
588
|
+
expect { io_reactor.connect('blackhole', 9042, 0.1, &protocol_handler_factory).value }.to raise_error(Cql::Io::ConnectionError)
|
584
589
|
io_reactor.stop.value
|
585
590
|
end
|
586
591
|
|
587
592
|
it 'does nothing the second time #start is called' do
|
588
|
-
|
593
|
+
protocol_handler_factory = lambda { |connection| Cql::Protocol::CqlProtocolHandler.new(connection, io_reactor, 2) }
|
594
|
+
io_reactor = Cql::Io::IoReactor.new
|
589
595
|
io_reactor.start.value
|
590
|
-
connection = io_reactor.connect(ENV['CASSANDRA_HOST'], 9042, 0.1).value
|
596
|
+
connection = io_reactor.connect(ENV['CASSANDRA_HOST'], 9042, 0.1, &protocol_handler_factory).value
|
591
597
|
response = connection.send_request(Cql::Protocol::StartupRequest.new('3.1.0')).value
|
592
598
|
if response.is_a?(Cql::Protocol::AuthenticateResponse)
|
593
599
|
response = connection.send_request(Cql::Protocol::AuthResponseRequest.new("\x00cassandra\x00cassandra")).value
|