em-synchrony 0.1.5 → 0.2.0

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.
@@ -0,0 +1,69 @@
1
+ require "spec/helper/all"
2
+
3
+ describe EM::Mongo do
4
+
5
+ it "should yield until connection is ready" do
6
+ EventMachine.synchrony do
7
+ connection = EM::Mongo::Connection.new
8
+ connection.connected?.should be_true
9
+
10
+ db = connection.db('db')
11
+ db.is_a?(EventMachine::Mongo::Database).should be_true
12
+
13
+ EventMachine.stop
14
+ end
15
+ end
16
+
17
+ it "should insert a record into db" do
18
+ EventMachine.synchrony do
19
+ collection = EM::Mongo::Connection.new.db('db').collection('test')
20
+ collection.remove({}) # nuke all keys in collection
21
+
22
+ obj = collection.insert('hello' => 'world')
23
+ obj.keys.should include '_id'
24
+
25
+ obj = collection.find
26
+ obj.size.should == 1
27
+ obj.first['hello'].should == 'world'
28
+
29
+ EventMachine.stop
30
+ end
31
+ end
32
+
33
+ it "should insert a record into db" do
34
+ EventMachine.synchrony do
35
+ collection = EM::Mongo::Connection.new.db('db').collection('test')
36
+ collection.remove({}) # nuke all keys in collection
37
+
38
+ obj = collection.insert('hello' => 'world')
39
+ obj = collection.insert('hello2' => 'world2')
40
+
41
+ obj = collection.find({})
42
+ obj.size.should == 2
43
+
44
+ obj2 = collection.find({}, {:limit => 1})
45
+ obj2.size.should == 1
46
+
47
+ obj3 = collection.first
48
+ obj3.is_a?(Hash).should be_true
49
+
50
+ EventMachine.stop
51
+ end
52
+ end
53
+
54
+ it "should update records in db" do
55
+ EventMachine.synchrony do
56
+ collection = EM::Mongo::Connection.new.db('db').collection('test')
57
+ collection.remove({}) # nuke all keys in collection
58
+
59
+ obj = collection.insert('hello' => 'world')
60
+ collection.update({'hello' => 'world'}, {'hello' => 'newworld'})
61
+
62
+ new_obj = collection.first({'_id' => obj['_id']})
63
+ new_obj['hello'].should == 'newworld'
64
+
65
+ EventMachine.stop
66
+ end
67
+ end
68
+
69
+ end
data/spec/helper/all.rb CHANGED
@@ -1,17 +1,27 @@
1
1
  require 'rubygems'
2
- require 'spec'
2
+ require 'rspec'
3
3
  require 'pp'
4
4
 
5
5
  require 'lib/em-synchrony'
6
6
  require 'lib/em-synchrony/em-http'
7
7
  require 'lib/em-synchrony/em-mysqlplus'
8
8
  require 'lib/em-synchrony/em-remcached'
9
+ require 'lib/em-synchrony/em-memcache'
10
+ require 'lib/em-synchrony/em-mongo'
11
+ require 'lib/em-synchrony/em-redis'
9
12
 
10
13
  require 'helper/tolerance_matcher'
11
14
  require 'helper/stub-http-server'
12
15
 
13
16
  def now(); Time.now.to_f; end
14
17
 
15
- Spec::Runner.configure do |config|
18
+ def silence_warnings()
19
+ old_verbose, $VERBOSE = $VERBOSE, nil
20
+ yield
21
+ ensure
22
+ $VERBOSE = old_verbose
23
+ end
24
+
25
+ RSpec.configure do |config|
16
26
  config.include(Sander6::CustomMatchers)
