cql-rb 1.1.3 → 1.2.0.pre0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -11
- data/lib/cql.rb +1 -0
- data/lib/cql/client.rb +41 -9
- data/lib/cql/client/asynchronous_client.rb +9 -4
- data/lib/cql/client/asynchronous_prepared_statement.rb +2 -2
- data/lib/cql/client/connection_helper.rb +43 -20
- data/lib/cql/client/execute_options_decoder.rb +4 -1
- data/lib/cql/client/query_result.rb +7 -3
- data/lib/cql/client/query_trace.rb +46 -0
- data/lib/cql/client/request_runner.rb +7 -2
- data/lib/cql/client/void_result.rb +42 -0
- data/lib/cql/compression.rb +53 -0
- data/lib/cql/compression/snappy_compressor.rb +42 -0
- data/lib/cql/io/io_reactor.rb +9 -4
- data/lib/cql/protocol.rb +5 -3
- data/lib/cql/protocol/cql_protocol_handler.rb +14 -9
- data/lib/cql/protocol/frame_decoder.rb +106 -0
- data/lib/cql/protocol/frame_encoder.rb +31 -0
- data/lib/cql/protocol/request.rb +7 -11
- data/lib/cql/protocol/requests/execute_request.rb +2 -2
- data/lib/cql/protocol/requests/options_request.rb +4 -0
- data/lib/cql/protocol/requests/prepare_request.rb +2 -2
- data/lib/cql/protocol/requests/query_request.rb +2 -2
- data/lib/cql/protocol/requests/startup_request.rb +12 -5
- data/lib/cql/protocol/response.rb +13 -2
- data/lib/cql/protocol/responses/authenticate_response.rb +5 -1
- data/lib/cql/protocol/responses/detailed_error_response.rb +2 -2
- data/lib/cql/protocol/responses/error_response.rb +7 -2
- data/lib/cql/protocol/responses/event_response.rb +4 -2
- data/lib/cql/protocol/responses/prepared_result_response.rb +20 -4
- data/lib/cql/protocol/responses/ready_response.rb +5 -1
- data/lib/cql/protocol/responses/result_response.rb +10 -2
- data/lib/cql/protocol/responses/rows_result_response.rb +5 -4
- data/lib/cql/protocol/responses/schema_change_event_response.rb +1 -1
- data/lib/cql/protocol/responses/schema_change_result_response.rb +5 -4
- data/lib/cql/protocol/responses/set_keyspace_result_response.rb +4 -3
- data/lib/cql/protocol/responses/{status_change_event_result_response.rb → status_change_event_response.rb} +1 -1
- data/lib/cql/protocol/responses/supported_response.rb +5 -1
- data/lib/cql/protocol/responses/{topology_change_event_result_response.rb → topology_change_event_response.rb} +0 -0
- data/lib/cql/protocol/responses/void_result_response.rb +2 -2
- data/lib/cql/version.rb +1 -1
- data/spec/cql/client/asynchronous_client_spec.rb +52 -31
- data/spec/cql/client/asynchronous_prepared_statement_spec.rb +16 -2
- data/spec/cql/client/connection_helper_spec.rb +90 -12
- data/spec/cql/client/query_trace_spec.rb +138 -0
- data/spec/cql/client/request_runner_spec.rb +44 -7
- data/spec/cql/client/void_result_spec.rb +43 -0
- data/spec/cql/compression/compression_common.rb +59 -0
- data/spec/cql/compression/snappy_compressor_spec.rb +23 -0
- data/spec/cql/io/io_reactor_spec.rb +8 -1
- data/spec/cql/protocol/cql_protocol_handler_spec.rb +40 -0
- data/spec/cql/protocol/frame_decoder_spec.rb +132 -0
- data/spec/cql/protocol/frame_encoder_spec.rb +105 -0
- data/spec/cql/protocol/requests/credentials_request_spec.rb +2 -4
- data/spec/cql/protocol/requests/execute_request_spec.rb +5 -5
- data/spec/cql/protocol/requests/options_request_spec.rb +10 -4
- data/spec/cql/protocol/requests/prepare_request_spec.rb +3 -3
- data/spec/cql/protocol/requests/query_request_spec.rb +10 -5
- data/spec/cql/protocol/requests/register_request_spec.rb +3 -3
- data/spec/cql/protocol/requests/startup_request_spec.rb +11 -5
- data/spec/cql/protocol/responses/authenticate_response_spec.rb +27 -0
- data/spec/cql/protocol/responses/detailed_error_response_spec.rb +78 -0
- data/spec/cql/protocol/responses/error_response_spec.rb +36 -0
- data/spec/cql/protocol/responses/event_response_spec.rb +40 -0
- data/spec/cql/protocol/responses/prepared_result_response_spec.rb +108 -0
- data/spec/cql/protocol/responses/ready_response_spec.rb +39 -0
- data/spec/cql/protocol/responses/result_response_spec.rb +57 -0
- data/spec/cql/protocol/responses/rows_result_response_spec.rb +273 -0
- data/spec/cql/protocol/responses/schema_change_event_response_spec.rb +93 -0
- data/spec/cql/protocol/responses/schema_change_result_response_spec.rb +51 -19
- data/spec/cql/protocol/responses/set_keyspace_result_response_spec.rb +34 -0
- data/spec/cql/protocol/responses/status_change_event_response_spec.rb +35 -0
- data/spec/cql/protocol/responses/supported_response_spec.rb +27 -0
- data/spec/cql/protocol/responses/topology_change_event_response_spec.rb +35 -0
- data/spec/cql/protocol/responses/void_result_response_spec.rb +29 -0
- data/spec/integration/client_spec.rb +45 -0
- data/spec/integration/protocol_spec.rb +46 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/support/fake_io_reactor.rb +1 -1
- metadata +51 -10
- data/lib/cql/protocol/response_frame.rb +0 -129
- data/spec/cql/protocol/request_spec.rb +0 -45
- data/spec/cql/protocol/response_frame_spec.rb +0 -811
@@ -5,9 +5,9 @@ module Cql
|
|
5
5
|
class ExecuteRequest < Request
|
6
6
|
attr_reader :id, :metadata, :values, :consistency
|
7
7
|
|
8
|
-
def initialize(id, metadata, values, consistency)
|
8
|
+
def initialize(id, metadata, values, consistency, trace=false)
|
9
9
|
raise ArgumentError, "Metadata for #{metadata.size} columns, but #{values.size} values given" if metadata.size != values.size
|
10
|
-
super(10)
|
10
|
+
super(10, trace)
|
11
11
|
@id = id
|
12
12
|
@metadata = metadata
|
13
13
|
@values = values
|
@@ -5,10 +5,10 @@ module Cql
|
|
5
5
|
class QueryRequest < Request
|
6
6
|
attr_reader :cql, :consistency
|
7
7
|
|
8
|
-
def initialize(cql, consistency)
|
8
|
+
def initialize(cql, consistency, trace=false)
|
9
9
|
raise ArgumentError, %(No CQL given!) unless cql
|
10
10
|
raise ArgumentError, %(No such consistency: #{consistency.inspect}) if consistency.nil? || !CONSISTENCIES.include?(consistency)
|
11
|
-
super(7)
|
11
|
+
super(7, trace)
|
12
12
|
@cql = cql
|
13
13
|
@consistency = consistency
|
14
14
|
end
|
@@ -3,22 +3,29 @@
|
|
3
3
|
module Cql
|
4
4
|
module Protocol
|
5
5
|
class StartupRequest < Request
|
6
|
-
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def initialize(cql_version=nil, compression=nil)
|
7
9
|
super(1)
|
8
|
-
@
|
9
|
-
@
|
10
|
+
@options = {CQL_VERSION => cql_version || DEFAULT_CQL_VERSION}
|
11
|
+
@options[COMPRESSION] = compression if compression
|
12
|
+
end
|
13
|
+
|
14
|
+
def compressable?
|
15
|
+
false
|
10
16
|
end
|
11
17
|
|
12
18
|
def write(io)
|
13
|
-
write_string_map(io, @
|
19
|
+
write_string_map(io, @options)
|
14
20
|
end
|
15
21
|
|
16
22
|
def to_s
|
17
|
-
%(STARTUP #@
|
23
|
+
%(STARTUP #@options)
|
18
24
|
end
|
19
25
|
|
20
26
|
private
|
21
27
|
|
28
|
+
DEFAULT_CQL_VERSION = '3.0.0'.freeze
|
22
29
|
CQL_VERSION = 'CQL_VERSION'.freeze
|
23
30
|
COMPRESSION = 'COMPRESSION'.freeze
|
24
31
|
end
|
@@ -1,13 +1,24 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
3
|
module Cql
|
5
4
|
module Protocol
|
6
5
|
class Response
|
7
6
|
extend Decoding
|
8
7
|
|
9
|
-
def self.decode!(buffer)
|
8
|
+
def self.decode!(opcode, buffer, trace_id)
|
9
|
+
response_class = RESPONSE_TYPES[opcode]
|
10
|
+
if response_class
|
11
|
+
response_class.decode!(buffer, trace_id)
|
12
|
+
else
|
13
|
+
raise UnsupportedOperationError, "The operation #{opcode} is not supported"
|
14
|
+
end
|
10
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
RESPONSE_TYPES = [
|
20
|
+
# populated by subclasses
|
21
|
+
]
|
11
22
|
end
|
12
23
|
end
|
13
24
|
end
|
@@ -5,7 +5,7 @@ module Cql
|
|
5
5
|
class AuthenticateResponse < Response
|
6
6
|
attr_reader :authentication_class
|
7
7
|
|
8
|
-
def self.decode!(buffer)
|
8
|
+
def self.decode!(buffer, trace_id=nil)
|
9
9
|
new(read_string!(buffer))
|
10
10
|
end
|
11
11
|
|
@@ -16,6 +16,10 @@ module Cql
|
|
16
16
|
def to_s
|
17
17
|
%(AUTHENTICATE #{authentication_class})
|
18
18
|
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
RESPONSE_TYPES[0x03] = self
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -10,7 +10,7 @@ module Cql
|
|
10
10
|
@details = details
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.decode!(code, message, buffer)
|
13
|
+
def self.decode!(code, message, buffer, trace_id=nil)
|
14
14
|
details = {}
|
15
15
|
case code
|
16
16
|
when 0x1000 # unavailable
|
@@ -37,7 +37,7 @@ module Cql
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def to_s
|
40
|
-
|
40
|
+
"#{super} #{@details}"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -9,7 +9,7 @@ module Cql
|
|
9
9
|
@code, @message = args
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.decode!(buffer)
|
12
|
+
def self.decode!(buffer, trace_id=nil)
|
13
13
|
code = read_int!(buffer)
|
14
14
|
message = read_string!(buffer)
|
15
15
|
case code
|
@@ -21,8 +21,13 @@ module Cql
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_s
|
24
|
-
|
24
|
+
hex_code = @code.to_s(16).rjust(4, '0').upcase
|
25
|
+
%(ERROR 0x#{hex_code} "#@message")
|
25
26
|
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
RESPONSE_TYPES[0x00] = self
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
@@ -3,15 +3,17 @@
|
|
3
3
|
module Cql
|
4
4
|
module Protocol
|
5
5
|
class EventResponse < ResultResponse
|
6
|
-
def self.decode!(buffer)
|
6
|
+
def self.decode!(buffer, trace_id=nil)
|
7
7
|
type = read_string!(buffer)
|
8
8
|
impl = EVENT_TYPES[type]
|
9
9
|
raise UnsupportedEventTypeError, %(Unsupported event type: "#{type}") unless impl
|
10
|
-
impl.decode!(buffer)
|
10
|
+
impl.decode!(buffer, trace_id)
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
+
RESPONSE_TYPES[0x0c] = self
|
16
|
+
|
15
17
|
EVENT_TYPES = {
|
16
18
|
# populated by subclasses
|
17
19
|
}
|
@@ -5,14 +5,30 @@ module Cql
|
|
5
5
|
class PreparedResultResponse < ResultResponse
|
6
6
|
attr_reader :id, :metadata
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
|
8
|
+
def initialize(id, metadata, trace_id)
|
9
|
+
super(trace_id)
|
10
|
+
@id, @metadata = id, metadata
|
10
11
|
end
|
11
12
|
|
12
|
-
def self.decode!(buffer)
|
13
|
+
def self.decode!(buffer, trace_id=nil)
|
13
14
|
id = read_short_bytes!(buffer)
|
14
15
|
metadata = RowsResultResponse.read_metadata!(buffer)
|
15
|
-
new(id, metadata)
|
16
|
+
new(id, metadata, trace_id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def eql?(other)
|
20
|
+
self.id == other.id && self.metadata == other.metadata && self.trace_id == other.trace_id
|
21
|
+
end
|
22
|
+
alias_method :==, :eql?
|
23
|
+
|
24
|
+
def hash
|
25
|
+
@h ||= begin
|
26
|
+
h = 0
|
27
|
+
h = ((h & 0x01ffffff) * 31) ^ @id.hash
|
28
|
+
h = ((h & 0x01ffffff) * 31) ^ @metadata.hash
|
29
|
+
h = ((h & 0x01ffffff) * 31) ^ @trace_id.hash
|
30
|
+
h
|
31
|
+
end
|
16
32
|
end
|
17
33
|
|
18
34
|
def to_s
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Cql
|
4
4
|
module Protocol
|
5
5
|
class ReadyResponse < Response
|
6
|
-
def self.decode!(buffer)
|
6
|
+
def self.decode!(buffer, trace_id=nil)
|
7
7
|
new
|
8
8
|
end
|
9
9
|
|
@@ -19,6 +19,10 @@ module Cql
|
|
19
19
|
def to_s
|
20
20
|
'READY'
|
21
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
RESPONSE_TYPES[0x02] = self
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
@@ -3,11 +3,17 @@
|
|
3
3
|
module Cql
|
4
4
|
module Protocol
|
5
5
|
class ResultResponse < Response
|
6
|
-
|
6
|
+
attr_reader :trace_id
|
7
|
+
|
8
|
+
def initialize(trace_id)
|
9
|
+
@trace_id = trace_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.decode!(buffer, trace_id=nil)
|
7
13
|
kind = read_int!(buffer)
|
8
14
|
impl = RESULT_TYPES[kind]
|
9
15
|
raise UnsupportedResultKindError, %(Unsupported result kind: #{kind}) unless impl
|
10
|
-
impl.decode!(buffer)
|
16
|
+
impl.decode!(buffer, trace_id)
|
11
17
|
end
|
12
18
|
|
13
19
|
def void?
|
@@ -16,6 +22,8 @@ module Cql
|
|
16
22
|
|
17
23
|
private
|
18
24
|
|
25
|
+
RESPONSE_TYPES[0x08] = self
|
26
|
+
|
19
27
|
RESULT_TYPES = [
|
20
28
|
# populated by subclasses
|
21
29
|
]
|
@@ -5,13 +5,14 @@ module Cql
|
|
5
5
|
class RowsResultResponse < ResultResponse
|
6
6
|
attr_reader :rows, :metadata
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
|
8
|
+
def initialize(rows, metadata, trace_id)
|
9
|
+
super(trace_id)
|
10
|
+
@rows, @metadata = rows, metadata
|
10
11
|
end
|
11
12
|
|
12
|
-
def self.decode!(buffer)
|
13
|
+
def self.decode!(buffer, trace_id=nil)
|
13
14
|
column_specs = read_metadata!(buffer)
|
14
|
-
new(read_rows!(buffer, column_specs), column_specs)
|
15
|
+
new(read_rows!(buffer, column_specs), column_specs, trace_id)
|
15
16
|
end
|
16
17
|
|
17
18
|
def to_s
|
@@ -5,12 +5,13 @@ module Cql
|
|
5
5
|
class SchemaChangeResultResponse < ResultResponse
|
6
6
|
attr_reader :change, :keyspace, :table
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
|
8
|
+
def initialize(change, keyspace, table, trace_id)
|
9
|
+
super(trace_id)
|
10
|
+
@change, @keyspace, @table = change, keyspace, table
|
10
11
|
end
|
11
12
|
|
12
|
-
def self.decode!(buffer)
|
13
|
-
new(read_string!(buffer), read_string!(buffer), read_string!(buffer))
|
13
|
+
def self.decode!(buffer, trace_id=nil)
|
14
|
+
new(read_string!(buffer), read_string!(buffer), read_string!(buffer), trace_id)
|
14
15
|
end
|
15
16
|
|
16
17
|
def eql?(other)
|
@@ -5,12 +5,13 @@ module Cql
|
|
5
5
|
class SetKeyspaceResultResponse < ResultResponse
|
6
6
|
attr_reader :keyspace
|
7
7
|
|
8
|
-
def initialize(keyspace)
|
8
|
+
def initialize(keyspace, trace_id)
|
9
|
+
super(trace_id)
|
9
10
|
@keyspace = keyspace
|
10
11
|
end
|
11
12
|
|
12
|
-
def self.decode!(buffer)
|
13
|
-
new(read_string!(buffer))
|
13
|
+
def self.decode!(buffer, trace_id=nil)
|
14
|
+
new(read_string!(buffer), trace_id)
|
14
15
|
end
|
15
16
|
|
16
17
|
def to_s
|
@@ -9,13 +9,17 @@ module Cql
|
|
9
9
|
@options = options
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.decode!(buffer)
|
12
|
+
def self.decode!(buffer, trace_id=nil)
|
13
13
|
new(read_string_multimap!(buffer))
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_s
|
17
17
|
%(SUPPORTED #{options})
|
18
18
|
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
RESPONSE_TYPES[0x06] = self
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
File without changes
|
data/lib/cql/version.rb
CHANGED
@@ -111,7 +111,7 @@ module Cql
|
|
111
111
|
case request.cql
|
112
112
|
when /FROM system\.local/
|
113
113
|
row = {'host_id' => connection[:spec_host_id], 'data_center' => connection[:spec_data_center]}
|
114
|
-
Protocol::RowsResultResponse.new([row], local_metadata)
|
114
|
+
Protocol::RowsResultResponse.new([row], local_metadata, nil)
|
115
115
|
when /FROM system\.peers/
|
116
116
|
other_host_ids = connections.reject { |c| c[:spec_host_id] == connection[:spec_host_id] }.map { |c| c[:spec_host_id] }
|
117
117
|
until other_host_ids.size >= min_peers[0]
|
@@ -126,7 +126,7 @@ module Cql
|
|
126
126
|
'rpc_address' => bind_all_rpc_addresses ? IPAddr.new('0.0.0.0') : ip
|
127
127
|
}
|
128
128
|
end
|
129
|
-
Protocol::RowsResultResponse.new(rows, peer_metadata)
|
129
|
+
Protocol::RowsResultResponse.new(rows, peer_metadata, nil)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
@@ -208,26 +208,23 @@ module Cql
|
|
208
208
|
last_connection.timeout.should == 10
|
209
209
|
end
|
210
210
|
|
211
|
-
it '
|
211
|
+
it 'is not in a keyspace' do
|
212
212
|
client.connect.value
|
213
|
-
|
213
|
+
client.keyspace.should be_nil
|
214
214
|
end
|
215
215
|
|
216
|
-
it '
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
c.connect.value
|
223
|
-
connections.each do |cc|
|
224
|
-
cc.requests.first.should be_a(Protocol::StartupRequest)
|
216
|
+
it 'enables compression when a compressor is specified' do
|
217
|
+
handle_request do |request|
|
218
|
+
case request
|
219
|
+
when Protocol::OptionsRequest
|
220
|
+
Protocol::SupportedResponse.new('CQL_VERSION' => %w[3.0.0], 'COMPRESSION' => %w[lz4 snappy])
|
221
|
+
end
|
225
222
|
end
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
223
|
+
compressor = double(:compressor, algorithm: 'lz4')
|
224
|
+
c = described_class.new(connection_options.merge(compressor: compressor))
|
225
|
+
c.connect.value
|
226
|
+
request = requests.find { |rq| rq.is_a?(Protocol::StartupRequest) }
|
227
|
+
request.options.should include('COMPRESSION' => 'lz4')
|
231
228
|
end
|
232
229
|
|
233
230
|
it 'changes to the keyspace given as an option' do
|
@@ -412,7 +409,7 @@ module Cql
|
|
412
409
|
it 'executes a USE query' do
|
413
410
|
handle_request do |request|
|
414
411
|
if request.is_a?(Protocol::QueryRequest) && request.cql == 'USE system'
|
415
|
-
Protocol::SetKeyspaceResultResponse.new('system')
|
412
|
+
Protocol::SetKeyspaceResultResponse.new('system', nil)
|
416
413
|
end
|
417
414
|
end
|
418
415
|
client.connect.value
|
@@ -440,7 +437,7 @@ module Cql
|
|
440
437
|
it 'knows which keyspace it changed to' do
|
441
438
|
handle_request do |request|
|
442
439
|
if request.is_a?(Protocol::QueryRequest) && request.cql == 'USE system'
|
443
|
-
Protocol::SetKeyspaceResultResponse.new('system')
|
440
|
+
Protocol::SetKeyspaceResultResponse.new('system', nil)
|
444
441
|
end
|
445
442
|
end
|
446
443
|
client.connect.value
|
@@ -456,7 +453,7 @@ module Cql
|
|
456
453
|
it 'allows the keyspace name to be quoted' do
|
457
454
|
handle_request do |request|
|
458
455
|
if request.is_a?(Protocol::QueryRequest) && request.cql == 'USE "system"'
|
459
|
-
Protocol::SetKeyspaceResultResponse.new('system')
|
456
|
+
Protocol::SetKeyspaceResultResponse.new('system', nil)
|
460
457
|
end
|
461
458
|
end
|
462
459
|
client.connect.value
|
@@ -497,14 +494,14 @@ module Cql
|
|
497
494
|
end
|
498
495
|
|
499
496
|
context 'with a void CQL query' do
|
500
|
-
it 'returns
|
497
|
+
it 'returns a VoidResult' do
|
501
498
|
handle_request do |request|
|
502
499
|
if request.is_a?(Protocol::QueryRequest) && request.cql =~ /UPDATE/
|
503
|
-
Protocol::VoidResultResponse.new
|
500
|
+
Protocol::VoidResultResponse.new(nil)
|
504
501
|
end
|
505
502
|
end
|
506
503
|
result = client.execute('UPDATE stuff SET thing = 1 WHERE id = 3').value
|
507
|
-
result.should
|
504
|
+
result.should be_a(VoidResult)
|
508
505
|
end
|
509
506
|
end
|
510
507
|
|
@@ -512,7 +509,7 @@ module Cql
|
|
512
509
|
it 'returns nil' do
|
513
510
|
handle_request do |request|
|
514
511
|
if request.is_a?(Protocol::QueryRequest) && request.cql == 'USE system'
|
515
|
-
Protocol::SetKeyspaceResultResponse.new('system')
|
512
|
+
Protocol::SetKeyspaceResultResponse.new('system', nil)
|
516
513
|
end
|
517
514
|
end
|
518
515
|
result = client.execute('USE system').value
|
@@ -522,7 +519,7 @@ module Cql
|
|
522
519
|
it 'knows which keyspace it changed to' do
|
523
520
|
handle_request do |request|
|
524
521
|
if request.is_a?(Protocol::QueryRequest) && request.cql == 'USE system'
|
525
|
-
Protocol::SetKeyspaceResultResponse.new('system')
|
522
|
+
Protocol::SetKeyspaceResultResponse.new('system', nil)
|
526
523
|
end
|
527
524
|
end
|
528
525
|
client.execute('USE system').value
|
@@ -536,7 +533,7 @@ module Cql
|
|
536
533
|
|
537
534
|
handle_request do |request, connection|
|
538
535
|
if request.is_a?(Protocol::QueryRequest) && request.cql == 'USE system'
|
539
|
-
Protocol::SetKeyspaceResultResponse.new('system')
|
536
|
+
Protocol::SetKeyspaceResultResponse.new('system', nil)
|
540
537
|
end
|
541
538
|
end
|
542
539
|
|
@@ -571,7 +568,7 @@ module Cql
|
|
571
568
|
before do
|
572
569
|
handle_request do |request|
|
573
570
|
if request.is_a?(Protocol::QueryRequest) && request.cql =~ /FROM things/
|
574
|
-
Protocol::RowsResultResponse.new(rows, metadata)
|
571
|
+
Protocol::RowsResultResponse.new(rows, metadata, nil)
|
575
572
|
end
|
576
573
|
end
|
577
574
|
end
|
@@ -648,6 +645,30 @@ module Cql
|
|
648
645
|
sent_timeout.should == 3
|
649
646
|
end
|
650
647
|
end
|
648
|
+
|
649
|
+
context 'with tracing' do
|
650
|
+
it 'sets the trace flag' do
|
651
|
+
tracing = false
|
652
|
+
handle_request do |request|
|
653
|
+
if request.is_a?(Protocol::QueryRequest)
|
654
|
+
tracing = request.trace
|
655
|
+
end
|
656
|
+
end
|
657
|
+
client.execute(cql, trace: true).value
|
658
|
+
tracing.should be_true
|
659
|
+
end
|
660
|
+
|
661
|
+
it 'returns the trace ID with the result' do
|
662
|
+
trace_id = Uuid.new('a1028490-3f05-11e3-9531-fb72eff05fbb')
|
663
|
+
handle_request do |request|
|
664
|
+
if request.is_a?(Protocol::QueryRequest) && request.cql == cql
|
665
|
+
Protocol::RowsResultResponse.new([], [], trace_id)
|
666
|
+
end
|
667
|
+
end
|
668
|
+
result = client.execute(cql, trace: true).value
|
669
|
+
result.trace_id.should == trace_id
|
670
|
+
end
|
671
|
+
end
|
651
672
|
end
|
652
673
|
|
653
674
|
describe '#prepare' do
|
@@ -666,7 +687,7 @@ module Cql
|
|
666
687
|
before do
|
667
688
|
handle_request do |request|
|
668
689
|
if request.is_a?(Protocol::PrepareRequest)
|
669
|
-
Protocol::PreparedResultResponse.new(id, metadata)
|
690
|
+
Protocol::PreparedResultResponse.new(id, metadata, nil)
|
670
691
|
end
|
671
692
|
end
|
672
693
|
end
|
@@ -721,7 +742,7 @@ module Cql
|
|
721
742
|
it 'returns a failed future' do
|
722
743
|
handle_request do |request|
|
723
744
|
if request.is_a?(Protocol::PrepareRequest)
|
724
|
-
Protocol::PreparedResultResponse.new(id, metadata)
|
745
|
+
Protocol::PreparedResultResponse.new(id, metadata, nil)
|
725
746
|
end
|
726
747
|
end
|
727
748
|
statement = client.prepare(cql).value
|
@@ -794,7 +815,7 @@ module Cql
|
|
794
815
|
it 'complains when #execute of a prepared statement is called after #close' do
|
795
816
|
handle_request do |request|
|
796
817
|
if request.is_a?(Protocol::PrepareRequest)
|
797
|
-
Protocol::PreparedResultResponse.new('A' * 32, [])
|
818
|
+
Protocol::PreparedResultResponse.new('A' * 32, [], nil)
|
798
819
|
end
|
799
820
|
end
|
800
821
|
client.connect.value
|