superfeedr-em-redis 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,149 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper.rb")
2
+
3
+ EM.describe EM::Protocols::Redis do
4
+ default_timeout 1
5
+
6
+ before do
7
+ @c = TestConnection.new
8
+ end
9
+
10
+ # Inline request protocol
11
+ should 'send inline commands correctly' do
12
+ @c.call_command(["GET", 'a'])
13
+ @c.sent_data.should == "get a\r\n"
14
+ done
15
+ end
16
+
17
+ should "space-separate multiple inline arguments" do
18
+ @c.call_command(["GET", 'a', 'b', 'c'])
19
+ @c.sent_data.should == "get a b c\r\n"
20
+ done
21
+ end
22
+
23
+ # Multiline request protocol
24
+ should "send multiline commands correctly" do
25
+ @c.call_command(["SET", "foo", "abc"])
26
+ @c.sent_data.should == "set foo 3\r\nabc\r\n"
27
+ done
28
+ end
29
+
30
+ should "send integers in multiline commands correctly" do
31
+ @c.call_command(["SET", "foo", 1_000_000])
32
+ @c.sent_data.should == "set foo 7\r\n1000000\r\n"
33
+ done
34
+ end
35
+
36
+ # Specific calls
37
+ #
38
+ # SORT
39
+ should "send sort command" do
40
+ @c.sort "foo"
41
+ @c.sent_data.should == "sort foo\r\n"
42
+ done
43
+ end
44
+
45
+ should "send sort command with all optional parameters" do
46
+ @c.sort "foo", :by => "foo_sort_*", :limit => [0, 10], :get => "data_*", :order => "DESC ALPHA"
47
+ @c.sent_data.should == "sort foo BY foo_sort_* GET data_* DESC ALPHA LIMIT 0 10\r\n"
48
+ done
49
+ end
50
+
51
+ should "parse keys response into an array" do
52
+ @c.keys("*") do |resp|
53
+ resp.should == ["a","b","c"]
54
+ done
55
+ end
56
+ @c.receive_data "$5\r\na b c\r\n"
57
+ end
58
+
59
+
60
+ # Inline response
61
+ should "parse an inline response" do
62
+ @c.call_command(["PING"]) do |resp|
63
+ resp.should == "OK"
64
+ done
65
+ end
66
+ @c.receive_data "+OK\r\n"
67
+ end
68
+
69
+ should "parse an inline integer response" do
70
+ @c.call_command(["integer"]) do |resp|
71
+ resp.should == 0
72
+ done
73
+ end
74
+ @c.receive_data ":0\r\n"
75
+ end
76
+
77
+ should "call processor if any" do
78
+ @c.call_command(["EXISTS"]) do |resp|
79
+ resp.should == false
80
+ done
81
+ end
82
+ @c.receive_data ":0\r\n"
83
+ end
84
+
85
+ should "parse an inline error response" do
86
+ lambda do
87
+ @c.call_command(["blarg"])
88
+ @c.receive_data "-FAIL\r\n"
89
+ end.should.raise(EM::P::Redis::RedisError)
90
+ done
91
+ end
92
+
93
+ should "trigger a given error callback (specified with on_error) for inline error response instead of raising an error" do
94
+ lambda do
95
+ @c.call_command(["blarg"])
96
+ @c.on_error {|code| code.should == "FAIL"; done }
97
+ @c.receive_data "-FAIL\r\n"
98
+ end.should.not.raise(EM::P::Redis::RedisError)
99
+ end
100
+
101
+ should "trigger a given error callback for inline error response instead of raising an error" do
102
+ lambda do
103
+ @c.call_command(["blarg"])
104
+ @c.errback { |code| code.should == "FAIL"; done }
105
+ @c.receive_data "-FAIL\r\n"
106
+ end.should.not.raise(EM::P::Redis::RedisError)
107
+ end
108
+
109
+ # Bulk response
110
+ should "parse a bulk response" do
111
+ @c.call_command(["GET", "foo"]) do |resp|
112
+ resp.should == "bar"
113
+ done
114
+ end
115
+ @c.receive_data "$3\r\n"
116
+ @c.receive_data "bar\r\n"
117
+ end
118
+
119
+ should "distinguish nil in a bulk response" do
120
+ @c.call_command(["GET", "bar"]) do |resp|
121
+ resp.should == nil
122
+ done
123
+ end
124
+ @c.receive_data "$-1\r\n"
125
+ end
126
+
127
+ # Multi-bulk response
128
+ should "parse a multi-bulk response" do
129
+ @c.call_command(["RANGE", 0, 10]) do |resp|
130
+ resp.should == ["a", "b", "foo"]
131
+ done
132
+ end
133
+ @c.receive_data "*3\r\n"
134
+ @c.receive_data "$1\r\na\r\n"
135
+ @c.receive_data "$1\r\nb\r\n"
136
+ @c.receive_data "$3\r\nfoo\r\n"
137
+ end
138
+
139
+ should "distinguish nil in a multi-bulk response" do
140
+ @c.call_command(["RANGE", 0, 10]) do |resp|
141
+ resp.should == ["a", nil, "foo"]
142
+ done
143
+ end
144
+ @c.receive_data "*3\r\n"
145
+ @c.receive_data "$1\r\na\r\n"
146
+ @c.receive_data "$-1\r\n"
147
+ @c.receive_data "$3\r\nfoo\r\n"
148
+ end
149
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/em-redis")
2
+ require 'em-spec/bacon'
3
+
4
+ EM.spec_backend = EventMachine::Spec::Bacon
5
+
6
+ class TestConnection
7
+ include EM::P::Redis
8
+
9
+ def send_data data
10
+ sent_data << data
11
+ end
12
+
13
+ def sent_data
14
+ @sent_data ||= ''
15
+ end
16
+
17
+ def initialize
18
+ super
19
+ connection_completed
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: superfeedr-em-redis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Broad
8
+ - Eugene Pimenov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-03-26 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: eventmachine
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.12.10
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: bacon
28
+ type: :development
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ version:
36
+ - !ruby/object:Gem::Dependency
37
+ name: em-spec
38
+ type: :development
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: bones
48
+ type: :development
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.4.1
55
+ version:
56
+ description: An eventmachine-based implementation of the Redis protocol
57
+ email: libc@me.com
58
+ executables: []
59
+
60
+ extensions: []
61
+
62
+ extra_rdoc_files:
63
+ - History.txt
64
+ - README.rdoc
65
+ files:
66
+ - .gitignore
67
+ - History.txt
68
+ - README.rdoc
69
+ - Rakefile
70
+ - lib/em-redis.rb
71
+ - lib/em-redis/redis_protocol.rb
72
+ - spec/live_redis_protocol_spec.rb
73
+ - spec/redis_commands_spec.rb
74
+ - spec/redis_protocol_spec.rb
75
+ - spec/test_helper.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/libc/em-redis
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --main
83
+ - README.rdoc
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ version:
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ version:
98
+ requirements: []
99
+
100
+ rubyforge_project: superfeedr-em-redis
101
+ rubygems_version: 1.3.5
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: An eventmachine-based implementation of the Redis protocol
105
+ test_files: []
106
+