cql-rb 2.0.0.pre0 → 2.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -8,8 +8,8 @@ module Cql
|
|
8
8
|
describe RegisterRequest do
|
9
9
|
describe '#write' do
|
10
10
|
it 'encodes a REGISTER request frame' do
|
11
|
-
bytes = RegisterRequest.new('TOPOLOGY_CHANGE', 'STATUS_CHANGE').write(1,
|
12
|
-
bytes.should
|
11
|
+
bytes = RegisterRequest.new('TOPOLOGY_CHANGE', 'STATUS_CHANGE').write(1, CqlByteBuffer.new)
|
12
|
+
bytes.should eql_bytes("\x00\x02\x00\x0fTOPOLOGY_CHANGE\x00\x0dSTATUS_CHANGE")
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -20,13 +20,13 @@ module Cql
|
|
20
20
|
|
21
21
|
describe '#write' do
|
22
22
|
it 'encodes a STARTUP request frame' do
|
23
|
-
bytes = StartupRequest.new('3.0.0', 'snappy').write(1,
|
24
|
-
bytes.should
|
23
|
+
bytes = StartupRequest.new('3.0.0', 'snappy').write(1, CqlByteBuffer.new)
|
24
|
+
bytes.should eql_bytes("\x00\x02\x00\x0bCQL_VERSION\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x06snappy")
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'defaults to no compression' do
|
28
|
-
bytes = StartupRequest.new('3.1.1').write(1,
|
29
|
-
bytes.should
|
28
|
+
bytes = StartupRequest.new('3.1.1').write(1, CqlByteBuffer.new)
|
29
|
+
bytes.should eql_bytes("\x00\x01\x00\x0bCQL_VERSION\x00\x053.1.1")
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -6,16 +6,16 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe AuthChallengeResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
it 'decodes the token' do
|
11
|
-
buffer =
|
12
|
-
response = described_class.decode
|
11
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x0cbingbongpong")
|
12
|
+
response = described_class.decode(1, buffer, buffer.length)
|
13
13
|
response.token.should == 'bingbongpong'
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'decodes a nil token' do
|
17
|
-
buffer =
|
18
|
-
response = described_class.decode
|
17
|
+
buffer = CqlByteBuffer.new("\xff\xff\xff\xff")
|
18
|
+
response = described_class.decode(1, buffer, buffer.length)
|
19
19
|
response.token.should be_nil
|
20
20
|
end
|
21
21
|
end
|
@@ -6,16 +6,16 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe AuthSuccessResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
it 'decodes the token' do
|
11
|
-
buffer =
|
12
|
-
response = described_class.decode
|
11
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x0cbingbongpong")
|
12
|
+
response = described_class.decode(1, buffer, buffer.length)
|
13
13
|
response.token.should == 'bingbongpong'
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'decodes a nil token' do
|
17
|
-
buffer =
|
18
|
-
response = described_class.decode
|
17
|
+
buffer = CqlByteBuffer.new("\xff\xff\xff\xff")
|
18
|
+
response = described_class.decode(1, buffer, buffer.length)
|
19
19
|
response.token.should be_nil
|
20
20
|
end
|
21
21
|
end
|
@@ -6,10 +6,10 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe AuthenticateResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
let :response do
|
11
|
-
buffer =
|
12
|
-
described_class.decode
|
11
|
+
buffer = CqlByteBuffer.new("\x00\x2forg.apache.cassandra.auth.PasswordAuthenticator")
|
12
|
+
described_class.decode(1, buffer, buffer.length)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'decodes the authentication class' do
|
@@ -6,10 +6,10 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe DetailedErrorResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
it 'decodes an unavailable error' do
|
11
|
-
buffer =
|
12
|
-
response = described_class.decode
|
11
|
+
buffer = CqlByteBuffer.new("\x00\x05\x00\x00\x00\x03\x00\x00\x00\x02")
|
12
|
+
response = described_class.decode(0x1000, '', 1, buffer, buffer.length)
|
13
13
|
response.details.should == {
|
14
14
|
:cl => :all,
|
15
15
|
:required => 3,
|
@@ -18,8 +18,8 @@ module Cql
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'decodes a write_timeout error' do
|
21
|
-
buffer =
|
22
|
-
response = described_class.decode
|
21
|
+
buffer = CqlByteBuffer.new("\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\tBATCH_LOG")
|
22
|
+
response = described_class.decode(0x1100, '', 1, buffer, buffer.length)
|
23
23
|
response.details.should == {
|
24
24
|
:cl => :one,
|
25
25
|
:received => 0,
|
@@ -29,16 +29,16 @@ module Cql
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'decodes a read_timeout error' do
|
32
|
-
buffer =
|
33
|
-
response = described_class.decode
|
32
|
+
buffer = CqlByteBuffer.new("\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x01")
|
33
|
+
response = described_class.decode(0x1200, '', 1, buffer, buffer.length)
|
34
34
|
response.details.should == {
|
35
35
|
:cl => :one,
|
36
36
|
:received => 0,
|
37
37
|
:blockfor => 1,
|
38
38
|
:data_present => true
|
39
39
|
}
|
40
|
-
buffer =
|
41
|
-
response = described_class.decode
|
40
|
+
buffer = CqlByteBuffer.new("\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00")
|
41
|
+
response = described_class.decode(0x1200, '', 1, buffer, buffer.length)
|
42
42
|
response.details.should == {
|
43
43
|
:cl => :one,
|
44
44
|
:received => 0,
|
@@ -48,8 +48,8 @@ module Cql
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'decodes an already_exists error with a keyspace' do
|
51
|
-
buffer =
|
52
|
-
response = described_class.decode
|
51
|
+
buffer = CqlByteBuffer.new("\x00\x05stuff\x00\x00")
|
52
|
+
response = described_class.decode(0x2400, '', 1, buffer, buffer.length)
|
53
53
|
response.details.should == {
|
54
54
|
:ks => 'stuff',
|
55
55
|
:table => '',
|
@@ -57,8 +57,8 @@ module Cql
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'decodes an already_exists error with a keyspace and table' do
|
60
|
-
buffer =
|
61
|
-
response = described_class.decode
|
60
|
+
buffer = CqlByteBuffer.new("\x00\x05stuff\x00\x06things")
|
61
|
+
response = described_class.decode(0x2400, '', 1, buffer, buffer.length)
|
62
62
|
response.details.should == {
|
63
63
|
:ks => 'stuff',
|
64
64
|
:table => 'things',
|
@@ -66,8 +66,8 @@ module Cql
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'decodes unprepared error' do
|
69
|
-
buffer =
|
70
|
-
response = described_class.decode
|
69
|
+
buffer = CqlByteBuffer.new("\x00\x10\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/")
|
70
|
+
response = described_class.decode(0x2500, '', 1, buffer, buffer.length)
|
71
71
|
response.details.should == {
|
72
72
|
:id => "\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/"
|
73
73
|
}
|
@@ -6,10 +6,10 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe ErrorResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
let :response do
|
11
|
-
buffer =
|
12
|
-
described_class.decode
|
11
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\n\x00PProvided version 4.0.0 is not supported by this server (supported: 2.0.0, 3.0.0)")
|
12
|
+
described_class.decode(1, buffer, buffer.length)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'decodes the error code' do
|
@@ -21,8 +21,8 @@ module Cql
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'decodes error frames with details' do
|
24
|
-
buffer =
|
25
|
-
response = described_class.decode
|
24
|
+
buffer = CqlByteBuffer.new("\x00\x00\x11\x00\x000Operation timed out - received only 0 responses.\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\tBATCH_LOG")
|
25
|
+
response = described_class.decode(1, buffer, buffer.length)
|
26
26
|
response.details.should_not be_nil
|
27
27
|
end
|
28
28
|
end
|
@@ -6,10 +6,10 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe EventResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
it 'decodes a SCHEMA_CHANGE event' do
|
11
|
-
buffer =
|
12
|
-
response = described_class.decode
|
11
|
+
buffer = CqlByteBuffer.new("\x00\rSCHEMA_CHANGE\x00\aDROPPED\x00\ncql_rb_609\x00\x05users")
|
12
|
+
response = described_class.decode(1, buffer, buffer.length)
|
13
13
|
response.type.should == 'SCHEMA_CHANGE'
|
14
14
|
response.change.should == 'DROPPED'
|
15
15
|
response.keyspace.should == 'cql_rb_609'
|
@@ -17,8 +17,8 @@ module Cql
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'decodes a STATUS_CHANGE event' do
|
20
|
-
buffer =
|
21
|
-
response = described_class.decode
|
20
|
+
buffer = CqlByteBuffer.new("\x00\rSTATUS_CHANGE\x00\x04DOWN\x04\x00\x00\x00\x00\x00\x00#R")
|
21
|
+
response = described_class.decode(1, buffer, buffer.length)
|
22
22
|
response.type.should == 'STATUS_CHANGE'
|
23
23
|
response.change.should == 'DOWN'
|
24
24
|
response.address.should == IPAddr.new('0.0.0.0')
|
@@ -26,8 +26,8 @@ module Cql
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'decodes a TOPOLOGY_CHANGE event' do
|
29
|
-
buffer =
|
30
|
-
response = described_class.decode
|
29
|
+
buffer = CqlByteBuffer.new("\x00\x0FTOPOLOGY_CHANGE\x00\fREMOVED_NODE\x04\x00\x00\x00\x00\x00\x00#R")
|
30
|
+
response = described_class.decode(1, buffer, buffer.length)
|
31
31
|
response.type.should == 'TOPOLOGY_CHANGE'
|
32
32
|
response.change.should == 'REMOVED_NODE'
|
33
33
|
response.address.should == IPAddr.new('0.0.0.0')
|
@@ -35,7 +35,7 @@ module Cql
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'complains when asked to decode an unknown event type' do
|
38
|
-
expect { described_class.decode
|
38
|
+
expect { described_class.decode(1, CqlByteBuffer.new("\x00\x04PING"), 6) }.to raise_error(UnsupportedEventTypeError, /PING/)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -6,16 +6,16 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe PreparedResultResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
context 'with a protocol v1 frame' do
|
11
11
|
let :response do
|
12
|
-
buffer =
|
12
|
+
buffer = CqlByteBuffer.new
|
13
13
|
buffer << "\x00\x10\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/" # statement ID
|
14
14
|
buffer << "\x00\x00\x00\x01" # flags (global_tables_spec)
|
15
15
|
buffer << "\x00\x00\x00\x01" # column count
|
16
16
|
buffer << "\x00\ncql_rb_911\x00\x05users" # global_tables_spec
|
17
17
|
buffer << "\x00\tuser_name\x00\r" # col_spec (name + type)
|
18
|
-
described_class.decode
|
18
|
+
described_class.decode(1, buffer, buffer.length)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'decodes the ID' do
|
@@ -29,7 +29,7 @@ module Cql
|
|
29
29
|
|
30
30
|
context 'with a protocol v2 frame' do
|
31
31
|
let :response do
|
32
|
-
buffer =
|
32
|
+
buffer = CqlByteBuffer.new
|
33
33
|
buffer << "\x00\x10\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/" # statement ID
|
34
34
|
buffer << "\x00\x00\x00\x01" # flags (global_tables_spec)
|
35
35
|
buffer << "\x00\x00\x00\x01" # column count
|
@@ -40,7 +40,7 @@ module Cql
|
|
40
40
|
buffer << "\x00\ncql_rb_911\x00\x05users" # global_tables_spec
|
41
41
|
buffer << "\x00\tuser_name\x00\r" # col_spec (name + type)
|
42
42
|
buffer << "\x00\x05email\x00\r" # col_spec (name + type)
|
43
|
-
described_class.decode
|
43
|
+
described_class.decode(2, buffer, buffer.length)
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'decodes the ID' do
|
@@ -61,7 +61,7 @@ module Cql
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'decodes the absence of result metadata' do
|
64
|
-
buffer =
|
64
|
+
buffer = CqlByteBuffer.new
|
65
65
|
buffer << "\x00\x10\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/" # statement ID
|
66
66
|
buffer << "\x00\x00\x00\x01" # flags (global_tables_spec)
|
67
67
|
buffer << "\x00\x00\x00\x01" # column count
|
@@ -69,7 +69,7 @@ module Cql
|
|
69
69
|
buffer << "\x00\tuser_name\x00\r" # col_spec (name + type)
|
70
70
|
buffer << "\x00\x00\x00\x04" # flags (no_metadata)
|
71
71
|
buffer << "\x00\x00\x00\x00" # column count
|
72
|
-
response = described_class.decode
|
72
|
+
response = described_class.decode(2, buffer, buffer.length)
|
73
73
|
response.result_metadata.should be_nil
|
74
74
|
end
|
75
75
|
end
|
@@ -11,7 +11,7 @@ module Cql
|
|
11
11
|
end
|
12
12
|
|
13
13
|
let :raw_rows do
|
14
|
-
|
14
|
+
CqlByteBuffer.new("\x00\x00\x00\x02\x00\x00\x00\x04phil\x00\x00\x00\x0dphil@heck.com\xff\xff\xff\xff\x00\x00\x00\x03sue\x00\x00\x00\x0dsue@inter.net\xff\xff\xff\xff")
|
15
15
|
end
|
16
16
|
|
17
17
|
let :metadata do
|
@@ -6,10 +6,10 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe ReadyResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
it 'returns a new instance' do
|
11
11
|
unused_byte_buffer = nil
|
12
|
-
described_class.decode
|
12
|
+
described_class.decode(1, unused_byte_buffer, 0).should be_a(described_class)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -6,17 +6,17 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe ResultResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
it 'decodes a set_keyspace result' do
|
11
|
-
buffer =
|
12
|
-
response = described_class.decode
|
11
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x03\x00\x06system")
|
12
|
+
response = described_class.decode(1, buffer, buffer.length)
|
13
13
|
response.should_not be_void
|
14
14
|
response.keyspace.should == 'system'
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'decodes a schema_change CREATED result' do
|
18
|
-
buffer =
|
19
|
-
response = described_class.decode
|
18
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x05\x00\aCREATED\x00\ncql_rb_477\x00\x00")
|
19
|
+
response = described_class.decode(1, buffer, buffer.length)
|
20
20
|
response.should_not be_void
|
21
21
|
response.change.should == 'CREATED'
|
22
22
|
response.keyspace.should == 'cql_rb_477'
|
@@ -24,8 +24,8 @@ module Cql
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'decodes a schema_change UPDATED result' do
|
27
|
-
buffer =
|
28
|
-
response = described_class.decode
|
27
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x05\x00\aUPDATED\x00\ncql_rb_973\x00\x05users")
|
28
|
+
response = described_class.decode(1, buffer, buffer.length)
|
29
29
|
response.should_not be_void
|
30
30
|
response.change.should == 'UPDATED'
|
31
31
|
response.keyspace.should == 'cql_rb_973'
|
@@ -33,35 +33,35 @@ module Cql
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'decodes a void result' do
|
36
|
-
buffer =
|
37
|
-
response = described_class.decode
|
36
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x01")
|
37
|
+
response = described_class.decode(1, buffer, buffer.length)
|
38
38
|
response.should be_void
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'decodes a rows result' do
|
42
|
-
buffer =
|
43
|
-
response = described_class.decode
|
42
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\ncql_rb_126\x00\x05users\x00\tuser_name\x00\r\x00\x05email\x00\r\x00\bpassword\x00\r\x00\x00\x00\x02\x00\x00\x00\x04phil\x00\x00\x00\rphil@heck.com\xFF\xFF\xFF\xFF\x00\x00\x00\x03sue\x00\x00\x00\rsue@inter.net\xFF\xFF\xFF\xFF")
|
43
|
+
response = described_class.decode(1, buffer, buffer.length)
|
44
44
|
response.should_not be_void
|
45
45
|
response.rows.size.should == 2
|
46
46
|
response.metadata.size.should == 3
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'decodes a rows result' do
|
50
|
-
buffer =
|
51
|
-
response = described_class.decode
|
50
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x03\x00\x05email\x00\r\x00\bpassword\x00\r\x00\x00\x00\x02\x00\x00\x00\x04phil\x00\x00\x00\rphil@heck.com\xFF\xFF\xFF\xFF\x00\x00\x00\x03sue\x00\x00\x00\rsue@inter.net\xFF\xFF\xFF\xFF")
|
51
|
+
response = described_class.decode(1, buffer, buffer.length)
|
52
52
|
response.should_not be_void
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'decodes a prepared result' do
|
56
|
-
buffer =
|
57
|
-
response = described_class.decode
|
56
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x04\x00\x10\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/\x00\x00\x00\x01\x00\x00\x00\x01\x00\ncql_rb_911\x00\x05users\x00\tuser_name\x00\r")
|
57
|
+
response = described_class.decode(1, buffer, buffer.length)
|
58
58
|
response.should_not be_void
|
59
59
|
response.id.should == "\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/"
|
60
60
|
response.metadata.size.should == 1
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'complains when asked to decode an unknown result type' do
|
64
|
-
expect { described_class.decode
|
64
|
+
expect { described_class.decode(1, CqlByteBuffer.new("\x00\x00\x00\xffhello"), 9) }.to raise_error(UnsupportedResultKindError)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -6,11 +6,11 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe RowsResultResponse do
|
9
|
-
describe '.decode
|
9
|
+
describe '.decode' do
|
10
10
|
context 'with rows from the same table' do
|
11
11
|
let :response do
|
12
|
-
buffer =
|
13
|
-
described_class.decode
|
12
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x01\x00\x00\x00\x03\x00\ncql_rb_126\x00\x05users\x00\tuser_name\x00\r\x00\x05email\x00\r\x00\bpassword\x00\r\x00\x00\x00\x02\x00\x00\x00\x04phil\x00\x00\x00\rphil@heck.com\xFF\xFF\xFF\xFF\x00\x00\x00\x03sue\x00\x00\x00\rsue@inter.net\xFF\xFF\xFF\xFF")
|
13
|
+
described_class.decode(1, buffer, buffer.length)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'decodes the rows as hashes of column name => column value' do
|
@@ -37,14 +37,14 @@ module Cql
|
|
37
37
|
let :response do
|
38
38
|
# TODO: not sure if this is really how it would be for real
|
39
39
|
# this frame was constructed from the spec not from an actual result
|
40
|
-
buffer =
|
40
|
+
buffer = CqlByteBuffer.new
|
41
41
|
buffer << "\x00\x00\x00\x00"
|
42
42
|
buffer << "\x00\x00\x00\x03"
|
43
43
|
buffer << "\x00\ncql_rb_126\x00\x06users1\x00\tuser_name\x00\r"
|
44
44
|
buffer << "\x00\ncql_rb_127\x00\x06users2\x00\x05email\x00\r"
|
45
45
|
buffer << "\x00\ncql_rb_128\x00\x06users3\x00\bpassword\x00\r"
|
46
46
|
buffer << "\x00\x00\x00\x02\x00\x00\x00\x04phil\x00\x00\x00\rphil@heck.com\xFF\xFF\xFF\xFF\x00\x00\x00\x03sue\x00\x00\x00\rsue@inter.net\xFF\xFF\xFF\xFF"
|
47
|
-
described_class.decode
|
47
|
+
described_class.decode(1, buffer, buffer.length)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'decodes the rows' do
|
@@ -65,11 +65,11 @@ module Cql
|
|
65
65
|
|
66
66
|
context 'when there is no metadata' do
|
67
67
|
let :response do
|
68
|
-
buffer =
|
68
|
+
buffer = CqlByteBuffer.new
|
69
69
|
buffer << "\x00\x00\x00\x05" # flags (global_tables_spec | no_metadata)
|
70
70
|
buffer << "\x00\x00\x00\x03" # column count
|
71
71
|
buffer << "\x00\x00\x00\x02\x00\x00\x00\x04phil\x00\x00\x00\rphil@heck.com\xFF\xFF\xFF\xFF\x00\x00\x00\x03sue\x00\x00\x00\rsue@inter.net\xFF\xFF\xFF\xFF"
|
72
|
-
described_class.decode
|
72
|
+
described_class.decode(2, buffer, buffer.length)
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'returns a RawRowsResultResponse' do
|
@@ -88,14 +88,14 @@ module Cql
|
|
88
88
|
|
89
89
|
context 'when there are more pages' do
|
90
90
|
let :response do
|
91
|
-
buffer =
|
91
|
+
buffer = CqlByteBuffer.new
|
92
92
|
buffer << "\x00\x00\x00\x03" # flags (global_tables_spec | has_more_pages)
|
93
93
|
buffer << "\x00\x00\x00\x03" # column count
|
94
94
|
buffer << "\x00\x00\x00\x03foo" # paging state
|
95
95
|
buffer << "\x00\ncql_rb_126\x00\x05users"
|
96
96
|
buffer << "\x00\tuser_name\x00\r\x00\x05email\x00\r\x00\bpassword\x00\r"
|
97
97
|
buffer << "\x00\x00\x00\x02\x00\x00\x00\x04phil\x00\x00\x00\rphil@heck.com\xFF\xFF\xFF\xFF\x00\x00\x00\x03sue\x00\x00\x00\rsue@inter.net\xFF\xFF\xFF\xFF"
|
98
|
-
described_class.decode
|
98
|
+
described_class.decode(2, buffer, buffer.length)
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'extracts the paging state' do
|
@@ -154,8 +154,8 @@ module Cql
|
|
154
154
|
# );
|
155
155
|
#
|
156
156
|
# SELECT * FROM lots_of_types WHERE ascii_column = 'hello';
|
157
|
-
buffer =
|
158
|
-
described_class.decode
|
157
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x01\x00\x00\x00\x12\x00\x04test\x00\rlots_of_types\x00\fascii_column\x00\x01\x00\rbigint_column\x00\x02\x00\vblob_column\x00\x03\x00\x0Eboolean_column\x00\x04\x00\x0Edecimal_column\x00\x06\x00\rdouble_column\x00\a\x00\ffloat_column\x00\b\x00\vinet_column\x00\x10\x00\nint_column\x00\t\x00\vlist_column\x00 \x00\x01\x00\nmap_column\x00!\x00\r\x00\x04\x00\nset_column\x00\"\x00\x03\x00\vtext_column\x00\r\x00\x10timestamp_column\x00\v\x00\x0Ftimeuuid_column\x00\x0F\x00\vuuid_column\x00\f\x00\x0Evarchar_column\x00\r\x00\rvarint_column\x00\x0E\x00\x00\x00\x01\x00\x00\x00\x05hello\x00\x00\x00\b\x00\x03\x98\xB1S\xC8\x7F\xAB\x00\x00\x00\x05\xFA\xB4^4V\x00\x00\x00\x01\x01\x00\x00\x00\x11\x00\x00\x00\x12\r'\xFDI\xAD\x80f\x11g\xDCfV\xAA\x00\x00\x00\b@\xC3\x88\x0F\xC2\x7F\x9DU\x00\x00\x00\x04AB\x14{\x00\x00\x00\x04\n\x00\x01\x02\x00\x00\x00\x04\x00\xBCj\xC2\x00\x00\x00\x11\x00\x03\x00\x03foo\x00\x03foo\x00\x03bar\x00\x00\x00\x14\x00\x02\x00\x03foo\x00\x01\x01\x00\x05hello\x00\x01\x00\x00\x00\x00\r\x00\x02\x00\x03\xABC!\x00\x04\xAF\xD8~\xCD\x00\x00\x00\vhello world\x00\x00\x00\b\x00\x00\x01</\xE9\xDC\xE3\x00\x00\x00\x10\xA4\xA7\t\x00$\xE1\x11\xDF\x89$\x00\x1F\xF3Y\x17\x11\x00\x00\x00\x10\xCF\xD6l\xCC\xD8WN\x90\xB1\xE5\xDF\x98\xA3\xD4\f\xD6\x00\x00\x00\x03foo\x00\x00\x00\x11\x03\x9EV \x15\f\x03\x9DK\x18\xCDI\\$?\a[")
|
158
|
+
described_class.decode(1, buffer, buffer.length)
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'decodes ASCII as an ASCII encoded string' do
|
@@ -237,8 +237,8 @@ module Cql
|
|
237
237
|
|
238
238
|
context 'with null values' do
|
239
239
|
it 'decodes nulls' do
|
240
|
-
buffer =
|
241
|
-
response = described_class.decode
|
240
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x01\x00\x00\x00\x13\x00\x12cql_rb_client_spec\x00\rlots_of_types\x00\x02id\x00\t\x00\fascii_column\x00\x01\x00\rbigint_column\x00\x02\x00\vblob_column\x00\x03\x00\x0Eboolean_column\x00\x04\x00\x0Edecimal_column\x00\x06\x00\rdouble_column\x00\a\x00\ffloat_column\x00\b\x00\vinet_column\x00\x10\x00\nint_column\x00\t\x00\vlist_column\x00 \x00\x01\x00\nmap_column\x00!\x00\r\x00\x04\x00\nset_column\x00\"\x00\x03\x00\vtext_column\x00\r\x00\x10timestamp_column\x00\v\x00\x0Ftimeuuid_column\x00\x0F\x00\vuuid_column\x00\f\x00\x0Evarchar_column\x00\r\x00\rvarint_column\x00\x0E\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x03\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF")
|
241
|
+
response = described_class.decode(1, buffer, buffer.length)
|
242
242
|
response.rows.first.should eql(
|
243
243
|
'id' => 3,
|
244
244
|
'ascii_column' => nil,
|
@@ -265,22 +265,22 @@ module Cql
|
|
265
265
|
|
266
266
|
context 'with COUNTER columns' do
|
267
267
|
it 'decodes COUNTER as a number' do
|
268
|
-
buffer =
|
269
|
-
response = described_class.decode
|
268
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x01\x00\x00\x00\x03\x00\x04test\x00\x04cnts\x00\x02id\x00\r\x00\x02c1\x00\x05\x00\x02c2\x00\x05\x00\x00\x00\x01\x00\x00\x00\x04theo\x00\x00\x00\b\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\b\x00\x00\x00\x00\x00\x00\x00\x01")
|
269
|
+
response = described_class.decode(1, buffer, buffer.length)
|
270
270
|
response.rows.first['c1'].should == 3
|
271
271
|
end
|
272
272
|
|
273
273
|
it 'decodes a null COUNTER as nil' do
|
274
|
-
buffer =
|
275
|
-
response = described_class.decode
|
274
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x01\x00\x00\x00\x02\x00\x12cql_rb_client_spec\x00\bcounters\x00\bcounter1\x00\x05\x00\bcounter2\x00\x05\x00\x00\x00\x01\x00\x00\x00\b\x00\x00\x00\x00\x00\x00\x00\x01\xFF\xFF\xFF\xFF")
|
275
|
+
response = described_class.decode(1, buffer, buffer.length)
|
276
276
|
response.rows.first['counter2'].should be_nil
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
280
280
|
context 'with an INET column' do
|
281
281
|
let :response do
|
282
|
-
buffer =
|
283
|
-
described_class.decode
|
282
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x01\x00\x00\x00\x01\x00\ntest_types\x00\rlots_of_types\x00\vinet_column\x00\x10\x00\x00\x00\x02\x00\x00\x00\x04\x7F\x00\x00\x01\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01")
|
283
|
+
described_class.decode(1, buffer, buffer.length)
|
284
284
|
end
|
285
285
|
|
286
286
|
it 'decodes IPv4 values' do
|
@@ -294,8 +294,8 @@ module Cql
|
|
294
294
|
|
295
295
|
context 'with an unknown column type' do
|
296
296
|
it 'raises an error when encountering an unknown column type' do
|
297
|
-
buffer =
|
298
|
-
expect { described_class.decode
|
297
|
+
buffer = CqlByteBuffer.new("\x00\x00\x00\x01\x00\x00\x00\x03\x00\ncql_rb_328\x00\x05users\x00\tuser_name\x00\xff\x00\x05email\x00\r\x00\bpassword\x00\r\x00\x00\x00\x00")
|
298
|
+
expect { described_class.decode(1, buffer, buffer.length) }.to raise_error(UnsupportedColumnTypeError)
|
299
299
|
end
|
300
300
|
end
|
301
301
|
end
|