17
- end
27
+ end
@@ -0,0 +1,37 @@
1
+ require "spec/helper/all"
2
+ require "em-synchrony/iterator"
3
+
4
+ describe EventMachine::Synchrony do
5
+
6
+ URL = "http://localhost:8081/"
7
+ DELAY = 0.01
8
+
9
+ it "should allow inline callbacks for Deferrable object" do
10
+ EM.synchrony do
11
+ s = StubServer.new("HTTP/1.0 200 OK\r\nConnection: close\r\n\r\nFoo", DELAY)
12
+
13
+ result = EM::Synchrony.sync EventMachine::HttpRequest.new(URL).aget
14
+ result.response.should match(/Foo/)
15
+
16
+ EM.stop
17
+ end
18
+ end
19
+
20
+ it "should inline errback/callback cases" do
21
+ EM.synchrony do
22
+ class E
23
+ include EventMachine::Deferrable
24
+ def run
25
+ EM.add_timer(0.01) {fail("uh oh!")}
26
+ self
27
+ end
28
+ end
29
+
30
+ result = EM::Synchrony.sync E.new.run
31
+ result.should match(/uh oh!/)
32
+
33
+ EM.stop
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,33 @@
1
+ require "spec/helper/all"
2
+
3
+ describe EM::P::Memcache do
4
+
5
+ it "should fire sequential memcached requests" do
6
+ EventMachine.synchrony do
7
+ conn = EM::P::Memcache.connect
8
+ key = 'key'
9
+ value = 'value for key'
10
+ fake_key = 'nonexistent key' # without a corresponding value
11
+
12
+ conn.delete(key)
13
+ conn.set(key, value)
14
+ conn.get(key).should == value
15
+
16
+ conn.delete(key)
17
+ conn.get(key).should be_nil
18
+
19
+ conn.set(key, value)
20
+ conn.get(key).should == value
21
+
22
+ conn.del(key)
23
+ conn.get(key).should be_nil
24
+
25
+ conn.set(key, value)
26
+ conn.get(key, fake_key).should == [value, nil]
27
+ conn.get_hash(key, fake_key).should == { key => value, fake_key => nil }
28
+
29
+ EventMachine.stop
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec/helper/all'
2
+ require 'lib/em-synchrony/mongo'
3
+ require 'mongo'
4
+
5
+ describe Mongo::Connection do
6
+ it 'connects to DB' do
7
+ EventMachine.synchrony do
8
+ conn = Mongo::Connection.new 'localhost', 27017, :connect => true
9
+ EM.stop
10
+ end
11
+ end
12
+ end
@@ -1,4 +1,5 @@
1
1
  require "spec/helper/all"
2
+ require "mysqlplus"
2
3
  require "em-mysqlplus"
3
4
 
4
5
  DELAY = 0.25
@@ -84,4 +85,14 @@ describe EventMachine::MySQL do
84
85
  end
85
86
  end
86
87
 
87
- end
88
+ it "should raise Mysql::Error in case of error" do
89
+ EventMachine.synchrony do
90
+ db = EventMachine::MySQL.new(host: "localhost")
91
+ proc {
92
+ db.query("SELECT * FROM i_hope_this_table_does_not_exist;")
93
+ }.should raise_error(Mysql::Error)
94
+ EventMachine.stop
95
+ end
96
+ end
97
+
98
+ end
@@ -0,0 +1,66 @@
1
+ require "spec/helper/all"
2
+
3
+ describe EM::Protocols::Redis do
4
+
5
+ it "should yield until connection is ready" do
6
+ EventMachine.synchrony do
7
+ connection = EM::Protocols::Redis.connect
8
+ connection.connected.should be_true
9
+
10
+ EventMachine.stop
11
+ end
12
+ end
13
+
14
+ it "should get/set records synchronously" do
15
+ EventMachine.synchrony do
16
+ redis = EM::Protocols::Redis.connect
17
+
18
+ redis.set('a', 'foo')
19
+ redis.get('a').should == 'foo'
20
+ redis.get('c').should == nil
21
+
22
+ EM.stop
23
+ end
24
+ end
25
+
26
+ it "should incr/decr key synchronously" do
27
+ EventMachine.synchrony do
28
+ redis = EM::Protocols::Redis.connect
29
+ redis.delete('key')
30
+
31
+ redis.incr('key')
32
+ redis.get('key').to_i.should == 1
33
+
34
+ redis.decr('key')
35
+ redis.get('key').to_i.should == 0
36
+
37
+ EM.stop
38
+ end
39
+ end
40
+
41
+ it "should execute async commands" do
42
+ EventMachine.synchrony do
43
+ redis = EM::Protocols::Redis.connect
44
+ redis.set('a', 'foobar')
45
+ redis.aget('a') do |response|
46
+ response.should == 'foobar'
47
+ EM.stop
48
+ end
49
+ end
50
+ end
51
+
52
+ it "should execute async set add" do
53
+ EventMachine.synchrony do
54
+ redis = EM::Protocols::Redis.connect
55
+
56
+ redis.asadd('test', 'hai') do
57
+ redis.asadd('test', 'bai') do
58
+ redis.aset_count('test') do |resp|
59
+ resp.to_i.should == 2
60
+ EM.stop
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,20 @@
1
+ require "spec/helper/all"
2
+
3
+ describe EventMachine::Synchrony::TCPSocket do
4
+ it 'connects to a TCP port' do
5
+ EventMachine.synchrony do
6
+ @socket = EventMachine::Synchrony::TCPSocket.new 'eventmachine.rubyforge.org', 80
7
+ @socket.should_not be_error
8
+ EM.stop
9
+ end
10
+ end
11
+
12
+ it 'errors on connection failure' do
13
+ EventMachine.synchrony do
14
+ proc {
15
+ EventMachine::Synchrony::TCPSocket.new 'localhost', 12345
16
+ }.should raise_error(SocketError)
17
+ EM.stop
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 5
9
- version: 0.1.5
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ilya Grigorik
@@ -14,13 +14,13 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-24 00:00:00 -04:00
17
+ date: 2010-10-30 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: eventmachine
22
- prerelease: false
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
@@ -30,47 +30,73 @@ dependencies:
30
30
  - 9
