opee 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,15 +12,16 @@ be written to improve performance.
12
12
 
13
13
  This is no where close to being ready for prime time.
14
14
 
15
- # Plans and Notes
15
+ ## <a name="release">Release Notes</a>
16
16
 
17
- - Env
18
- - test
19
- - create and close actors and make sure each_actor changes
20
- - test logger return Log instance
21
- - queue_count
22
- - start/stop
23
- - wait_close
17
+ ### Release 0.0.3
18
+
19
+ - Filled out Env and Actor tests.
20
+
21
+ - Fixed ordering problem with method execution.
22
+
23
+
24
+ # Plans and Notes
24
25
 
25
26
  - Log
26
27
  - allow forward attribute to be set that forwards messages to another Actor
@@ -29,6 +30,7 @@ This is no where close to being ready for prime time.
29
30
  - set formatter and stringio and test env methods
30
31
  - test forwarding
31
32
 
33
+ - Env
32
34
  - Actor
33
35
 
34
36
  - implement a design pattern for a shared work queue
@@ -63,21 +63,21 @@ module Opee
63
63
  # deep copy and freeze args if not already frozen or primitive types
64
64
  def ask(op, *args)
65
65
  @ask_mutex.synchronize {
66
- @queue << Act.new(op, args)
66
+ @queue.insert(0, Act.new(op, args))
67
67
  }
68
68
  @loop.wakeup() if RUNNING == @state
69
69
  end
70
70
 
71
71
  def on_idle(op, *args)
72
72
  @idle_mutex.synchronize {
73
- @idle << Act.new(op, args)
73
+ @idle.insert(0, Act.new(op, args))
74
74
  }
75
75
  @loop.wakeup() if RUNNING == @state
76
76
  end
77
77
 
78
78
  def priority_ask(op, *args)
79
79
  @priority_mutex.synchronize {
80
- @priority << Act.new(op, args)
80
+ @priority.insert(0, Act.new(op, args))
81
81
  }
82
82
  @loop.wakeup() if RUNNING == @state
83
83
  end
@@ -101,6 +101,10 @@ module Opee
101
101
  sleep(max_wait)
102
102
  end
103
103
 
104
+ def wakeup()
105
+ @loop.wakeup()
106
+ end
107
+
104
108
  def start()
105
109
  @state = RUNNING
106
110
  @loop.wakeup()
@@ -18,6 +18,10 @@ module Opee
18
18
  @@actors.each { |a| blk.yield(a) }
19
19
  end
20
20
 
21
+ def self.actor_count()
22
+ @@actors.size
23
+ end
24
+
21
25
  def self.shutdown()
22
26
  until @@actors.empty?
23
27
  a = @@actors.pop()
@@ -62,6 +66,7 @@ module Opee
62
66
 
63
67
  def self.wait_finish()
64
68
  @@finish_thread = Thread.current
69
+ @@actors.each { |a| a.wakeup() }
65
70
  while 0 < queue_count()
66
71
  sleep(0.2) # actors should wake up when queue is empty
67
72
  end
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Opee
3
3
  # Current version of the module.
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
@@ -3,13 +3,18 @@ require 'opee'
3
3
 
4
4
  class Relay < ::Opee::Actor
5
5
  attr_reader :last_data
6
+ attr_reader :buddy
6
7
 
7
- def initialize(buddy)
8
- super
9
- @buddy = buddy
8
+ def initialize(options={})
9
+ @buddy = nil
10
10
  @last_data = nil
11
+ super(options)
11
12
  end
12
13
 
14
+ def set_options(options)
15
+ @buddy = options[:buddy]
16
+ end
17
+
13
18
  private
14
19
 
15
20
  def relay(data)
@@ -12,7 +12,7 @@ require 'relay'
12
12
  class OpeeTest < ::Test::Unit::TestCase
13
13
 
14
14
  def test_opee_actor_queue
15
- a = ::Relay.new(nil)
15
+ a = ::Relay.new()
16
16
  assert_equal(0, a.queue_count())
17
17
  a.stop()
18
18
  a.ask(:relay, 5)
@@ -23,7 +23,7 @@ class OpeeTest < ::Test::Unit::TestCase
23
23
  end
24
24
 
25
25
  def test_opee_actor_ask
26
- a = ::Relay.new(nil)
26
+ a = ::Relay.new()
27
27
  a.ask(:relay, 7)
