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.
- checksums.yaml +4 -4
- data/README.md +19 -11
- data/lib/cql.rb +1 -0
- data/lib/cql/client.rb +41 -9
- data/lib/cql/client/asynchronous_client.rb +9 -4
- data/lib/cql/client/asynchronous_prepared_statement.rb +2 -2
- data/lib/cql/client/connection_helper.rb +43 -20
- data/lib/cql/client/execute_options_decoder.rb +4 -1
- data/lib/cql/client/query_result.rb +7 -3
- data/lib/cql/client/query_trace.rb +46 -0
- data/lib/cql/client/request_runner.rb +7 -2
- data/lib/cql/client/void_result.rb +42 -0
- data/lib/cql/compression.rb +53 -0
- data/lib/cql/compression/snappy_compressor.rb +42 -0
- data/lib/cql/io/io_reactor.rb +9 -4
- data/lib/cql/protocol.rb +5 -3
- data/lib/cql/protocol/cql_protocol_handler.rb +14 -9
- data/lib/cql/protocol/frame_decoder.rb +106 -0
- data/lib/cql/protocol/frame_encoder.rb +31 -0
- data/lib/cql/protocol/request.rb +7 -11
- data/lib/cql/protocol/requests/execute_request.rb +2 -2
- data/lib/cql/protocol/requests/options_request.rb +4 -0
- data/lib/cql/protocol/requests/prepare_request.rb +2 -2
- data/lib/cql/protocol/requests/query_request.rb +2 -2
- data/lib/cql/protocol/requests/startup_request.rb +12 -5
- data/lib/cql/protocol/response.rb +13 -2
- data/lib/cql/protocol/responses/authenticate_response.rb +5 -1
- data/lib/cql/protocol/responses/detailed_error_response.rb +2 -2
- data/lib/cql/protocol/responses/error_response.rb +7 -2
- data/lib/cql/protocol/responses/event_response.rb +4 -2
- data/lib/cql/protocol/responses/prepared_result_response.rb +20 -4
- data/lib/cql/protocol/responses/ready_response.rb +5 -1
- data/lib/cql/protocol/responses/result_response.rb +10 -2
- data/lib/cql/protocol/responses/rows_result_response.rb +5 -4
- data/lib/cql/protocol/responses/schema_change_event_response.rb +1 -1
- data/lib/cql/protocol/responses/schema_change_result_response.rb +5 -4
- data/lib/cql/protocol/responses/set_keyspace_result_response.rb +4 -3
- data/lib/cql/protocol/responses/{status_change_event_result_response.rb → status_change_event_response.rb} +1 -1
- data/lib/cql/protocol/responses/supported_response.rb +5 -1
- data/lib/cql/protocol/responses/{topology_change_event_result_response.rb → topology_change_event_response.rb} +0 -0
- data/lib/cql/protocol/responses/void_result_response.rb +2 -2
- data/lib/cql/version.rb +1 -1
- data/spec/cql/client/asynchronous_client_spec.rb +52 -31
- data/spec/cql/client/asynchronous_prepared_statement_spec.rb +16 -2
- data/spec/cql/client/connection_helper_spec.rb +90 -12
- data/spec/cql/client/query_trace_spec.rb +138 -0
- data/spec/cql/client/request_runner_spec.rb +44 -7
- data/spec/cql/client/void_result_spec.rb +43 -0
- data/spec/cql/compression/compression_common.rb +59 -0
- data/spec/cql/compression/snappy_compressor_spec.rb +23 -0
- data/spec/cql/io/io_reactor_spec.rb +8 -1
- data/spec/cql/protocol/cql_protocol_handler_spec.rb +40 -0
- data/spec/cql/protocol/frame_decoder_spec.rb +132 -0
- data/spec/cql/protocol/frame_encoder_spec.rb +105 -0
- data/spec/cql/protocol/requests/credentials_request_spec.rb +2 -4
- data/spec/cql/protocol/requests/execute_request_spec.rb +5 -5
- data/spec/cql/protocol/requests/options_request_spec.rb +10 -4
- data/spec/cql/protocol/requests/prepare_request_spec.rb +3 -3
- data/spec/cql/protocol/requests/query_request_spec.rb +10 -5
- data/spec/cql/protocol/requests/register_request_spec.rb +3 -3
- data/spec/cql/protocol/requests/startup_request_spec.rb +11 -5
- data/spec/cql/protocol/responses/authenticate_response_spec.rb +27 -0
- data/spec/cql/protocol/responses/detailed_error_response_spec.rb +78 -0
- data/spec/cql/protocol/responses/error_response_spec.rb +36 -0
- data/spec/cql/protocol/responses/event_response_spec.rb +40 -0
- data/spec/cql/protocol/responses/prepared_result_response_spec.rb +108 -0
- data/spec/cql/protocol/responses/ready_response_spec.rb +39 -0
- data/spec/cql/protocol/responses/result_response_spec.rb +57 -0
- data/spec/cql/protocol/responses/rows_result_response_spec.rb +273 -0
- data/spec/cql/protocol/responses/schema_change_event_response_spec.rb +93 -0
- data/spec/cql/protocol/responses/schema_change_result_response_spec.rb +51 -19
- data/spec/cql/protocol/responses/set_keyspace_result_response_spec.rb +34 -0
- data/spec/cql/protocol/responses/status_change_event_response_spec.rb +35 -0
- data/spec/cql/protocol/responses/supported_response_spec.rb +27 -0
- data/spec/cql/protocol/responses/topology_change_event_response_spec.rb +35 -0
- data/spec/cql/protocol/responses/void_result_response_spec.rb +29 -0
- data/spec/integration/client_spec.rb +45 -0
- data/spec/integration/protocol_spec.rb +46 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/support/fake_io_reactor.rb +1 -1
- metadata +51 -10
- data/lib/cql/protocol/response_frame.rb +0 -129
- data/spec/cql/protocol/request_spec.rb +0 -45
- data/spec/cql/protocol/response_frame_spec.rb +0 -811
@@ -12,10 +12,10 @@ module Cql
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe '#
|
15
|
+
describe '#write' do
|
16
16
|
it 'encodes a PREPARE request frame' do
|
17
|
-
bytes = PrepareRequest.new('UPDATE users SET email = ? WHERE user_name = ?').
|
18
|
-
bytes.should == "\
|
17
|
+
bytes = PrepareRequest.new('UPDATE users SET email = ? WHERE user_name = ?').write('')
|
18
|
+
bytes.should == "\x00\x00\x00\x2eUPDATE users SET email = ? WHERE user_name = ?"
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -20,15 +20,20 @@ module Cql
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe '#
|
23
|
+
describe '#write' do
|
24
24
|
it 'encodes a QUERY request frame' do
|
25
|
-
bytes = QueryRequest.new('USE system', :all).
|
26
|
-
bytes.should == "\
|
25
|
+
bytes = QueryRequest.new('USE system', :all).write('')
|
26
|
+
bytes.should == "\x00\x00\x00\x0aUSE system\x00\x05"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'encodes a QUERY request frame with tracing' do
|
30
|
+
bytes = QueryRequest.new('USE system', :all, true).write('')
|
31
|
+
bytes.should == "\x00\x00\x00\x0aUSE system\x00\x05"
|
27
32
|
end
|
28
33
|
|
29
34
|
it 'correctly encodes queries with multibyte characters' do
|
30
|
-
bytes = QueryRequest.new("INSERT INTO users (user_id, first, last, age) VALUES ('test', 'ümlaut', 'test', 1)", :all).
|
31
|
-
bytes.should eql_bytes("\
|
35
|
+
bytes = QueryRequest.new("INSERT INTO users (user_id, first, last, age) VALUES ('test', 'ümlaut', 'test', 1)", :all).write('')
|
36
|
+
bytes.should eql_bytes("\x00\x00\x00SINSERT INTO users (user_id, first, last, age) VALUES ('test', '\xC3\xBCmlaut', 'test', 1)\x00\x05")
|
32
37
|
end
|
33
38
|
end
|
34
39
|
|
@@ -6,10 +6,10 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe RegisterRequest do
|
9
|
-
describe '#
|
9
|
+
describe '#write' do
|
10
10
|
it 'encodes a REGISTER request frame' do
|
11
|
-
bytes = RegisterRequest.new('TOPOLOGY_CHANGE', 'STATUS_CHANGE').
|
12
|
-
bytes.should == "\
|
11
|
+
bytes = RegisterRequest.new('TOPOLOGY_CHANGE', 'STATUS_CHANGE').write('')
|
12
|
+
bytes.should == "\x00\x02\x00\x0fTOPOLOGY_CHANGE\x00\x0dSTATUS_CHANGE"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -6,15 +6,21 @@ require 'spec_helper'
|
|
6
6
|
module Cql
|
7
7
|
module Protocol
|
8
8
|
describe StartupRequest do
|
9
|
-
describe '#
|
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
|
10
16
|
it 'encodes a STARTUP request frame' do
|
11
|
-
bytes = StartupRequest.new('3.0.0', 'snappy').
|
12
|
-
bytes.should == "\
|
17
|
+
bytes = StartupRequest.new('3.0.0', 'snappy').write('')
|
18
|
+
bytes.should == "\x00\x02\x00\x0bCQL_VERSION\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x06snappy"
|
13
19
|
end
|
14
20
|
|
15
21
|
it 'defaults to CQL 3.0.0 and no compression' do
|
16
|
-
bytes = StartupRequest.new.
|
17
|
-
bytes.should == "\
|
22
|
+
bytes = StartupRequest.new.write('')
|
23
|
+
bytes.should == "\x00\x01\x00\x0bCQL_VERSION\x00\x053.0.0"
|
18
24
|
end
|
19
25
|
end
|
20
26
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
|
6
|
+
module Cql
|
7
|
+
module Protocol
|
8
|
+
describe AuthenticateResponse do
|
9
|
+
describe '.decode!' do
|
10
|
+
let :response do
|
11
|
+
described_class.decode!(ByteBuffer.new("\x00\x2forg.apache.cassandra.auth.PasswordAuthenticator"))
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'decodes the authentication class' do
|
15
|
+
response.authentication_class.should == 'org.apache.cassandra.auth.PasswordAuthenticator'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#to_s' do
|
20
|
+
it 'returns a string with the authentication class' do
|
21
|
+
response = described_class.new('org.apache.cassandra.auth.PasswordAuthenticator')
|
22
|
+
response.to_s.should == 'AUTHENTICATE org.apache.cassandra.auth.PasswordAuthenticator'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
|
6
|
+
module Cql
|
7
|
+
module Protocol
|
8
|
+
describe DetailedErrorResponse do
|
9
|
+
describe '.decode!' do
|
10
|
+
it 'decodes an unavailable error' do
|
11
|
+
response = described_class.decode!(0x1000, '', ByteBuffer.new("\x00\x05\x00\x00\x00\x03\x00\x00\x00\x02"))
|
12
|
+
response.details.should == {
|
13
|
+
:cl => :all,
|
14
|
+
:required => 3,
|
15
|
+
:alive => 2
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'decodes a write_timeout error' do
|
20
|
+
response = described_class.decode!(0x1100, '', ByteBuffer.new("\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\tBATCH_LOG"))
|
21
|
+
response.details.should == {
|
22
|
+
:cl => :one,
|
23
|
+
:received => 0,
|
24
|
+
:blockfor => 1,
|
25
|
+
:write_type => 'BATCH_LOG'
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'decodes a read_timeout error' do
|
30
|
+
response = described_class.decode!(0x1200, '', ByteBuffer.new("\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x01"))
|
31
|
+
response.details.should == {
|
32
|
+
:cl => :one,
|
33
|
+
:received => 0,
|
34
|
+
:blockfor => 1,
|
35
|
+
:data_present => true
|
36
|
+
}
|
37
|
+
response = described_class.decode!(0x1200, '', ByteBuffer.new("\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00"))
|
38
|
+
response.details.should == {
|
39
|
+
:cl => :one,
|
40
|
+
:received => 0,
|
41
|
+
:blockfor => 1,
|
42
|
+
:data_present => false
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'decodes an already_exists error with a keyspace' do
|
47
|
+
response = described_class.decode!(0x2400, '', ByteBuffer.new("\x00\x05stuff\x00\x00"))
|
48
|
+
response.details.should == {
|
49
|
+
:ks => 'stuff',
|
50
|
+
:table => '',
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'decodes an already_exists error with a keyspace and table' do
|
55
|
+
response = described_class.decode!(0x2400, '', ByteBuffer.new("\x00\x05stuff\x00\x06things"))
|
56
|
+
response.details.should == {
|
57
|
+
:ks => 'stuff',
|
58
|
+
:table => 'things',
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'decodes unprepared error' do
|
63
|
+
response = described_class.decode!(0x2500, '', ByteBuffer.new("\x00\x10\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/"))
|
64
|
+
response.details.should == {
|
65
|
+
:id => "\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/"
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#to_s' do
|
71
|
+
it 'returns a string with the error code, message and details' do
|
72
|
+
response = described_class.new(0xffff, 'This is an error', {:foo => 'bar'})
|
73
|
+
response.to_s.should == 'ERROR 0xFFFF "This is an error" {:foo=>"bar"}'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
|
6
|
+
module Cql
|
7
|
+
module Protocol
|
8
|
+
describe ErrorResponse do
|
9
|
+
describe '.decode!' do
|
10
|
+
let :response do
|
11
|
+
described_class.decode!(ByteBuffer.new("\x00\x00\x00\n\x00PProvided version 4.0.0 is not supported by this server (supported: 2.0.0, 3.0.0)"))
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'decodes the error code' do
|
15
|
+
response.code.should == 10
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'decodes the error message' do
|
19
|
+
response.message.should == 'Provided version 4.0.0 is not supported by this server (supported: 2.0.0, 3.0.0)'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'decodes error frames with details' do
|
23
|
+
response = described_class.decode!(ByteBuffer.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"))
|
24
|
+
response.details.should_not be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#to_s' do
|
29
|
+
it 'returns a string with the error code and the message' do
|
30
|
+
response = described_class.new(0xffff, 'This is an error')
|
31
|
+
response.to_s.should == 'ERROR 0xFFFF "This is an error"'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
|
6
|
+
module Cql
|
7
|
+
module Protocol
|
8
|
+
describe EventResponse do
|
9
|
+
describe '.decode!' do
|
10
|
+
it 'decodes a SCHEMA_CHANGE event' do
|
11
|
+
response = described_class.decode!(ByteBuffer.new("\x00\rSCHEMA_CHANGE\x00\aDROPPED\x00\ncql_rb_609\x00\x05users"))
|
12
|
+
response.type.should == 'SCHEMA_CHANGE'
|
13
|
+
response.change.should == 'DROPPED'
|
14
|
+
response.keyspace.should == 'cql_rb_609'
|
15
|
+
response.table.should == 'users'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'decodes a STATUS_CHANGE event' do
|
19
|
+
response = described_class.decode!(ByteBuffer.new("\x00\rSTATUS_CHANGE\x00\x04DOWN\x04\x00\x00\x00\x00\x00\x00#R"))
|
20
|
+
response.type.should == 'STATUS_CHANGE'
|
21
|
+
response.change.should == 'DOWN'
|
22
|
+
response.address.should == IPAddr.new('0.0.0.0')
|
23
|
+
response.port.should == 9042
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'decodes a TOPOLOGY_CHANGE event' do
|
27
|
+
response = described_class.decode!(ByteBuffer.new("\x00\x0FTOPOLOGY_CHANGE\x00\fREMOVED_NODE\x04\x00\x00\x00\x00\x00\x00#R"))
|
28
|
+
response.type.should == 'TOPOLOGY_CHANGE'
|
29
|
+
response.change.should == 'REMOVED_NODE'
|
30
|
+
response.address.should == IPAddr.new('0.0.0.0')
|
31
|
+
response.port.should == 9042
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'complains when asked to decode an unknown event type' do
|
35
|
+
expect { described_class.decode!(ByteBuffer.new("\x00\x04PING")) }.to raise_error(UnsupportedEventTypeError, /PING/)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
|
6
|
+
module Cql
|
7
|
+
module Protocol
|
8
|
+
describe PreparedResultResponse do
|
9
|
+
describe '.decode!' do
|
10
|
+
let :response do
|
11
|
+
described_class.decode!(ByteBuffer.new("\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"))
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'decodes the ID' do
|
15
|
+
response.id.should == "\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/"
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'decodes the column metadata' do
|
19
|
+
response.metadata.should == [['cql_rb_911', 'users', 'user_name', :varchar]]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#void?' do
|
24
|
+
it 'is not void' do
|
25
|
+
response = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
26
|
+
response.should_not be_void
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#to_s' do
|
31
|
+
it 'returns a string with the ID and metadata' do
|
32
|
+
response = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
33
|
+
response.to_s.should match(/^RESULT PREPARED [0-9a-f]{32} \[\["ks", "tbl", "col", :varchar\]\]$/)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#eql?' do
|
38
|
+
it 'is equal to an identical response' do
|
39
|
+
r1 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
40
|
+
r2 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
41
|
+
r1.should eql(r2)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'is not equal when the IDs differ' do
|
45
|
+
r1 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
46
|
+
r2 = described_class.new("\x00" * 16, [['ks', 'tbl', 'col', :varchar]], nil)
|
47
|
+
r1.should_not eql(r2)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'is not equal when the metadata differ' do
|
51
|
+
r1 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
52
|
+
r2 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar], ['ks', 'tbl', 'col2', :uuid]], nil)
|
53
|
+
r1.should_not eql(r2)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'is not equal when one has a trace ID' do
|
57
|
+
r1 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], Uuid.new('00b69180-d0e1-11e2-8b8b-0800200c9a66'))
|
58
|
+
r2 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
59
|
+
r1.should_not eql(r2)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'is not equal when the trace IDs differ' do
|
63
|
+
r1 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], Uuid.new('00b69180-d0e1-11e2-8b8b-0800200c9a66'))
|
64
|
+
r2 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], Uuid.new('11111111-d0e1-11e2-8b8b-0800200c9a66'))
|
65
|
+
r1.should_not eql(r2)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'is aliased as ==' do
|
69
|
+
r1 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
70
|
+
r2 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
71
|
+
r1.should == r2
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#hash' do
|
76
|
+
it 'is the same for an identical response' do
|
77
|
+
r1 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
78
|
+
r2 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
79
|
+
r1.hash.should == r2.hash
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'is not the same when the IDs differ' do
|
83
|
+
r1 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
84
|
+
r2 = described_class.new("\x00" * 16, [['ks', 'tbl', 'col', :varchar]], nil)
|
85
|
+
r1.hash.should_not == r2.hash
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'is not the same when the metadata differ' do
|
89
|
+
r1 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
90
|
+
r2 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar], ['ks', 'tbl', 'col2', :uuid]], nil)
|
91
|
+
r1.hash.should_not == r2.hash
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'is not the same when one has a trace ID' do
|
95
|
+
r1 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], Uuid.new('00b69180-d0e1-11e2-8b8b-0800200c9a66'))
|
96
|
+
r2 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], nil)
|
97
|
+
r1.hash.should_not == r2.hash
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'is not equal when the trace IDs differ' do
|
101
|
+
r1 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], Uuid.new('00b69180-d0e1-11e2-8b8b-0800200c9a66'))
|
102
|
+
r2 = described_class.new("\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/", [['ks', 'tbl', 'col', :varchar]], Uuid.new('11111111-d0e1-11e2-8b8b-0800200c9a66'))
|
103
|
+
r1.hash.should_not == r2.hash
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
|
6
|
+
module Cql
|
7
|
+
module Protocol
|
8
|
+
describe ReadyResponse do
|
9
|
+
describe '.decode!' do
|
10
|
+
it 'returns a new instance' do
|
11
|
+
unused_byte_buffer = nil
|
12
|
+
described_class.decode!(unused_byte_buffer).should be_a(described_class)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#to_s' do
|
17
|
+
it 'returns a string' do
|
18
|
+
described_class.new.to_s.should == 'READY'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#eql?' do
|
23
|
+
it 'is equal to all other ready responses' do
|
24
|
+
described_class.new.should eql(described_class.new)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'aliased as ==' do
|
28
|
+
described_class.new.should == described_class.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#hash' do
|
33
|
+
it 'has the same hash code as all other ready responses' do
|
34
|
+
described_class.new.hash.should == described_class.new.hash
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
|
6
|
+
module Cql
|
7
|
+
module Protocol
|
8
|
+
describe ResultResponse do
|
9
|
+
describe '.decode!' do
|
10
|
+
it 'decodes a set_keyspace result' do
|
11
|
+
response = described_class.decode!(ByteBuffer.new("\x00\x00\x00\x03\x00\x06system"))
|
12
|
+
response.should_not be_void
|
13
|
+
response.keyspace.should == 'system'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'decodes a schema_change CREATED result' do
|
17
|
+
response = described_class.decode!(ByteBuffer.new("\x00\x00\x00\x05\x00\aCREATED\x00\ncql_rb_477\x00\x00"))
|
18
|
+
response.should_not be_void
|
19
|
+
response.change.should == 'CREATED'
|
20
|
+
response.keyspace.should == 'cql_rb_477'
|
21
|
+
response.table.should be_empty
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'decodes a schema_change UPDATED result' do
|
25
|
+
response = described_class.decode!(ByteBuffer.new("\x00\x00\x00\x05\x00\aUPDATED\x00\ncql_rb_973\x00\x05users"))
|
26
|
+
response.should_not be_void
|
27
|
+
response.change.should == 'UPDATED'
|
28
|
+
response.keyspace.should == 'cql_rb_973'
|
29
|
+
response.table.should == 'users'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'decodes a void result' do
|
33
|
+
response = described_class.decode!(ByteBuffer.new("\x00\x00\x00\x01"))
|
34
|
+
response.should be_void
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'decodes a rows result' do
|
38
|
+
response = described_class.decode!(ByteBuffer.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"))
|
39
|
+
response.should_not be_void
|
40
|
+
response.rows.size.should == 2
|
41
|
+
response.metadata.size.should == 3
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'decodes a prepared result' do
|
45
|
+
response = described_class.decode!(ByteBuffer.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"))
|
46
|
+
response.should_not be_void
|
47
|
+
response.id.should == "\xCAH\x7F\x1Ez\x82\xD2<N\x8A\xF35Qq\xA5/"
|
48
|
+
response.metadata.size.should == 1
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'complains when asked to decode an unknown result type' do
|
52
|
+
expect { described_class.decode!(ByteBuffer.new("\x00\x00\x00\xffhello")) }.to raise_error(UnsupportedResultKindError)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|