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.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -11
  3. data/lib/cql.rb +1 -0
  4. data/lib/cql/client.rb +41 -9
  5. data/lib/cql/client/asynchronous_client.rb +9 -4
  6. data/lib/cql/client/asynchronous_prepared_statement.rb +2 -2
  7. data/lib/cql/client/connection_helper.rb +43 -20
  8. data/lib/cql/client/execute_options_decoder.rb +4 -1
  9. data/lib/cql/client/query_result.rb +7 -3
  10. data/lib/cql/client/query_trace.rb +46 -0
  11. data/lib/cql/client/request_runner.rb +7 -2
  12. data/lib/cql/client/void_result.rb +42 -0
  13. data/lib/cql/compression.rb +53 -0
  14. data/lib/cql/compression/snappy_compressor.rb +42 -0
  15. data/lib/cql/io/io_reactor.rb +9 -4
  16. data/lib/cql/protocol.rb +5 -3
  17. data/lib/cql/protocol/cql_protocol_handler.rb +14 -9
  18. data/lib/cql/protocol/frame_decoder.rb +106 -0
  19. data/lib/cql/protocol/frame_encoder.rb +31 -0
  20. data/lib/cql/protocol/request.rb +7 -11
  21. data/lib/cql/protocol/requests/execute_request.rb +2 -2
  22. data/lib/cql/protocol/requests/options_request.rb +4 -0
  23. data/lib/cql/protocol/requests/prepare_request.rb +2 -2
  24. data/lib/cql/protocol/requests/query_request.rb +2 -2
  25. data/lib/cql/protocol/requests/startup_request.rb +12 -5
  26. data/lib/cql/protocol/response.rb +13 -2
  27. data/lib/cql/protocol/responses/authenticate_response.rb +5 -1
  28. data/lib/cql/protocol/responses/detailed_error_response.rb +2 -2
  29. data/lib/cql/protocol/responses/error_response.rb +7 -2
  30. data/lib/cql/protocol/responses/event_response.rb +4 -2
  31. data/lib/cql/protocol/responses/prepared_result_response.rb +20 -4
  32. data/lib/cql/protocol/responses/ready_response.rb +5 -1
  33. data/lib/cql/protocol/responses/result_response.rb +10 -2
  34. data/lib/cql/protocol/responses/rows_result_response.rb +5 -4
  35. data/lib/cql/protocol/responses/schema_change_event_response.rb +1 -1
  36. data/lib/cql/protocol/responses/schema_change_result_response.rb +5 -4
  37. data/lib/cql/protocol/responses/set_keyspace_result_response.rb +4 -3
  38. data/lib/cql/protocol/responses/{status_change_event_result_response.rb → status_change_event_response.rb} +1 -1
  39. data/lib/cql/protocol/responses/supported_response.rb +5 -1
  40. data/lib/cql/protocol/responses/{topology_change_event_result_response.rb → topology_change_event_response.rb} +0 -0
  41. data/lib/cql/protocol/responses/void_result_response.rb +2 -2
  42. data/lib/cql/version.rb +1 -1
  43. data/spec/cql/client/asynchronous_client_spec.rb +52 -31
  44. data/spec/cql/client/asynchronous_prepared_statement_spec.rb +16 -2
  45. data/spec/cql/client/connection_helper_spec.rb +90 -12
  46. data/spec/cql/client/query_trace_spec.rb +138 -0
  47. data/spec/cql/client/request_runner_spec.rb +44 -7
  48. data/spec/cql/client/void_result_spec.rb +43 -0
  49. data/spec/cql/compression/compression_common.rb +59 -0
  50. data/spec/cql/compression/snappy_compressor_spec.rb +23 -0
  51. data/spec/cql/io/io_reactor_spec.rb +8 -1
  52. data/spec/cql/protocol/cql_protocol_handler_spec.rb +40 -0
  53. data/spec/cql/protocol/frame_decoder_spec.rb +132 -0
  54. data/spec/cql/protocol/frame_encoder_spec.rb +105 -0
  55. data/spec/cql/protocol/requests/credentials_request_spec.rb +2 -4
  56. data/spec/cql/protocol/requests/execute_request_spec.rb +5 -5
  57. data/spec/cql/protocol/requests/options_request_spec.rb +10 -4
  58. data/spec/cql/protocol/requests/prepare_request_spec.rb +3 -3
  59. data/spec/cql/protocol/requests/query_request_spec.rb +10 -5
  60. data/spec/cql/protocol/requests/register_request_spec.rb +3 -3
  61. data/spec/cql/protocol/requests/startup_request_spec.rb +11 -5
  62. data/spec/cql/protocol/responses/authenticate_response_spec.rb +27 -0
  63. data/spec/cql/protocol/responses/detailed_error_response_spec.rb +78 -0
  64. data/spec/cql/protocol/responses/error_response_spec.rb +36 -0
  65. data/spec/cql/protocol/responses/event_response_spec.rb +40 -0
  66. data/spec/cql/protocol/responses/prepared_result_response_spec.rb +108 -0
  67. data/spec/cql/protocol/responses/ready_response_spec.rb +39 -0
  68. data/spec/cql/protocol/responses/result_response_spec.rb +57 -0
  69. data/spec/cql/protocol/responses/rows_result_response_spec.rb +273 -0
  70. data/spec/cql/protocol/responses/schema_change_event_response_spec.rb +93 -0
  71. data/spec/cql/protocol/responses/schema_change_result_response_spec.rb +51 -19
  72. data/spec/cql/protocol/responses/set_keyspace_result_response_spec.rb +34 -0
  73. data/spec/cql/protocol/responses/status_change_event_response_spec.rb +35 -0
  74. data/spec/cql/protocol/responses/supported_response_spec.rb +27 -0
  75. data/spec/cql/protocol/responses/topology_change_event_response_spec.rb +35 -0
  76. data/spec/cql/protocol/responses/void_result_response_spec.rb +29 -0
  77. data/spec/integration/client_spec.rb +45 -0
  78. data/spec/integration/protocol_spec.rb +46 -0
  79. data/spec/spec_helper.rb +2 -1
  80. data/spec/support/fake_io_reactor.rb +1 -1
  81. metadata +51 -10
  82. data/lib/cql/protocol/response_frame.rb +0 -129
  83. data/spec/cql/protocol/request_spec.rb +0 -45
  84. 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
