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
@@ -13,21 +13,21 @@ module Cql
|
|
13
13
|
describe '#decode_frame' do
|
14
14
|
context 'with an uncompressed frame' do
|
15
15
|
it 'returns a partial frame when not all the frame\'s bytes are in the buffer' do
|
16
|
-
frame = decoder.decode_frame(
|
16
|
+
frame = decoder.decode_frame(CqlByteBuffer.new)
|
17
17
|
frame.should_not be_complete
|
18
|
-
frame = decoder.decode_frame(
|
18
|
+
frame = decoder.decode_frame(CqlByteBuffer.new("\x81\x00\x00\x02\x00\x00\x00\x16"))
|
19
19
|
frame.should_not be_complete
|
20
|
-
frame = decoder.decode_frame(
|
20
|
+
frame = decoder.decode_frame(CqlByteBuffer.new("\x81\x00\x00\x02\x00\x00\x00\x16\x01\x23\x45"))
|
21
21
|
frame.should_not be_complete
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'returns a partial frame less than eight bytes are missing' do
|
25
|
-
frame = decoder.decode_frame(
|
25
|
+
frame = decoder.decode_frame(CqlByteBuffer.new("\x81\x02\x00\x08\x00\x00\x00\x14\a\xE4\xBE\x10?\x03\x11\xE3\x951\xFBr\xEF\xF0_\xBB\x00\x00"))
|
26
26
|
frame.should_not be_complete
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'returns a complete frame when all bytes are in the buffer' do
|
30
|
-
buffer =
|
30
|
+
buffer = CqlByteBuffer.new
|
31
31
|
buffer << "\x81\x00\x00\x06\x00\x00\x00\x27"
|
32
32
|
buffer << "\x00\x02\x00\x0bCQL_VERSION\x00\x01\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x00"
|
33
33
|
frame = decoder.decode_frame(buffer)
|
@@ -36,19 +36,19 @@ module Cql
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'returns the stream ID' do
|
39
|
-
buffer =
|
39
|
+
buffer = CqlByteBuffer.new("\x81\x00\x03\x02\x00\x00\x00\x00")
|
40
40
|
frame = decoder.decode_frame(buffer)
|
41
41
|
frame.stream_id.should == 3
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'returns the stream ID when it is negative' do
|
45
|
-
buffer =
|
45
|
+
buffer = CqlByteBuffer.new("\x81\x00\xff\x02\x00\x00\x00\x00")
|
46
46
|
frame = decoder.decode_frame(buffer)
|
47
47
|
frame.stream_id.should == -1
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'first returns a partial frame, then a complete frame' do
|
51
|
-
buffer =
|
51
|
+
buffer = CqlByteBuffer.new
|
52
52
|
buffer << "\x81\x00\x00\x06\x00\x00\x00\x27"
|
53
53
|
frame = decoder.decode_frame(buffer)
|
54
54
|
buffer << "\x00\x02\x00\x0bCQL_VERSION"
|
@@ -59,7 +59,7 @@ module Cql
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'leaves extra bytes in the buffer' do
|
62
|
-
buffer =
|
62
|
+
buffer = CqlByteBuffer.new
|
63
63
|
buffer << "\x81\x00\x00\x06\x00\x00\x00\x27"
|
64
64
|
buffer << "\x00\x02\x00\x0bCQL_VERSION\x00\x01\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x00\xca\xfe"
|
65
65
|
frame = decoder.decode_frame(buffer)
|
@@ -68,7 +68,7 @@ module Cql
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'consumes the number of bytes specified in the frame header' do
|
71
|
-
buffer =
|
71
|
+
buffer = CqlByteBuffer.new
|
72
72
|
buffer << "\x81\x00\x00\x06\x00\x00\x00\x29"
|
73
73
|
buffer << "\x00\x02\x00\x0bCQL_VERSION\x00\x01\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x00\xca\xfe"
|
74
74
|
frame = decoder.decode_frame(buffer)
|
@@ -77,18 +77,18 @@ module Cql
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'extracts a trace ID' do
|
80
|
-
buffer =
|
80
|
+
buffer = CqlByteBuffer.new
|
81
81
|
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"
|
82
82
|
frame = decoder.decode_frame(buffer)
|
83
83
|
frame.body.trace_id.should == Uuid.new('07e4be10-3f03-11e3-9531-fb72eff05fbb')
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'complains when the frame is a request frame' do
|
87
|
-
expect { decoder.decode_frame(
|
87
|
+
expect { decoder.decode_frame(CqlByteBuffer.new("\x01\x00\x00\x05\x00\x00\x00\x00")) }.to raise_error(UnsupportedFrameTypeError)
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'complains when the opcode is unknown' do
|
91
|
-
expect { decoder.decode_frame(
|
91
|
+
expect { decoder.decode_frame(CqlByteBuffer.new("\x81\x00\x00\xff\x00\x00\x00\x00")) }.to raise_error(UnsupportedOperationError)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -102,7 +102,7 @@ module Cql
|
|
102
102
|
end
|
103
103
|
|
104
104
|
let :buffer do
|
105
|
-
|
105
|
+
CqlByteBuffer.new("\x81\x01\x00\x06\x00\x00\x00\x12FAKECOMPRESSEDBODY")
|
106
106
|
end
|
107
107
|
|
108
108
|
before do
|
@@ -24,11 +24,11 @@ module Cql
|
|
24
24
|
it 'asks the request to write itself to a buffer' do
|
25
25
|
encoder = described_class.new(1)
|
26
26
|
encoder.encode_frame(request)
|
27
|
-
request.should have_received(:write).with(anything, an_instance_of(
|
27
|
+
request.should have_received(:write).with(anything, an_instance_of(CqlByteBuffer))
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'appends what the request wrote to the specified buffer, after a header' do
|
31
|
-
buffer =
|
31
|
+
buffer = CqlByteBuffer.new('hello')
|
32
32
|
request.stub(:write) { |pv, bb| bb << "\x01\x02\x03" }
|
33
33
|
encoder = described_class.new(1)
|
34
34
|
encoder.encode_frame(request, 0, buffer)
|
@@ -37,7 +37,7 @@ module Cql
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'returns the specified buffer' do
|
40
|
-
buffer =
|
40
|
+
buffer = CqlByteBuffer.new('hello')
|
41
41
|
encoder = described_class.new(1)
|
42
42
|
returned_buffer = encoder.encode_frame(request, 0, buffer)
|
43
43
|
returned_buffer.should equal(buffer)
|
@@ -81,7 +81,7 @@ module Cql
|
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'encodes the body size' do
|
84
|
-
request.stub(:write).and_return(
|
84
|
+
request.stub(:write).and_return(CqlByteBuffer.new('helloworld'))
|
85
85
|
encoder = described_class.new(1)
|
86
86
|
buffer = encoder.encode_frame(request, 9)
|
87
87
|
buffer.to_s[4, 4].should == "\x00\x00\x00\x0a"
|
@@ -90,7 +90,7 @@ module Cql
|
|
90
90
|
context 'when a compressor has been specified' do
|
91
91
|
before do
|
92
92
|
request.stub(:compressable?).and_return(true)
|
93
|
-
request.stub(:write).and_return(
|
93
|
+
request.stub(:write).and_return(CqlByteBuffer.new('helloworld'))
|
94
94
|
compressor.stub(:compress?).and_return(true)
|
95
95
|
compressor.stub(:compress).with('helloworld').and_return('COMPRESSEDFRAME')
|
96
96
|
end
|
@@ -136,14 +136,14 @@ module Cql
|
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'changes the stream ID byte' do
|
139
|
-
buffer =
|
139
|
+
buffer = CqlByteBuffer.new("\x01\x00\x03\x02\x00\x00\x00\x00")
|
140
140
|
encoder.change_stream_id(99, buffer)
|
141
141
|
buffer.discard(2)
|
142
142
|
buffer.read_byte.should == 99
|
143
143
|
end
|
144
144
|
|
145
145
|
it 'changes the stream ID byte of the frame starting at the specified offset' do
|
146
|
-
buffer =
|
146
|
+
buffer = CqlByteBuffer.new("hello foo\x01\x00\x03\x02\x00\x00\x00\x00")
|
147
147
|
encoder.change_stream_id(99, buffer, 9)
|
148
148
|
buffer.discard(11)
|
149
149
|
buffer.read_byte.should == 99
|
@@ -8,13 +8,13 @@ module Cql
|
|
8
8
|
describe AuthResponseRequest do
|
9
9
|
describe '#write' do
|
10
10
|
it 'encodes an AUTH_RESPONSE request frame' do
|
11
|
-
bytes = described_class.new('bingbongpong').write(2,
|
12
|
-
bytes.should
|
11
|
+
bytes = described_class.new('bingbongpong').write(2, CqlByteBuffer.new)
|
12
|
+
bytes.should eql_bytes("\x00\x00\x00\x0cbingbongpong")
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'encodes a nil token' do
|
16
|
-
bytes = described_class.new(nil).write(2,
|
17
|
-
bytes.should
|
16
|
+
bytes = described_class.new(nil).write(2, CqlByteBuffer.new)
|
17
|
+
bytes.should eql_bytes("\xff\xff\xff\xff")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -18,8 +18,8 @@ module Cql
|
|
18
18
|
it 'encodes a BATCH request frame with a single prepared query' do
|
19
19
|
batch = described_class.new(described_class::LOGGED_TYPE, :two)
|
20
20
|
batch.add_prepared(statement_id, metadata, ['arg', 3])
|
21
|
-
bytes = batch.write(2,
|
22
|
-
bytes.should
|
21
|
+
bytes = batch.write(2, CqlByteBuffer.new)
|
22
|
+
bytes.should eql_bytes(
|
23
23
|
"\x00" +
|
24
24
|
"\x00\x01" +
|
25
25
|
"\x01" +
|
@@ -32,8 +32,8 @@ module Cql
|
|
32
32
|
it 'encodes a BATCH request frame with a single query' do
|
33
33
|
batch = described_class.new(described_class::LOGGED_TYPE, :one)
|
34
34
|
batch.add_query(%<INSERT INTO things (a, b) VALUES ('foo', 3)>)
|
35
|
-
bytes = batch.write(2,
|
36
|
-
bytes.should
|
35
|
+
bytes = batch.write(2, CqlByteBuffer.new)
|
36
|
+
bytes.should eql_bytes(
|
37
37
|
"\x00" +
|
38
38
|
"\x00\x01" +
|
39
39
|
"\x00" +
|
@@ -46,8 +46,8 @@ module Cql
|
|
46
46
|
it 'encodes a BATCH request frame with a single query with on-the-fly bound values' do
|
47
47
|
batch = described_class.new(described_class::LOGGED_TYPE, :two)
|
48
48
|
batch.add_query('INSERT INTO things (a, b) VALUES (?, ?)', ['foo', 5])
|
49
|
-
bytes = batch.write(2,
|
50
|
-
bytes.should
|
49
|
+
bytes = batch.write(2, CqlByteBuffer.new)
|
50
|
+
bytes.should eql_bytes(
|
51
51
|
"\x00" +
|
52
52
|
"\x00\x01" +
|
53
53
|
"\x00" +
|
@@ -62,8 +62,8 @@ module Cql
|
|
62
62
|
batch.add_prepared(statement_id, metadata, ['arg', 3])
|
63
63
|
batch.add_query(%<INSERT INTO things (a, b) VALUES (?, ?)>, ['foo', 5])
|
64
64
|
batch.add_query(%<INSERT INTO things (a, b) VALUES ('foo', 3)>)
|
65
|
-
bytes = batch.write(2,
|
66
|
-
bytes.should
|
65
|
+
bytes = batch.write(2, CqlByteBuffer.new)
|
66
|
+
bytes.should eql_bytes(
|
67
67
|
"\x00" +
|
68
68
|
"\x00\x03" +
|
69
69
|
"\x01" +
|
@@ -82,22 +82,22 @@ module Cql
|
|
82
82
|
it 'encodes the type when it is "logged"' do
|
83
83
|
batch = described_class.new(described_class::LOGGED_TYPE, :two)
|
84
84
|
batch.add_prepared(statement_id, metadata, ['arg', 3])
|
85
|
-
bytes = batch.write(2,
|
86
|
-
bytes[0].should == "\x00"
|
85
|
+
bytes = batch.write(2, CqlByteBuffer.new)
|
86
|
+
bytes.to_s[0].should == "\x00"
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'encodes the type when it is "unlogged"' do
|
90
90
|
batch = described_class.new(described_class::UNLOGGED_TYPE, :two)
|
91
91
|
batch.add_prepared(statement_id, metadata, ['arg', 3])
|
92
|
-
bytes = batch.write(2,
|
93
|
-
bytes[0].should == "\x01"
|
92
|
+
bytes = batch.write(2, CqlByteBuffer.new)
|
93
|
+
bytes.to_s[0].should == "\x01"
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'encodes the type when it is "counter"' do
|
97
97
|
batch = described_class.new(described_class::COUNTER_TYPE, :two)
|
98
98
|
batch.add_prepared(statement_id, metadata, ['arg', 3])
|
99
|
-
bytes = batch.write(2,
|
100
|
-
bytes[0].should == "\x02"
|
99
|
+
bytes = batch.write(2, CqlByteBuffer.new)
|
100
|
+
bytes.to_s[0].should == "\x02"
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'encodes the number of statements in the batch' do
|
@@ -105,24 +105,24 @@ module Cql
|
|
105
105
|
batch.add_prepared(statement_id, metadata, ['arg', 3])
|
106
106
|
batch.add_prepared(statement_id, metadata, ['foo', 4])
|
107
107
|
batch.add_prepared(statement_id, metadata, ['bar', 5])
|
108
|
-
bytes = batch.write(2,
|
109
|
-
bytes[1, 2].should == "\x00\x03"
|
108
|
+
bytes = batch.write(2, CqlByteBuffer.new)
|
109
|
+
bytes.to_s[1, 2].should == "\x00\x03"
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'encodes the type of each statement' do
|
113
113
|
batch = described_class.new(described_class::LOGGED_TYPE, :two)
|
114
114
|
batch.add_prepared(statement_id, metadata, ['arg', 3])
|
115
115
|
batch.add_query(%<INSERT INTO things (a, b) VALUES ('arg', 3)>)
|
116
|
-
bytes = batch.write(2,
|
117
|
-
bytes[3, 1].should == "\x01"
|
118
|
-
bytes[39, 1].should == "\x00"
|
116
|
+
bytes = batch.write(2, CqlByteBuffer.new)
|
117
|
+
bytes.to_s[3, 1].should == "\x01"
|
118
|
+
bytes.to_s[39, 1].should == "\x00"
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'uses the type hints given to #add_query' do
|
122
122
|
batch = described_class.new(described_class::LOGGED_TYPE, :two)
|
123
123
|
batch.add_query(%<INSERT INTO things (a, b) VALUES (?, ?)>, ['foo', 3], [nil, :int])
|
124
|
-
bytes = batch.write(2,
|
125
|
-
bytes[56, 8].should == "\x00\x00\x00\x04\x00\x00\x00\x03"
|
124
|
+
bytes = batch.write(2, CqlByteBuffer.new)
|
125
|
+
bytes.to_s[56, 8].should == "\x00\x00\x00\x04\x00\x00\x00\x03"
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
@@ -8,8 +8,8 @@ module Cql
|
|
8
8
|
describe CredentialsRequest do
|
9
9
|
describe '#write' do
|
10
10
|
it 'encodes a CREDENTIALS request frame' do
|
11
|
-
bytes = CredentialsRequest.new('username' => 'cassandra', 'password' => 'ardnassac').write(1,
|
12
|
-
bytes.should
|
11
|
+
bytes = CredentialsRequest.new('username' => 'cassandra', 'password' => 'ardnassac').write(1, CqlByteBuffer.new)
|
12
|
+
bytes.should eql_bytes(
|
13
13
|
"\x00\x02" +
|
14
14
|
"\x00\x08username" +
|
15
15
|
"\x00\x09cassandra" +
|
@@ -66,7 +66,7 @@ module Cql
|
|
66
66
|
describe '#write' do
|
67
67
|
context 'when the protocol version is 1' do
|
68
68
|
let :frame_bytes do
|
69
|
-
ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], true, :each_quorum, nil, nil, nil, false).write(1,
|
69
|
+
ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], true, :each_quorum, nil, nil, nil, false).write(1, CqlByteBuffer.new)
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'writes the statement ID' do
|
@@ -88,7 +88,7 @@ module Cql
|
|
88
88
|
|
89
89
|
context 'when the protocol version is 2' do
|
90
90
|
let :frame_bytes do
|
91
|
-
ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], true, :each_quorum, nil, nil, nil, false).write(2,
|
91
|
+
ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], true, :each_quorum, nil, nil, nil, false).write(2, CqlByteBuffer.new)
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'writes the statement ID' do
|
@@ -104,12 +104,12 @@ module Cql
|
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'does not write the bound values flag when there are no values, and does not write anything more' do
|
107
|
-
frame_bytes = ExecuteRequest.new(id, [], [], true, :each_quorum, nil, nil, nil, false).write(2,
|
107
|
+
frame_bytes = ExecuteRequest.new(id, [], [], true, :each_quorum, nil, nil, nil, false).write(2, CqlByteBuffer.new)
|
108
108
|
frame_bytes.to_s[20, 999].should == "\x00"
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'writes flags saying that the result doesn\'t need to contain metadata' do
|
112
|
-
frame_bytes = ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], false, :each_quorum, nil, nil, nil, false).write(2,
|
112
|
+
frame_bytes = ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], false, :each_quorum, nil, nil, nil, false).write(2, CqlByteBuffer.new)
|
113
113
|
frame_bytes.to_s[20, 1].should == "\x03"
|
114
114
|
end
|
115
115
|
|
@@ -122,22 +122,22 @@ module Cql
|
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'sets the serial flag and includes the serial consistency' do
|
125
|
-
frame_bytes = ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], false, :each_quorum, :local_serial, false).write(2,
|
125
|
+
frame_bytes = ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], false, :each_quorum, :local_serial, false).write(2, CqlByteBuffer.new)
|
126
126
|
frame_bytes.to_s[20, 1].should == "\x13"
|
127
127
|
frame_bytes.to_s[47, 2].should == "\x00\x09"
|
128
128
|
end
|
129
129
|
|
130
130
|
it 'writes the page size flag and page size' do
|
131
|
-
frame_bytes = ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], true, :one, nil, 10, nil, false).write(2,
|
132
|
-
(frame_bytes[20, 1].ord & 0x04).should == 0x04
|
133
|
-
frame_bytes[47, 4].should == "\x00\x00\x00\x0a"
|
131
|
+
frame_bytes = ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], true, :one, nil, 10, nil, false).write(2, CqlByteBuffer.new)
|
132
|
+
(frame_bytes.to_s[20, 1].ord & 0x04).should == 0x04
|
133
|
+
frame_bytes.to_s[47, 4].should == "\x00\x00\x00\x0a"
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'writes the page size and paging state flag and the page size and paging state' do
|
137
|
-
frame_bytes = ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], true, :one, nil, 10, 'foobar', false).write(2,
|
138
|
-
(frame_bytes[20, 1].ord & 0x0c).should == 0x0c
|
139
|
-
frame_bytes[47, 4].should == "\x00\x00\x00\x0a"
|
140
|
-
frame_bytes[51, 10].should == "\x00\x00\x00\x06foobar"
|
137
|
+
frame_bytes = ExecuteRequest.new(id, column_metadata, ['hello', 42, 'foo'], true, :one, nil, 10, 'foobar', false).write(2, CqlByteBuffer.new)
|
138
|
+
(frame_bytes.to_s[20, 1].ord & 0x0c).should == 0x0c
|
139
|
+
frame_bytes.to_s[47, 4].should == "\x00\x00\x00\x0a"
|
140
|
+
frame_bytes.to_s[51, 10].should == "\x00\x00\x00\x06foobar"
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
@@ -173,7 +173,7 @@ module Cql
|
|
173
173
|
specs.each do |type, value, expected_bytes|
|
174
174
|
it "encodes #{type} values" do
|
175
175
|
metadata = [['ks', 'tbl', 'id_column', type]]
|
176
|
-
buffer = ExecuteRequest.new(id, metadata, [value], true, :one, nil, nil, nil, false).write(1,
|
176
|
+
buffer = ExecuteRequest.new(id, metadata, [value], true, :one, nil, nil, nil, false).write(1, CqlByteBuffer.new)
|
177
177
|
buffer.discard(2 + 16 + 2)
|
178
178
|
length = buffer.read_int
|
179
179
|
result_bytes = buffer.read(length)
|
@@ -14,8 +14,8 @@ module Cql
|
|
14
14
|
|
15
15
|
describe '#write' do
|
16
16
|
it 'encodes a PREPARE request frame' do
|
17
|
-
bytes = PrepareRequest.new('UPDATE users SET email = ? WHERE user_name = ?').write(1,
|
18
|
-
bytes.should
|
17
|
+
bytes = PrepareRequest.new('UPDATE users SET email = ? WHERE user_name = ?').write(1, CqlByteBuffer.new)
|
18
|
+
bytes.should eql_bytes("\x00\x00\x00\x2eUPDATE users SET email = ? WHERE user_name = ?")
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -35,7 +35,7 @@ module Cql
|
|
35
35
|
describe '#write' do
|
36
36
|
context 'when the protocol version is 1' do
|
37
37
|
let :frame_bytes do
|
38
|
-
QueryRequest.new('USE system', [], [], :all, nil, nil, nil, false).write(1,
|
38
|
+
QueryRequest.new('USE system', [], [], :all, nil, nil, nil, false).write(1, CqlByteBuffer.new)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'encodes the CQL' do
|
@@ -50,7 +50,7 @@ module Cql
|
|
50
50
|
context 'when the protocol version is 2' do
|
51
51
|
context 'and there are no bound values' do
|
52
52
|
let :frame_bytes do
|
53
|
-
QueryRequest.new('USE system', [], [], :all, nil, nil, nil, false).write(2,
|
53
|
+
QueryRequest.new('USE system', [], [], :all, nil, nil, nil, false).write(2, CqlByteBuffer.new)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'encodes the CQL' do
|
@@ -66,12 +66,12 @@ module Cql
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'accepts that the bound values list is nil' do
|
69
|
-
frame_bytes = QueryRequest.new('USE system', nil, [], :all, nil, nil, nil, false).write(2,
|
69
|
+
frame_bytes = QueryRequest.new('USE system', nil, [], :all, nil, nil, nil, false).write(2, CqlByteBuffer.new)
|
70
70
|
frame_bytes.to_s[16, 999].should == "\x00"
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'accepts that the type hints list is nil' do
|
74
|
-
expect { QueryRequest.new('SELECT * FROM foo WHERE a = ? AND b = ?', ['x', 'y'], nil, :all, nil, nil, nil, false).write(2,
|
74
|
+
expect { QueryRequest.new('SELECT * FROM foo WHERE a = ? AND b = ?', ['x', 'y'], nil, :all, nil, nil, nil, false).write(2, CqlByteBuffer.new) }.to_not raise_error
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -81,7 +81,7 @@ module Cql
|
|
81
81
|
end
|
82
82
|
|
83
83
|
let :frame_bytes do
|
84
|
-
QueryRequest.new(cql, ['foobar'], nil, :all, nil, nil, nil, false).write(2,
|
84
|
+
QueryRequest.new(cql, ['foobar'], nil, :all, nil, nil, nil, false).write(2, CqlByteBuffer.new)
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'encodes the CQL' do
|
@@ -121,23 +121,23 @@ module Cql
|
|
121
121
|
[[Math::PI, Math::PI/2].to_set, 'SET<DOUBLE>', "\x00\x00\x00\x16\x00\x02\x00\x08\x40\x09\x21\xfb\x54\x44\x2d\x18\x00\x08\x3f\xf9\x21\xfb\x54\x44\x2d\x18"],
|
122
122
|
].each do |value, cql_type, expected_bytes|
|
123
123
|
it "encodes bound #{value.class}s as #{cql_type}" do
|
124
|
-
frame_bytes = QueryRequest.new(cql, [value], nil, :all, nil, nil, nil, false).write(2,
|
124
|
+
frame_bytes = QueryRequest.new(cql, [value], nil, :all, nil, nil, nil, false).write(2, CqlByteBuffer.new)
|
125
125
|
frame_bytes.to_s[45, 999].should == expected_bytes
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'complains if it cannot guess the type to encode a value as' do
|
130
|
-
expect { QueryRequest.new(cql, [self], nil, :all, nil, nil, nil, false).write(2,
|
130
|
+
expect { QueryRequest.new(cql, [self], nil, :all, nil, nil, nil, false).write(2, CqlByteBuffer.new) }.to raise_error(EncodingError)
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'uses the type hints to encode values' do
|
134
|
-
frame_bytes = QueryRequest.new(cql, [4, 3.14], [:int, :float], :all, nil, nil, nil, false).write(2,
|
134
|
+
frame_bytes = QueryRequest.new(cql, [4, 3.14], [:int, :float], :all, nil, nil, nil, false).write(2, CqlByteBuffer.new)
|
135
135
|
frame_bytes.to_s[45, 8].should == "\x00\x00\x00\x04\x00\x00\x00\x04"
|
136
136
|
frame_bytes.to_s[45 + 8, 8].should == "\x00\x00\x00\x04\x40\x48\xf5\xc3"
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'accepts that some hints are nil and defaults to guessing' do
|
140
|
-
frame_bytes = QueryRequest.new(cql, [4, 4], [:int, nil], :all, nil, nil, nil, false).write(2,
|
140
|
+
frame_bytes = QueryRequest.new(cql, [4, 4], [:int, nil], :all, nil, nil, nil, false).write(2, CqlByteBuffer.new)
|
141
141
|
frame_bytes.to_s[45, 8].should == "\x00\x00\x00\x04\x00\x00\x00\x04"
|
142
142
|
frame_bytes.to_s[45 + 8, 12].should == "\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x04"
|
143
143
|
end
|
@@ -145,7 +145,7 @@ module Cql
|
|
145
145
|
|
146
146
|
context 'and the serial consistency is LOCAL_SERIAL' do
|
147
147
|
it 'sets the serial flag' do
|
148
|
-
frame_bytes = QueryRequest.new('UPDATE x SET y = 3 WHERE z = 4 IF w = 6', nil, nil, :two, :local_serial, nil, nil, false).write(2,
|
148
|
+
frame_bytes = QueryRequest.new('UPDATE x SET y = 3 WHERE z = 4 IF w = 6', nil, nil, :two, :local_serial, nil, nil, false).write(2, CqlByteBuffer.new)
|
149
149
|
frame_bytes.to_s[43, 2].should == "\x00\x02"
|
150
150
|
frame_bytes.to_s[45, 1].should == "\x10"
|
151
151
|
frame_bytes.to_s[46, 2].should == "\x00\x09"
|
@@ -154,13 +154,13 @@ module Cql
|
|
154
154
|
|
155
155
|
context 'and page size and/or page state is set' do
|
156
156
|
it 'sets the page size flag and includes the page size' do
|
157
|
-
frame_bytes = QueryRequest.new('SELECT * FROM users', nil, nil, :one, nil, 10, nil, false).write(2,
|
157
|
+
frame_bytes = QueryRequest.new('SELECT * FROM users', nil, nil, :one, nil, 10, nil, false).write(2, CqlByteBuffer.new)
|
158
158
|
frame_bytes.to_s[25, 1].should == "\x04"
|
159
159
|
frame_bytes.to_s[26, 4].should == "\x00\x00\x00\x0a"
|
160
160
|
end
|
161
161
|
|
162
162
|
it 'sets both the page size and paging state flags and includes both the page size and the paging state' do
|
163
|
-
frame_bytes = QueryRequest.new('SELECT * FROM users', nil, nil, :one, nil, 10, 'foo', false).write(2,
|
163
|
+
frame_bytes = QueryRequest.new('SELECT * FROM users', nil, nil, :one, nil, 10, 'foo', false).write(2, CqlByteBuffer.new)
|
164
164
|
frame_bytes.to_s[25, 1].should == "\x0c"
|
165
165
|
frame_bytes.to_s[26, 4].should == "\x00\x00\x00\x0a"
|
166
166
|
frame_bytes.to_s[30, 7].should == "\x00\x00\x00\x03foo"
|
@@ -170,7 +170,7 @@ module Cql
|
|
170
170
|
|
171
171
|
context 'with multibyte characters' do
|
172
172
|
it 'correctly encodes the frame' do
|
173
|
-
bytes = QueryRequest.new("INSERT INTO users (user_id, first, last, age) VALUES ('test', 'ümlaut', 'test', 1)", nil, nil, :all, nil, nil, nil, false).write(1,
|
173
|
+
bytes = QueryRequest.new("INSERT INTO users (user_id, first, last, age) VALUES ('test', 'ümlaut', 'test', 1)", nil, nil, :all, nil, nil, nil, false).write(1, CqlByteBuffer.new)
|
174
174
|
bytes.should eql_bytes("\x00\x00\x00SINSERT INTO users (user_id, first, last, age) VALUES ('test', '\xC3\xBCmlaut', 'test', 1)\x00\x05")
|
175
175
|
end
|
176
176
|
end
|