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
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+
6
+ shared_examples 'compressor' do |algorithm|
7
+ describe '#algorithm' do
8
+ it %(returns "#{algorithm}") do
9
+ described_class.new.algorithm.should == algorithm
10
+ end
11
+ end
12
+
13
+ describe '#compress?' do
14
+ it 'returns true for arguments larger than 64 bytes' do
15
+ described_class.new.compress?('x' * 65).should be_true
16
+ end
17
+
18
+ it 'returns false for arguments smaller than 64 bytes' do
19
+ described_class.new.compress?('x' * 64).should be_false
20
+ end
21
+
22
+ it 'is customizable via a constructor argument' do
23
+ described_class.new(89).compress?('x' * 90).should be_true
24
+ described_class.new(89).compress?('x' * 89).should be_false
25
+ end
26
+ end
27
+
28
+ describe '#compress/#decompress' do
29
+ let :compressor do
30
+ described_class.new
31
+ end
32
+
33
+ it 'compresses strings' do
34
+ input = 'hello' * 100
35
+ compressed = compressor.compress(input)
36
+ compressed.bytesize.should be < input.bytesize
37
+ end
38
+
39
+ it 'decompresses compressed strings' do
40
+ input = "\x19\x10helloN\x05\x00"
41
+ decompressed = compressor.decompress(input)
42
+ decompressed.should == 'hellohellohellohellohello'
43
+ end
44
+
45
+ it 'decompresses its own compressed output' do
46
+ input = 'Ķ' * 100
47
+ output = compressor.decompress(compressor.compress(input))
48
+ output.force_encoding(::Encoding::UTF_8)
49
+ output.should == input
50
+ end
51
+
52
+ it 'returns binary strings' do
53
+ compressed = compressor.compress('hello' * 100)
54
+ decompressed = compressor.decompress(compressed)
55
+ compressed.encoding.should == ::Encoding::BINARY
56
+ decompressed.encoding.should == ::Encoding::BINARY
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'cql/compression/compression_common'
5
+
6
+
7
+ module Cql
8
+ module Compression
9
+ begin
10
+ require 'cql/compression/snappy_compressor'
11
+
12
+ describe SnappyCompressor do
13
+ include_examples 'compressor', 'snappy'
14
+ end
15
+ rescue LoadError => e
16
+ describe 'SnappyCompressor' do
17
+ it 'supports Snappy' do
18
+ pending e.message
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -141,7 +141,7 @@ module Cql
141
141
  end
142
142
 
143
143
  before do
144
- protocol_handler_factory.stub(:new) do |connection, _|
144
+ protocol_handler_factory.stub(:call) do |connection, _|
145
145
  connection.to_io.stub(:connect_nonblock)
146
146
  protocol_handler.stub(:connection).and_return(connection)
147
147
  protocol_handler
@@ -165,7 +165,14 @@ module Cql
165
165
  reactor.stop if reactor.running?
166
166
  end
167
167
 
168
+ it 'calls #call on the protocol handler factory with the connection and the reactor itself' do
169
+ reactor.start.value
170
+ reactor.connect('example.com', 9999, 5).value
171
+ protocol_handler_factory.should have_received(:call).with(an_instance_of(Connection), reactor)
172
+ end
173
+
168
174
  it 'calls #new on the protocol handler factory with the connection and the reactor itself' do
175
+ protocol_handler_factory.stub(:new)
169
176
  reactor.start.value
170
177
  reactor.connect('example.com', 9999, 5).value
171
178
  protocol_handler_factory.should have_received(:new).with(an_instance_of(Connection), reactor)
@@ -112,6 +112,46 @@ module Cql
112
112
  futures[128].should be_resolved
113
113
  end
114
114
 
