cql-rb 1.0.2 → 1.0.3
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.
- data/lib/cql/protocol/decoding.rb +13 -3
- data/lib/cql/version.rb +1 -1
- data/spec/cql/protocol/decoding_spec.rb +12 -2
- data/spec/integration/protocol_spec.rb +70 -0
- metadata +3 -3
@@ -38,8 +38,14 @@ module Cql
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def read_long!(buffer)
|
41
|
-
|
42
|
-
(
|
41
|
+
hi, lo = buffer.read(8).unpack(Formats::TWO_INTS_FORMAT)
|
42
|
+
if (hi > 0x7fffffff)
|
43
|
+
hi ^= 0xffffffff
|
44
|
+
lo ^= 0xffffffff
|
45
|
+
0 - (hi << 32) - lo - 1
|
46
|
+
else
|
47
|
+
(hi << 32) + lo
|
48
|
+
end
|
43
49
|
rescue RangeError => e
|
44
50
|
raise DecodingError, e.message, e.backtrace
|
45
51
|
end
|
@@ -57,7 +63,11 @@ module Cql
|
|
57
63
|
end
|
58
64
|
|
59
65
|
def read_int!(buffer)
|
60
|
-
buffer.read_int
|
66
|
+
val = buffer.read_int
|
67
|
+
if (val > 0x7fffffff)
|
68
|
+
val = 0 - ((val - 1) ^ 0xffffffff)
|
69
|
+
end
|
70
|
+
val
|
61
71
|
rescue RangeError => e
|
62
72
|
raise DecodingError, "Not enough bytes available to decode an int: #{e.message}", e.backtrace
|
63
73
|
end
|
data/lib/cql/version.rb
CHANGED
@@ -79,11 +79,16 @@ module Cql
|
|
79
79
|
end
|
80
80
|
|
81
81
|
describe '#read_long!' do
|
82
|
-
it 'decodes a long' do
|
82
|
+
it 'decodes a positive long' do
|
83
83
|
buffer = ByteBuffer.new("\x00\x00\xca\xfe\xba\xbe\x00\x00")
|
84
84
|
Decoding.read_long!(buffer).should == 0x0000cafebabe0000
|
85
85
|
end
|
86
86
|
|
87
|
+
it 'decodes a negative long' do
|
88
|
+
buffer = ByteBuffer.new("\xff\xff\xff\xff\xff\xff\xff\xff")
|
89
|
+
Decoding.read_long!(buffer).should == -1
|
90
|
+
end
|
91
|
+
|
87
92
|
it 'consumes the bytes' do
|
88
93
|
buffer = ByteBuffer.new("\xca\xfe\xba\xbe\xca\xfe\xba\xbe\xca\xfe\xba\xbe")
|
89
94
|
Decoding.read_long!(buffer)
|
@@ -137,10 +142,15 @@ module Cql
|
|
137
142
|
ByteBuffer.new("\x00\xff\x00\xff")
|
138
143
|
end
|
139
144
|
|
140
|
-
it 'decodes
|
145
|
+
it 'decodes a positive int' do
|
141
146
|
Decoding.read_int!(buffer).should == 0x00ff00ff
|
142
147
|
end
|
143
148
|
|
149
|
+
it 'decodes a negative int' do
|
150
|
+
buffer = ByteBuffer.new("\xff\xff\xff\xff")
|
151
|
+
Decoding.read_int!(buffer).should == -1
|
152
|
+
end
|
153
|
+
|
144
154
|
it 'consumes the bytes' do
|
145
155
|
buffer << "\xab\xcd"
|
146
156
|
Decoding.read_int!(buffer)
|
@@ -285,6 +285,76 @@ describe 'Protocol parsing and communication' do
|
|
285
285
|
end
|
286
286
|
end
|
287
287
|
|
288
|
+
it 'decodes positive counters' do
|
289
|
+
in_keyspace_with_counters_table do
|
290
|
+
max_long = (1 << 63) -1
|
291
|
+
response = query(%<UPDATE counters SET c1 = c1 + 1, c2 = c2 +#{max_long} WHERE id = 'positive'>)
|
292
|
+
response = query(%<SELECT * FROM counters>, :quorum)
|
293
|
+
response.rows.should == [
|
294
|
+
{'id' => 'positive', 'c1' => 1, 'c2' => max_long},
|
295
|
+
]
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'decodes negative counters' do
|
300
|
+
in_keyspace_with_counters_table do
|
301
|
+
min_long = 0 - (1 << 63)
|
302
|
+
response = query(%<UPDATE counters SET c1 = c1 - 1 , c2 = c2 -#{min_long.abs} WHERE id = 'negative'>)
|
303
|
+
response = query(%<SELECT * FROM counters>, :quorum)
|
304
|
+
response.rows.should == [
|
305
|
+
{'id' => 'negative', 'c1' => -1 , 'c2' => min_long}
|
306
|
+
]
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
it 'decodes positive bigints' do
|
311
|
+
in_keyspace do
|
312
|
+
max_long = (1 << 63) -1
|
313
|
+
response = query('CREATE TABLE stuff (id VARCHAR, c1 bigint, c2 bigint, PRIMARY KEY (id))')
|
314
|
+
response = query(%<UPDATE stuff SET c1 = 1, c2 = #{max_long} WHERE id = 'stuff'>)
|
315
|
+
response = query(%<SELECT * FROM stuff>, :quorum)
|
316
|
+
response.rows.should == [
|
317
|
+
{'id' => 'stuff', 'c1' => 1, 'c2' => max_long}
|
318
|
+
]
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
it 'decodes negative bigints' do
|
323
|
+
in_keyspace do
|
324
|
+
min_long = 0 - (1 << 63)
|
325
|
+
response = query('CREATE TABLE stuff (id VARCHAR, c1 bigint, c2 bigint, PRIMARY KEY (id))')
|
326
|
+
response = query(%<UPDATE stuff SET c1 = -1, c2 = #{min_long} WHERE id = 'stuff'>)
|
327
|
+
response = query(%<SELECT * FROM stuff>, :quorum)
|
328
|
+
response.rows.should == [
|
329
|
+
{'id' => 'stuff', 'c1' => -1, 'c2' => min_long}
|
330
|
+
]
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'decodes positive ints' do
|
335
|
+
in_keyspace do
|
336
|
+
max_int = (1 << 31) -1
|
337
|
+
response = query('CREATE TABLE stuff (id VARCHAR, c1 int, c2 int, PRIMARY KEY (id))')
|
338
|
+
response = query(%<UPDATE stuff SET c1 = 1, c2 = #{max_int} WHERE id = 'stuff'>)
|
339
|
+
response = query(%<SELECT * FROM stuff>, :quorum)
|
340
|
+
response.rows.should == [
|
341
|
+
{'id' => 'stuff', 'c1' => 1, 'c2' => max_int}
|
342
|
+
]
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'decodes negative ints' do
|
347
|
+
in_keyspace do
|
348
|
+
min_int = 0 - (1 << 31)
|
349
|
+
response = query('CREATE TABLE stuff (id VARCHAR, c1 int, c2 int, PRIMARY KEY (id))')
|
350
|
+
response = query(%<UPDATE stuff SET c1 = -1, c2 = #{min_int} WHERE id = 'stuff'>)
|
351
|
+
response = query(%<SELECT * FROM stuff>, :quorum)
|
352
|
+
response.rows.should == [
|
353
|
+
{'id' => 'stuff', 'c1' => -1, 'c2' => min_int}
|
354
|
+
]
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
288
358
|
it 'sends a DELETE command' do
|
289
359
|
in_keyspace_with_table do
|
290
360
|
response = query(%<DELETE email FROM users WHERE user_name = 'sue'>)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cql-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A pure Ruby CQL3 driver for Cassandra
|
15
15
|
email:
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
segments:
|
114
114
|
- 0
|
115
|
-
hash:
|
115
|
+
hash: -3215276701075097941
|
116
116
|
requirements: []
|
117
117
|
rubyforge_project:
|
118
118
|
rubygems_version: 1.8.23
|