PageRenderTime 28ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/test/functional/ft_63_participants_221.rb

http://github.com/jmettraux/ruote
Ruby | 458 lines | 322 code | 99 blank | 37 comment | 0 complexity | ed393c4f78628e69a394226994509a32 MD5 | raw file
  1. #
  2. # testing ruote
  3. #
  4. # Mon Jun 27 15:18:18 JST 2011
  5. #
  6. require File.expand_path('../base', __FILE__)
  7. class FtParticipantsTwoTwoOne < Test::Unit::TestCase
  8. include FunctionalBase
  9. #
  10. # on_workitem / consume
  11. class ClassicParticipant
  12. include Ruote::LocalParticipant
  13. def consume(workitem)
  14. (workitem.fields['trace'] ||= []) << workitem.participant_name
  15. reply_to_engine(workitem)
  16. end
  17. end
  18. class AlphaParticipant
  19. include Ruote::LocalParticipant
  20. def on_workitem(workitem)
  21. (workitem.fields['trace'] ||= []) << workitem.participant_name
  22. reply_to_engine(workitem)
  23. end
  24. end
  25. class BravoParticipant
  26. include Ruote::LocalParticipant
  27. def on_workitem
  28. (workitem.fields['trace'] ||= []) << workitem.participant_name
  29. reply_to_engine
  30. end
  31. end
  32. class CharlyParticipant
  33. include Ruote::LocalParticipant
  34. def consume
  35. (workitem.fields['trace'] ||= []) << workitem.participant_name
  36. reply_to_engine
  37. end
  38. end
  39. class DeltaParticipant
  40. include Ruote::LocalParticipant
  41. def on_workitem
  42. (workitem.fields['trace'] ||= []) << workitem.participant_name
  43. reply
  44. end
  45. end
  46. def test_on_workitem
  47. @dashboard.register do
  48. classic ClassicParticipant
  49. alpha AlphaParticipant
  50. bravo BravoParticipant
  51. charly CharlyParticipant
  52. delta DeltaParticipant
  53. end
  54. #@dashboard.noisy = true
  55. wfid = @dashboard.launch(Ruote.define do
  56. classic; alpha; bravo; charly; delta
  57. end)
  58. r = @dashboard.wait_for(wfid)
  59. assert_equal(
  60. %w[ classic alpha bravo charly delta ], r['workitem']['fields']['trace'])
  61. end
  62. #
  63. # on_cancel / cancel
  64. class ZuluParticipant
  65. include Ruote::LocalParticipant
  66. def on_workitem
  67. # do nothing
  68. end
  69. def cancel(fei, flavour)
  70. (workitem.fields['trace'] ||= []) <<
  71. "#{workitem.participant_name}/#{fei.sid}/#{flavour}"
  72. end
  73. end
  74. class YankeeParticipant
  75. include Ruote::LocalParticipant
  76. def on_workitem
  77. # do nothing
  78. end
  79. def on_cancel(fei, flavour)
  80. (workitem.fields['trace'] ||= []) <<
  81. "#{workitem.participant_name}/#{fei.sid}/#{flavour}"
  82. end
  83. end
  84. class XrayParticipant
  85. include Ruote::LocalParticipant
  86. def on_workitem
  87. # do nothing
  88. end
  89. def on_cancel
  90. (workitem.fields['trace'] ||= []) <<
  91. "#{workitem.participant_name}/#{fei.sid}/#{flavour}"
  92. end
  93. end
  94. def test_on_cancel
  95. @dashboard.register do
  96. xray XrayParticipant
  97. yankee YankeeParticipant
  98. zulu ZuluParticipant
  99. end
  100. #@dashboard.noisy = true
  101. wfid = @dashboard.launch(Ruote.define do
  102. xray; yankee; zulu
  103. end)
  104. [ :xray, :yankee, :zulu ].each do |participant|
  105. r = @dashboard.wait_for(participant)
  106. @dashboard.wait_for(1)
  107. @dashboard.cancel(r['fei'])
  108. end
  109. @dashboard.wait_for(wfid)
  110. end
  111. #
  112. # accept?
  113. class AcAlphaParticipant
  114. include Ruote::LocalParticipant
  115. def on_workitem
  116. @context.tracer << workitem.participant_name + "\n"
  117. reply
  118. end
  119. def accept?(workitem)
  120. @context.tracer << "a/#{workitem.participant_name}\n"
  121. true
  122. end
  123. end
  124. class AcBravoParticipant
  125. include Ruote::LocalParticipant
  126. def on_workitem
  127. @context.tracer << workitem.participant_name + "\n"
  128. reply
  129. end
  130. def accept?
  131. @context.tracer << "a/#{workitem.participant_name}\n"
  132. true
  133. end
  134. end
  135. def test_accept
  136. #@dashboard.noisy = true
  137. @dashboard.register do
  138. alpha AcAlphaParticipant
  139. bravo AcBravoParticipant
  140. end
  141. wfid = @dashboard.launch(Ruote.define do
  142. alpha; bravo
  143. end)
  144. @dashboard.wait_for(wfid)
  145. assert_equal %w[ a/alpha alpha a/bravo bravo ], @tracer.to_a
  146. end
  147. #
  148. # on_reply
  149. class OrAlphaParticipant
  150. include Ruote::LocalParticipant
  151. def on_workitem
  152. @context.tracer << "ow/#{workitem.participant_name}\n"
  153. reply
  154. end
  155. def on_reply(workitem)
  156. @context.tracer << "or/#{workitem.participant_name}\n"
  157. end
  158. end
  159. class OrBravoParticipant
  160. include Ruote::LocalParticipant
  161. def on_workitem
  162. @context.tracer << "ow/#{workitem.participant_name}\n"
  163. reply
  164. end
  165. def on_reply
  166. @context.tracer << "or/#{workitem.participant_name}\n"
  167. end
  168. end
  169. def test_on_reply
  170. #@dashboard.noisy = true
  171. @dashboard.register do
  172. alpha OrAlphaParticipant
  173. bravo OrBravoParticipant
  174. end
  175. wfid = @dashboard.launch(Ruote.define do
  176. alpha; bravo
  177. end)
  178. @dashboard.wait_for(wfid)
  179. assert_equal %w[ ow/alpha or/alpha ow/bravo or/bravo ], @tracer.to_a
  180. end
  181. #
  182. # do_not_thread? / do_not_thread
  183. class DntAlphaParticipant
  184. include Ruote::LocalParticipant
  185. def on_workitem
  186. @context.tracer << "ow/#{workitem.participant_name}\n"
  187. reply
  188. end
  189. def do_not_thread(workitem)
  190. @context.tracer << "dnt/#{workitem.participant_name}\n"
  191. end
  192. end
  193. class DntBravoParticipant
  194. include Ruote::LocalParticipant
  195. def on_workitem
  196. @context.tracer << "ow/#{workitem.participant_name}\n"
  197. reply
  198. end
  199. def do_not_thread?(workitem)
  200. @context.tracer << "dnt/#{workitem.participant_name}\n"
  201. end
  202. end
  203. class DntCharlyParticipant
  204. include Ruote::LocalParticipant
  205. def on_workitem
  206. @context.tracer << "ow/#{workitem.participant_name}\n"
  207. reply
  208. end
  209. def do_not_thread?
  210. @context.tracer << "dnt/#{workitem.participant_name}\n"
  211. end
  212. end
  213. class DntDeltaParticipant
  214. include Ruote::LocalParticipant
  215. def on_workitem
  216. @context.tracer << "ow/#{workitem.participant_name}\n"
  217. reply
  218. end
  219. def dont_thread?
  220. @context.tracer << "dnt/#{workitem.participant_name}\n"
  221. end
  222. end
  223. def test_do_not_thread
  224. #@dashboard.noisy = true
  225. @dashboard.register do
  226. alpha DntAlphaParticipant
  227. bravo DntBravoParticipant
  228. charly DntCharlyParticipant
  229. delta DntDeltaParticipant
  230. end
  231. wfid = @dashboard.launch(Ruote.define do
  232. alpha; bravo; charly; delta
  233. end)
  234. @dashboard.wait_for(wfid)
  235. assert_equal(
  236. %w[ dnt/alpha ow/alpha
  237. dnt/bravo ow/bravo
  238. dnt/charly ow/charly
  239. dnt/delta ow/delta ],
  240. @tracer.to_a)
  241. end
  242. #
  243. # on_pause / on_resume
  244. class OpAlphaParticipant
  245. include Ruote::LocalParticipant
  246. def on_workitem
  247. @context.tracer << "ow/#{workitem.participant_name}\n"
  248. end
  249. def on_cancel
  250. @context.tracer << "oc/#{fei.expid}\n"
  251. end
  252. def on_pause(fei)
  253. @context.tracer << "op/#{fei.expid}\n"
  254. end
  255. def on_resume(fei)
  256. @context.tracer << "or/#{fei.expid}\n"
  257. end
  258. end
  259. class OpBravoParticipant
  260. include Ruote::LocalParticipant
  261. def on_workitem
  262. @context.tracer << "ow/#{workitem.participant_name}\n"
  263. end
  264. def on_pause
  265. @context.tracer << "op/#{fei.expid}\n"
  266. end
  267. def on_resume
  268. @context.tracer << "or/#{fei.expid}\n"
  269. end
  270. end
  271. def test_on_pause_on_resume
  272. #@dashboard.noisy = true
  273. @dashboard.register do
  274. alpha OpAlphaParticipant
  275. bravo OpBravoParticipant
  276. end
  277. wfid = @dashboard.launch(Ruote.define do
  278. alpha; bravo
  279. end)
  280. r = @dashboard.wait_for(:alpha)
  281. @dashboard.wait_for(1)
  282. @dashboard.pause(r['fei'])
  283. @dashboard.wait_for(2)
  284. @dashboard.resume(r['fei'])
  285. @dashboard.wait_for(2)
  286. @dashboard.cancel(r['fei'])
  287. r = @dashboard.wait_for(:bravo)
  288. @dashboard.wait_for(1)
  289. @dashboard.pause(r['fei'])
  290. @dashboard.wait_for(2)
  291. @dashboard.resume(r['fei'])
  292. @dashboard.wait_for(2)
  293. assert_equal(
  294. %w[ ow/alpha op/0_0 or/0_0 oc/0_0 ow/bravo op/0_1 or/0_1 ],
  295. @tracer.to_a)
  296. end
  297. #
  298. # implicit participant name
  299. class IpnParticipant
  300. include Ruote::LocalParticipant
  301. def consume
  302. @context.tracer << participant_name
  303. reply
  304. end
  305. end
  306. def test_implicit_participant_name
  307. @dashboard.register { hypno IpnParticipant }
  308. #@dashboard.noisy = true
  309. wfid = @dashboard.launch(Ruote.define do
  310. hypno
  311. end)
  312. @dashboard.wait_for(wfid)
  313. assert_equal 'hypno', @tracer.to_s
  314. end
  315. #
  316. # fexp, fexp(fei)
  317. # workitem, workitem(fei)
  318. # applied_workitem, applied_workitem(fei)
  319. class FexpParticipant
  320. include Ruote::LocalParticipant
  321. def consume
  322. @context.tracer << fexp.lookup_variable('nada') + "\n"
  323. @context.tracer << fexp(fei).lookup_variable('nada') + "\n"
  324. @context.tracer << workitem.fields.size.to_s + "\n"
  325. @context.tracer << workitem(fei).fields.size.to_s + "\n"
  326. @context.tracer << applied_workitem.fields.size.to_s + "\n"
  327. @context.tracer << applied_workitem(fei).fields.size.to_s + "\n"
  328. reply
  329. end
  330. end
  331. def test_helper_methods
  332. @dashboard.register { felix FexpParticipant }
  333. #@dashboard.noisy = true
  334. wfid = @dashboard.launch(
  335. Ruote.define() { felix },
  336. {},
  337. { 'nada' => 'surf' })
  338. @dashboard.wait_for(wfid)
  339. assert_equal(
  340. %w[ surf surf 2 1 1 1 ],
  341. @tracer.to_a)
  342. end
  343. #
  344. # lookup_variable(key)
  345. class LvParticipant
  346. include Ruote::LocalParticipant
  347. def on_workitem
  348. @context.tracer << lookup_variable('nada') + "\n"
  349. reply
  350. end
  351. end
  352. def test_lookup_variable
  353. @dashboard.register { louis LvParticipant }
  354. #@dashboard.noisy = true
  355. wfid = @dashboard.launch(Ruote.define() { louis }, {}, { 'nada' => 'surf' })
  356. @dashboard.wait_for(wfid)
  357. assert_equal 'surf', @tracer.to_s
  358. end
  359. end