linda 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 +115 -0
- data/Rakefile +8 -0
- data/lib/linda/tuple.rb +39 -0
- data/lib/linda/tuplespace.rb +119 -0
- data/lib/linda/version.rb +3 -0
- data/lib/linda.rb +6 -0
- data/linda.gemspec +24 -0
- data/test/test_helper.rb +5 -0
- data/test/test_tuple.rb +53 -0
- data/test/test_tuplespace.rb +132 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 146404ba1cf1f376a8754616b292b0ff61e31bad
|
4
|
+
data.tar.gz: d1a42ff0cd3844a5c284651535f92b6ae1db37df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 155875330105acc2169853d1a52a8c2f7847997a0e0249d246e4df97f9950a26371ebfe90d8db05272146e46e2d703b65e6cbf9b1c48c6bd60ac32f07dad37e1
|
7
|
+
data.tar.gz: 3f7fa331981194463618bb2c9df007e6ea57727efc59da57d46d8cd39232408bc3bbb98df2e7fd82b3e45b42c55d04b97286f102d9bc85bb660b0068d7d00ffd
|
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,115 @@
|
|
1
|
+
Linda
|
2
|
+
=====
|
3
|
+
Tuple and TupleSpace implementation of Linda
|
4
|
+
|
5
|
+
- https://github.com/shokai/linda-ruby
|
6
|
+
- https://rubygems.org/gems/linda
|
7
|
+
|
8
|
+
|
9
|
+
Installation
|
10
|
+
------------
|
11
|
+
|
12
|
+
% gem install linda
|
13
|
+
|
14
|
+
|
15
|
+
Linda
|
16
|
+
-----
|
17
|
+
Linda is a coordination launguage for parallel programming.
|
18
|
+
|
19
|
+
- http://en.wikipedia.org/wiki/Linda_(coordination_language)
|
20
|
+
- http://ja.wikipedia.org/wiki/Linda
|
21
|
+
|
22
|
+
|
23
|
+
Usage
|
24
|
+
-----
|
25
|
+
Linda rubygem provides
|
26
|
+
|
27
|
+
- on-memory Tuple/TupleSpace implementation
|
28
|
+
- common tests for your Linda implementation, such as using KVS or RDB
|
29
|
+
|
30
|
+
[Sinatra::RocketIO::Linda](http://rubygems.org/gems/sinatra-rocketio-linda) is using Linda rubygem inside.
|
31
|
+
|
32
|
+
|
33
|
+
Tuple Matching
|
34
|
+
--------------
|
35
|
+
Array Tuple `[1, 2, 3]`
|
36
|
+
|
37
|
+
- matches `[1, 2, 3]`
|
38
|
+
- matches `[1, 2, 3, 4]`
|
39
|
+
- matches `[1, 2, 3, "a"]`
|
40
|
+
- NOT matches `[1, 2, "a"]`
|
41
|
+
- NOT matches `[2, 1, 3]`
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Linda::Tuple.new([1, 2]).match? [1, 2, 3] # => true
|
45
|
+
Linda::Tuple.new([1, 2]).match? [1, "a"] # => false
|
46
|
+
```
|
47
|
+
|
48
|
+
Hash Tuple {:a => 1, :b => 2}
|
49
|
+
|
50
|
+
- matches `{:a => 1, :b => 2}`
|
51
|
+
- matches `{:a => 1, :b => 2, :c => 3}`
|
52
|
+
- matches `{:a => 1, :b => 2, :name => "shokai"}`
|
53
|
+
- NOT matches `{:a => 1, :b => 5}`
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
Linda::Tuple.new(:a => 1, :b => 2).match?(:a => 1, :b => 2, :name => "shokai") # => true
|
57
|
+
Linda::Tuple.new(:a => 1, :b => 2).match?(:a => 1, :b => 5) # => false
|
58
|
+
```
|
59
|
+
|
60
|
+
Tuple/TupleSpace Functions
|
61
|
+
--------------------------
|
62
|
+
|
63
|
+
### TupleSpace#write( tuple, options={} )
|
64
|
+
|
65
|
+
- write a Tuple into TupleSpace.
|
66
|
+
- default : options = {:expire => 300}
|
67
|
+
- expire 300(sec) after.
|
68
|
+
- similar to `out` function in C-Linda.
|
69
|
+
|
70
|
+
### TupleSpace#read( tuple )
|
71
|
+
|
72
|
+
- return a Tuple which matches in TupleSpace. return `nil` if not exists.
|
73
|
+
- similar to `rdp` function in C-Linda.
|
74
|
+
|
75
|
+
|
76
|
+
### TupleSpace#read( tuple, &callback(tuple) )
|
77
|
+
|
78
|
+
- callback a Tuple which matches in TupleSpace. wait until available.
|
79
|
+
- async function : it does not return a value.
|
80
|
+
- similar to `rd` function in C-Linda.
|
81
|
+
|
82
|
+
|
83
|
+
### TupleSpace#take( tuple )
|
84
|
+
|
85
|
+
- delete a Tuple, then return it which matches in TupleSpace. return `nil` if not exists.
|
86
|
+
- similar to `inp` function in C-Linda.
|
87
|
+
|
88
|
+
|
89
|
+
### TupleSpace#take( tuple, &callback(tuple) )
|
90
|
+
|
91
|
+
- delete a Tuple, then callback it which matches in TupleSpace. wait until available.
|
92
|
+
- async function : it does not return a value.
|
93
|
+
- similar to `in` function in C-Linda.
|
94
|
+
|
95
|
+
|
96
|
+
### TupleSpace#watch( tuple, &callback(tuple) )
|
97
|
+
|
98
|
+
- callback Tuples which matches when TupleSpace#write(tuple) is called.
|
99
|
+
|
100
|
+
|
101
|
+
Test
|
102
|
+
----
|
103
|
+
|
104
|
+
% gem install bundler
|
105
|
+
% bundle install
|
106
|
+
% rake test
|
107
|
+
|
108
|
+
|
109
|
+
Contributing
|
110
|
+
------------
|
111
|
+
1. Fork it
|
112
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
113
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
114
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
115
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/linda/tuple.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Linda
|
2
|
+
|
3
|
+
class Tuple
|
4
|
+
attr_reader :data, :type, :expire_at
|
5
|
+
def initialize(data, opts={})
|
6
|
+
unless data.kind_of? Array or data.kind_of? Hash
|
7
|
+
raise ArgumentError, 'argument must be instance of Array or Hash'
|
8
|
+
end
|
9
|
+
@data = data
|
10
|
+
@type = data.class
|
11
|
+
if opts[:expire].class == Fixnum and opts[:expire] > 0
|
12
|
+
@expire_at = Time.now + opts[:expire]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def match?(target)
|
17
|
+
target = self.class.new target unless target.kind_of? self.class
|
18
|
+
return false if @type != target.type
|
19
|
+
if @type == Array
|
20
|
+
return false if @data.length > target.data.length
|
21
|
+
@data.each_with_index do |v,i|
|
22
|
+
return false if target.data[i] != v
|
23
|
+
end
|
24
|
+
return true
|
25
|
+
elsif @type == Hash
|
26
|
+
@data.each do |k,v|
|
27
|
+
return false if target.data[k] != v
|
28
|
+
end
|
29
|
+
return true
|
30
|
+
end
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
@data.to_s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
module Linda
|
2
|
+
|
3
|
+
class TupleSpace
|
4
|
+
include Enumerable
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(name="__default__")
|
8
|
+
@name = name
|
9
|
+
@tuples = Array.new
|
10
|
+
@callbacks = Array.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def each(&block)
|
14
|
+
@tuples.each do |tp|
|
15
|
+
yield tp
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove_callback(callback)
|
20
|
+
@callbacks.delete callback
|
21
|
+
end
|
22
|
+
|
23
|
+
def size
|
24
|
+
@tuples.size
|
25
|
+
end
|
26
|
+
|
27
|
+
DEFAULT_WRITE_OPTIONS = {
|
28
|
+
:expire => 300
|
29
|
+
}
|
30
|
+
|
31
|
+
def write(tuple, opts={})
|
32
|
+
raise ArgumentError, "options must be Hash" unless opts.kind_of? Hash
|
33
|
+
DEFAULT_WRITE_OPTIONS.each do |k,v|
|
34
|
+
opts[k] = v unless opts.include? k
|
35
|
+
end
|
36
|
+
tuple = Tuple.new tuple, opts unless tuple.kind_of? Tuple
|
37
|
+
calleds = []
|
38
|
+
taked = nil
|
39
|
+
@callbacks.each do |callback|
|
40
|
+
next unless callback[:tuple].match? tuple
|
41
|
+
callback[:callback].call tuple
|
42
|
+
calleds.push callback unless callback[:type] == :watch
|
43
|
+
if callback[:type] == :take
|
44
|
+
taked = tuple
|
45
|
+
break
|
46
|
+
end
|
47
|
+
end
|
48
|
+
calleds.each do |called|
|
49
|
+
@callbacks.delete called
|
50
|
+
end
|
51
|
+
@tuples.unshift tuple unless taked
|
52
|
+
tuple
|
53
|
+
end
|
54
|
+
|
55
|
+
def read(tuple, &block)
|
56
|
+
tuple = Tuple.new tuple unless tuple.kind_of? Tuple
|
57
|
+
@tuples.each do |t|
|
58
|
+
if tuple.match? t
|
59
|
+
if block_given?
|
60
|
+
block.call t
|
61
|
+
return
|
62
|
+
else
|
63
|
+
return t
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
if block_given?
|
68
|
+
callback = {:type => :read, :callback => block, :tuple => tuple}
|
69
|
+
@callbacks.push callback
|
70
|
+
return callback
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def take(tuple, &block)
|
75
|
+
tuple = Tuple.new tuple unless tuple.kind_of? Tuple
|
76
|
+
matched_tuple = nil
|
77
|
+
@tuples.each do |t|
|
78
|
+
if tuple.match? t
|
79
|
+
matched_tuple = t
|
80
|
+
break
|
81
|
+
end
|
82
|
+
end
|
83
|
+
if matched_tuple
|
84
|
+
@tuples.delete matched_tuple
|
85
|
+
if block_given?
|
86
|
+
block.call matched_tuple
|
87
|
+
else
|
88
|
+
return matched_tuple
|
89
|
+
end
|
90
|
+
else
|
91
|
+
if block_given?
|
92
|
+
callback = {:type => :take, :callback => block, :tuple => tuple}
|
93
|
+
@callbacks.push callback
|
94
|
+
return callback
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def watch(tuple, &block)
|
100
|
+
raise ArgumentError, "block not given" unless block_given?
|
101
|
+
tuple = Tuple.new tuple unless tuple.kind_of? Tuple
|
102
|
+
callback = {:type => :watch, :callback => block, :tuple => tuple}
|
103
|
+
@callbacks.unshift callback
|
104
|
+
callback
|
105
|
+
end
|
106
|
+
|
107
|
+
def check_expire
|
108
|
+
expires = []
|
109
|
+
self.each do |tuple|
|
110
|
+
expires.push(tuple) if tuple.expire_at and tuple.expire_at < Time.now
|
111
|
+
end
|
112
|
+
expires.each do |tuple|
|
113
|
+
@tuples.delete tuple
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
data/lib/linda.rb
ADDED
data/linda.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'linda/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "linda"
|
8
|
+
spec.version = Linda::VERSION
|
9
|
+
spec.authors = ["Sho Hashimoto"]
|
10
|
+
spec.email = ["hashimoto@shokai.org"]
|
11
|
+
spec.description = %q{Tuple and TupleSpace implementation of Linda - coordinational language for parallel processing}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = "https://github.com/shokai/linda-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/).reject{|i| i == "Gemfile.lock" }
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/test_tuple.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path 'test_helper', File.dirname(__FILE__)
|
2
|
+
|
3
|
+
class TestTuple < MiniTest::Test
|
4
|
+
def test_match_array_tuple
|
5
|
+
tuple = Linda::Tuple.new [1,2,3]
|
6
|
+
assert tuple.match? Linda::Tuple.new [1,2,3]
|
7
|
+
assert tuple.match? Linda::Tuple.new [1,2,3,4]
|
8
|
+
assert !tuple.match?(Linda::Tuple.new [1,2])
|
9
|
+
assert !tuple.match?(Linda::Tuple.new [1,"a",3])
|
10
|
+
assert !tuple.match?(Linda::Tuple.new :a => 1, :b => 2)
|
11
|
+
tuple = Linda::Tuple.new ["a","b","c"]
|
12
|
+
assert tuple.match? Linda::Tuple.new ["a","b","c"]
|
13
|
+
assert tuple.match? Linda::Tuple.new ["a","b","c","d","efg",123,"h"]
|
14
|
+
assert !tuple.match?(Linda::Tuple.new ["a","b"])
|
15
|
+
assert !tuple.match?(Linda::Tuple.new ["a","b",789])
|
16
|
+
assert !tuple.match?(Linda::Tuple.new :foo => 1, :bar => 2)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_match_array
|
20
|
+
tuple = Linda::Tuple.new [1,2,3]
|
21
|
+
assert tuple.match? [1,2,3]
|
22
|
+
assert tuple.match? [1,2,3,4]
|
23
|
+
assert !tuple.match?([1,2])
|
24
|
+
assert !tuple.match?([1,"a",3])
|
25
|
+
assert !tuple.match?(:a => 1, :b => 2)
|
26
|
+
tuple = Linda::Tuple.new ["a","b","c"]
|
27
|
+
assert tuple.match? ["a","b","c"]
|
28
|
+
assert tuple.match? ["a","b","c","d","efg",123,"h"]
|
29
|
+
assert !tuple.match?(["a","b"])
|
30
|
+
assert !tuple.match?(["a","b",789])
|
31
|
+
assert !tuple.match?(:foo => 1, :bar => 2)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_match_hash_tuple
|
35
|
+
tuple = Linda::Tuple.new :a => 1, :b => 2
|
36
|
+
assert tuple.match? Linda::Tuple.new :a => 1, :b => 2
|
37
|
+
assert tuple.match? Linda::Tuple.new :a => 1, :b => 2, :c => 3
|
38
|
+
assert tuple.match? Linda::Tuple.new :a => 1, :b => 2, :c => {:foo => "bar"}
|
39
|
+
assert !tuple.match?(Linda::Tuple.new :a => 0, :b => 2)
|
40
|
+
assert !tuple.match?(Linda::Tuple.new :b => 2, :c => 3)
|
41
|
+
assert !tuple.match?(Linda::Tuple.new [1,2,3])
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_match_hash
|
45
|
+
tuple = Linda::Tuple.new :a => 1, :b => 2
|
46
|
+
assert tuple.match? :a => 1, :b => 2
|
47
|
+
assert tuple.match? :a => 1, :b => 2, :c => 3
|
48
|
+
assert tuple.match? :a => 1, :b => 2, :c => {:foo => "bar"}
|
49
|
+
assert !tuple.match?(:a => 0, :b => 2)
|
50
|
+
assert !tuple.match?(:b => 2, :c => 3)
|
51
|
+
assert !tuple.match?([1,2,3])
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require File.expand_path 'test_helper', File.dirname(__FILE__)
|
2
|
+
|
3
|
+
class TestTupleSpace < MiniTest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@space = Linda::TupleSpace.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_write_read
|
10
|
+
assert_equal @space.size, 0
|
11
|
+
@space.write Linda::Tuple.new [1,2,3]
|
12
|
+
assert_equal @space.size, 1
|
13
|
+
assert_equal @space.read([1,2]).data, [1,2,3]
|
14
|
+
@space.write :a => 1, :b => 2, :c => 999
|
15
|
+
@space.write :a => 1, :b => 2, :c => 3
|
16
|
+
assert_equal @space.size, 3
|
17
|
+
assert_equal @space.read(:a => 1, :c => 999).data, {:a => 1, :b => 2, :c => 999}
|
18
|
+
assert_equal @space.read(:a => 1, :c => 999).data, {:a => 1, :b => 2, :c => 999}
|
19
|
+
assert_equal @space.read(:a => 1).data, {:a => 1, :b => 2, :c => 3}
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_write_read_callback
|
23
|
+
assert_equal @space.size, 0
|
24
|
+
_tuple1 = nil
|
25
|
+
@space.read [1,2] do |tuple|
|
26
|
+
_tuple1 = tuple
|
27
|
+
end
|
28
|
+
_tuple2 = nil
|
29
|
+
@space.read [1,"a"] do |tuple|
|
30
|
+
_tuple2 = tuple
|
31
|
+
end
|
32
|
+
_tuple3 = nil
|
33
|
+
@space.read [1,2,3] do |tuple|
|
34
|
+
_tuple3 = tuple
|
35
|
+
end
|
36
|
+
@space.write [1,2,3]
|
37
|
+
assert_equal _tuple1.data, [1,2,3]
|
38
|
+
assert_equal _tuple2, nil
|
39
|
+
assert_equal _tuple3.data, [1,2,3]
|
40
|
+
assert_equal @space.read([1]).data, [1,2,3]
|
41
|
+
assert_equal @space.size, 1
|
42
|
+
@space.write [1,2,4]
|
43
|
+
assert_equal _tuple1.data, [1,2,3]
|
44
|
+
assert_equal @space.size, 2
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_take
|
48
|
+
assert_equal @space.size, 0
|
49
|
+
1.upto(3) do |i|
|
50
|
+
@space.write [1,2,3,"a"*i]
|
51
|
+
end
|
52
|
+
assert_equal @space.size, 3
|
53
|
+
assert_equal @space.take([1,2,3]).data, [1,2,3,"aaa"]
|
54
|
+
assert_equal @space.size, 2
|
55
|
+
@space.write :a => 1, :b => 2, :c => 3
|
56
|
+
assert_equal @space.size, 3
|
57
|
+
assert_equal @space.take([1,3]), nil
|
58
|
+
assert_equal @space.take(:a => 1, :b => 2, :c => 4), nil
|
59
|
+
assert_equal @space.take([1,2,3]).data, [1,2,3,"aa"]
|
60
|
+
assert_equal @space.size, 2
|
61
|
+
assert_equal @space.take([1,2,3]).data, [1,2,3,"a"]
|
62
|
+
assert_equal @space.size, 1
|
63
|
+
assert_equal @space.take(:b => 2, :a => 1).data, {:a => 1, :b => 2, :c => 3}
|
64
|
+
assert_equal @space.size, 0
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_take_callback
|
68
|
+
assert_equal @space.size, 0
|
69
|
+
_tuple1 = nil
|
70
|
+
@space.take [1,2] do |tuple|
|
71
|
+
_tuple1 = tuple
|
72
|
+
end
|
73
|
+
_tuple2 = nil
|
74
|
+
@space.take [1,"a"] do |tuple|
|
75
|
+
_tuple2 = tuple
|
76
|
+
end
|
77
|
+
_tuple3 = nil
|
78
|
+
@space.read [1,2,3] do |tuple|
|
79
|
+
_tuple3 = tuple
|
80
|
+
end
|
81
|
+
_tuple4 = nil
|
82
|
+
@space.take [1,2,3] do |tuple|
|
83
|
+
_tuple4 = tuple
|
84
|
+
end
|
85
|
+
1.upto(3) do |i|
|
86
|
+
@space.write [1,2,3,"a"*i]
|
87
|
+
end
|
88
|
+
assert_equal @space.size, 1
|
89
|
+
assert_equal _tuple1.data, [1,2,3,"a"]
|
90
|
+
assert_equal _tuple2, nil
|
91
|
+
assert_equal _tuple3.data, [1,2,3,"aa"]
|
92
|
+
assert_equal _tuple4.data, [1,2,3,"aa"]
|
93
|
+
assert_equal @space.take([1]).data, [1,2,3,"aaa"]
|
94
|
+
assert_equal @space.size, 0
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_watch
|
98
|
+
assert_equal @space.size, 0
|
99
|
+
_tuple1 = nil
|
100
|
+
@space.take [1] do |tuple|
|
101
|
+
_tuple1 = tuple
|
102
|
+
end
|
103
|
+
results = []
|
104
|
+
@space.watch [1,2] do |tuple|
|
105
|
+
results << tuple
|
106
|
+
end
|
107
|
+
@space.write [1,2,3]
|
108
|
+
@space.write [1,2,"aa"]
|
109
|
+
@space.write [1,"a",3]
|
110
|
+
assert_equal _tuple1.data, [1,2,3]
|
111
|
+
assert_equal @space.size, 2
|
112
|
+
assert_equal results.size, 2
|
113
|
+
assert_equal results[0].data, [1,2,3]
|
114
|
+
assert_equal results[1].data, [1,2,"aa"]
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_tuple_expire
|
118
|
+
@space.write [1,2,999], :expire => false
|
119
|
+
@space.write [1,2,3], :expire => 3
|
120
|
+
@space.write [1,2,"a","b"], :expire => 2
|
121
|
+
assert_equal @space.size, 3
|
122
|
+
sleep 2
|
123
|
+
@space.check_expire
|
124
|
+
assert_equal @space.size, 2
|
125
|
+
assert_equal @space.take([1,2]).data, [1,2,3]
|
126
|
+
assert_equal @space.size, 1
|
127
|
+
sleep 1
|
128
|
+
assert_equal @space.take([1,2]).data, [1,2,999]
|
129
|
+
assert_equal @space.size, 0
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: linda
|
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-18 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
|
+
description: Tuple and TupleSpace implementation of Linda - coordinational language
|
56
|
+
for parallel processing
|
57
|
+
email:
|
58
|
+
- hashimoto@shokai.org
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- History.txt
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/linda.rb
|
70
|
+
- lib/linda/tuple.rb
|
71
|
+
- lib/linda/tuplespace.rb
|
72
|
+
- lib/linda/version.rb
|
73
|
+
- linda.gemspec
|
74
|
+
- test/test_helper.rb
|
75
|
+
- test/test_tuple.rb
|
76
|
+
- test/test_tuplespace.rb
|
77
|
+
homepage: https://github.com/shokai/linda-ruby
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.0.3
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Tuple and TupleSpace implementation of Linda - coordinational language for
|
101
|
+
parallel processing
|
102
|
+
test_files:
|
103
|
+
- test/test_helper.rb
|
104
|
+
- test/test_tuple.rb
|
105
|
+
- test/test_tuplespace.rb
|