115
+ context 'when a compressor is specified' do
116
+ let :protocol_handler do
117
+ described_class.new(connection, scheduler, compressor)
118
+ end
119
+
120
+ let :compressor do
121
+ double(:compressor)
122
+ end
123
+
124
+ let :request do
125
+ Protocol::PrepareRequest.new('SELECT * FROM things')
126
+ end
127
+
128
+ before do
129
+ compressor.stub(:compress?).and_return(true)
130
+ compressor.stub(:compress).and_return('FAKECOMPRESSEDBODY')
131
+ end
132
+
133
+ it 'compresses request frames' do
134
+ protocol_handler.send_request(request)
135
+ buffer.to_s.should == [1, 1, 0, 9, 18].pack('C4N') + 'FAKECOMPRESSEDBODY'
136
+ end
137
+
138
+ it 'compresses queued request frames' do
139
+ 130.times { protocol_handler.send_request(request) }
140
+ compressor.should have_received(:compress).exactly(130).times
141
+ end
142
+
143
+ it 'decompresses response frames' do
144
+ id = "\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/".force_encoding(::Encoding::BINARY)
145
+ compressor.stub(:decompress).with('FAKECOMPRESSEDBODY').and_return("\x00\x00\x00\x04" + "\x00\x10" + id + "\x00\x00\x00\x01\x00\x00\x00\x01\x00\ncql_rb_911\x00\x05users\x00\tuser_name\x00\r")
146
+ f1 = protocol_handler.send_request(request)
147
+ f2 = protocol_handler.send_request(request)
148
+ connection.data_listener.call("\x81\x01\x00\x08\x00\x00\x00\x12FAKECOMPRESSEDBODY")
149
+ connection.data_listener.call("\x81\x01\x01\x08\x00\x00\x00\x12FAKECOMPRESSEDBODY")
150
+ f1.value.should == Protocol::PreparedResultResponse.new(id, [["cql_rb_911", "users", "user_name", :varchar]], nil)
151
+ f2.value.should == Protocol::PreparedResultResponse.new(id, [["cql_rb_911", "users", "user_name", :varchar]], nil)
152
+ end
153
+ end
154
+
115
155
  context 'when the protocol handler closes' do
116
156
  it 'fails all requests waiting for a reply' do
117
157
  futures = Array.new(5) { protocol_handler.send_request(request) }
