ruote-maestrodev 2.2.1

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 (265) hide show
  1. data/CHANGELOG.txt +290 -0
  2. data/CREDITS.txt +99 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.rdoc +88 -0
  5. data/Rakefile +108 -0
  6. data/TODO.txt +488 -0
  7. data/lib/ruote.rb +7 -0
  8. data/lib/ruote/context.rb +194 -0
  9. data/lib/ruote/engine.rb +1062 -0
  10. data/lib/ruote/engine/process_error.rb +122 -0
  11. data/lib/ruote/engine/process_status.rb +448 -0
  12. data/lib/ruote/exp/command.rb +87 -0
  13. data/lib/ruote/exp/commanded.rb +69 -0
  14. data/lib/ruote/exp/condition.rb +227 -0
  15. data/lib/ruote/exp/fe_add_branches.rb +138 -0
  16. data/lib/ruote/exp/fe_apply.rb +154 -0
  17. data/lib/ruote/exp/fe_cancel_process.rb +78 -0
  18. data/lib/ruote/exp/fe_command.rb +156 -0
  19. data/lib/ruote/exp/fe_concurrence.rb +321 -0
  20. data/lib/ruote/exp/fe_concurrent_iterator.rb +219 -0
  21. data/lib/ruote/exp/fe_cron.rb +141 -0
  22. data/lib/ruote/exp/fe_cursor.rb +324 -0
  23. data/lib/ruote/exp/fe_define.rb +112 -0
  24. data/lib/ruote/exp/fe_echo.rb +60 -0
  25. data/lib/ruote/exp/fe_equals.rb +115 -0
  26. data/lib/ruote/exp/fe_error.rb +82 -0
  27. data/lib/ruote/exp/fe_filter.rb +648 -0
  28. data/lib/ruote/exp/fe_forget.rb +88 -0
  29. data/lib/ruote/exp/fe_given.rb +154 -0
  30. data/lib/ruote/exp/fe_if.rb +127 -0
  31. data/lib/ruote/exp/fe_inc.rb +205 -0
  32. data/lib/ruote/exp/fe_iterator.rb +234 -0
  33. data/lib/ruote/exp/fe_let.rb +75 -0
  34. data/lib/ruote/exp/fe_listen.rb +304 -0
  35. data/lib/ruote/exp/fe_lose.rb +110 -0
  36. data/lib/ruote/exp/fe_noop.rb +45 -0
  37. data/lib/ruote/exp/fe_once.rb +215 -0
  38. data/lib/ruote/exp/fe_participant.rb +287 -0
  39. data/lib/ruote/exp/fe_read.rb +69 -0
  40. data/lib/ruote/exp/fe_redo.rb +82 -0
  41. data/lib/ruote/exp/fe_ref.rb +152 -0
  42. data/lib/ruote/exp/fe_registerp.rb +110 -0
  43. data/lib/ruote/exp/fe_reserve.rb +126 -0
  44. data/lib/ruote/exp/fe_restore.rb +102 -0
  45. data/lib/ruote/exp/fe_save.rb +72 -0
  46. data/lib/ruote/exp/fe_sequence.rb +59 -0
  47. data/lib/ruote/exp/fe_set.rb +154 -0
  48. data/lib/ruote/exp/fe_subprocess.rb +211 -0
  49. data/lib/ruote/exp/fe_that.rb +92 -0
  50. data/lib/ruote/exp/fe_undo.rb +67 -0
  51. data/lib/ruote/exp/fe_unregisterp.rb +69 -0
  52. data/lib/ruote/exp/fe_wait.rb +95 -0
  53. data/lib/ruote/exp/flowexpression.rb +886 -0
  54. data/lib/ruote/exp/iterator.rb +81 -0
  55. data/lib/ruote/exp/merge.rb +118 -0
  56. data/lib/ruote/exp/ro_attributes.rb +212 -0
  57. data/lib/ruote/exp/ro_filters.rb +136 -0
  58. data/lib/ruote/exp/ro_persist.rb +154 -0
  59. data/lib/ruote/exp/ro_variables.rb +189 -0
  60. data/lib/ruote/exp/ro_vf.rb +68 -0
  61. data/lib/ruote/fei.rb +260 -0
  62. data/lib/ruote/id/mnemo_wfid_generator.rb +43 -0
  63. data/lib/ruote/id/wfid_generator.rb +81 -0
  64. data/lib/ruote/log/default_history.rb +122 -0
  65. data/lib/ruote/log/pretty.rb +176 -0
  66. data/lib/ruote/log/storage_history.rb +159 -0
  67. data/lib/ruote/log/test_logger.rb +208 -0
  68. data/lib/ruote/log/wait_logger.rb +64 -0
  69. data/lib/ruote/part/block_participant.rb +137 -0
  70. data/lib/ruote/part/code_participant.rb +81 -0
  71. data/lib/ruote/part/engine_participant.rb +189 -0
  72. data/lib/ruote/part/local_participant.rb +138 -0
  73. data/lib/ruote/part/no_op_participant.rb +60 -0
  74. data/lib/ruote/part/null_participant.rb +54 -0
  75. data/lib/ruote/part/rev_participant.rb +169 -0
  76. data/lib/ruote/part/smtp_participant.rb +116 -0
  77. data/lib/ruote/part/storage_participant.rb +392 -0
  78. data/lib/ruote/part/template.rb +84 -0
  79. data/lib/ruote/participant.rb +7 -0
  80. data/lib/ruote/reader.rb +278 -0
  81. data/lib/ruote/reader/json.rb +49 -0
  82. data/lib/ruote/reader/radial.rb +290 -0
  83. data/lib/ruote/reader/ruby_dsl.rb +186 -0
  84. data/lib/ruote/reader/xml.rb +99 -0
  85. data/lib/ruote/receiver/base.rb +212 -0
  86. data/lib/ruote/storage/base.rb +364 -0
  87. data/lib/ruote/storage/composite_storage.rb +121 -0
  88. data/lib/ruote/storage/fs_storage.rb +139 -0
  89. data/lib/ruote/storage/hash_storage.rb +211 -0
  90. data/lib/ruote/svc/dispatch_pool.rb +158 -0
  91. data/lib/ruote/svc/dollar_sub.rb +298 -0
  92. data/lib/ruote/svc/error_handler.rb +138 -0
  93. data/lib/ruote/svc/expression_map.rb +97 -0
  94. data/lib/ruote/svc/participant_list.rb +397 -0
  95. data/lib/ruote/svc/tracker.rb +172 -0
  96. data/lib/ruote/svc/treechecker.rb +141 -0
  97. data/lib/ruote/tree_dot.rb +85 -0
  98. data/lib/ruote/util/filter.rb +525 -0
  99. data/lib/ruote/util/hashdot.rb +79 -0
  100. data/lib/ruote/util/look.rb +128 -0
  101. data/lib/ruote/util/lookup.rb +127 -0
  102. data/lib/ruote/util/misc.rb +167 -0
  103. data/lib/ruote/util/ometa.rb +71 -0
  104. data/lib/ruote/util/serializer.rb +103 -0
  105. data/lib/ruote/util/subprocess.rb +88 -0
  106. data/lib/ruote/util/time.rb +100 -0
  107. data/lib/ruote/util/tree.rb +58 -0
  108. data/lib/ruote/version.rb +29 -0
  109. data/lib/ruote/worker.rb +386 -0
  110. data/lib/ruote/workitem.rb +394 -0
  111. data/phil.txt +14 -0
  112. data/ruote.gemspec +44 -0
  113. data/test/bm/ci.rb +55 -0
  114. data/test/bm/ici.rb +71 -0
  115. data/test/bm/juuman.rb +54 -0
  116. data/test/bm/launch_bench.rb +37 -0
  117. data/test/bm/load_26c.rb +97 -0
  118. data/test/bm/mega.rb +64 -0
  119. data/test/bm/seq_thousand.rb +31 -0
  120. data/test/bm/t.rb +35 -0
  121. data/test/functional/base.rb +247 -0
  122. data/test/functional/concurrent_base.rb +98 -0
  123. data/test/functional/crunner.rb +31 -0
  124. data/test/functional/ct_0_concurrence.rb +65 -0
  125. data/test/functional/ct_1_iterator.rb +67 -0
  126. data/test/functional/ct_2_cancel.rb +81 -0
  127. data/test/functional/eft_0_process_definition.rb +65 -0
  128. data/test/functional/eft_10_cancel_process.rb +46 -0
  129. data/test/functional/eft_11_wait.rb +109 -0
  130. data/test/functional/eft_12_listen.rb +500 -0
  131. data/test/functional/eft_13_iterator.rb +342 -0
  132. data/test/functional/eft_14_cursor.rb +456 -0
  133. data/test/functional/eft_15_loop.rb +69 -0
  134. data/test/functional/eft_16_if.rb +183 -0
  135. data/test/functional/eft_17_equals.rb +55 -0
  136. data/test/functional/eft_18_concurrent_iterator.rb +410 -0
  137. data/test/functional/eft_19_reserve.rb +136 -0
  138. data/test/functional/eft_1_echo.rb +68 -0
  139. data/test/functional/eft_20_save.rb +116 -0
  140. data/test/functional/eft_21_restore.rb +61 -0
  141. data/test/functional/eft_22_noop.rb +28 -0
  142. data/test/functional/eft_23_apply.rb +168 -0
  143. data/test/functional/eft_24_add_branches.rb +98 -0
  144. data/test/functional/eft_25_command.rb +28 -0
  145. data/test/functional/eft_26_error.rb +77 -0
  146. data/test/functional/eft_27_inc.rb +280 -0
  147. data/test/functional/eft_28_once.rb +135 -0
  148. data/test/functional/eft_29_cron.rb +64 -0
  149. data/test/functional/eft_2_sequence.rb +58 -0
  150. data/test/functional/eft_30_ref.rb +155 -0
  151. data/test/functional/eft_31_registerp.rb +130 -0
  152. data/test/functional/eft_32_lose.rb +93 -0
  153. data/test/functional/eft_33_let.rb +31 -0
  154. data/test/functional/eft_34_given.rb +123 -0
  155. data/test/functional/eft_35_filter.rb +375 -0
  156. data/test/functional/eft_36_read.rb +95 -0
  157. data/test/functional/eft_3_participant.rb +149 -0
  158. data/test/functional/eft_4_set.rb +296 -0
  159. data/test/functional/eft_5_subprocess.rb +163 -0
  160. data/test/functional/eft_6_concurrence.rb +304 -0
  161. data/test/functional/eft_7_forget.rb +61 -0
  162. data/test/functional/eft_8_undo.rb +114 -0
  163. data/test/functional/eft_9_redo.rb +138 -0
  164. data/test/functional/ft_0_worker.rb +65 -0
  165. data/test/functional/ft_10_dollar.rb +304 -0
  166. data/test/functional/ft_11_recursion.rb +109 -0
  167. data/test/functional/ft_12_launchitem.rb +43 -0
  168. data/test/functional/ft_13_variables.rb +151 -0
  169. data/test/functional/ft_14_re_apply.rb +324 -0
  170. data/test/functional/ft_15_timeout.rb +226 -0
  171. data/test/functional/ft_16_participant_params.rb +98 -0
  172. data/test/functional/ft_17_conditional.rb +102 -0
  173. data/test/functional/ft_18_kill.rb +138 -0
  174. data/test/functional/ft_19_participant_code.rb +67 -0
  175. data/test/functional/ft_1_process_status.rb +796 -0
  176. data/test/functional/ft_20_storage_participant.rb +543 -0
  177. data/test/functional/ft_21_forget.rb +153 -0
  178. data/test/functional/ft_22_process_definitions.rb +90 -0
  179. data/test/functional/ft_23_load_defs.rb +79 -0
  180. data/test/functional/ft_24_block_participant.rb +235 -0
  181. data/test/functional/ft_25_receiver.rb +207 -0
  182. data/test/functional/ft_26_participant_rtimeout.rb +179 -0
  183. data/test/functional/ft_27_var_indirection.rb +128 -0
  184. data/test/functional/ft_28_null_noop_participants.rb +51 -0
  185. data/test/functional/ft_29_part_template.rb +60 -0
  186. data/test/functional/ft_2_errors.rb +380 -0
  187. data/test/functional/ft_30_smtp_participant.rb +122 -0
  188. data/test/functional/ft_31_part_blocking.rb +72 -0
  189. data/test/functional/ft_33_participant_subprocess_priority.rb +32 -0
  190. data/test/functional/ft_34_cursor_rewind.rb +101 -0
  191. data/test/functional/ft_35_add_service.rb +56 -0
  192. data/test/functional/ft_36_storage_history.rb +150 -0
  193. data/test/functional/ft_37_default_history.rb +109 -0
  194. data/test/functional/ft_38_participant_more.rb +193 -0
  195. data/test/functional/ft_39_wait_for.rb +136 -0
  196. data/test/functional/ft_3_participant_registration.rb +574 -0
  197. data/test/functional/ft_40_wait_logger.rb +62 -0
  198. data/test/functional/ft_41_participants.rb +91 -0
  199. data/test/functional/ft_42_storage_copy.rb +71 -0
  200. data/test/functional/ft_43_participant_on_reply.rb +87 -0
  201. data/test/functional/ft_44_var_participant.rb +35 -0
  202. data/test/functional/ft_45_participant_accept.rb +64 -0
  203. data/test/functional/ft_46_launch_single.rb +83 -0
  204. data/test/functional/ft_47_wfid_generator.rb +54 -0
  205. data/test/functional/ft_48_lose.rb +112 -0
  206. data/test/functional/ft_49_engine_on_error.rb +201 -0
  207. data/test/functional/ft_4_cancel.rb +132 -0
  208. data/test/functional/ft_50_engine_config.rb +22 -0
  209. data/test/functional/ft_51_misc.rb +67 -0
  210. data/test/functional/ft_52_case.rb +134 -0
  211. data/test/functional/ft_53_engine_on_terminate.rb +95 -0
  212. data/test/functional/ft_54_patterns.rb +104 -0
  213. data/test/functional/ft_55_engine_participant.rb +303 -0
  214. data/test/functional/ft_56_filter_attribute.rb +259 -0
  215. data/test/functional/ft_57_rev_participant.rb +252 -0
  216. data/test/functional/ft_58_workitem.rb +69 -0
  217. data/test/functional/ft_59_pause.rb +343 -0
  218. data/test/functional/ft_5_on_error.rb +384 -0
  219. data/test/functional/ft_60_code_participant.rb +45 -0
  220. data/test/functional/ft_61_trailing_fields.rb +34 -0
  221. data/test/functional/ft_62_exp_name_and_dollar_substitution.rb +35 -0
  222. data/test/functional/ft_6_on_cancel.rb +221 -0
  223. data/test/functional/ft_7_tags.rb +177 -0
  224. data/test/functional/ft_8_participant_consumption.rb +124 -0
  225. data/test/functional/ft_9_subprocesses.rb +146 -0
  226. data/test/functional/restart_base.rb +34 -0
  227. data/test/functional/rt_0_wait.rb +55 -0
  228. data/test/functional/rt_1_listen.rb +56 -0
  229. data/test/functional/rt_2_errors.rb +56 -0
  230. data/test/functional/rt_3_once.rb +70 -0
  231. data/test/functional/rt_4_cron.rb +64 -0
  232. data/test/functional/rt_5_timeout.rb +60 -0
  233. data/test/functional/rtest.rb +8 -0
  234. data/test/functional/storage_helper.rb +93 -0
  235. data/test/functional/test.rb +44 -0
  236. data/test/functional/vertical.rb +46 -0
  237. data/test/path_helper.rb +15 -0
  238. data/test/test.rb +13 -0
  239. data/test/test_helper.rb +28 -0
  240. data/test/unit/storage.rb +428 -0
  241. data/test/unit/storages.rb +37 -0
  242. data/test/unit/test.rb +28 -0
  243. data/test/unit/ut_0_ruby_reader.rb +223 -0
  244. data/test/unit/ut_11_lookup.rb +122 -0
  245. data/test/unit/ut_13_serializer.rb +65 -0
  246. data/test/unit/ut_14_is_uri.rb +28 -0
  247. data/test/unit/ut_15_util.rb +57 -0
  248. data/test/unit/ut_16_reader.rb +225 -0
  249. data/test/unit/ut_18_engine.rb +47 -0
  250. data/test/unit/ut_19_part_template.rb +86 -0
  251. data/test/unit/ut_1_fei.rb +165 -0
  252. data/test/unit/ut_20_composite_storage.rb +74 -0
  253. data/test/unit/ut_21_svc_participant_list.rb +46 -0
  254. data/test/unit/ut_22_filter.rb +1094 -0
  255. data/test/unit/ut_23_svc_tracker.rb +48 -0
  256. data/test/unit/ut_24_radial_reader.rb +332 -0
  257. data/test/unit/ut_25_merge.rb +113 -0
  258. data/test/unit/ut_3_wait_logger.rb +39 -0
  259. data/test/unit/ut_4_expmap.rb +20 -0
  260. data/test/unit/ut_5_tree.rb +54 -0
  261. data/test/unit/ut_6_condition.rb +303 -0
  262. data/test/unit/ut_7_workitem.rb +99 -0
  263. data/test/unit/ut_8_tree_to_dot.rb +72 -0
  264. data/test/unit/ut_9_xml_reader.rb +61 -0
  265. metadata +504 -0
