cql-rb 1.0.0.pre0
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/README.md +13 -0
- data/bin/cqlexec +135 -0
- data/lib/cql.rb +11 -0
- data/lib/cql/client.rb +196 -0
- data/lib/cql/future.rb +176 -0
- data/lib/cql/io.rb +13 -0
- data/lib/cql/io/io_reactor.rb +351 -0
- data/lib/cql/protocol.rb +39 -0
- data/lib/cql/protocol/decoding.rb +156 -0
- data/lib/cql/protocol/encoding.rb +109 -0
- data/lib/cql/protocol/request_frame.rb +228 -0
- data/lib/cql/protocol/response_frame.rb +551 -0
- data/lib/cql/uuid.rb +46 -0
- data/lib/cql/version.rb +5 -0
- data/spec/cql/client_spec.rb +368 -0
- data/spec/cql/future_spec.rb +297 -0
- data/spec/cql/io/io_reactor_spec.rb +290 -0
- data/spec/cql/protocol/decoding_spec.rb +464 -0
- data/spec/cql/protocol/encoding_spec.rb +338 -0
- data/spec/cql/protocol/request_frame_spec.rb +359 -0
- data/spec/cql/protocol/response_frame_spec.rb +746 -0
- data/spec/cql/uuid_spec.rb +40 -0
- data/spec/integration/client_spec.rb +101 -0
- data/spec/integration/protocol_spec.rb +326 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/fake_io_reactor.rb +55 -0
- data/spec/support/fake_server.rb +95 -0
- metadata +87 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class FakeIoReactor
|
4
|
+
attr_reader :connections, :last_used_connection
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@running = false
|
8
|
+
@connections = []
|
9
|
+
@queued_responses = Hash.new { |h, k| h[k] = [] }
|
10
|
+
@default_host = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def queue_response(response, host=nil)
|
14
|
+
@queued_responses[host] << response
|
15
|
+
end
|
16
|
+
|
17
|
+
def start
|
18
|
+
@running = true
|
19
|
+
@connections = []
|
20
|
+
@connections.each do |connection|
|
21
|
+
connection[:future].complete! unless connection[:future].complete?
|
22
|
+
end
|
23
|
+
Cql::Future.completed
|
24
|
+
end
|
25
|
+
|
26
|
+
def stop
|
27
|
+
@running = false
|
28
|
+
Cql::Future.completed
|
29
|
+
end
|
30
|
+
|
31
|
+
def running?
|
32
|
+
@running
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_connection(host, port)
|
36
|
+
@default_host ||= host
|
37
|
+
future = Cql::Future.new
|
38
|
+
connection = {:host => host, :port => port, :future => future, :requests => []}
|
39
|
+
@connections << connection
|
40
|
+
future.complete!(connection.object_id) if @running
|
41
|
+
future
|
42
|
+
end
|
43
|
+
|
44
|
+
def queue_request(request, connection_id=nil)
|
45
|
+
if connection_id
|
46
|
+
connection = @connections.find { |c| c.object_id == connection_id }
|
47
|
+
else
|
48
|
+
connection = @connections.sample
|
49
|
+
end
|
50
|
+
connection[:requests] << request
|
51
|
+
response = @queued_responses[connection[:host]].shift || @queued_responses[nil].shift
|
52
|
+
@last_used_connection = connection
|
53
|
+
Cql::Future.completed([response, connection.object_id])
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class FakeServer
|
4
|
+
attr_reader :connects, :disconnects
|
5
|
+
|
6
|
+
def initialize(port)
|
7
|
+
@port = port
|
8
|
+
@state = {}
|
9
|
+
@lock = Mutex.new
|
10
|
+
@connects = 0
|
11
|
+
@disconnects = 0
|
12
|
+
@connections = []
|
13
|
+
@received_bytes = ''
|
14
|
+
end
|
15
|
+
|
16
|
+
def start!
|
17
|
+
@lock.synchronize do
|
18
|
+
return if @running
|
19
|
+
@running = true
|
20
|
+
end
|
21
|
+
@sockets = [TCPServer.new(@port)]
|
22
|
+
@started = Cql::Future.new
|
23
|
+
@thread = Thread.start do
|
24
|
+
Thread.current.abort_on_exception = true
|
25
|
+
@started.complete!
|
26
|
+
io_loop
|
27
|
+
end
|
28
|
+
@started.get
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def stop!
|
33
|
+
@lock.synchronize do
|
34
|
+
return unless @running
|
35
|
+
@running = false
|
36
|
+
end
|
37
|
+
@thread.join
|
38
|
+
@sockets.each(&:close)
|
39
|
+
end
|
40
|
+
|
41
|
+
def broadcast!(bytes)
|
42
|
+
@lock.synchronize do
|
43
|
+
@connections.each { |c| c.write_nonblock(bytes) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def await_connects!(n=1)
|
48
|
+
sleep(0.01) until @connects >= n
|
49
|
+
end
|
50
|
+
|
51
|
+
def await_disconnects!(n=1)
|
52
|
+
sleep(0.01) until @disconnects >= n
|
53
|
+
end
|
54
|
+
|
55
|
+
def received_bytes
|
56
|
+
@lock.synchronize do
|
57
|
+
return @received_bytes.dup
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def io_loop
|
64
|
+
while @running
|
65
|
+
acceptables, _ = IO.select(@sockets, @connections, nil, 0)
|
66
|
+
readables, writables, _ = IO.select(@connections, @connections, nil, 0)
|
67
|
+
|
68
|
+
if acceptables
|
69
|
+
acceptables.each do |socket|
|
70
|
+
connection, _ = socket.accept_nonblock
|
71
|
+
@lock.synchronize do
|
72
|
+
@connects += 1
|
73
|
+
@connections << connection
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
if readables
|
79
|
+
readables.each do |readable|
|
80
|
+
begin
|
81
|
+
bytes = readable.read_nonblock(2**16)
|
82
|
+
@lock.synchronize do
|
83
|
+
@received_bytes << bytes
|
84
|
+
end
|
85
|
+
rescue EOFError
|
86
|
+
@lock.synchronize do
|
87
|
+
@connections.delete(readable)
|
88
|
+
@disconnects += 1
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cql-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre0
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Theo Hultberg
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A pure Ruby CQL3 driver for Cassandra
|
15
|
+
email:
|
16
|
+
- theo@iconara.net
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/cql/client.rb
|
22
|
+
- lib/cql/future.rb
|
23
|
+
- lib/cql/io/io_reactor.rb
|
24
|
+
- lib/cql/io.rb
|
25
|
+
- lib/cql/protocol/decoding.rb
|
26
|
+
- lib/cql/protocol/encoding.rb
|
27
|
+
- lib/cql/protocol/request_frame.rb
|
28
|
+
- lib/cql/protocol/response_frame.rb
|
29
|
+
- lib/cql/protocol.rb
|
30
|
+
- lib/cql/uuid.rb
|
31
|
+
- lib/cql/version.rb
|
32
|
+
- lib/cql.rb
|
33
|
+
- bin/cqlexec
|
34
|
+
- README.md
|
35
|
+
- spec/cql/client_spec.rb
|
36
|
+
- spec/cql/future_spec.rb
|
37
|
+
- spec/cql/io/io_reactor_spec.rb
|
38
|
+
- spec/cql/protocol/decoding_spec.rb
|
39
|
+
- spec/cql/protocol/encoding_spec.rb
|
40
|
+
- spec/cql/protocol/request_frame_spec.rb
|
41
|
+
- spec/cql/protocol/response_frame_spec.rb
|
42
|
+
- spec/cql/uuid_spec.rb
|
43
|
+
- spec/integration/client_spec.rb
|
44
|
+
- spec/integration/protocol_spec.rb
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
- spec/support/fake_io_reactor.rb
|
47
|
+
- spec/support/fake_server.rb
|
48
|
+
homepage: http://github.com/iconara/cql-rb
|
49
|
+
licenses:
|
50
|
+
- Apache
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.9.2
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>'
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.3.1
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.23
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Cassandra CQL3 driver
|
73
|
+
test_files:
|
74
|
+
- spec/cql/client_spec.rb
|
75
|
+
- spec/cql/future_spec.rb
|
76
|
+
- spec/cql/io/io_reactor_spec.rb
|
77
|
+
- spec/cql/protocol/decoding_spec.rb
|
78
|
+
- spec/cql/protocol/encoding_spec.rb
|
79
|
+
- spec/cql/protocol/request_frame_spec.rb
|
80
|
+
- spec/cql/protocol/response_frame_spec.rb
|
81
|
+
- spec/cql/uuid_spec.rb
|
82
|
+
- spec/integration/client_spec.rb
|
83
|
+
- spec/integration/protocol_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
- spec/support/fake_io_reactor.rb
|
86
|
+
- spec/support/fake_server.rb
|
87
|
+
has_rdoc:
|