@@ -0,0 +1,132 @@
1
+ # encoding: ascii-8bit
2
+
3
+ require 'spec_helper'
4
+
5
+
6
+ module Cql
7
+ module Protocol
8
+ describe FrameDecoder do
9
+ let :decoder do
10
+ described_class.new
11
+ end
12
+
13
+ describe '#decode_frame' do
14
+ context 'with an uncompressed frame' do
15
+ it 'returns a partial frame when not all the frame\'s bytes are in the buffer' do
16
+ frame = decoder.decode_frame(ByteBuffer.new)
17
+ frame.should_not be_complete
18
+ frame = decoder.decode_frame(ByteBuffer.new("\x81\x00\x00\x02\x00\x00\x00\x16"))
19
+ frame.should_not be_complete
20
+ frame = decoder.decode_frame(ByteBuffer.new("\x81\x00\x00\x02\x00\x00\x00\x16\x01\x23\x45"))
21
+ frame.should_not be_complete
22
+ end
23
+
24
+ it 'returns a complete frame when all bytes are in the buffer' do
25
+ buffer = ByteBuffer.new
26
+ buffer << "\x81\x00\x00\x06\x00\x00\x00\x27"
27
+ buffer << "\x00\x02\x00\x0bCQL_VERSION\x00\x01\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x00"
28
+ frame = decoder.decode_frame(buffer)
29
+ frame.should be_complete
30
+ frame.body.should be_a(Response)
31
+ end
32
+
33
+ it 'returns the stream ID' do
34
+ buffer = ByteBuffer.new("\x81\x00\x03\x02\x00\x00\x00\x00")
35
+ frame = decoder.decode_frame(buffer)
36
+ frame.stream_id.should == 3
37
+ end
38
+
39
+ it 'returns the stream ID when it is negative' do
40
+ buffer = ByteBuffer.new("\x81\x00\xff\x02\x00\x00\x00\x00")
41
+ frame = decoder.decode_frame(buffer)
42
+ frame.stream_id.should == -1
43
+ end
44
+
45
+ it 'first returns a partial frame, then a complete frame' do
46
+ buffer = ByteBuffer.new
47
+ buffer << "\x81\x00\x00\x06\x00\x00\x00\x27"
48
+ frame = decoder.decode_frame(buffer)
49
+ buffer << "\x00\x02\x00\x0bCQL_VERSION"
50
+ frame = decoder.decode_frame(buffer, frame)
51
+ buffer << "\x00\x01\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x00"
52
+ frame = decoder.decode_frame(buffer, frame)
53
+ frame.should be_complete
54
+ end
55
+
56
+ it 'leaves extra bytes in the buffer' do
57
+ buffer = ByteBuffer.new
58
+ buffer << "\x81\x00\x00\x06\x00\x00\x00\x27"
59
+ buffer << "\x00\x02\x00\x0bCQL_VERSION\x00\x01\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x00\xca\xfe"
60
+ frame = decoder.decode_frame(buffer)
61
+ frame.should be_complete
62
+ buffer.to_s.should == "\xca\xfe"
63
+ end
64
+
65
+ it 'consumes the number of bytes specified in the frame header' do
66
+ buffer = ByteBuffer.new
67
+ buffer << "\x81\x00\x00\x06\x00\x00\x00\x29"
68
+ buffer << "\x00\x02\x00\x0bCQL_VERSION\x00\x01\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x00\xca\xfe"
69
+ frame = decoder.decode_frame(buffer)
70
+ frame.should be_complete
71
+ buffer.to_s.should be_empty
72
+ end
73
+
74
+ it 'extracts a trace ID' do
75
+ buffer = ByteBuffer.new
76
+ buffer << "\x81\x02\x00\x08\x00\x00\x00\x14\a\xE4\xBE\x10?\x03\x11\xE3\x951\xFBr\xEF\xF0_\xBB\x00\x00\x00\x01"
77
+ frame = decoder.decode_frame(buffer)
78
+ frame.body.trace_id.should == Uuid.new('07e4be10-3f03-11e3-9531-fb72eff05fbb')
79
+ end
80
+
81
+ it 'complains when the frame is a request frame' do
82
+ expect { decoder.decode_frame(ByteBuffer.new("\x01\x00\x00\x05\x00\x00\x00\x00")) }.to raise_error(UnsupportedFrameTypeError)
83
+ end
84
+
85
+ it 'complains when the opcode is unknown' do
86
+ expect { decoder.decode_frame(ByteBuffer.new("\x81\x00\x00\xff\x00\x00\x00\x00")) }.to raise_error(UnsupportedOperationError)
87
+ end
88
+ end
89
+
90
+ context 'with a compressed frame' do
91
+ let :decoder do
92
+ described_class.new(compressor)
93
+ end
94
+
95
+ let :compressor do
96
+ double(:compressor)
97
+ end
98
+
99
+ let :buffer do
100
+ ByteBuffer.new("\x81\x01\x00\x06\x00\x00\x00\x12FAKECOMPRESSEDBODY")
101
+ end
102
+
103
+ before do
104
+ compressor.stub(:decompress).with('FAKECOMPRESSEDBODY').and_return("\x00\x02\x00\x0bCQL_VERSION\x00\x01\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x00")
105
+ end
106
+
107
+ it 'decompresses the body bytes' do
108
+ frame = decoder.decode_frame(buffer)
109
+ frame.body.should be_a(Response)
110
+ end
111
+
112
+ it 'leaves extra bytes in the buffer' do
113
+ buffer << 'EXTRABYTES'
114
+ frame = decoder.decode_frame(buffer)
115
+ buffer.to_s.should == 'EXTRABYTES'
116
+ end
117
+
118
+ it 'extracts a trace ID' do
119
+ buffer.update(1, "\x03\x00\x08")
120
+ compressor.stub(:decompress).with('FAKECOMPRESSEDBODY').and_return("\a\xE4\xBE\x10?\x03\x11\xE3\x951\xFBr\xEF\xF0_\xBB\x00\x00\x00\x01")
121
+ frame = decoder.decode_frame(buffer)
122
+ frame.body.trace_id.should == Uuid.new('07e4be10-3f03-11e3-9531-fb72eff05fbb')
123
+ end
124
+
125
+ it 'complains when there is no compressor' do
126
+ expect { described_class.new.decode_frame(buffer) }.to raise_error(UnexpectedCompressionError)
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,105 @@
1
+ # encoding: ascii-8bit
2
+
3
+ require 'spec_helper'
4
+
5
+
6
+ module Cql
7
+ module Protocol
8
+ describe FrameEncoder do
9
+ let :encoder do
10
+ described_class.new
11
+ end
12
+
13
+ describe '#encode_frame' do
14
+ it 'returns a rendered request frame for the specified channel' do
15
+ request = PrepareRequest.new('SELECT * FROM things')
16
+ stream_id = 3
17
+ encoded_frame = encoder.encode_frame(request, stream_id)
18
+ encoded_frame.to_s.should == "\x01\x00\x03\x09\x00\x00\x00\x18\x00\x00\x00\x14SELECT * FROM things"
19
+ end
20
+
21
+ it 'appends a rendered request frame to the specified buffer' do
22
+ buffer = ByteBuffer.new('hello')
23
+ request = PrepareRequest.new('SELECT * FROM things')
24
+ stream_id = 3
25
+ encoded_frame = encoder.encode_frame(request, stream_id, buffer)
26
+ buffer.to_s.should == "hello\x01\x00\x03\x09\x00\x00\x00\x18\x00\x00\x00\x14SELECT * FROM things"
27
+ end
28
+
29
+ it 'returns the specified buffer' do
30
+ buffer = ByteBuffer.new('hello')
31
+ request = PrepareRequest.new('SELECT * FROM things')
32
+ stream_id = 3
33
+ encoded_frame = encoder.encode_frame(request, stream_id, buffer)
34
+ encoded_frame.should equal(buffer)
35
+ end
36
+
37
+ context 'with a compressor' do
38
+ let :encoder do
39
+ described_class.new(compressor)
40
+ end
41
+
42
+ let :compressor do
43
+ double(:compressor)
44
+ end
45
+
46
+ let :request do
47
+ PrepareRequest.new('SELECT * FROM things')
48
+ end
49
+
50
+ let :compressed_frame do
51
+ encoder.encode_frame(request, 3).to_s
52
+ end
53
+
54
+ before do
55
+ compressor.stub(:compress?).with("\x00\x00\x00\x14SELECT * FROM things").and_return(true)
56
+ compressor.stub(:compress).with("\x00\x00\x00\x14SELECT * FROM things").and_return('FAKECOMPRESSEDBODY')
57
+ end
58
+
59
+ it 'sets the compression flag' do
60
+ compressed_frame[1].should == "\x01"
61
+ end
62
+
63
+ it 'sets the size to the compressed size' do
64
+ compressed_frame[4, 4].unpack('N').first.should == 18
65
+ end
66
+
67
+ it 'compresses the frame body' do
68
+ compressed_frame[8, 18].should == 'FAKECOMPRESSEDBODY'
69
+ compressed_frame.bytesize.should == 26
70
+ end
71
+
72
+ it 'does not clobber the trace flag' do
73
+ request = PrepareRequest.new('SELECT * FROM things', true)
74
+ stream_id = 3
75
+ compressed_frame = encoder.encode_frame(request, stream_id)
76
+ compressed_frame.to_s[1].should == "\x03"
77
+ end
78
+
79
+ it 'does not compress when the compressor responds to #compress? with false' do
80
+ compressor.stub(:compress?).and_return(false)
81
+ compressed_frame[1].should == "\x00"
82
+ compressed_frame.should include('SELECT * FROM things')
83
+ compressed_frame.bytesize.should == 32
84
+ end
85
+ end
86
+ end
87
+
88
+ describe '#change_stream_id' do
89
+ it 'changes the stream ID byte' do
90
+ buffer = ByteBuffer.new("\x01\x00\x03\x02\x00\x00\x00\x00")
91
+ encoder.change_stream_id(99, buffer)
92
+ buffer.discard(2)
93
+ buffer.read_byte.should == 99
94
+ end
95
+
96
+ it 'changes the stream ID byte of the frame starting at the specified offset' do
97
+ buffer = ByteBuffer.new("hello foo\x01\x00\x03\x02\x00\x00\x00\x00")
98
+ encoder.change_stream_id(99, buffer, 9)
99
+ buffer.discard(11)
100
+ buffer.read_byte.should == 99
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -6,12 +6,10 @@ require 'spec_helper'
6
6
  module Cql