31
31
  version: 0.12.9
32
32
  type: :runtime
33
+ prerelease: false
33
34
  version_requirements: *id001
34
35
  description: Fiber aware EventMachine libraries
35
- email: ilya@igvita.com
36
+ email:
37
+ - ilya@igvita.com
36
38
  executables: []
37
39
 
38
40
  extensions: []
39
41
 
40
- extra_rdoc_files:
41
- - README.md
42
+ extra_rdoc_files: []
43
+
42
44
  files:
45
+ - Gemfile
43
46
  - README.md
44
47
  - Rakefile
45
- - VERSION
48
+ - em-synchrony.gemspec
49
+ - examples/all.rb
50
+ - examples/bitly.rb
51
+ - examples/go/README.md
52
+ - examples/go/channel.go
53
+ - examples/go/channel.rb
54
+ - examples/go/consumer-publisher.go
55
+ - examples/go/consumer-publisher.rb
56
+ - examples/go/go.rb
57
+ - examples/nethttp.rb
46
58
  - lib/em-synchrony.rb
47
59
  - lib/em-synchrony/connection_pool.rb
48
60
  - lib/em-synchrony/em-bitly.rb
49
61
  - lib/em-synchrony/em-http.rb
50
62
  - lib/em-synchrony/em-jack.rb
63
+ - lib/em-synchrony/em-memcache.rb
64
+ - lib/em-synchrony/em-mongo.rb
51
65
  - lib/em-synchrony/em-multi.rb
52
66
  - lib/em-synchrony/em-mysqlplus.rb
67
+ - lib/em-synchrony/em-redis.rb
53
68
  - lib/em-synchrony/em-remcached.rb
54
69
  - lib/em-synchrony/iterator.rb
70
+ - lib/em-synchrony/mongo.rb
71
+ - lib/em-synchrony/mongoid.rb
72
+ - lib/em-synchrony/tcpsocket.rb
73
+ - lib/em-synchrony/thread.rb
55
74
  - spec/beanstalk_spec.rb
56
75
  - spec/connection_pool_spec.rb
76
+ - spec/em-mongo_spec.rb
57
77
  - spec/helper/all.rb
58
78
  - spec/helper/stub-http-server.rb
59
79
  - spec/helper/tolerance_matcher.rb
60
80
  - spec/http_spec.rb
81
+ - spec/inlinesync_spec.rb
61
82
  - spec/iterator_spec.rb
83
+ - spec/memcache_spec.rb
84
+ - spec/mongo_spec.rb
62
85
  - spec/mysqlplus_spec.rb
86
+ - spec/redis_spec.rb
63
87
  - spec/remcached_spec.rb
88
+ - spec/tcpsocket_spec.rb
64
89
  has_rdoc: true
65
90
  homepage: http://github.com/igrigorik/em-synchrony
66
91
  licenses: []
67
92
 
68
93
  post_install_message:
69
- rdoc_options:
70
- - --charset=UTF-8
94
+ rdoc_options: []
95
+
71
96
  require_paths:
72
97
  - lib
73
98
  required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
74
100
  requirements:
75
101
  - - ">="
76
102
  - !ruby/object:Gem::Version
@@ -79,6 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
105
  - 9
80
106
  version: "1.9"
81
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
82
109
  requirements:
83
110
  - - ">="
84
111
  - !ruby/object:Gem::Version
@@ -88,18 +115,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
115
  requirements: []
89
116
 
90
117
  rubyforge_project: em-synchrony
91
- rubygems_version: 1.3.6
118
+ rubygems_version: 1.3.7
92
119
  signing_key:
93
120
  specification_version: 3
94
121
  summary: Fiber aware EventMachine libraries
95
122
  test_files:
96
123
  - spec/beanstalk_spec.rb
97
124
  - spec/connection_pool_spec.rb
125
+ - spec/em-mongo_spec.rb
98
126
  - spec/helper/all.rb
99
127
  - spec/helper/stub-http-server.rb
100
128
  - spec/helper/tolerance_matcher.rb
101
129
  - spec/http_spec.rb
130
+ - spec/inlinesync_spec.rb
102
131
  - spec/iterator_spec.rb
132
+ - spec/memcache_spec.rb
133
+ - spec/mongo_spec.rb
103
134
  - spec/mysqlplus_spec.rb
135
+ - spec/redis_spec.rb
104
136
  - spec/remcached_spec.rb
105
- - examples/all.rb
137
+ - spec/tcpsocket_spec.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.5