roby 0.7

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.
Files changed (240) hide show
  1. data/.gitignore +29 -0
  2. data/History.txt +4 -0
  3. data/License-fr.txt +519 -0
  4. data/License.txt +515 -0
  5. data/Manifest.txt +245 -0
  6. data/NOTES +4 -0
  7. data/README.txt +163 -0
  8. data/Rakefile +161 -0
  9. data/TODO.txt +146 -0
  10. data/app/README.txt +24 -0
  11. data/app/Rakefile +8 -0
  12. data/app/config/ROBOT.rb +5 -0
  13. data/app/config/app.yml +91 -0
  14. data/app/config/init.rb +7 -0
  15. data/app/config/roby.yml +3 -0
  16. data/app/controllers/.gitattributes +0 -0
  17. data/app/controllers/ROBOT.rb +2 -0
  18. data/app/data/.gitattributes +0 -0
  19. data/app/planners/ROBOT/main.rb +6 -0
  20. data/app/planners/main.rb +5 -0
  21. data/app/scripts/distributed +3 -0
  22. data/app/scripts/generate/bookmarks +3 -0
  23. data/app/scripts/replay +3 -0
  24. data/app/scripts/results +3 -0
  25. data/app/scripts/run +3 -0
  26. data/app/scripts/server +3 -0
  27. data/app/scripts/shell +3 -0
  28. data/app/scripts/test +3 -0
  29. data/app/tasks/.gitattributes +0 -0
  30. data/app/tasks/ROBOT/.gitattributes +0 -0
  31. data/bin/roby +210 -0
  32. data/bin/roby-log +168 -0
  33. data/bin/roby-shell +25 -0
  34. data/doc/images/event_generalization.png +0 -0
  35. data/doc/images/exception_propagation_1.png +0 -0
  36. data/doc/images/exception_propagation_2.png +0 -0
  37. data/doc/images/exception_propagation_3.png +0 -0
  38. data/doc/images/exception_propagation_4.png +0 -0
  39. data/doc/images/exception_propagation_5.png +0 -0
  40. data/doc/images/replay_handler_error.png +0 -0
  41. data/doc/images/replay_handler_error_0.png +0 -0
  42. data/doc/images/replay_handler_error_1.png +0 -0
  43. data/doc/images/roby_cycle_overview.png +0 -0
  44. data/doc/images/roby_replay_02.png +0 -0
  45. data/doc/images/roby_replay_03.png +0 -0
  46. data/doc/images/roby_replay_04.png +0 -0
  47. data/doc/images/roby_replay_event_representation.png +0 -0
  48. data/doc/images/roby_replay_first_state.png +0 -0
  49. data/doc/images/roby_replay_relations.png +0 -0
  50. data/doc/images/roby_replay_startup.png +0 -0
  51. data/doc/images/task_event_generalization.png +0 -0
  52. data/doc/papers.rdoc +11 -0
  53. data/doc/styles/allison.css +314 -0
  54. data/doc/styles/allison.js +316 -0
  55. data/doc/styles/allison.rb +276 -0
  56. data/doc/styles/jamis.rb +593 -0
  57. data/doc/tutorials/01-GettingStarted.rdoc +86 -0
  58. data/doc/tutorials/02-GoForward.rdoc +220 -0
  59. data/doc/tutorials/03-PlannedPath.rdoc +268 -0
  60. data/doc/tutorials/04-EventPropagation.rdoc +236 -0
  61. data/doc/tutorials/05-ErrorHandling.rdoc +319 -0
  62. data/doc/tutorials/06-Overview.rdoc +40 -0
  63. data/doc/videos.rdoc +69 -0
  64. data/ext/droby/dump.cc +175 -0
  65. data/ext/droby/extconf.rb +3 -0
  66. data/ext/graph/algorithm.cc +746 -0
  67. data/ext/graph/extconf.rb +7 -0
  68. data/ext/graph/graph.cc +529 -0
  69. data/ext/graph/graph.hh +183 -0
  70. data/ext/graph/iterator_sequence.hh +102 -0
  71. data/ext/graph/undirected_dfs.hh +226 -0
  72. data/ext/graph/undirected_graph.hh +421 -0
  73. data/lib/roby.rb +41 -0
  74. data/lib/roby/app.rb +870 -0
  75. data/lib/roby/app/rake.rb +56 -0
  76. data/lib/roby/app/run.rb +14 -0
  77. data/lib/roby/app/scripts/distributed.rb +13 -0
  78. data/lib/roby/app/scripts/generate/bookmarks.rb +162 -0
  79. data/lib/roby/app/scripts/replay.rb +31 -0
  80. data/lib/roby/app/scripts/results.rb +15 -0
  81. data/lib/roby/app/scripts/run.rb +26 -0
  82. data/lib/roby/app/scripts/server.rb +18 -0
  83. data/lib/roby/app/scripts/shell.rb +88 -0
  84. data/lib/roby/app/scripts/test.rb +40 -0
  85. data/lib/roby/basic_object.rb +151 -0
  86. data/lib/roby/config.rb +5 -0
  87. data/lib/roby/control.rb +747 -0
  88. data/lib/roby/decision_control.rb +17 -0
  89. data/lib/roby/distributed.rb +32 -0
  90. data/lib/roby/distributed/base.rb +440 -0
  91. data/lib/roby/distributed/communication.rb +871 -0
  92. data/lib/roby/distributed/connection_space.rb +592 -0
  93. data/lib/roby/distributed/distributed_object.rb +206 -0
  94. data/lib/roby/distributed/drb.rb +62 -0
  95. data/lib/roby/distributed/notifications.rb +539 -0
  96. data/lib/roby/distributed/peer.rb +550 -0
  97. data/lib/roby/distributed/protocol.rb +529 -0
  98. data/lib/roby/distributed/proxy.rb +343 -0
  99. data/lib/roby/distributed/subscription.rb +311 -0
  100. data/lib/roby/distributed/transaction.rb +498 -0
  101. data/lib/roby/event.rb +897 -0
  102. data/lib/roby/exceptions.rb +234 -0
  103. data/lib/roby/executives/simple.rb +30 -0
  104. data/lib/roby/graph.rb +166 -0
  105. data/lib/roby/interface.rb +390 -0
  106. data/lib/roby/log.rb +3 -0
  107. data/lib/roby/log/chronicle.rb +303 -0
  108. data/lib/roby/log/console.rb +72 -0
  109. data/lib/roby/log/data_stream.rb +197 -0
  110. data/lib/roby/log/dot.rb +279 -0
  111. data/lib/roby/log/event_stream.rb +151 -0
  112. data/lib/roby/log/file.rb +340 -0
  113. data/lib/roby/log/gui/basic_display.ui +83 -0
  114. data/lib/roby/log/gui/chronicle.rb +26 -0
  115. data/lib/roby/log/gui/chronicle_view.rb +40 -0
  116. data/lib/roby/log/gui/chronicle_view.ui +70 -0
  117. data/lib/roby/log/gui/data_displays.rb +172 -0
  118. data/lib/roby/log/gui/data_displays.ui +155 -0
  119. data/lib/roby/log/gui/notifications.rb +26 -0
  120. data/lib/roby/log/gui/relations.rb +248 -0
  121. data/lib/roby/log/gui/relations.ui +123 -0
  122. data/lib/roby/log/gui/relations_view.rb +185 -0
  123. data/lib/roby/log/gui/relations_view.ui +149 -0
  124. data/lib/roby/log/gui/replay.rb +327 -0
  125. data/lib/roby/log/gui/replay_controls.rb +200 -0
  126. data/lib/roby/log/gui/replay_controls.ui +259 -0
  127. data/lib/roby/log/gui/runtime.rb +130 -0
  128. data/lib/roby/log/hooks.rb +185 -0
  129. data/lib/roby/log/logger.rb +202 -0
  130. data/lib/roby/log/notifications.rb +244 -0
  131. data/lib/roby/log/plan_rebuilder.rb +470 -0
  132. data/lib/roby/log/relations.rb +1056 -0
  133. data/lib/roby/log/server.rb +550 -0
  134. data/lib/roby/log/sqlite.rb +47 -0
  135. data/lib/roby/log/timings.rb +164 -0
  136. data/lib/roby/plan-object.rb +247 -0
  137. data/lib/roby/plan.rb +762 -0
  138. data/lib/roby/planning.rb +13 -0
  139. data/lib/roby/planning/loops.rb +302 -0
  140. data/lib/roby/planning/model.rb +906 -0
  141. data/lib/roby/planning/task.rb +151 -0
  142. data/lib/roby/propagation.rb +562 -0
  143. data/lib/roby/query.rb +619 -0
  144. data/lib/roby/relations.rb +583 -0
  145. data/lib/roby/relations/conflicts.rb +70 -0
  146. data/lib/roby/relations/ensured.rb +20 -0
  147. data/lib/roby/relations/error_handling.rb +23 -0
  148. data/lib/roby/relations/events.rb +9 -0
  149. data/lib/roby/relations/executed_by.rb +193 -0
  150. data/lib/roby/relations/hierarchy.rb +239 -0
  151. data/lib/roby/relations/influence.rb +10 -0
  152. data/lib/roby/relations/planned_by.rb +63 -0
  153. data/lib/roby/robot.rb +7 -0
  154. data/lib/roby/standard_errors.rb +218 -0
  155. data/lib/roby/state.rb +5 -0
  156. data/lib/roby/state/events.rb +221 -0
  157. data/lib/roby/state/information.rb +55 -0
  158. data/lib/roby/state/pos.rb +110 -0
  159. data/lib/roby/state/shapes.rb +32 -0
  160. data/lib/roby/state/state.rb +353 -0
  161. data/lib/roby/support.rb +92 -0
  162. data/lib/roby/task-operations.rb +182 -0
  163. data/lib/roby/task.rb +1618 -0
  164. data/lib/roby/test/common.rb +399 -0
  165. data/lib/roby/test/distributed.rb +214 -0
  166. data/lib/roby/test/tasks/empty_task.rb +9 -0
  167. data/lib/roby/test/tasks/goto.rb +36 -0
  168. data/lib/roby/test/tasks/simple_task.rb +23 -0
  169. data/lib/roby/test/testcase.rb +519 -0
  170. data/lib/roby/test/tools.rb +160 -0
  171. data/lib/roby/thread_task.rb +87 -0
  172. data/lib/roby/transactions.rb +462 -0
  173. data/lib/roby/transactions/proxy.rb +292 -0
  174. data/lib/roby/transactions/updates.rb +139 -0
  175. data/plugins/fault_injection/History.txt +4 -0
  176. data/plugins/fault_injection/README.txt +37 -0
  177. data/plugins/fault_injection/Rakefile +18 -0
  178. data/plugins/fault_injection/TODO.txt +0 -0
  179. data/plugins/fault_injection/app.rb +52 -0
  180. data/plugins/fault_injection/fault_injection.rb +89 -0
  181. data/plugins/fault_injection/test/test_fault_injection.rb +84 -0
  182. data/plugins/subsystems/README.txt +40 -0
  183. data/plugins/subsystems/Rakefile +18 -0
  184. data/plugins/subsystems/app.rb +171 -0
  185. data/plugins/subsystems/test/app/README +24 -0
  186. data/plugins/subsystems/test/app/Rakefile +8 -0
  187. data/plugins/subsystems/test/app/config/app.yml +71 -0
  188. data/plugins/subsystems/test/app/config/init.rb +9 -0
  189. data/plugins/subsystems/test/app/config/roby.yml +3 -0
  190. data/plugins/subsystems/test/app/planners/main.rb +20 -0
  191. data/plugins/subsystems/test/app/scripts/distributed +3 -0
  192. data/plugins/subsystems/test/app/scripts/replay +3 -0
  193. data/plugins/subsystems/test/app/scripts/results +3 -0
  194. data/plugins/subsystems/test/app/scripts/run +3 -0
  195. data/plugins/subsystems/test/app/scripts/server +3 -0
  196. data/plugins/subsystems/test/app/scripts/shell +3 -0
  197. data/plugins/subsystems/test/app/scripts/test +3 -0
  198. data/plugins/subsystems/test/app/tasks/services.rb +15 -0
  199. data/plugins/subsystems/test/test_subsystems.rb +71 -0
  200. data/test/distributed/test_communication.rb +178 -0
  201. data/test/distributed/test_connection.rb +282 -0
  202. data/test/distributed/test_execution.rb +373 -0
  203. data/test/distributed/test_mixed_plan.rb +341 -0
  204. data/test/distributed/test_plan_notifications.rb +238 -0
  205. data/test/distributed/test_protocol.rb +516 -0
  206. data/test/distributed/test_query.rb +102 -0
  207. data/test/distributed/test_remote_plan.rb +491 -0
  208. data/test/distributed/test_transaction.rb +463 -0
  209. data/test/mockups/tasks.rb +27 -0
  210. data/test/planning/test_loops.rb +380 -0
  211. data/test/planning/test_model.rb +427 -0
  212. data/test/planning/test_task.rb +106 -0
  213. data/test/relations/test_conflicts.rb +42 -0
  214. data/test/relations/test_ensured.rb +38 -0
  215. data/test/relations/test_executed_by.rb +149 -0
  216. data/test/relations/test_hierarchy.rb +158 -0
  217. data/test/relations/test_planned_by.rb +54 -0
  218. data/test/suite_core.rb +24 -0
  219. data/test/suite_distributed.rb +9 -0
  220. data/test/suite_planning.rb +3 -0
  221. data/test/suite_relations.rb +8 -0
  222. data/test/test_bgl.rb +508 -0
  223. data/test/test_control.rb +399 -0
  224. data/test/test_event.rb +894 -0
  225. data/test/test_exceptions.rb +592 -0
  226. data/test/test_interface.rb +37 -0
  227. data/test/test_log.rb +114 -0
  228. data/test/test_log_server.rb +132 -0
  229. data/test/test_plan.rb +584 -0
  230. data/test/test_propagation.rb +210 -0
  231. data/test/test_query.rb +266 -0
  232. data/test/test_relations.rb +180 -0
  233. data/test/test_state.rb +414 -0
  234. data/test/test_support.rb +16 -0
  235. data/test/test_task.rb +938 -0
  236. data/test/test_testcase.rb +122 -0
  237. data/test/test_thread_task.rb +73 -0
  238. data/test/test_transactions.rb +569 -0
  239. data/test/test_transactions_proxy.rb +198 -0
  240. metadata +570 -0