7
7
  module Protocol
8
8
  describe CredentialsRequest do
9
- describe '#encode_frame' do
9
+ describe '#write' do
10
10
  it 'encodes a CREDENTIALS request frame' do
11
- bytes = CredentialsRequest.new('username' => 'cassandra', 'password' => 'ardnassac').encode_frame(3)
11
+ bytes = CredentialsRequest.new('username' => 'cassandra', 'password' => 'ardnassac').write('')
12
12
  bytes.should == (
13
- "\x01\x00\x03\04" +
14
- "\x00\x00\x00\x2c" +
15
13
  "\x00\x02" +
16
14
  "\x00\x08username" +
17
15
  "\x00\x09cassandra" +
@@ -47,10 +47,10 @@ module Cql
47
47
  end
48
48
  end
49
49
 
50
- describe '#encode_frame' do
50
+ describe '#write' do
51
51
  it 'encodes an EXECUTE request frame' do
52
- bytes = ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], :each_quorum).encode_frame(3)
53
- bytes.should == "\x01\x00\x03\x0a\x00\x00\x00\x2e\x00\x10\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/\x00\x03\x00\x00\x00\x05hello\x00\x00\x00\x04\x00\x00\x00\x2a\x00\x00\x00\x03foo\x00\x07"
52
+ bytes = ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], :each_quorum).write('')
53
+ bytes.should == "\x00\x10\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/\x00\x03\x00\x00\x00\x05hello\x00\x00\x00\x04\x00\x00\x00\x2a\x00\x00\x00\x03foo\x00\x07"
54
54
  end