28
28
  sleep(0.5) # minimize dependencies for simplest possible test
29
29
  assert_equal(7, a.last_data)
@@ -31,7 +31,7 @@ class OpeeTest < ::Test::Unit::TestCase
31
31
  end
32
32
 
33
33
  def test_opee_actor_method_missing
34
- a = ::Relay.new(nil)
34
+ a = ::Relay.new()
35
35
  a.relay(7)
36
36
  ::Opee::Env.wait_close()
37
37
  assert_equal(7, a.last_data)
@@ -39,13 +39,13 @@ class OpeeTest < ::Test::Unit::TestCase
39
39
  end
40
40
 
41
41
  def test_opee_actor_raise_after_close
42
- a = ::Relay.new(nil)
42
+ a = ::Relay.new()
43
43
  a.close()
44
44
  assert_raise(ThreadError) { a.start() }
45
45
  end
46
46
 
47
47
  def test_opee_actor_priority
48
- a = ::Relay.new(nil)
48
+ a = ::Relay.new()
49
49
  a.priority_ask(:relay, 7)
50
50
  ::Opee::Env.wait_close()
51
51
  assert_equal(7, a.last_data)
@@ -53,7 +53,7 @@ class OpeeTest < ::Test::Unit::TestCase
53
53
  end
54
54
 
55
55
  def test_opee_actor_idle
56
- a = ::Relay.new(nil)
56
+ a = ::Relay.new()
57
57
  a.on_idle(:relay, 7)
58
58
  ::Opee::Env.wait_close()
59
59
  assert_equal(7, a.last_data)
@@ -61,7 +61,7 @@ class OpeeTest < ::Test::Unit::TestCase
61
61
  end
62
62
 
63
63
  def test_opee_actor_order
64
- a = ::Relay.new(nil)
64
+ a = ::Relay.new()
65
65
  a.stop()
66
66
  a.on_idle(:relay, 17)
67
67
  a.priority_ask(:relay, 3)
@@ -11,12 +11,53 @@ require 'relay'
11
11
 
12
12
  class OpeeTest < ::Test::Unit::TestCase
13
13
 
14
- def test_wait_close
15
- a = ::Relay.new(nil)
16
- a.ask(:relay, 7)
14
+ def test_opee_env_add_remove
15
+ assert_equal(0, ::Opee::Env.actor_count)
16
+ a = ::Relay.new()
17
+ assert_equal(1, ::Opee::Env.actor_count)
18
+ a.close()
19
+ assert_equal(0, ::Opee::Env.actor_count)
20
+ end
21
+
22
+ def test_opee_env_each_actor
23
+ a = ::Relay.new()
24
+ b = ::Relay.new()
25
+ c = ::Relay.new()
26
+ all = []
27
+ ::Opee::Env.each_actor { |x| all << x }
28
+ assert_equal([a, b, c], all)
29
+ a.close()
30
+ b.close()
31
+ c.close()
32
+ end
33
+
34
+ def test_opee_env_shutdown
35
+ a = ::Relay.new()
36
+ ::Opee::Env.shutdown
37
+ assert_raise(ThreadError) { a.start() }
38
+ end
39
+
40
+ def test_opee_env_wait_close
41
+ # chain 3 together to make sure all processing is completed
42
+ a = ::Relay.new()
43
+ b = ::Relay.new(:buddy => a)
44
+ c = ::Relay.new(:buddy => b)
45
+ c.ask(:relay, 7)
17
46
  ::Opee::Env.wait_close()
18
47
  assert_equal(7, a.last_data)
19
48
  a.close()
20
49
  end
21
50
 
51
+ def test_opee_env_start_stop
52
+ a = ::Relay.new()
53
+ ::Opee::Env.stop()
54
+ a.ask(:relay, 5)
55
+ assert_equal(1, ::Opee::Env.queue_count())
56
+ a.ask(:relay, 7)
57
+ assert_equal(2, ::Opee::Env.queue_count())
58
+ ::Opee::Env.start()
59
+ ::Opee::Env.wait_close()
60
+ assert_equal(7, a.last_data)
61
+ end
62
+
22
63
  end # OpeeTest
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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: 2012-04-29 00:00:00.000000000 Z
12
+ date: 2012-04-30 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'An experimental Object-base Parallel Evaluation Environment. '
15
15
  email: peter@ohler.com