@@ -0,0 +1,543 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Thu Dec 3 22:39:03 JST 2009
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'base')
9
+
10
+ require 'ruote/part/storage_participant'
11
+
12
+
13
+ class FtStorageParticipantTest < Test::Unit::TestCase
14
+ include FunctionalBase
15
+
16
+ def test_participant
17
+
18
+ pdef = Ruote.process_definition :name => 'def0' do
19
+ alpha
20
+ end
21
+
22
+ @engine.register_participant :alpha, Ruote::StorageParticipant
23
+
24
+ #noisy
25
+
26
+ wfid = @engine.launch(pdef)
27
+
28
+ wait_for(:alpha)
29
+
30
+ assert_equal 1, @engine.storage.get_many('workitems').size
31
+
32
+ alpha = Ruote::StorageParticipant.new
33
+ alpha.context = @engine.context
34
+
35
+ wi = alpha.first
36
+
37
+ assert_equal Ruote::Workitem, wi.class
38
+
39
+ wi = alpha[alpha.first.fei]
40
+ assert_equal Ruote::Workitem, wi.class
41
+
42
+ alpha.proceed(wi)
43
+
44
+ wait_for(wfid)
45
+
46
+ assert_nil @engine.process(wfid)
47
+ end
48
+
49
+ def test_purge
50
+
51
+ pdef = Ruote.process_definition :name => 'def0' do
52
+ alpha
53
+ end
54
+
55
+ @engine.register_participant :alpha, Ruote::StorageParticipant
56
+
57
+ #noisy
58
+
59
+ wfid = @engine.launch(pdef)
60
+
61
+ wait_for(:alpha)
62
+
63
+ assert_equal 1, @engine.storage.get_many('workitems').size
64
+
65
+ alpha = Ruote::StorageParticipant.new
66
+ alpha.context = @engine.context
67
+
68
+ assert !alpha.first.nil?
69
+
70
+ alpha.purge!
71
+
72
+ assert alpha.first.nil?
73
+ end
74
+
75
+ def test_all
76
+
77
+ n = 3
78
+
79
+ pdef = Ruote.process_definition :name => 'def0' do
80
+ alpha
81
+ end
82
+
83
+ @engine.register_participant :alpha, Ruote::StorageParticipant
84
+
85
+ wfids = []
86
+
87
+ n.times { wfids << @engine.launch(pdef) }
88
+
89
+ while @engine.storage_participant.size < n
90
+ sleep 0.400
91
+ end
92
+
93
+ assert_equal(
94
+ [ Ruote::Workitem ] * 3,
95
+ @engine.storage_participant.all.collect { |wi| wi.class })
96
+
97
+ assert_equal 3, @engine.storage_participant.size
98
+ assert_equal 3, @engine.storage_participant.all(:count => true)
99
+ end
100
+
101
+ def test_by_wfid
102
+
103
+ pdef = Ruote.process_definition :name => 'def0' do
104
+ concurrence do
105
+ alpha
106
+ alpha
107
+ end
108
+ end
109
+
110
+ @engine.register_participant :alpha, Ruote::StorageParticipant
111
+
112
+ wfid = @engine.launch(pdef)
113
+
114
+ wait_for(:alpha)
115
+ wait_for(:alpha)
116
+ # wait for the two workitems
117
+
118
+ alpha = Ruote::StorageParticipant.new
119
+ alpha.context = @engine.context
120
+
121
+ assert_equal 2, alpha.size
122
+ assert_equal 2, alpha.by_wfid(wfid).size
123
+ assert_equal 2, alpha.by_wfid(wfid, :count => true)
124
+ end
125
+
126
+ CON_AL_BRAVO = Ruote.process_definition :name => 'con_al_bravo' do
127
+ set 'f:place' => 'heiankyou'
128
+ concurrence do
129
+ sequence do
130
+ set 'f:character' => 'minamoto no hirosama'
131
+ alpha
132
+ end
133
+ sequence do
134
+ set 'f:character' => 'seimei'
135
+ set 'f:adversary' => 'doson'
136
+ bravo
137
+ end
138
+ end
139
+ end
140
+
141
+ def prepare_al_bravo
142
+
143
+ @engine.register_participant :alpha, Ruote::StorageParticipant
144
+ @engine.register_participant :bravo, Ruote::StorageParticipant
145
+
146
+ @wfid = @engine.launch(CON_AL_BRAVO)
147
+
148
+ wait_for(:bravo)
149
+
150
+ @part = Ruote::StorageParticipant.new
151
+ @part.context = @engine.context
152
+ end
153
+
154
+ def test_by_participant
155
+
156
+ prepare_al_bravo
157
+
158
+ assert_equal 2, @part.size
159
+ #@part.by_participant('alpha').each { |wi| p wi }
160
+ assert_equal Ruote::Workitem, @part.by_participant('alpha').first.class
161
+ assert_equal 1, @part.by_participant('alpha').size
162
+ assert_equal 1, @part.by_participant('bravo').size
163
+
164
+ assert_equal 1, @part.by_participant('alpha', :count => true)
165
+ assert_equal 1, @part.by_participant('bravo', :count => true)
166
+ end
167
+
168
+ def test_by_participant_and_limit
169
+
170
+ 3.times do |i|
171
+ @engine.storage.put(
172
+ 'type' => 'workitems',
173
+ '_id' => "0_#{i}!ffffff!20101219-yamamba",
174
+ 'participant_name' => 'al',
175
+ 'wfid' => '20101220-yamamba',
176
+ 'fields' => {})
177
+ end
178
+ 3.times do |i|
179
+ @engine.storage.put(
180
+ 'type' => 'workitems',
181
+ '_id' => "1_#{i}!eeeeee!20101219-yamamba",
182
+ 'participant_name' => 'bob',
183
+ 'wfid' => '20101220-yamamba',
184
+ 'fields' => {})
185
+ end
186
+
187
+ sp = @engine.storage_participant
188
+
189
+ assert_equal 6, sp.size
190
+
191
+ assert_equal 0, sp.by_participant('nada', :limit => 2).size
192
+ assert_equal 2, sp.by_participant('al', :limit => 2).size
193
+ assert_equal 2, sp.by_participant('al', :skip => 0, :limit => 2).size
194
+ assert_equal 2, sp.by_participant('al', :skip => 1, :limit => 2).size
195
+
196
+ assert_equal 2, sp.by_participant('bob', :skip => 0, :limit => 2).size
197
+ assert_equal 1, sp.by_participant('bob', :skip => 2, :limit => 2).size
198
+ end
199
+
200
+ def test_by_field
201
+
202
+ prepare_al_bravo
203
+
204
+ assert_equal 2, @part.size
205
+ assert_equal Ruote::Workitem, @part.by_field('place').first.class
206
+ assert_equal 2, @part.by_field('place').size
207
+ assert_equal 2, @part.by_field('character').size
208
+ assert_equal 1, @part.by_field('adversary').size
209
+ assert_equal 2, @part.by_field('character', :count => true)
210
+ end
211
+
212
+ def test_by_field_and_limit
213
+
214
+ prepare_al_bravo
215
+
216
+ assert_equal(
217
+ %w[ bravo ],
218
+ @part.by_field(
219
+ 'character', :skip => 1, :limit => 2
220
+ ).collect { |wi| wi.participant_name })
221
+ end
222
+
223
+ def test_by_field_and_value
224
+
225
+ prepare_al_bravo
226
+
227
+ assert_equal 2, @part.size
228
+ assert_equal 0, @part.by_field('place', 'nara').size
229
+ assert_equal 2, @part.by_field('place', 'heiankyou').size
230
+ assert_equal 1, @part.by_field('character', 'minamoto no hirosama').size
231
+ assert_equal 2, @part.by_field('place', 'heiankyou', :count => true)
232
+ end
233
+
234
+ def test_query
235
+
236
+ prepare_al_bravo
237
+
238
+ wfid2 = @engine.launch(CON_AL_BRAVO, 'adversary' => 'B')
239
+ wait_for(:bravo)
240
+
241
+ #@part.query({}).each { |wi| puts '-' * 80; p wi }
242
+
243
+ assert_equal 4, @part.size
244
+ assert_equal 4, @part.query({}).size
245
+ assert_equal Ruote::Workitem, @part.query({}).first.class
246
+ assert_equal 2, @part.query(:wfid => @wfid).size
247
+ assert_equal 0, @part.query('place' => 'nara').size
248
+ assert_equal 4, @part.query('place' => 'heiankyou').size
249
+ assert_equal 2, @part.query(:wfid => @wfid, :place => 'heiankyou').size
250
+
251
+ assert_equal(
252
+ 1,
253
+ @part.query(:adversary => 'B', :place => 'heiankyou').size)
254
+
255
+ assert_equal 2, @part.query('place' => 'heiankyou', :limit => 2).size
256
+ assert_equal 4, @part.query('place' => 'heiankyou', :limit => 20).size
257
+
258
+ assert_equal 4, @part.query(:count => true)
259
+
260
+ page0 =
261
+ @part.query('place' => 'heiankyou', :limit => 2).collect { |wi|
262
+ "#{wi.fei.wfid}-#{wi.participant_name}" }
263
+ page1 =
264
+ @part.query('place' => 'heiankyou', :offset => 2, :limit => 2).collect { |wi|
265
+ "#{wi.fei.wfid}-#{wi.participant_name}" }
266
+
267
+ assert_equal 4, (page0 + page1).sort.uniq.size
268
+
269
+ assert_equal(
270
+ 2, @part.query('place' => 'heiankyou', :participant => 'alpha').size)
271
+
272
+ assert_equal 2, @part.query(:participant => 'alpha').size
273
+ assert_equal 2, @part.query(:participant => 'alpha', :count => true)
274
+ end
275
+
276
+ # Issue reported in
277
+ # http://groups.google.com/group/openwferu-users/browse_thread/thread/d0557c58f8636c9
278
+ #
279
+ def test_query_and_limit
280
+
281
+ n = 7
282
+
283
+ n.times do |i|
284
+ @engine.storage.put(
285
+ 'type' => 'workitems',
286
+ '_id' => "0_#{i}!ffffff!20101219-yamamba",
287
+ 'participant_name' => 'al',
288
+ 'wfid' => '20101219-yamamba',
289
+ 'fields' => {})
290
+ end
291
+ n.times do |i|
292
+ @engine.storage.put(
293
+ 'type' => 'workitems',
294
+ '_id' => "1_#{i}!ffffff!20101219-yamamba",
295
+ 'participant_name' => 'bob',
296
+ 'wfid' => '20101219-yamamba',
297
+ 'fields' => {})
298
+ end
299
+
300
+ sp = @engine.storage_participant
301
+
302
+ assert_equal n * 2, sp.query({}).size
303
+ assert_equal n * 2, sp.query(:offset => 0, :limit => 100).size
304
+ assert_equal n * 2, sp.query(:skip => 0, :limit => 100).size
305
+
306
+ assert_equal n / 2, sp.query(:offset => 0, :limit => n / 2).size
307
+ assert_equal n / 2, sp.query(:skip => 0, :limit => n / 2).size
308
+
309
+ assert_equal(
310
+ n / 2,
311
+ sp.query(:participant_name => 'al', :offset => 0, :limit => n / 2).size)
312
+ assert_equal(
313
+ n / 2,
314
+ sp.query(:participant_name => 'al', :skip => 0, :limit => n / 2).size)
315
+
316
+ assert_equal(
317
+ [ 'al' ] * (n / 2),
318
+ sp.query(
319
+ :participant_name => 'al', :skip => 0, :limit => n / 2
320
+ ).collect { |wi| wi.participant_name })
321
+ end
322
+
323
+ def test_initialize_engine_then_opts
324
+
325
+ @engine.register_participant :alpha, Ruote::StorageParticipant
326
+
327
+ wfid = @engine.launch(Ruote.process_definition do
328
+ alpha
329
+ end)
330
+
331
+ wait_for(:alpha)
332
+
333
+ part = Ruote::StorageParticipant.new(@engine)
334
+
335
+ assert_equal 1, part.size
336
+ end
337
+
338
+ def test_cancel
339
+
340
+ pdef = Ruote.process_definition :name => 'def0' do
341
+ alpha
342
+ end
343
+
344
+ @engine.register_participant :alpha, Ruote::StorageParticipant
345
+
346
+ #noisy
347
+
348
+ wfid = @engine.launch(pdef)
349
+
350
+ wait_for(:alpha)
351
+
352
+ @engine.cancel_process(wfid)
353
+
354
+ wait_for(wfid)
355
+
356
+ assert_nil @engine.process(wfid)
357
+ assert_equal 0, Ruote::StorageParticipant.new(@engine).size
358
+ end
359
+
360
+ def test_shared_participant
361
+
362
+ @engine.register_participant 'step_.*', Ruote::StorageParticipant
363
+
364
+ wfid = @engine.launch(
365
+ Ruote.process_definition { sequence { step_one; step_two } })
366
+
367
+ wait_for(:step_one)
368
+
369
+ participant = Ruote::StorageParticipant.new(@engine)
370
+
371
+ items = participant.by_wfid(wfid)
372
+
373
+ assert_equal 1, participant.size
374
+ assert_equal 1, items.size
375
+ assert_equal 'step_one', items.first.participant_name
376
+
377
+ participant.proceed(items.first)
378
+
379
+ wait_for(:step_two)
380
+
381
+ items = participant.by_wfid(wfid)
382
+
383
+ assert_equal 1, participant.size
384
+ assert_equal 1, items.size
385
+ assert_equal 'step_two', items.first.participant_name
386
+
387
+ participant.proceed(items.first)
388
+
389
+ wait_for(wfid)
390
+
391
+ assert_nil @engine.process(wfid)
392
+ end
393
+
394
+ def test_update_workitem
395
+
396
+ @engine.register_participant 'alpha', Ruote::StorageParticipant
397
+
398
+ wfid = @engine.launch(Ruote.process_definition { alpha })
399
+
400
+ alpha = Ruote::StorageParticipant.new(@engine)
401
+
402
+ wait_for(:alpha)
403
+
404
+ wi = alpha.first
405
+
406
+ wi.fields['jidai'] = 'heian'
407
+
408
+ alpha.update(wi)
409
+
410
+ assert_equal 'heian', alpha.first.fields['jidai']
411
+ end
412
+
413
+ def test_registration
414
+
415
+ pa = @engine.register_participant 'alpha', Ruote::StorageParticipant
416
+
417
+ assert_equal Ruote::StorageParticipant, pa.class
418
+
419
+ assert_equal [], pa.all
420
+ end
421
+
422
+ def test_various_args
423
+
424
+ sp = @engine.register_participant 'alpha', Ruote::StorageParticipant
425
+
426
+ wfid = @engine.launch(Ruote.process_definition { alpha })
427
+
428
+ wait_for(:alpha)
429
+
430
+ wi = sp.first
431
+
432
+ assert_equal wi, sp[wi]
433
+ assert_equal wi, sp[wi.fei]
434
+ assert_equal wi, sp[wi.to_h]
435
+ assert_equal wi, sp[wi.fei.to_h]
436
+ assert_equal wi, sp[wi.fei.to_storage_id]
437
+ end
438
+
439
+ def test_by_fei
440
+
441
+ sp = @engine.register_participant 'alpha', Ruote::StorageParticipant
442
+
443
+ wfid = @engine.launch(Ruote.process_definition { alpha })
444
+
445
+ wait_for(:alpha)
446
+
447
+ wi = sp.first
448
+
449
+ assert_equal wi, sp.by_fei(wi)
450
+ assert_equal wi, sp.by_fei(wi.fei)
451
+ assert_equal wi, sp.by_fei(wi.to_h)
452
+ assert_equal wi, sp.by_fei(wi.fei.to_h)
453
+ assert_equal wi, sp.by_fei(wi.fei.to_storage_id)
454
+ end
455
+
456
+ def test_engine_storage_participant
457
+
458
+ @engine.register_participant 'step_.*', Ruote::StorageParticipant
459
+
460
+ wfid = @engine.launch(Ruote.process_definition { step_one })
461
+
462
+ wait_for(:step_one)
463
+
464
+ assert_equal 1, @engine.storage_participant.size
465
+ assert_equal 'step_one', @engine.storage_participant.first.participant_name
466
+ end
467
+
468
+ class MyParticipant < Ruote::StorageParticipant
469
+ def consume(wi)
470
+ @context.tracer << "consume\n"
471
+ super
472
+ end
473
+ #def update(wi)
474
+ # @context.tracer << "update\n"
475
+ # super
476
+ #end
477
+ end
478
+
479
+ def test_override_update
480
+
481
+ pdef = Ruote.define do
482
+ alpha
483
+ end
484
+
485
+ @engine.register do
486
+ alpha MyParticipant
487
+ end
488
+
489
+ @engine.launch(pdef)
490
+ @engine.wait_for(:alpha)
491
+
492
+ part = @engine.participant(:alpha)
493
+
494
+ initial_rev = part.first.h['_rev']
495
+
496
+ part.update(part.first)
497
+
498
+ assert_not_equal initial_rev, part.first.h['_rev']
499
+ assert_equal %w[ consume ], @tracer.to_a
500
+ end
501
+
502
+ def test_fetch
503
+
504
+ @engine.register do
505
+ catchall
506
+ end
507
+
508
+ @engine.launch(Ruote.define do
509
+ alpha
510
+ end)
511
+
512
+ @engine.wait_for(:alpha)
513
+
514
+ fei = @engine.storage_participant.first.fei
515
+
516
+ wi = @engine.storage_participant.send(:fetch, fei)
517
+
518
+ assert_equal Hash, wi.class
519
+ end
520
+
521
+ # StorageParticipant includes Enumerable, therefore, it should respond
522
+ # to select...
523
+ #
524
+ # http://groups.google.com/group/openwferu-users/t/6b594fd141f5d4b1
525
+ #
526
+ def test_select
527
+
528
+ @engine.register { catchall }
529
+
530
+ @engine.launch(Ruote.define do
531
+ concurrence { alpha; bravo; charly }
532
+ end)
533
+
534
+ while @engine.storage_participant.size < 3; end
535
+
536
+ assert_equal(
537
+ 1,
538
+ @engine.storage_participant.select { |wi|
539
+ wi.participant_name == 'bravo'
540
+ }.size)
541
+ end
542
+ end
543
+