@@ -0,0 +1,24 @@
1
+ == Directories
2
+ A basic Roby application has the following directories:
3
+ config:: configuration files. config/init.rb is the main configuration file (loaded
4
+ by all robots). Robot-specific configuration is in config/ROBOTNAME.rb.
5
+ The main Roby configuration file is config/roby.yml. The default file
6
+ describes all available configuration options.
7
+ planners:: planner models. Global planners (shared by all robots) are in
8
+ planners/. Robot-specific planners are in planners/ROBOTNAME/
9
+ controllers:: robot controllers. These files are supposed to start the basic robot
10
+ services, to make the robot ready. A robot shall have a controllers/ROBOTNAME.rb
11
+ file which does that.
12
+ tasks:: task models
13
+ data:: where all data files are. See #find_data.
14
+ scripts:: various scripts needed to run and debug a Roby application
15
+
16
+ The basic directory structure, and the global files, are installed by <tt>roby init</tt>. Basic
17
+ robot files can be added by <tt>roby robot ROBOTNAME</tt>
18
+
19
+ == Genom/Pocosim integration
20
+ An application can use the Genom/Pocosim integration by calling <tt>roby init --module genom</tt>.
21
+ The following files and directories are added:
22
+ config/ROBOTNAME-genom.rb:: Genom-specific configuration for ROBOTNAME
23
+ tasks/genom/:: per-Genom module tasks
24
+
@@ -0,0 +1,8 @@
1
+ require 'rake/rdoctask'
2
+
3
+ Rake::RDocTask.new('doc') do |doc|
4
+ doc.rdoc_files.include 'README'
5
+ doc.rdoc_files.include 'tasks/**/*.rb'
6
+ doc.rdoc_files.include 'planners/**/*.rb'
7
+ doc.rdoc_files.include 'controllers/**/*.rb'
8
+ end
@@ -0,0 +1,71 @@
1
+ # dRoby neighbour discovery
2
+ discovery:
3
+ # The host:port at which we can connect to a discovery tuplespace
4
+ # (default: no discovery tuplespace)
5
+ # tuplespace: "localhost:29568"
6
+ # The port at which we do ring discovery (default: disabled)
7
+ # ring: 42865
8
+
9
+ # dRoby host configuration
10
+ droby:
11
+ # How many errors are allowed before disconnecting from a peer
12
+ # (default: 10)
13
+ # max_errors: 1
14
+ # The ring discovery period if we do ring discovery (default: 0.5)
15
+ # period: 0.5
16
+
17
+ # Pocosim configuration
18
+ pocosim:
19
+ # The host of the GDHE display
20
+ # display: localhost
21
+
22
+ # An initialization script to display the scene on GDHE. The file is searched
23
+ # in the data/ director
24
+ # gdhe: lousa.gdhe
25
+
26
+ # The Gazebo world file for pocosim/gazebo simulations. The file is searched
27
+ # in the data/ directory
28
+ # gazebo: lousa.world
29
+
30
+ # Logging configuration
31
+ log:
32
+ # Log system events (default: false)
33
+ # events: true
34
+
35
+ # Disables the log server (default: enabled)
36
+ # server: false
37
+ #
38
+ # ... or configure it
39
+ # server:
40
+ # # The port to listen on (for service discovery)
41
+ # port: 48933
42
+ # # The discovery period
43
+ # period: 10
44
+
45
+ # Logging levels. It is a hash of Component: level (where level
46
+ # is one of DEBUG, INFO, WARN and FATAL).
47
+ # levels:
48
+ # Roby: INFO
49
+ # Genom: INFO
50
+
51
+ # Control configuration
52
+ control:
53
+ # Abort if a task/event exception is not caught (default: false)
54
+ # abort_on_exception: true
55
+ # Abort if an application exception occurs (default: false)
56
+ # abort_on_application_exception: true
57
+
58
+ # If the GC should be run at each control loop (default: false)
59
+ # WARNING: for now, the performance hit for GCing at each control loop
60
+ # WARNING: is too high
61
+ # control_gc: false
62
+
63
+
64
+ # Per-robot configuration. In these, you can override global options, or set
65
+ # new options.
66
+ # dala:
67
+ # droby:
68
+ # # The host:port at which this robot listens
69
+ # host: "localhost:1287"
70
+
71
+ # vim: sw=2
@@ -0,0 +1,9 @@
1
+ # This file is called to do application-global configuration. For configuration
2
+ # specific to a robot, edit config/NAME.rb, where NAME is the robot name.
3
+
4
+ # Require Roby components
5
+ #
6
+ # Roby.app.using 'planning'
7
+ # Roby.app.using 'distributed'
8
+ # Roby.app.using 'genom'
9
+
@@ -0,0 +1,3 @@
1
+ ---
2
+ plugins:
3
+ - subsystems
@@ -0,0 +1,20 @@
1
+ # The main planner. A planner of this model is automatically added in the
2
+ # Interface planner list.
3
+ class MainPlanner < Roby::Planning::Planner
4
+ method(:navigation, :returns => Services::Navigation)
5
+ method(:localization, :returns => Services::Localization)
6
+
7
+ method(:localization, :id => 'test') do
8
+ Services::Localization.new(:id => 'localization')
9
+ end
10
+ method(:localization, :id => 'another') do
11
+ Services::Localization.new(:id => 'another_localization')
12
+ end
13
+
14
+ method(:navigation, :id => 'test') do
15
+ root = Services::Navigation.new
16
+ root.realized_by(loc = localization)
17
+ root
18
+ end
19
+ end
20
+
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env ruby
2
+ APP_DIR = File.expand_path('..', File.dirname(__FILE__))
3
+ require 'roby/app/scripts/distributed'
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env ruby
2
+ APP_DIR = File.expand_path('..', File.dirname(__FILE__))
3
+ require 'roby/app/scripts/replay'
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env ruby
2
+ APP_DIR = File.expand_path('..', File.dirname(__FILE__))
3
+ require 'roby/app/scripts/results'
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env ruby
2
+ APP_DIR = File.expand_path('..', File.dirname(__FILE__))
3
+ require 'roby/app/scripts/run'
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env ruby
2
+ APP_DIR = File.expand_path('..', File.dirname(__FILE__))
3
+ require 'roby/app/scripts/server'
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env ruby
2
+ APP_DIR = File.expand_path('..', File.dirname(__FILE__))
3
+ require 'roby/app/scripts/shell'
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env ruby
2
+ APP_DIR = File.expand_path('..', File.dirname(__FILE__))
3
+ require 'roby/app/scripts/test'
@@ -0,0 +1,15 @@
1
+ require 'roby/test/tasks/simple_task'
2
+ SimpleTask = Roby::Test::SimpleTask
3
+
4
+ module Services
5
+ class Navigation < SimpleTask; end
6
+ class Localization < SimpleTask
7
+ event :ready, :command => true
8
+ on :start => :ready
9
+
10
+ def update_localization(state)
11
+ state.pos += 1
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,71 @@
1
+ require 'test/unit'
2
+ require 'roby'
3
+ require 'roby/app'
4
+ require 'roby/test/common'
5
+ require 'roby/test/tasks/simple_task'
6
+
7
+ APP_DIR = File.expand_path('app', File.dirname(__FILE__))
8
+ require "#{APP_DIR}/tasks/services"
9
+ require "#{APP_DIR}/planners/main"
10
+ Roby.app.using :subsystems
11
+
12
+ State = Roby::State
13
+ Robot = Roby
14
+
15
+ class TC_Subsystems < Test::Unit::TestCase
16
+ include Roby::Test
17
+ include Roby::Subsystems
18
+
19
+ def setup
20
+ super
21
+ DRb.start_service
22
+ State.pos = 0
23
+ State.services do |s|
24
+ s.localization = 'test'
25
+ s.navigation = 'test'
26
+ end
27
+ end
28
+
29
+ def nav_loc
30
+ tasks = plan.known_tasks.to_a
31
+ assert_equal(2, tasks.size, tasks)
32
+ if tasks.first.kind_of?(Services::Navigation)
33
+ tasks
34
+ else tasks.reverse
35
+ end
36
+ end
37
+
38
+ def test_initialize_plan
39
+ start_with, ready = Application.initialize_plan
40
+
41
+ nav, loc = nav_loc
42
+ assert(plan.permanent?(nav))
43
+ assert(plan.permanent?(loc))
44
+ assert(nav.realized_by?(loc))
45
+
46
+ assert_equal([loc.event(:start)], start_with.child_objects(EventStructure::Signal).to_a)
47
+
48
+ and_gen = loc.event(:ready).child_objects(EventStructure::Signal).to_a.first
49
+ assert_equal([nav.event(:start)], and_gen.child_objects(EventStructure::Signal).to_a)
50
+
51
+ assert_equal([nav.event(:start), loc.event(:ready)].to_set, ready.parent_objects(EventStructure::Signal).to_set)
52
+
53
+ rescue Roby::Planning::NotFound
54
+ STDERR.puts $!.full_message
55
+ raise
56
+ end
57
+
58
+ def test_start_subsystems
59
+ Roby.logger.level = Logger::FATAL
60
+ Roby.control.run :detach => true
61
+
62
+ Application.run(Roby.app) { }
63
+ nav, loc = nav_loc
64
+ assert(nav.running?)
65
+ assert(loc.running?)
66
+
67
+ sleep(0.5)
68
+ assert(State.pos > 0)
69
+ end
70
+ end
71
+
@@ -0,0 +1,178 @@
1
+ require 'test/unit'
2
+ require 'roby/distributed'
3
+ require 'roby/test/distributed'
4
+ require 'flexmock'
5
+
6
+ class TC_DistributedCommunication < Test::Unit::TestCase
7
+ include Roby
8
+ include Roby::Distributed::Test
9
+
10
+ attr_reader :local_peer
11
+ module FakePeerServerMethods
12
+ def reply(mock, value)
13
+ mock.method_called(value) if mock
14
+ value
15
+ end
16
+ def reply_error(count)
17
+ @error_count ||= count
18
+ if @error_count == 0
19
+ return
20
+ end
21
+
22
+ @error_count -= 1
23
+ raise
24
+ end
25
+
26
+ def reply_with_callback(mock, value)
27
+ peer.disable_tx
28
+ mock.method_called(value)
29
+ peer.transmit(:reply, mock, value + 1)
30
+ mock.method_called(value + 2)
31
+ peer.enable_tx
32
+ value
33
+ end
34
+
35
+ def recursive_callbacks
36
+ peer.transmit(:recursive_callbacks)
37
+ end
38
+
39
+ def setup(server); peer.setup(server) end
40
+ def peer_drb_object; DRbObject.new(peer) end
41
+ end
42
+
43
+ def setup
44
+ super
45
+
46
+ peer2peer(true) do |remote|
47
+ def remote.install_fake_methods
48
+ local_peer.local_server.extend FakePeerServerMethods
49
+ end
50
+ end
51
+
52
+ remote_peer.local_server.extend FakePeerServerMethods
53
+ remote.install_fake_methods
54
+ end
55
+
56
+ def test_transmit
57
+ FlexMock.use do |mock|
58
+ # Check that nothing is sent while the link is not alive
59
+ remote_peer.disable_tx
60
+ remote_peer.transmit(:reply, DRbObject.new(mock), 42) do |result|
61
+ mock.block_called(result)
62
+ end
63
+
64
+ remote_peer.transmit(:reply, DRbObject.new(mock), 24)
65
+ remote_peer.transmit(:reply, DRbObject.new(mock), 24) do |result|
66
+ mock.block_called(result)
67
+ end
68
+
69
+ mock.should_receive(:link_alive).once.ordered
70
+ mock.should_receive(:method_called).with(42).once.ordered(:first_call)
71
+ mock.should_receive(:method_called).with(24).twice.ordered(:second_calls)
72
+ mock.should_receive(:block_called).with(42).once.ordered(:second_calls)
73
+ mock.should_receive(:block_called).with(24).once.ordered
74
+
75
+ mock.link_alive
76
+ remote_peer.enable_tx
77
+ remote_peer.synchro_point
78
+ end
79
+ end
80
+
81
+ def test_transmit_error
82
+ FlexMock.use do |mock|
83
+ remote_peer.disable_tx
84
+ remote_peer.transmit(:reply_error, 2) do |result|
85
+ mock.block_called
86
+ end
87
+ mock.should_receive(:block_called).never
88
+ remote_peer.enable_tx
89
+ assert_raises(Roby::Distributed::DisconnectedError) { remote_peer.synchro_point }
90
+
91
+ assert(!remote_peer.connected?)
92
+ end
93
+ end
94
+
95
+ def test_call(value = 42)
96
+ FlexMock.use do |mock|
97
+ mock.should_receive(:method_called).with(value).once
98
+ assert_equal(value, remote_peer.call(:reply, DRbObject.new(mock), value))
99
+ end
100
+ end
101
+
102
+ def test_concurrent_calls
103
+ remote_peer.disable_tx
104
+
105
+ t1 = Thread.new { test_call(42) }
106
+ # wait for the TX thread to notice the new entry in the queue and
107
+ # wake up
108
+ sleep(0.5)
109
+
110
+ t2 = Thread.new { test_call(21) }
111
+ # Wait for +t2+ to insert its entry in the TX queue
112
+ sleep(0.5)
113
+
114
+ remote_peer.enable_tx
115
+ t1.value
116
+ t2.value
117
+ end
118
+
119
+ def test_call_raises
120
+ Roby.logger.level = Logger::FATAL
121
+ assert_raises(RuntimeError) do
122
+ remote_peer.call(:reply_error, 2)
123
+ end
124
+ end
125
+
126
+ def test_call_disconnects
127
+ Roby.logger.level = Logger::FATAL
128
+ remote_peer.disable_tx
129
+
130
+ remote_peer.transmit(:reply_error, 2)
131
+ sleep(0.5)
132
+
133
+ Thread.new do
134
+ sleep(0.5)
135
+ remote_peer.enable_tx
136
+ end
137
+ assert_raises(DisconnectedError) { remote_peer.call(:reply, nil, 42) }
138
+ end
139
+
140
+ def test_callback
141
+ FlexMock.use do |mock|
142
+ # Check that nothing is sent while the link is not alive
143
+ mock.should_receive(:method_called).with(42).once.ordered
144
+ mock.should_receive(:method_called).with(44).once.ordered
145
+ mock.should_receive(:method_called).with(43).once.ordered
146
+
147
+ assert_equal(42, remote_peer.call(:reply_with_callback, DRbObject.new(mock), 42))
148
+ end
149
+ end
150
+
151
+ def test_recursive_callbacks
152
+ Roby.logger.level = Logger::FATAL
153
+ assert_raises(DisconnectedError) { remote_peer.call(:recursive_callbacks) }
154
+ end
155
+
156
+ def test_synchro_point
157
+ remote_peer.disable_tx
158
+ remote.send_local_peer(:disable_tx)
159
+ FlexMock.use do |mock|
160
+ remote_peer.transmit(:reply, DRbObject.new(mock), 42)
161
+ remote_peer.transmit(:reply, DRbObject.new(mock), 21)
162
+ remote.send_local_peer(:transmit, :reply, DRbObject.new(mock), 42)
163
+ remote.send_local_peer(:transmit, :reply, DRbObject.new(mock), 21)
164
+
165
+ Thread.current.priority = 10
166
+ sleep(0.5)
167
+ mock.should_receive(:method_called).times(4)
168
+
169
+ remote_peer.enable_tx
170
+ remote.send_local_peer(:enable_tx)
171
+ remote_peer.synchro_point
172
+ end
173
+
174
+ ensure
175
+ Thread.current.priority = 0
176
+ end
177
+ end
178
+