@@ -7,6 +7,10 @@ module Cql
7
7
  super(5)
8
8
  end
9
9
 
10
+ def compressable?
11
+ false
12
+ end
13
+
10
14
  def write(io)
11
15
  io
12
16
  end
@@ -5,9 +5,9 @@ module Cql
5
5
  class PrepareRequest < Request
6
6
  attr_reader :cql
7
7
 
8
- def initialize(cql)
8
+ def initialize(cql, trace=false)
9
9
  raise ArgumentError, 'No CQL given!' unless cql
10
- super(9)
10
+ super(9, trace)
11
11
  @cql = cql
12
12
  end
13
13
 
@@ -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
- def initialize(cql_version='3.0.0', compression=nil)
6
+ attr_reader :options
7
+
8
+ def initialize(cql_version=nil, compression=nil)
7
9
  super(1)
8
- @arguments = {CQL_VERSION => cql_version}
9
- @arguments[COMPRESSION] = compression if compression
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, @arguments)
19
+ write_string_map(io, @options)
14
20
  end
15
21
 
16
22
  def to_s
17
- %(STARTUP #@arguments)
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
- %(ERROR #@code "#@message" #@details)
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
- %(ERROR #@code "#@message")
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(*args)
9
- @id, @metadata = args
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
- def self.decode!(buffer)
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(*args)
9
- @rows, @metadata = args
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
@@ -12,7 +12,7 @@ module Cql
12
12
  @type = TYPE
13
13
  end
14
14
 
15
- def self.decode!(buffer)
15
+ def self.decode!(buffer, trace_id=nil)
16
16
  new(read_string!(buffer), read_string!(buffer), read_string!(buffer))
17
17
  end
18
18
 
@@ -5,12 +5,13 @@ module Cql
5
5
  class SchemaChangeResultResponse < ResultResponse
6
6
  attr_reader :change, :keyspace, :table
7
7
 
8
- def initialize(*args)
9
- @change, @keyspace, @table = args
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
@@ -12,7 +12,7 @@ module Cql
12
12
  @type = TYPE
13
13
  end
14
14
 
15
- def self.decode!(buffer)
15
+ def self.decode!(buffer, trace_id=nil)
16
16
  new(read_string!(buffer), *read_inet!(buffer))
17
17
  end
18
18
 
@@ -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
@@ -3,8 +3,8 @@
3
3
  module Cql
4
4
  module Protocol
5
5
  class VoidResultResponse < ResultResponse
6
- def self.decode!(buffer)
7
- new
6
+ def self.decode!(buffer, trace_id=nil)
7
+ new(trace_id)
8
8
  end
9
9
 
10
10
  def to_s
data/lib/cql/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Cql
4
- VERSION = '1.1.3'.freeze
4
+ VERSION = '1.2.0.pre0'.freeze
5
5
  end
@@ -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 'sends a startup request' do
211
+ it 'is not in a keyspace' do
212
212
  client.connect.value
213
- requests.first.should be_a(Protocol::StartupRequest)
213
+ client.keyspace.should be_nil
214
214
  end
215
215
 
216
- it 'sends a startup request to each connection' do
217
- client.close.value
218
- io_reactor.stop.value
219
- io_reactor.start.value
220
-
221
- c = described_class.new(connection_options.merge(hosts: %w[h1.example.com h2.example.com h3.example.com]))
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
- end
227
-
228
- it 'is not in a keyspace' do
229
- client.connect.value
230
- client.keyspace.should be_nil
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 nil' do
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 be_nil
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