55
55
 
56
56
  specs = [
@@ -84,8 +84,8 @@ module Cql
84
84
  specs.each do |type, value, expected_bytes|
85
85
  it "encodes #{type} values" do
86
86
  metadata = [['ks', 'tbl', 'id_column', type]]
87
- buffer = ExecuteRequest.new(id, metadata, [value], :one).encode_frame(3)
88
- buffer.discard(8 + 2 + 16 + 2)
87
+ buffer = ExecuteRequest.new(id, metadata, [value], :one).write(ByteBuffer.new)
88
+ buffer.discard(2 + 16 + 2)
89
89
  length = buffer.read_int
90
90
  result_bytes = buffer.read(length)
91
91
  result_bytes.should eql_bytes(expected_bytes)
@@ -6,10 +6,16 @@ require 'spec_helper'
6
6
  module Cql
7
7
  module Protocol
8
8
  describe OptionsRequest do
9
- describe '#encode_frame' do
10
- it 'encodes an OPTIONS request frame' do
11
- bytes = OptionsRequest.new.encode_frame(3)
12
- bytes.should == "\x01\x00\x03\x05\x00\x00\x00\x00"
9
+ describe '#compressable?' do
10
+ it 'is not compressable' do
11
+ described_class.new.should_not be_compressable
12
+ end
13
+ end
14
+
15
+ describe '#write' do
16
+ it 'encodes an OPTIONS request frame (i.e. an empty body)' do
17
+ bytes = OptionsRequest.new.write('')
18
+ bytes.should be_empty
13
19
  end
14
20
  end
15
21