em-rocketio-linda-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/History.txt +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +78 -0
- data/Rakefile +14 -0
- data/em-rocketio-linda-client.gemspec +29 -0
- data/lib/em-rocketio-linda-client.rb +15 -0
- data/lib/em-rocketio-linda-client/client.rb +69 -0
- data/lib/em-rocketio-linda-client/version.rb +9 -0
- data/sample/sample.rb +22 -0
- data/test/app.rb +38 -0
- data/test/app/config.ru +14 -0
- data/test/app/main.rb +28 -0
- data/test/test_client_disconnect.rb +54 -0
- data/test/test_em_rocketio_linda_client.rb +159 -0
- data/test/test_helper.rb +6 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b1b67a7956122386c9d98158958c06677447acd
|
4
|
+
data.tar.gz: 5e2694046612f0a8b0bd4cac71e03f6a0fb8cbaa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 507b12f18fca968eac264b77472c29db111ad765ef22a306fb015a98814d3469e177ef07b98af46fcc2712d666d1454c4692b429da6f478b518684f7d1c8c5c1
|
7
|
+
data.tar.gz: b438e51efb1b5e4a5f6dc4a198b6be50872b3377aab8f25b02b84ab97d8ba2c72f066496612f83d2446f454bc2263437adceae70920913cb9f8fa4a56f21a13b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/History.txt
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Sho Hashimoto
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
em-rocketio-linda-client
|
2
|
+
========================
|
3
|
+
[Sinatra::RocketIO::Linda](https://github.com/shokai/sinatra-rocketio-linda) Client for eventmachine
|
4
|
+
|
5
|
+
* https://github.com/shokai/em-rocketio-client-linda
|
6
|
+
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
% gem install em-rocketio-linda-client
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
require 'eventmachine'
|
18
|
+
require 'em-rocketio-linda-client'
|
19
|
+
|
20
|
+
EM::run do
|
21
|
+
linda = EM::RocketIO::Linda::Client.new('http://localhost:5000')
|
22
|
+
ts = linda.tuplespace["test_space"]
|
23
|
+
|
24
|
+
linda.io.on :connect do
|
25
|
+
puts "#{linda.io.type} connect!! (sessin_id:#{linda.io.session})"
|
26
|
+
end
|
27
|
+
|
28
|
+
linda.io.on :disconnect do
|
29
|
+
puts "#{io.type} disconnect"
|
30
|
+
end
|
31
|
+
|
32
|
+
io.on :error do |err|
|
33
|
+
STDERR.puts err
|
34
|
+
end
|
35
|
+
|
36
|
+
## watch Tuples
|
37
|
+
ts.watch [1,2] do |tuple|
|
38
|
+
p tuple
|
39
|
+
end
|
40
|
+
|
41
|
+
## write a Tuple
|
42
|
+
EM::add_periodic_timer 1 do
|
43
|
+
ts.write [1, 2, Time.now]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
|
49
|
+
Sample
|
50
|
+
------
|
51
|
+
|
52
|
+
% ruby sample/sample.rb
|
53
|
+
|
54
|
+
|
55
|
+
Test
|
56
|
+
----
|
57
|
+
|
58
|
+
% gem install bundler
|
59
|
+
% bundle install
|
60
|
+
|
61
|
+
start server
|
62
|
+
|
63
|
+
% export PORT=5000
|
64
|
+
% export WS_PORT=9000
|
65
|
+
% rake test_server
|
66
|
+
|
67
|
+
run test
|
68
|
+
|
69
|
+
% rake test
|
70
|
+
|
71
|
+
|
72
|
+
Contributing
|
73
|
+
------------
|
74
|
+
1. Fork it
|
75
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
76
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
77
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
78
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.pattern = "test/test_*.rb"
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Start test server"
|
9
|
+
task :test_server do
|
10
|
+
require File.expand_path 'test/app', File.dirname(__FILE__)
|
11
|
+
App.start
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :test
|
@@ -0,0 +1,29 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'em-rocketio-linda-client/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "em-rocketio-linda-client"
|
7
|
+
spec.version = EM::RocketIO::Linda::Client::VERSION
|
8
|
+
spec.authors = ["Sho Hashimoto"]
|
9
|
+
spec.email = ["hashimoto@shokai.org"]
|
10
|
+
spec.description = %q{RocketIO Linda client for eventmachine}
|
11
|
+
spec.summary = spec.description
|
12
|
+
spec.homepage = "https://github.com/shokai/em-rocketio-linda-client"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/).reject{|i| i=="Gemfile.lock" }
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "minitest"
|
23
|
+
spec.add_development_dependency "sinatra-rocketio-linda"
|
24
|
+
spec.add_development_dependency "thin"
|
25
|
+
|
26
|
+
spec.add_dependency "em-rocketio-client"
|
27
|
+
spec.add_dependency "eventmachine"
|
28
|
+
spec.add_dependency "event_emitter"
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "eventmachine"
|
2
|
+
require "em-rocketio-client"
|
3
|
+
require "event_emitter"
|
4
|
+
|
5
|
+
require "em-rocketio-linda-client/version"
|
6
|
+
require "em-rocketio-linda-client/client"
|
7
|
+
|
8
|
+
module EM
|
9
|
+
module RocketIO
|
10
|
+
module Linda
|
11
|
+
class Client
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module EM
|
2
|
+
module RocketIO
|
3
|
+
module Linda
|
4
|
+
class Client
|
5
|
+
class Error < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
include EventEmitter
|
9
|
+
attr_reader :io, :tuplespace
|
10
|
+
def initialize(io_or_url)
|
11
|
+
if io_or_url.kind_of? String and io_or_url =~ /^https*:\/\/.+$/
|
12
|
+
@io = ::EM::RocketIO::Client.new(io_or_url).connect
|
13
|
+
elsif io_or_url.kind_of? ::EM::RocketIO::Client
|
14
|
+
@io = io_or_url
|
15
|
+
else
|
16
|
+
raise ArgumentError, "argument must be URL or EM::RocketIO::Client"
|
17
|
+
end
|
18
|
+
@tuplespace = Hash.new{|h,k|
|
19
|
+
h[k] = EM::RocketIO::Linda::Client::TupleSpace.new(k, self)
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
class TupleSpace
|
24
|
+
attr_reader :name, :linda
|
25
|
+
def initialize(name, linda)
|
26
|
+
@name = name
|
27
|
+
@linda = linda
|
28
|
+
end
|
29
|
+
|
30
|
+
def write(tuple, opts={})
|
31
|
+
unless [Hash, Array].include? tuple.class
|
32
|
+
raise ArgumentError, "tuple must be Array or Hash"
|
33
|
+
end
|
34
|
+
@linda.io.push "__linda_write", [@name, tuple, opts]
|
35
|
+
end
|
36
|
+
|
37
|
+
def read(tuple, &block)
|
38
|
+
unless [Hash, Array].include? tuple.class
|
39
|
+
raise ArgumentError, "tuple must be Array or Hash"
|
40
|
+
end
|
41
|
+
callback_id = "#{Time.now.to_i}#{Time.now.usec}"
|
42
|
+
@linda.io.once "__linda_read_callback_#{callback_id}", &block
|
43
|
+
@linda.io.push "__linda_read", [@name, tuple, callback_id]
|
44
|
+
end
|
45
|
+
|
46
|
+
def take(tuple, &block)
|
47
|
+
unless [Hash, Array].include? tuple.class
|
48
|
+
raise ArgumentError, "tuple must be Array or Hash"
|
49
|
+
end
|
50
|
+
callback_id = "#{Time.now.to_i}#{Time.now.usec}"
|
51
|
+
@linda.io.once "__linda_take_callback_#{callback_id}", &block
|
52
|
+
@linda.io.push "__linda_take", [@name, tuple, callback_id]
|
53
|
+
end
|
54
|
+
|
55
|
+
def watch(tuple, &block)
|
56
|
+
unless [Hash, Array].include? tuple.class
|
57
|
+
raise ArgumentError, "tuple must be Array or Hash"
|
58
|
+
end
|
59
|
+
callback_id = "#{Time.now.to_i}#{Time.now.usec}"
|
60
|
+
@linda.io.on "__linda_watch_callback_#{callback_id}", &block
|
61
|
+
@linda.io.push "__linda_watch", [@name, tuple, callback_id]
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/sample/sample.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "rubygems"
|
3
|
+
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
4
|
+
require 'em-rocketio-linda-client'
|
5
|
+
|
6
|
+
EM::run do
|
7
|
+
client = EM::RocketIO::Linda::Client.new "http://linda.shokai.org"
|
8
|
+
ts = client.tuplespace["test_spae"]
|
9
|
+
|
10
|
+
client.io.on :connect do
|
11
|
+
puts "connect #{client.io.type} (#{client.io.session})"
|
12
|
+
|
13
|
+
ts.watch [1,2] do |tuple|
|
14
|
+
p tuple
|
15
|
+
end
|
16
|
+
|
17
|
+
EM::add_periodic_timer 1 do
|
18
|
+
ts.write [1,2, Time.now]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/test/app.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
class App
|
2
|
+
|
3
|
+
def self.running
|
4
|
+
@running ? true : false
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.port
|
8
|
+
ENV['PORT'] || 5000
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.ws_port
|
12
|
+
ENV['WS_PORT'] || 5001
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.url
|
16
|
+
"http://localhost:#{port}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.websocketio_url
|
20
|
+
"ws://localhost:#{ws_port}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.cometio_url
|
24
|
+
"http://localhost:#{port}/cometio/io"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.app_dir
|
28
|
+
File.expand_path 'app', File.dirname(__FILE__)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.start
|
32
|
+
return if running
|
33
|
+
@running = true
|
34
|
+
cmd = "cd #{app_dir} && WS_PORT=#{ws_port} rackup config.ru -p #{port}"
|
35
|
+
system cmd
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/test/app/config.ru
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'sinatra'
|
4
|
+
require 'sinatra/base'
|
5
|
+
$stdout.sync = true
|
6
|
+
$:.unshift File.expand_path '../../lib', File.dirname(__FILE__)
|
7
|
+
require 'sinatra/rocketio'
|
8
|
+
require 'sinatra/rocketio/linda'
|
9
|
+
require File.dirname(__FILE__)+'/main'
|
10
|
+
|
11
|
+
set :linda, :expire_check => 30
|
12
|
+
set :websocketio, :port => ENV['WS_PORT'].to_i
|
13
|
+
|
14
|
+
run TestApp
|
data/test/app/main.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class TestApp < Sinatra::Base
|
2
|
+
register Sinatra::RocketIO
|
3
|
+
io = Sinatra::RocketIO
|
4
|
+
register Sinatra::RocketIO::Linda
|
5
|
+
linda = Sinatra::RocketIO::Linda
|
6
|
+
|
7
|
+
get '/' do
|
8
|
+
"sinatra-rocketio-linda v#{Sinatra::RocketIO::Linda::VERSION}"
|
9
|
+
end
|
10
|
+
|
11
|
+
io.on :connect do |client|
|
12
|
+
puts "new client <session:#{client.session}> <type:#{client.type}>"
|
13
|
+
end
|
14
|
+
|
15
|
+
io.on :disconnect do |client|
|
16
|
+
puts "disconnect client <session:#{client.session}> <type:#{client.type}>"
|
17
|
+
end
|
18
|
+
|
19
|
+
io.on :check_expire do |data, client|
|
20
|
+
puts "check_expire"
|
21
|
+
linda.check_expire
|
22
|
+
end
|
23
|
+
|
24
|
+
io.on :* do |event, data, client|
|
25
|
+
next unless event.to_s =~ /linda/
|
26
|
+
puts "#{event} - #{data} from #{client}"
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path 'test_helper', File.dirname(__FILE__)
|
2
|
+
|
3
|
+
class TestClientDisconnect < MiniTest::Test
|
4
|
+
|
5
|
+
def test_client_disconnect
|
6
|
+
ts_name = "ts_#{Time.now.to_i}_#{Time.now.usec}"
|
7
|
+
_tuple1 = nil
|
8
|
+
_tuple2 = nil
|
9
|
+
_tuple3 = nil
|
10
|
+
_tuple4 = nil
|
11
|
+
|
12
|
+
EM::run do
|
13
|
+
client1 = EM::RocketIO::Linda::Client.new App.url
|
14
|
+
|
15
|
+
client1.io.on :connect do
|
16
|
+
client2 = EM::RocketIO::Linda::Client.new App.url
|
17
|
+
client2.io.on :connect do
|
18
|
+
ts1 = client1.tuplespace[ts_name]
|
19
|
+
ts2 = client2.tuplespace[ts_name]
|
20
|
+
ts1.read [1,2] do |tuple|
|
21
|
+
_tuple1 = tuple
|
22
|
+
end
|
23
|
+
ts1.take [1,2] do |tuple|
|
24
|
+
_tuple2 = tuple
|
25
|
+
end
|
26
|
+
ts1.watch [1,2] do |tuple|
|
27
|
+
_tuple3 = tuple
|
28
|
+
end
|
29
|
+
ts2.take [1,2] do |tuple|
|
30
|
+
_tuple4 = tuple
|
31
|
+
end
|
32
|
+
client1.io.close
|
33
|
+
sleep 3
|
34
|
+
ts2.write [1,2,3]
|
35
|
+
ts2.write [1,2,3,4]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
EM::defer do
|
39
|
+
50.times do
|
40
|
+
sleep 0.1
|
41
|
+
break if _tuple4
|
42
|
+
end
|
43
|
+
EM::add_timer 1 do
|
44
|
+
EM::stop
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
assert_equal _tuple1, nil
|
49
|
+
assert_equal _tuple2, nil
|
50
|
+
assert_equal _tuple3, nil
|
51
|
+
assert_equal _tuple4, [1,2,3]
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require File.expand_path 'test_helper', File.dirname(__FILE__)
|
2
|
+
|
3
|
+
class TestEmRocketIOLindaClient < MiniTest::Test
|
4
|
+
|
5
|
+
def test_write_read_take
|
6
|
+
ts_name = "ts_#{rand Time.now.to_i}"
|
7
|
+
_tuple1 = nil
|
8
|
+
_tuple2 = nil
|
9
|
+
_tuple3 = nil
|
10
|
+
_tuple4 = nil
|
11
|
+
|
12
|
+
EM::run do
|
13
|
+
client = EM::RocketIO::Linda::Client.new App.url
|
14
|
+
ts = client.tuplespace[ts_name]
|
15
|
+
|
16
|
+
client.io.on :connect do
|
17
|
+
ts.write ["rw",1,2,3]
|
18
|
+
ts.write ["rw",1,2,"a"]
|
19
|
+
ts.write ["rw",1,"a",2]
|
20
|
+
ts.take ["rw",1,2] do |tuple|
|
21
|
+
_tuple1 = tuple
|
22
|
+
end
|
23
|
+
ts.read ["rw",1,2] do |tuple|
|
24
|
+
_tuple2 = tuple
|
25
|
+
end
|
26
|
+
ts.take ["rw",1,2] do |tuple|
|
27
|
+
_tuple3 = tuple
|
28
|
+
end
|
29
|
+
client2 = EM::RocketIO::Linda::Client.new App.url
|
30
|
+
ts2 = client2.tuplespace[ts_name]
|
31
|
+
client2.io.on :connect do
|
32
|
+
ts2.take ["rw",1] do |tuple|
|
33
|
+
_tuple4 = tuple
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
EM::defer do
|
39
|
+
50.times do
|
40
|
+
sleep 0.1
|
41
|
+
break if _tuple4
|
42
|
+
end
|
43
|
+
EM::add_timer 1 do
|
44
|
+
EM::stop
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
assert_equal _tuple1, ["rw",1,2,"a"] # take
|
49
|
+
assert_equal _tuple2, ["rw",1,2,3] # read
|
50
|
+
assert_equal _tuple3, ["rw",1,2,3] # take
|
51
|
+
assert_equal _tuple4, ["rw",1,"a",2]
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_watch
|
55
|
+
results = []
|
56
|
+
_tuple1 = nil
|
57
|
+
_tuple2 = nil
|
58
|
+
EM::run do
|
59
|
+
client = EM::RocketIO::Linda::Client.new App.url
|
60
|
+
ts = client.tuplespace["ts_#{rand Time.now.to_i}"]
|
61
|
+
client.io.on :connect do
|
62
|
+
ts.take ["watch",1,2] do |tuple|
|
63
|
+
_tuple1 = tuple
|
64
|
+
end
|
65
|
+
ts.read ["watch",1,2] do |tuple|
|
66
|
+
_tuple2 = tuple
|
67
|
+
end
|
68
|
+
ts.watch ["watch",1,2] do |tuple|
|
69
|
+
results.push tuple
|
70
|
+
end
|
71
|
+
ts.write ["watch",1,2,3]
|
72
|
+
ts.write ["watch",1,"a",2]
|
73
|
+
ts.write ["watch",1,2,3,4]
|
74
|
+
end
|
75
|
+
|
76
|
+
EM::defer do
|
77
|
+
50.times do
|
78
|
+
sleep 0.1
|
79
|
+
break if _tuple1 != nil and _tuple2 != nil
|
80
|
+
end
|
81
|
+
EM::add_timer 1 do
|
82
|
+
EM::stop
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
assert_equal _tuple1, ["watch",1,2,3]
|
87
|
+
assert_equal _tuple2, ["watch",1,2,3,4]
|
88
|
+
assert_equal results.size, 2
|
89
|
+
assert_equal results[0], ["watch",1,2,3]
|
90
|
+
assert_equal results[1], ["watch",1,2,3,4]
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_tuplespaces
|
94
|
+
_tuple1 = nil
|
95
|
+
_tuple2 = nil
|
96
|
+
|
97
|
+
EM::run do
|
98
|
+
client = EM::RocketIO::Linda::Client.new App.url
|
99
|
+
ts1 = client.tuplespace["ts1_#{rand Time.now.to_i}"]
|
100
|
+
ts2 = client.tuplespace["ts2_#{rand Time.now.to_i}"]
|
101
|
+
|
102
|
+
client.io.on :connect do
|
103
|
+
ts2.take ["a"] do |tuple|
|
104
|
+
_tuple2 = tuple
|
105
|
+
end
|
106
|
+
ts1.take [1] do |tuple|
|
107
|
+
_tuple1 = tuple
|
108
|
+
end
|
109
|
+
ts1.write [1,2,3]
|
110
|
+
ts2.write ["a","b","c"]
|
111
|
+
end
|
112
|
+
EM::defer do
|
113
|
+
50.times do
|
114
|
+
sleep 0.1
|
115
|
+
break if _tuple1
|
116
|
+
end
|
117
|
+
EM::add_timer 1 do
|
118
|
+
EM::stop
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
assert_equal _tuple1, [1,2,3]
|
123
|
+
assert_equal _tuple2, ["a","b","c"]
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_tuple_expire
|
127
|
+
_tuple1 = nil
|
128
|
+
_tuple2 = nil
|
129
|
+
EM::run do
|
130
|
+
client = EM::RocketIO::Linda::Client.new App.url
|
131
|
+
ts = client.tuplespace["ts_#{rand Time.now.to_i}"]
|
132
|
+
|
133
|
+
client.io.on :connect do
|
134
|
+
ts.write ["expire",1,2,999], :expire => false
|
135
|
+
ts.write ["expire",1,2,3], :expire => 10
|
136
|
+
ts.write ["expire",1,2,"a","b"], :expire => 2
|
137
|
+
ts.read ["expire",1,2] do |tuple|
|
138
|
+
_tuple1 = tuple
|
139
|
+
end
|
140
|
+
sleep 3
|
141
|
+
push :check_expire, nil
|
142
|
+
ts.read ["expire",1,2] do |tuple|
|
143
|
+
_tuple2 = tuple
|
144
|
+
end
|
145
|
+
end
|
146
|
+
EM::defer do
|
147
|
+
50.times do
|
148
|
+
sleep 0.1
|
149
|
+
break if _tuple2
|
150
|
+
end
|
151
|
+
EM::add_timer 1 do
|
152
|
+
EM::stop
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
assert_equal _tuple1, ["expire",1,2,"a","b"]
|
157
|
+
assert_equal _tuple2, ["expire",1,2,3]
|
158
|
+
end
|
159
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-rocketio-linda-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sho Hashimoto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sinatra-rocketio-linda
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thin
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: em-rocketio-client
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: eventmachine
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: event_emitter
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: RocketIO Linda client for eventmachine
|
126
|
+
email:
|
127
|
+
- hashimoto@shokai.org
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- .gitignore
|
133
|
+
- Gemfile
|
134
|
+
- History.txt
|
135
|
+
- LICENSE.txt
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- em-rocketio-linda-client.gemspec
|
139
|
+
- lib/em-rocketio-linda-client.rb
|
140
|
+
- lib/em-rocketio-linda-client/client.rb
|
141
|
+
- lib/em-rocketio-linda-client/version.rb
|
142
|
+
- sample/sample.rb
|
143
|
+
- test/app.rb
|
144
|
+
- test/app/config.ru
|
145
|
+
- test/app/main.rb
|
146
|
+
- test/test_client_disconnect.rb
|
147
|
+
- test/test_em_rocketio_linda_client.rb
|
148
|
+
- test/test_helper.rb
|
149
|
+
homepage: https://github.com/shokai/em-rocketio-linda-client
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
metadata: {}
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 2.0.3
|
170
|
+
signing_key:
|
171
|
+
specification_version: 4
|
172
|
+
summary: RocketIO Linda client for eventmachine
|
173
|
+
test_files:
|
174
|
+
- test/app.rb
|
175
|
+
- test/app/config.ru
|
176
|
+
- test/app/main.rb
|
177
|
+
- test/test_client_disconnect.rb
|
178
|
+
- test/test_em_rocketio_linda_client.rb
|
179
|
+
- test/test_helper.rb
|
180
|
+
has_rdoc:
|