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
@@ -15,16 +15,16 @@ module Cql
|
|
15
15
|
@cql = cql
|
16
16
|
@values = values || EMPTY_LIST
|
17
17
|
@type_hints = type_hints || EMPTY_LIST
|
18
|
-
@encoded_values = self.class.encode_values(
|
18
|
+
@encoded_values = self.class.encode_values(CqlByteBuffer.new, @values, @type_hints)
|
19
19
|
@consistency = consistency
|
20
20
|
@serial_consistency = serial_consistency
|
21
21
|
@page_size = page_size
|
22
22
|
@paging_state = paging_state
|
23
23
|
end
|
24
24
|
|
25
|
-
def write(protocol_version,
|
26
|
-
|
27
|
-
|
25
|
+
def write(protocol_version, buffer)
|
26
|
+
buffer.append_long_string(@cql)
|
27
|
+
buffer.append_consistency(@consistency)
|
28
28
|
if protocol_version > 1
|
29
29
|
flags = 0
|
30
30
|
flags |= 0x04 if @page_size
|
@@ -32,16 +32,16 @@ module Cql
|
|
32
32
|
flags |= 0x10 if @serial_consistency
|
33
33
|
if @values && @values.size > 0
|
34
34
|
flags |= 0x01
|
35
|
-
|
36
|
-
|
35
|
+
buffer.append(flags.chr)
|
36
|
+
buffer.append(@encoded_values)
|
37
37
|
else
|
38
|
-
|
38
|
+
buffer.append(flags.chr)
|
39
39
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
buffer.append_int(@page_size) if @page_size
|
41
|
+
buffer.append_bytes(@paging_state) if @paging_state
|
42
|
+
buffer.append_consistency(@serial_consistency) if @serial_consistency
|
43
43
|
end
|
44
|
-
|
44
|
+
buffer
|
45
45
|
end
|
46
46
|
|
47
47
|
def to_s
|
@@ -74,7 +74,7 @@ module Cql
|
|
74
74
|
|
75
75
|
def self.encode_values(buffer, values, hints)
|
76
76
|
if values && values.size > 0
|
77
|
-
|
77
|
+
buffer.append_short(values.size)
|
78
78
|
values.each_with_index do |value, index|
|
79
79
|
type = (hints && hints[index]) || guess_type(value)
|
80
80
|
raise EncodingError, "Could not guess a suitable type for #{value.inspect}" unless type
|
@@ -82,7 +82,7 @@ module Cql
|
|
82
82
|
end
|
83
83
|
buffer
|
84
84
|
else
|
85
|
-
|
85
|
+
buffer.append_short(0)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -3,12 +3,10 @@
|
|
3
3
|
module Cql
|
4
4
|
module Protocol
|
5
5
|
class Response
|
6
|
-
|
7
|
-
|
8
|
-
def self.decode!(opcode, protocol_version, buffer, length, trace_id)
|
6
|
+
def self.decode(opcode, protocol_version, buffer, length, trace_id)
|
9
7
|
response_class = RESPONSE_TYPES[opcode]
|
10
8
|
if response_class
|
11
|
-
response_class.decode
|
9
|
+
response_class.decode(protocol_version, buffer, length, trace_id)
|
12
10
|
else
|
13
11
|
raise UnsupportedOperationError, "The operation #{opcode} is not supported"
|
14
12
|
end
|
@@ -5,8 +5,8 @@ module Cql
|
|
5
5
|
class AuthChallengeResponse < Response
|
6
6
|
attr_reader :token
|
7
7
|
|
8
|
-
def self.decode
|
9
|
-
new(read_bytes
|
8
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
9
|
+
new(buffer.read_bytes)
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize(token)
|
@@ -5,8 +5,8 @@ module Cql
|
|
5
5
|
class AuthSuccessResponse < Response
|
6
6
|
attr_reader :token
|
7
7
|
|
8
|
-
def self.decode
|
9
|
-
new(read_bytes
|
8
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
9
|
+
new(buffer.read_bytes)
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize(token)
|
@@ -5,8 +5,8 @@ module Cql
|
|
5
5
|
class AuthenticateResponse < Response
|
6
6
|
attr_reader :authentication_class
|
7
7
|
|
8
|
-
def self.decode
|
9
|
-
new(read_string
|
8
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
9
|
+
new(buffer.read_string)
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize(authentication_class)
|
@@ -10,28 +10,28 @@ module Cql
|
|
10
10
|
@details = details
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.decode
|
13
|
+
def self.decode(code, message, protocol_version, buffer, length, trace_id=nil)
|
14
14
|
details = {}
|
15
15
|
case code
|
16
16
|
when 0x1000 # unavailable
|
17
|
-
details[:cl] = read_consistency
|
18
|
-
details[:required] = read_int
|
19
|
-
details[:alive] = read_int
|
17
|
+
details[:cl] = buffer.read_consistency
|
18
|
+
details[:required] = buffer.read_int
|
19
|
+
details[:alive] = buffer.read_int
|
20
20
|
when 0x1100 # write_timeout
|
21
|
-
details[:cl] = read_consistency
|
22
|
-
details[:received] = read_int
|
23
|
-
details[:blockfor] = read_int
|
24
|
-
details[:write_type] = read_string
|
21
|
+
details[:cl] = buffer.read_consistency
|
22
|
+
details[:received] = buffer.read_int
|
23
|
+
details[:blockfor] = buffer.read_int
|
24
|
+
details[:write_type] = buffer.read_string
|
25
25
|
when 0x1200 # read_timeout
|
26
|
-
details[:cl] = read_consistency
|
27
|
-
details[:received] = read_int
|
28
|
-
details[:blockfor] = read_int
|
29
|
-
details[:data_present] = read_byte
|
26
|
+
details[:cl] = buffer.read_consistency
|
27
|
+
details[:received] = buffer.read_int
|
28
|
+
details[:blockfor] = buffer.read_int
|
29
|
+
details[:data_present] = buffer.read_byte != 0
|
30
30
|
when 0x2400 # already_exists
|
31
|
-
details[:ks] = read_string
|
32
|
-
details[:table] = read_string
|
31
|
+
details[:ks] = buffer.read_string
|
32
|
+
details[:table] = buffer.read_string
|
33
33
|
when 0x2500
|
34
|
-
details[:id] = read_short_bytes
|
34
|
+
details[:id] = buffer.read_short_bytes
|
35
35
|
end
|
36
36
|
new(code, message, details)
|
37
37
|
end
|
@@ -9,13 +9,13 @@ module Cql
|
|
9
9
|
@code, @message = args
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.decode
|
13
|
-
code = read_int
|
14
|
-
message = read_string
|
12
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
13
|
+
code = buffer.read_int
|
14
|
+
message = buffer.read_string
|
15
15
|
case code
|
16
16
|
when 0x1000, 0x1100, 0x1200, 0x2400, 0x2500
|
17
17
|
new_length = length - 4 - 4 - message.bytesize
|
18
|
-
DetailedErrorResponse.decode
|
18
|
+
DetailedErrorResponse.decode(code, message, protocol_version, buffer, new_length)
|
19
19
|
else
|
20
20
|
new(code, message)
|
21
21
|
end
|
@@ -3,12 +3,12 @@
|
|
3
3
|
module Cql
|
4
4
|
module Protocol
|
5
5
|
class EventResponse < ResultResponse
|
6
|
-
def self.decode
|
7
|
-
type = read_string
|
6
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
7
|
+
type = buffer.read_string
|
8
8
|
impl = EVENT_TYPES[type]
|
9
9
|
raise UnsupportedEventTypeError, %(Unsupported event type: "#{type}") unless impl
|
10
10
|
new_length = length - 4 - type.bytesize
|
11
|
-
impl.decode
|
11
|
+
impl.decode(protocol_version, buffer, new_length, trace_id)
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
@@ -10,12 +10,12 @@ module Cql
|
|
10
10
|
@id, @metadata, @result_metadata = id, metadata, result_metadata
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.decode
|
14
|
-
id = read_short_bytes
|
15
|
-
metadata, _ = RowsResultResponse.read_metadata
|
13
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
14
|
+
id = buffer.read_short_bytes
|
15
|
+
metadata, _ = RowsResultResponse.read_metadata(protocol_version, buffer)
|
16
16
|
result_metadata = nil
|
17
17
|
if protocol_version > 1
|
18
|
-
result_metadata, _, _ = RowsResultResponse.read_metadata
|
18
|
+
result_metadata, _, _ = RowsResultResponse.read_metadata(protocol_version, buffer)
|
19
19
|
end
|
20
20
|
new(id, metadata, result_metadata, trace_id)
|
21
21
|
end
|
@@ -9,11 +9,11 @@ module Cql
|
|
9
9
|
@trace_id = trace_id
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.decode
|
13
|
-
kind = read_int
|
12
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
13
|
+
kind = buffer.read_int
|
14
14
|
impl = RESULT_TYPES[kind]
|
15
15
|
raise UnsupportedResultKindError, %(Unsupported result kind: #{kind}) unless impl
|
16
|
-
impl.decode
|
16
|
+
impl.decode(protocol_version, buffer, length - 4, trace_id)
|
17
17
|
end
|
18
18
|
|
19
19
|
def void?
|
@@ -10,15 +10,15 @@ module Cql
|
|
10
10
|
@rows, @metadata, @paging_state = rows, metadata, paging_state
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.decode
|
13
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
14
14
|
original_buffer_length = buffer.length
|
15
|
-
column_specs, columns_count, paging_state = read_metadata
|
15
|
+
column_specs, columns_count, paging_state = read_metadata(protocol_version, buffer)
|
16
16
|
if column_specs.nil?
|
17
17
|
consumed_bytes = original_buffer_length - buffer.length
|
18
|
-
remaining_bytes =
|
18
|
+
remaining_bytes = CqlByteBuffer.new(buffer.read(length - consumed_bytes))
|
19
19
|
RawRowsResultResponse.new(protocol_version, remaining_bytes, paging_state, trace_id)
|
20
20
|
else
|
21
|
-
new(read_rows
|
21
|
+
new(read_rows(protocol_version, buffer, column_specs), column_specs, paging_state, trace_id)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -56,19 +56,19 @@ module Cql
|
|
56
56
|
HAS_MORE_PAGES_FLAG = 0x02
|
57
57
|
NO_METADATA_FLAG = 0x04
|
58
58
|
|
59
|
-
def self.read_column_type
|
60
|
-
id, type = read_option
|
59
|
+
def self.read_column_type(buffer)
|
60
|
+
id, type = buffer.read_option do |id, b|
|
61
61
|
if id > 0 && id <= 0x10
|
62
62
|
COLUMN_TYPES[id]
|
63
63
|
elsif id == 0x20
|
64
|
-
sub_type = read_column_type
|
64
|
+
sub_type = read_column_type(buffer)
|
65
65
|
[:list, sub_type]
|
66
66
|
elsif id == 0x21
|
67
|
-
key_type = read_column_type
|
68
|
-
value_type = read_column_type
|
67
|
+
key_type = read_column_type(buffer)
|
68
|
+
value_type = read_column_type(buffer)
|
69
69
|
[:map, key_type, value_type]
|
70
70
|
elsif id == 0x22
|
71
|
-
sub_type = read_column_type
|
71
|
+
sub_type = read_column_type(buffer)
|
72
72
|
[:set, sub_type]
|
73
73
|
else
|
74
74
|
raise UnsupportedColumnTypeError, %(Unsupported column type: #{id})
|
@@ -77,37 +77,37 @@ module Cql
|
|
77
77
|
type
|
78
78
|
end
|
79
79
|
|
80
|
-
def self.read_metadata
|
81
|
-
flags = read_int
|
82
|
-
columns_count = read_int
|
80
|
+
def self.read_metadata(protocol_version, buffer)
|
81
|
+
flags = buffer.read_int
|
82
|
+
columns_count = buffer.read_int
|
83
83
|
paging_state = nil
|
84
84
|
column_specs = nil
|
85
85
|
if flags & HAS_MORE_PAGES_FLAG != 0
|
86
|
-
paging_state = read_bytes
|
86
|
+
paging_state = buffer.read_bytes
|
87
87
|
end
|
88
88
|
if flags & NO_METADATA_FLAG == 0
|
89
89
|
if flags & GLOBAL_TABLES_SPEC_FLAG != 0
|
90
|
-
global_keyspace_name = read_string
|
91
|
-
global_table_name = read_string
|
90
|
+
global_keyspace_name = buffer.read_string
|
91
|
+
global_table_name = buffer.read_string
|
92
92
|
end
|
93
93
|
column_specs = columns_count.times.map do
|
94
94
|
if global_keyspace_name
|
95
95
|
keyspace_name = global_keyspace_name
|
96
96
|
table_name = global_table_name
|
97
97
|
else
|
98
|
-
keyspace_name = read_string
|
99
|
-
table_name = read_string
|
98
|
+
keyspace_name = buffer.read_string
|
99
|
+
table_name = buffer.read_string
|
100
100
|
end
|
101
|
-
column_name = read_string
|
102
|
-
type = read_column_type
|
101
|
+
column_name = buffer.read_string
|
102
|
+
type = read_column_type(buffer)
|
103
103
|
[keyspace_name, table_name, column_name, type]
|
104
104
|
end
|
105
105
|
end
|
106
106
|
[column_specs, columns_count, paging_state]
|
107
107
|
end
|
108
108
|
|
109
|
-
def self.read_rows
|
110
|
-
rows_count = read_int
|
109
|
+
def self.read_rows(protocol_version, buffer, column_specs)
|
110
|
+
rows_count = buffer.read_int
|
111
111
|
rows = []
|
112
112
|
rows_count.times do |row_index|
|
113
113
|
row = {}
|
@@ -12,8 +12,8 @@ module Cql
|
|
12
12
|
@type = TYPE
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.decode
|
16
|
-
new(read_string
|
15
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
16
|
+
new(buffer.read_string, buffer.read_string, buffer.read_string)
|
17
17
|
end
|
18
18
|
|
19
19
|
def eql?(rs)
|
@@ -10,8 +10,8 @@ module Cql
|
|
10
10
|
@change, @keyspace, @table = change, keyspace, table
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.decode
|
14
|
-
new(read_string
|
13
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
14
|
+
new(buffer.read_string, buffer.read_string, buffer.read_string, trace_id)
|
15
15
|
end
|
16
16
|
|
17
17
|
def eql?(other)
|
@@ -10,8 +10,8 @@ module Cql
|
|
10
10
|
@keyspace = keyspace
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.decode
|
14
|
-
new(read_string
|
13
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
14
|
+
new(buffer.read_string, trace_id)
|
15
15
|
end
|
16
16
|
|
17
17
|
def to_s
|
@@ -12,8 +12,8 @@ module Cql
|
|
12
12
|
@type = TYPE
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.decode
|
16
|
-
new(read_string
|
15
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
16
|
+
new(buffer.read_string, *buffer.read_inet)
|
17
17
|
end
|
18
18
|
|
19
19
|
def to_s
|
@@ -9,8 +9,8 @@ module Cql
|
|
9
9
|
@options = options
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.decode
|
13
|
-
new(read_string_multimap
|
12
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
13
|
+
new(buffer.read_string_multimap)
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_s
|