ichannel 7.0.0 → 7.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -2
- data/ChangeLog.txt +7 -0
- data/README.md +10 -10
- data/lib/ichannel/redis.rb +0 -1
- data/lib/ichannel/unix_socket.rb +0 -1
- data/lib/ichannel/version.rb +1 -1
- data/test/ichannel_redis_test.rb +5 -2
- data/test/ichannel_unix_test.rb +6 -106
- data/test/setup.rb +1 -0
- data/test/uniform_ichannel_test.rb +111 -0
- metadata +6 -4
data/.travis.yml
CHANGED
data/ChangeLog.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== v7.1.0
|
2
|
+
- Redis#last_msg, UNIXSocket#last_msg return last read value
|
3
|
+
after a channel has been closed.
|
4
|
+
The old behavior was to return nil. I'm not sure why I decided to
|
5
|
+
do that but it's not useful.
|
6
|
+
|
7
|
+
|
1
8
|
== v7.0.0
|
2
9
|
- IChannel::UNIXSocket#get! raises Timeout::Error
|
3
10
|
When a read does not complete in time a Timeout::Error will be
|
data/README.md
CHANGED
@@ -16,8 +16,8 @@ the same machine or network. The basic premise is that you can "put" a ruby
|
|
16
16
|
object onto the channel and on the other end(maybe in a different process,
|
17
17
|
or maybe on a different machine) you can "get" the object from the channel.
|
18
18
|
A [unix socket](http://www.ruby-doc.org/stdlib-2.0/libdoc/socket/rdoc/UNIXSocket.html)
|
19
|
-
(local to a single machine)
|
20
|
-
|
19
|
+
(local to a single machine) or [redis](https://redis.io) can be used for
|
20
|
+
storage.
|
21
21
|
|
22
22
|
A channel depends on a serializer when reading and writing from the underlying
|
23
23
|
socket(e.g: redis or a unix socket) but you can use any serializer that
|
@@ -32,7 +32,7 @@ __1.__
|
|
32
32
|
|
33
33
|
A demo of how to pass ruby objects through a channel and also between processes.
|
34
34
|
[Marshal](http://rubydoc.info/stdlib/core/Marshal) is the serializer of choice,
|
35
|
-
and a streamed UNIXSocket is used for
|
35
|
+
and a streamed UNIXSocket is used for storage:
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
channel = IChannel.unix Marshal
|
@@ -47,7 +47,7 @@ channel.get # => 'Hello!'
|
|
47
47
|
__2.__
|
48
48
|
|
49
49
|
A demo of a channel sending messages between machines by using
|
50
|
-
[redis](https://redis.io) for
|
50
|
+
[redis](https://redis.io) for storage:
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
channel = IChannel.redis Marshal, host: "10.0.0.1", key: "readme-example"
|
@@ -99,12 +99,12 @@ __PLATFORM SUPPORT__
|
|
99
99
|
|
100
100
|
_supported_
|
101
101
|
|
102
|
-
* CRuby (1.9+)
|
103
|
-
* Rubinius (1.9+)
|
102
|
+
* CRuby (1.9+)
|
103
|
+
* Rubinius (1.9+)
|
104
104
|
* JRuby (1.9+ - some tests skipped)
|
105
|
-
JRuby is supported and passes the test suite but it
|
106
|
-
|
107
|
-
|
105
|
+
JRuby is supported and passes the test suite but it skips any
|
106
|
+
tests(three/four) that invoke Kernel#fork. The other tests pass
|
107
|
+
on jruby, and those tests cover unix sockets/redis.
|
108
108
|
|
109
109
|
_unsupported_
|
110
110
|
|
@@ -114,7 +114,7 @@ _unsupported_
|
|
114
114
|
__INSTALL__
|
115
115
|
|
116
116
|
If you plan on using redis you'll need to install the 'redis' gem. It's
|
117
|
-
optional:
|
117
|
+
optional and only loaded when `IChannel.redis` is invoked:
|
118
118
|
|
119
119
|
$ gem install redis
|
120
120
|
|
data/lib/ichannel/redis.rb
CHANGED
data/lib/ichannel/unix_socket.rb
CHANGED
data/lib/ichannel/version.rb
CHANGED
data/test/ichannel_redis_test.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require_relative 'setup'
|
2
|
-
|
3
|
-
|
2
|
+
class IChannelRedisTest < Test::Unit::TestCase
|
3
|
+
# This includes the tests all channels should pass(redis or unix
|
4
|
+
# socket). Any tests specific to redis can go in this class.
|
5
|
+
include UniformIChannelTest
|
6
|
+
|
4
7
|
def setup
|
5
8
|
serializer = Object.const_get ENV["SERIALIZER"] || "Marshal"
|
6
9
|
@channel = IChannel.redis serializer
|
data/test/ichannel_unix_test.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
require_relative
|
2
|
-
class
|
1
|
+
require_relative "setup"
|
2
|
+
class IChannelTest < Test::Unit::TestCase
|
3
|
+
# This includes the tests all channels should pass(redis or unix
|
4
|
+
# socket). Any tests specific to a unit socket can go in this class.
|
5
|
+
include UniformIChannelTest
|
6
|
+
|
3
7
|
def setup
|
4
8
|
serializer = Object.const_get ENV["SERIALIZER"] || "Marshal"
|
5
9
|
@channel = IChannel.unix serializer
|
@@ -8,108 +12,4 @@ class IChannelUNIXTest < Test::Unit::TestCase
|
|
8
12
|
def teardown
|
9
13
|
@channel.close
|
10
14
|
end
|
11
|
-
|
12
|
-
def test_interface
|
13
|
-
%w(write
|
14
|
-
write!
|
15
|
-
get
|
16
|
-
get!
|
17
|
-
close
|
18
|
-
closed?
|
19
|
-
readable?
|
20
|
-
last_msg
|
21
|
-
put
|
22
|
-
put!
|
23
|
-
recv
|
24
|
-
recv!).each do |method|
|
25
|
-
assert @channel.respond_to? method
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_blocking_get
|
30
|
-
assert_raises Timeout::Error do
|
31
|
-
Timeout.timeout(1) { @channel.get }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_timeout_on_get
|
36
|
-
assert_raises Timeout::Error do
|
37
|
-
@channel.get! 0.1
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_last_msg_after_read
|
42
|
-
@channel.put [42]
|
43
|
-
@channel.get
|
44
|
-
assert_equal [42], @channel.last_msg
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_fork
|
48
|
-
if RUBY_ENGINE == "jruby"
|
49
|
-
skip "jruby does not implement Kernel.fork"
|
50
|
-
end
|
51
|
-
pid = fork do
|
52
|
-
@channel.put [42]
|
53
|
-
end
|
54
|
-
Process.wait pid
|
55
|
-
assert_equal [42], @channel.get
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_last_msg
|
59
|
-
@channel.put %w(a)
|
60
|
-
@channel.put %w(b)
|
61
|
-
assert_equal %w(b), @channel.last_msg
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_last_msg_cache
|
65
|
-
@channel.put %w(a)
|
66
|
-
2.times { assert_equal %w(a), @channel.last_msg }
|
67
|
-
@channel.close
|
68
|
-
assert_equal nil, @channel.last_msg
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_bust_last_msg_cache
|
72
|
-
@channel.put %w(a)
|
73
|
-
assert_equal %w(a), @channel.last_msg
|
74
|
-
@channel.put %w(b)
|
75
|
-
2.times { assert_equal %w(b), @channel.last_msg }
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_put_on_closed_channel
|
79
|
-
@channel.close
|
80
|
-
assert_raises IOError do
|
81
|
-
@channel.put %w(a)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_get_on_closed_channel
|
86
|
-
@channel.close
|
87
|
-
assert_raises IOError do
|
88
|
-
@channel.get
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_queued_messages
|
93
|
-
@channel.put %w(a)
|
94
|
-
@channel.put %w(b)
|
95
|
-
assert_equal %w(a), @channel.get
|
96
|
-
assert_equal %w(b), @channel.get
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_readable_on_populated_channel
|
100
|
-
@channel.put %w(a)
|
101
|
-
@channel.put %w(b)
|
102
|
-
assert @channel.readable?
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_readable_on_empty_channel
|
106
|
-
@channel.put %w(42)
|
107
|
-
@channel.get # discard
|
108
|
-
refute @channel.readable?
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_readable_on_closed_channel
|
112
|
-
@channel.close
|
113
|
-
refute @channel.readable?
|
114
|
-
end
|
115
15
|
end
|
data/test/setup.rb
CHANGED
@@ -0,0 +1,111 @@
|
|
1
|
+
#
|
2
|
+
# These are the tests any ichannel-like interface should pass.
|
3
|
+
# The redis and unix socket channel are tested against all these
|
4
|
+
# tests.
|
5
|
+
#
|
6
|
+
require_relative 'setup'
|
7
|
+
module UniformIChannelTest
|
8
|
+
def test_interface
|
9
|
+
%w(write
|
10
|
+
write!
|
11
|
+
get
|
12
|
+
get!
|
13
|
+
close
|
14
|
+
closed?
|
15
|
+
readable?
|
16
|
+
last_msg
|
17
|
+
put
|
18
|
+
put!
|
19
|
+
recv
|
20
|
+
recv!).each do |method|
|
21
|
+
assert @channel.respond_to? method
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_blocking_get
|
26
|
+
assert_raises Timeout::Error do
|
27
|
+
Timeout.timeout(1) { @channel.get }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_timeout_on_get
|
32
|
+
assert_raises Timeout::Error do
|
33
|
+
@channel.get! 0.1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_last_msg_after_read
|
38
|
+
@channel.put [42]
|
39
|
+
@channel.get
|
40
|
+
assert_equal [42], @channel.last_msg
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_fork
|
44
|
+
if RUBY_ENGINE == "jruby"
|
45
|
+
skip "jruby does not implement Kernel.fork"
|
46
|
+
end
|
47
|
+
pid = fork do
|
48
|
+
@channel.put [42]
|
49
|
+
end
|
50
|
+
Process.wait pid
|
51
|
+
assert_equal [42], @channel.get
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_last_msg
|
55
|
+
@channel.put %w(a)
|
56
|
+
@channel.put %w(b)
|
57
|
+
assert_equal %w(b), @channel.last_msg
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_last_msg_cache
|
61
|
+
@channel.put %w(a)
|
62
|
+
2.times { assert_equal %w(a), @channel.last_msg }
|
63
|
+
@channel.close
|
64
|
+
assert_equal %w(a), @channel.last_msg
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_bust_last_msg_cache
|
68
|
+
@channel.put %w(a)
|
69
|
+
assert_equal %w(a), @channel.last_msg
|
70
|
+
@channel.put %w(b)
|
71
|
+
2.times { assert_equal %w(b), @channel.last_msg }
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_put_on_closed_channel
|
75
|
+
@channel.close
|
76
|
+
assert_raises IOError do
|
77
|
+
@channel.put %w(a)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_get_on_closed_channel
|
82
|
+
@channel.close
|
83
|
+
assert_raises IOError do
|
84
|
+
@channel.get
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_queued_messages
|
89
|
+
@channel.put %w(a)
|
90
|
+
@channel.put %w(b)
|
91
|
+
assert_equal %w(a), @channel.get
|
92
|
+
assert_equal %w(b), @channel.get
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_readable_on_populated_channel
|
96
|
+
@channel.put %w(a)
|
97
|
+
@channel.put %w(b)
|
98
|
+
assert @channel.readable?
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_readable_on_empty_channel
|
102
|
+
@channel.put %w(42)
|
103
|
+
@channel.get # discard
|
104
|
+
refute @channel.readable?
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_readable_on_closed_channel
|
108
|
+
@channel.close
|
109
|
+
refute @channel.readable?
|
110
|
+
end
|
111
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ichannel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07
|
12
|
+
date: 2013-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: interprocess communication channel
|
15
15
|
email:
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- test/ichannel_redis_test.rb
|
38
38
|
- test/ichannel_unix_test.rb
|
39
39
|
- test/setup.rb
|
40
|
+
- test/uniform_ichannel_test.rb
|
40
41
|
homepage: https://github.com/robgleeson/ichannel
|
41
42
|
licenses: []
|
42
43
|
post_install_message:
|
@@ -51,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
52
|
version: '0'
|
52
53
|
segments:
|
53
54
|
- 0
|
54
|
-
hash:
|
55
|
+
hash: 3208859644147126315
|
55
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
57
|
none: false
|
57
58
|
requirements:
|
@@ -60,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
61
|
version: '0'
|
61
62
|
segments:
|
62
63
|
- 0
|
63
|
-
hash:
|
64
|
+
hash: 3208859644147126315
|
64
65
|
requirements: []
|
65
66
|
rubyforge_project:
|
66
67
|
rubygems_version: 1.8.23
|
@@ -71,4 +72,5 @@ test_files:
|
|
71
72
|
- test/ichannel_redis_test.rb
|
72
73
|
- test/ichannel_unix_test.rb
|
73
74
|
- test/setup.rb
|
75
|
+
- test/uniform_ichannel_test.rb
|
74
76
|
has_rdoc:
|