fraggle 0.4.0 → 1.0.0pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +17 -0
- data/example/again.rb +21 -0
- data/example/getdir.rb +24 -0
- data/example/ping.rb +19 -0
- data/example/session.rb +16 -0
- data/example/set.rb +21 -0
- data/example/stat.rb +23 -0
- data/example/walk.rb +23 -0
- data/example/watch.rb +22 -0
- data/fraggle.gemspec +25 -0
- data/lib/fraggle.rb +28 -35
- data/lib/fraggle/client.rb +70 -287
- data/lib/fraggle/connection.rb +139 -0
- data/lib/fraggle/msg.pb.rb +62 -0
- data/lib/fraggle/request.rb +37 -10
- data/lib/fraggle/response.rb +17 -38
- data/lib/fraggle/version.rb +3 -0
- data/test/fraggle_client_test.rb +185 -165
- data/test/fraggle_protocol_test.rb +27 -39
- data/test/fraggle_test.rb +5 -10
- data/test/fraggle_transaction_test.rb +220 -0
- data/test/helper.rb +84 -0
- metadata +59 -36
- data/lib/fraggle/emitter.rb +0 -39
- data/lib/fraggle/errors.rb +0 -3
- data/lib/fraggle/logger.rb +0 -32
- data/lib/fraggle/meta.rb +0 -9
- data/lib/fraggle/msg.rb +0 -77
- data/lib/fraggle/protocol.rb +0 -43
- data/lib/fraggle/test.rb +0 -72
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fraggle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 961915988
|
5
|
+
prerelease: 5
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
- 4
|
9
9
|
- 0
|
10
|
-
|
10
|
+
- pre
|
11
|
+
version: 1.0.0pre
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Blake Mizerany
|
@@ -15,7 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2011-03-
|
19
|
+
date: 2011-03-28 00:00:00 -07:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
@@ -24,54 +25,72 @@ dependencies:
|
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
26
|
none: false
|
26
27
|
requirements:
|
27
|
-
- -
|
28
|
+
- - ~>
|
28
29
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
30
|
+
hash: 13
|
30
31
|
segments:
|
31
32
|
- 0
|
32
|
-
-
|
33
|
-
|
34
|
-
version: 0.1.1
|
33
|
+
- 3
|
34
|
+
version: "0.3"
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
|
-
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: turn
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description: An EventMachine Client for Doozer
|
38
52
|
email:
|
53
|
+
- blake.mizerany@gmail.com
|
39
54
|
executables: []
|
40
55
|
|
41
56
|
extensions: []
|
42
57
|
|
43
|
-
extra_rdoc_files:
|
44
|
-
|
45
|
-
- LICENSE
|
58
|
+
extra_rdoc_files: []
|
59
|
+
|
46
60
|
files:
|
61
|
+
- .gitignore
|
62
|
+
- Gemfile
|
47
63
|
- LICENSE
|
48
64
|
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- example/again.rb
|
67
|
+
- example/getdir.rb
|
68
|
+
- example/ping.rb
|
69
|
+
- example/session.rb
|
70
|
+
- example/set.rb
|
71
|
+
- example/stat.rb
|
72
|
+
- example/walk.rb
|
73
|
+
- example/watch.rb
|
74
|
+
- fraggle.gemspec
|
75
|
+
- lib/fraggle.rb
|
49
76
|
- lib/fraggle/client.rb
|
50
|
-
- lib/fraggle/
|
51
|
-
- lib/fraggle/
|
52
|
-
- lib/fraggle/logger.rb
|
53
|
-
- lib/fraggle/meta.rb
|
54
|
-
- lib/fraggle/msg.rb
|
55
|
-
- lib/fraggle/protocol.rb
|
77
|
+
- lib/fraggle/connection.rb
|
78
|
+
- lib/fraggle/msg.pb.rb
|
56
79
|
- lib/fraggle/request.rb
|
57
80
|
- lib/fraggle/response.rb
|
58
|
-
- lib/fraggle/
|
59
|
-
- lib/fraggle.rb
|
81
|
+
- lib/fraggle/version.rb
|
60
82
|
- test/fraggle_client_test.rb
|
61
83
|
- test/fraggle_protocol_test.rb
|
62
84
|
- test/fraggle_test.rb
|
85
|
+
- test/fraggle_transaction_test.rb
|
86
|
+
- test/helper.rb
|
63
87
|
has_rdoc: true
|
64
|
-
homepage:
|
88
|
+
homepage: ""
|
65
89
|
licenses: []
|
66
90
|
|
67
91
|
post_install_message:
|
68
|
-
rdoc_options:
|
69
|
-
|
70
|
-
- --inline-source
|
71
|
-
- --title
|
72
|
-
- Sinatra
|
73
|
-
- --main
|
74
|
-
- README.rdoc
|
92
|
+
rdoc_options: []
|
93
|
+
|
75
94
|
require_paths:
|
76
95
|
- lib
|
77
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -86,20 +105,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
106
|
none: false
|
88
107
|
requirements:
|
89
|
-
- - "
|
108
|
+
- - ">"
|
90
109
|
- !ruby/object:Gem::Version
|
91
|
-
hash:
|
110
|
+
hash: 25
|
92
111
|
segments:
|
93
|
-
-
|
94
|
-
|
112
|
+
- 1
|
113
|
+
- 3
|
114
|
+
- 1
|
115
|
+
version: 1.3.1
|
95
116
|
requirements: []
|
96
117
|
|
97
118
|
rubyforge_project: fraggle
|
98
119
|
rubygems_version: 1.5.2
|
99
120
|
signing_key:
|
100
|
-
specification_version:
|
101
|
-
summary:
|
121
|
+
specification_version: 3
|
122
|
+
summary: An EventMachine Client for Doozer
|
102
123
|
test_files:
|
103
124
|
- test/fraggle_client_test.rb
|
104
125
|
- test/fraggle_protocol_test.rb
|
105
126
|
- test/fraggle_test.rb
|
127
|
+
- test/fraggle_transaction_test.rb
|
128
|
+
- test/helper.rb
|
data/lib/fraggle/emitter.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module Fraggle
|
2
|
-
|
3
|
-
module Emitter
|
4
|
-
|
5
|
-
def callbacks
|
6
|
-
@callbacks ||= Hash.new(lambda {})
|
7
|
-
end
|
8
|
-
|
9
|
-
def emit(name, *args)
|
10
|
-
callbacks[name].call(*args)
|
11
|
-
end
|
12
|
-
|
13
|
-
def valid(&blk) ; must_callback!(:valid, blk) ; end
|
14
|
-
def done(&blk) ; must_callback!(:done, blk) ; end
|
15
|
-
def error(&blk) ; must_callback!(:error, blk) ; end
|
16
|
-
def again(&blk) ; must_callback!(:again, blk) ; end
|
17
|
-
|
18
|
-
def must_callback!(name, blk)
|
19
|
-
if ! blk
|
20
|
-
raise ArgumentError, "no block given to `#{name}`"
|
21
|
-
end
|
22
|
-
callbacks[name] = blk
|
23
|
-
|
24
|
-
self
|
25
|
-
end
|
26
|
-
|
27
|
-
def aggr(coll=[], &blk)
|
28
|
-
valid do |item|
|
29
|
-
coll << item
|
30
|
-
end
|
31
|
-
|
32
|
-
done do
|
33
|
-
blk.call(coll)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
data/lib/fraggle/errors.rb
DELETED
data/lib/fraggle/logger.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module Fraggle
|
2
|
-
module Logger
|
3
|
-
|
4
|
-
DEBUG = 0
|
5
|
-
INFO = 1
|
6
|
-
WARN = 2
|
7
|
-
ERROR = 3
|
8
|
-
|
9
|
-
attr_writer :writer, :level
|
10
|
-
|
11
|
-
def log(lv, msg)
|
12
|
-
label = case lv
|
13
|
-
when DEBUG then "debug "
|
14
|
-
when INFO then "info "
|
15
|
-
when WARN then "warn "
|
16
|
-
when ERROR then "error "
|
17
|
-
end
|
18
|
-
|
19
|
-
if lv >= level
|
20
|
-
writer.puts "#{label}: #{msg}"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def writer ; @writer ||= STDERR ; end
|
25
|
-
def level ; @level ||= WARN ; end
|
26
|
-
|
27
|
-
def debug(msg) ; log(DEBUG, msg) ; end
|
28
|
-
def info(msg) ; log(INFO, msg) ; end
|
29
|
-
def warn(msg) ; log(WARN, msg) ; end
|
30
|
-
def error(msg) ; log(ERROR, msg) ; end
|
31
|
-
end
|
32
|
-
end
|
data/lib/fraggle/meta.rb
DELETED
data/lib/fraggle/msg.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'beefcake'
|
2
|
-
|
3
|
-
module Fraggle
|
4
|
-
|
5
|
-
class Request
|
6
|
-
include Beefcake::Message
|
7
|
-
|
8
|
-
required :tag, :int32, 1
|
9
|
-
|
10
|
-
module Verb
|
11
|
-
CHECKIN = 0; # rev, id => rev
|
12
|
-
GET = 1; # path, id => rev, value
|
13
|
-
SET = 2; # rev, path, value => rev
|
14
|
-
DEL = 3; # rev, path => {}
|
15
|
-
ESET = 4; # rev, path => {}
|
16
|
-
REV = 5; # {} => seqn, id
|
17
|
-
NOOP = 7; # {} => {}
|
18
|
-
WATCH = 8; # path => {rev, path, value}+
|
19
|
-
CANCEL = 10; # id => {}
|
20
|
-
STAT = 16; # path, id => rev, len
|
21
|
-
|
22
|
-
# future
|
23
|
-
GETDIR = 14; # path => {rev, value}+
|
24
|
-
MONITOR = 11; # path => {rev, path, value}+
|
25
|
-
SYNCPATH = 12; # path => rev, value
|
26
|
-
WALK = 9; # path, id => {rev, path, value}+
|
27
|
-
|
28
|
-
# deprecated
|
29
|
-
JOIN = 13;
|
30
|
-
end
|
31
|
-
|
32
|
-
required :verb, Verb, 2
|
33
|
-
|
34
|
-
optional :path, :string, 4
|
35
|
-
optional :value, :bytes, 5
|
36
|
-
optional :id, :int32, 6
|
37
|
-
|
38
|
-
optional :offset, :int32, 7
|
39
|
-
optional :limit, :int32, 8
|
40
|
-
|
41
|
-
optional :rev, :int64, 9
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
class Response
|
46
|
-
include Beefcake::Message
|
47
|
-
|
48
|
-
required :tag, :uint32, 1
|
49
|
-
required :flags, :int32, 2
|
50
|
-
|
51
|
-
optional :rev, :int64, 3
|
52
|
-
optional :cas, :int64, 4
|
53
|
-
optional :path, :string, 5
|
54
|
-
optional :value, :bytes, 6
|
55
|
-
optional :id, :int32, 7
|
56
|
-
optional :len, :int32, 8
|
57
|
-
|
58
|
-
module Err
|
59
|
-
# don't use value 0
|
60
|
-
OTHER = 127
|
61
|
-
TAG_IN_USE = 1
|
62
|
-
UNKNOWN_VERB = 2
|
63
|
-
REDIRECT = 3
|
64
|
-
TOO_LATE = 4
|
65
|
-
CAS_MISMATCH = 5
|
66
|
-
|
67
|
-
# match unix errno
|
68
|
-
NOTDIR = 20
|
69
|
-
ISDIR = 21
|
70
|
-
NOINT = 22
|
71
|
-
end
|
72
|
-
|
73
|
-
optional :err_code, Err, 100
|
74
|
-
optional :err_detail, :string, 101
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
data/lib/fraggle/protocol.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'fraggle/response'
|
2
|
-
|
3
|
-
module Fraggle
|
4
|
-
|
5
|
-
module Protocol
|
6
|
-
|
7
|
-
attr_reader :last_received
|
8
|
-
|
9
|
-
def receive_data(data)
|
10
|
-
@last_received = Time.now
|
11
|
-
|
12
|
-
(@buf ||= "") << data
|
13
|
-
|
14
|
-
while @buf.length > 0
|
15
|
-
if @len && @buf.length >= @len
|
16
|
-
bytes = @buf.slice!(0, @len)
|
17
|
-
@len = nil
|
18
|
-
res = Response.decode(bytes)
|
19
|
-
receive_response(res)
|
20
|
-
elsif @buf.length >= 4
|
21
|
-
bytes = @buf.slice!(0, 4)
|
22
|
-
@len = bytes.unpack("N")[0]
|
23
|
-
else
|
24
|
-
break
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# The default receive_response
|
30
|
-
def receive_response(res)
|
31
|
-
p res
|
32
|
-
end
|
33
|
-
|
34
|
-
def send_request(req)
|
35
|
-
data = req.encode
|
36
|
-
head = [data.length].pack("N")
|
37
|
-
|
38
|
-
send_data("#{head}#{data}")
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
data/lib/fraggle/test.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'fraggle/request'
|
2
|
-
require 'fraggle/response'
|
3
|
-
|
4
|
-
module Fraggle
|
5
|
-
|
6
|
-
##
|
7
|
-
# I want this to be a great starting point for testing fraggle applications.
|
8
|
-
# It's currently a work in progress. Think Rack::Test for fraggle.
|
9
|
-
#
|
10
|
-
module Test
|
11
|
-
|
12
|
-
V = Fraggle::Request::Verb
|
13
|
-
F = Fraggle::Response::Flag
|
14
|
-
E = Fraggle::Response::Err
|
15
|
-
|
16
|
-
|
17
|
-
class TestClient < Array
|
18
|
-
include Fraggle::Client
|
19
|
-
alias :send_request :<<
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
# This is handy for testing callbacks
|
24
|
-
class Blk < Array
|
25
|
-
def to_proc
|
26
|
-
Proc.new {|res| self << res }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
def assert_sent(tag, attrs={})
|
32
|
-
req = Fraggle::Request.new(attrs)
|
33
|
-
req.tag = tag
|
34
|
-
|
35
|
-
msg = "This was not sent:\n"
|
36
|
-
msg << " #{req.inspect}\n"
|
37
|
-
msg << "Sent:\n "
|
38
|
-
msg << c.map {|r| r.inspect }.join("\n ")
|
39
|
-
msg << "\n"
|
40
|
-
|
41
|
-
assert_block(msg) { c.include?(req) }
|
42
|
-
end
|
43
|
-
|
44
|
-
def assert_recv(attrs)
|
45
|
-
req = Fraggle::Response.new(attrs)
|
46
|
-
msg = "This was not recieved:\n"
|
47
|
-
msg << " #{req.inspect}\n"
|
48
|
-
msg << "Received:\n "
|
49
|
-
msg << blk.map {|r| r.inspect }.join("\n ")
|
50
|
-
msg << "\n"
|
51
|
-
|
52
|
-
assert_block(msg) { blk.include?(attrs) }
|
53
|
-
end
|
54
|
-
|
55
|
-
# Replies with a valid response
|
56
|
-
def reply(tag, attrs={})
|
57
|
-
res = Fraggle::Response.new(attrs)
|
58
|
-
res.tag = tag
|
59
|
-
res.flags ||= 0
|
60
|
-
res.flags |= Fraggle::Response::Flag::VALID
|
61
|
-
c.receive_response(res)
|
62
|
-
res
|
63
|
-
end
|
64
|
-
|
65
|
-
# Replies with a valid + done response
|
66
|
-
def reply!(tag, attrs={})
|
67
|
-
reply(tag, attrs.merge(:flags => Fraggle::Response::Flag::DONE))
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|