unageanu-jiji 1.1.4 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. data/ChangeLog +24 -1
  2. data/README +0 -0
  3. data/base/shared_lib/moving_average.rb +34 -33
  4. data/base/shared_lib/system/cross.rb +76 -0
  5. data/base/shared_lib/system/position_manager.rb +160 -0
  6. data/base/shared_lib/system/signal.rb +347 -0
  7. data/html/css/datatable.css +4 -4
  8. data/html/css/default.css +57 -5
  9. data/html/css/treeview.css +205 -0
  10. data/html/img/bin_closed.png +0 -0
  11. data/html/img/bin_empty.png +0 -0
  12. data/html/img/button_add_small.gif +0 -0
  13. data/html/img/button_add_small_gray.gif +0 -0
  14. data/html/img/button_add_small_over.gif +0 -0
  15. data/html/img/button_mkcol.gif +0 -0
  16. data/html/img/button_mkcol_gray.gif +0 -0
  17. data/html/img/button_mkcol_over.gif +0 -0
  18. data/html/img/button_remove_small.gif +0 -0
  19. data/html/img/button_remove_small_gray.gif +0 -0
  20. data/html/img/button_remove_small_over.gif +0 -0
  21. data/html/img/button_rename.gif +0 -0
  22. data/html/img/button_rename_gray.gif +0 -0
  23. data/html/img/button_rename_over.gif +0 -0
  24. data/html/img/control_play.png +0 -0
  25. data/html/img/control_play_blue.png +0 -0
  26. data/html/img/folder.png +0 -0
  27. data/html/img/folder_brick.png +0 -0
  28. data/html/img/folder_user.png +0 -0
  29. data/html/{js/codepress/images → img}/line-numbers.png +0 -0
  30. data/html/img/page_white_ruby.png +0 -0
  31. data/html/img/sidebar_agent_edit.png +0 -0
  32. data/html/img/sidebar_agent_edit_over.png +0 -0
  33. data/html/img/sidebar_agent_edit_s.png +0 -0
  34. data/html/img/yui/treeview-sprite.gif +0 -0
  35. data/html/index.html +34 -18
  36. data/html/js/agent-editor/agent-editor-page.js +324 -0
  37. data/html/js/agent-editor/agent-editor.js +363 -0
  38. data/html/js/agent-editor/agent-list-tree.js +251 -0
  39. data/html/js/agent-selector.js +23 -28
  40. data/html/js/app.js +63 -91
  41. data/html/js/bt-create-page.js +25 -19
  42. data/html/js/container-min.js +1 -1
  43. data/html/js/container.js +944 -0
  44. data/html/js/edit_area/autocompletion.js +11 -13
  45. data/html/js/edit_area/edit_area.css +79 -40
  46. data/html/js/edit_area/edit_area.js +255 -226
  47. data/html/js/edit_area/edit_area_compressor.php +4 -4
  48. data/html/js/edit_area/edit_area_full.gz +0 -0
  49. data/html/js/edit_area/edit_area_full.js +31 -31
  50. data/html/js/edit_area/edit_area_full_with_plugins.gz +0 -0
  51. data/html/js/edit_area/edit_area_full_with_plugins.js +31 -31
  52. data/html/js/edit_area/edit_area_functions.js +448 -341
  53. data/html/js/edit_area/edit_area_loader.js +409 -397
  54. data/html/js/edit_area/elements_functions.js +120 -123
  55. data/html/js/edit_area/highlight.js +305 -197
  56. data/html/js/edit_area/images/goto.png +0 -0
  57. data/html/js/edit_area/images/help.png +0 -0
  58. data/html/js/edit_area/images/redo.png +0 -0
  59. data/html/js/edit_area/images/save.png +0 -0
  60. data/html/js/edit_area/images/search.png +0 -0
  61. data/html/js/edit_area/images/undo.png +0 -0
  62. data/html/js/edit_area/images/word_wrap.gif +0 -0
  63. data/html/js/edit_area/keyboard.js +5 -5
  64. data/html/js/edit_area/langs/bg.js +73 -0
  65. data/html/js/edit_area/langs/cs.js +2 -0
  66. data/html/js/edit_area/langs/de.js +2 -0
  67. data/html/js/edit_area/langs/dk.js +2 -0
  68. data/html/js/edit_area/langs/en.js +2 -0
  69. data/html/js/edit_area/langs/eo.js +2 -0
  70. data/html/js/edit_area/langs/es.js +2 -0
  71. data/html/js/edit_area/langs/fi.js +67 -0
  72. data/html/js/edit_area/langs/fr.js +2 -0
  73. data/html/js/edit_area/langs/hr.js +2 -0
  74. data/html/js/edit_area/langs/it.js +2 -0
  75. data/html/js/edit_area/langs/ja.js +2 -0
  76. data/html/js/edit_area/langs/mk.js +2 -0
  77. data/html/js/edit_area/langs/nl.js +2 -0
  78. data/html/js/edit_area/langs/pl.js +2 -0
  79. data/html/js/edit_area/langs/pt.js +2 -0
  80. data/html/js/edit_area/langs/ru.js +2 -0
  81. data/html/js/edit_area/langs/sk.js +2 -0
  82. data/html/js/edit_area/langs/zh.js +67 -0
  83. data/html/js/edit_area/manage_area.js +362 -205
  84. data/html/js/edit_area/plugins/charmap/langs/bg.js +12 -0
  85. data/html/js/edit_area/plugins/charmap/langs/zh.js +6 -0
  86. data/html/js/edit_area/plugins/test/langs/bg.js +10 -0
  87. data/html/js/edit_area/plugins/test/langs/zh.js +4 -0
  88. data/html/js/edit_area/reg_syntax/java.js +56 -0
  89. data/html/js/edit_area/reg_syntax/ruby.js +9 -9
  90. data/html/js/edit_area/reg_syntax.js +15 -13
  91. data/html/js/edit_area/regexp.js +36 -32
  92. data/html/js/edit_area/resize_area.js +43 -47
  93. data/html/js/edit_area/search_replace.js +29 -29
  94. data/html/js/edit_area/template.html +6 -4
  95. data/html/js/json-broker-client.js +23 -17
  96. data/html/js/result-page.js +107 -57
  97. data/html/js/rt-setting-page.js +38 -15
  98. data/html/js/sidebar.js +41 -27
  99. data/html/js/templates.js +167 -32
  100. data/html/js/utils.js +143 -7
  101. data/html/js/yui/treeview.js +3671 -0
  102. data/html/swf/chart.swf +0 -0
  103. data/html/test/agent_editor_spec.js +815 -0
  104. data/html/test/index.html +40 -0
  105. data/html/test/jsspec/JSSpec.css +224 -0
  106. data/html/test/jsspec/JSSpec.js +1549 -0
  107. data/html/test/jsspec/diff_match_patch.js +1 -0
  108. data/html/test/utils_spec.js +111 -0
  109. data/lib/jiji/agent/agent.rb +69 -12
  110. data/lib/jiji/agent/agent_manager.rb +18 -12
  111. data/lib/jiji/agent/agent_registry.rb +35 -121
  112. data/lib/jiji/collector.rb +16 -6
  113. data/lib/jiji/command.rb +46 -5
  114. data/lib/jiji/dao/file_system_dao.rb +158 -0
  115. data/lib/jiji/dao/timed_data_dao.rb +2 -0
  116. data/lib/jiji/dao/trade_result_dao.rb +1 -1
  117. data/lib/jiji/error.rb +24 -8
  118. data/lib/jiji/migration/migrator1_2_0.rb +67 -0
  119. data/lib/jiji/models.rb +82 -24
  120. data/lib/jiji/operator.rb +55 -51
  121. data/lib/jiji/output.rb +85 -29
  122. data/lib/jiji/output_manager.rb +84 -0
  123. data/lib/jiji/plugin/embedded/single_click_client.rb +2 -2
  124. data/lib/jiji/plugin/securities_plugin.rb +0 -1
  125. data/lib/jiji/process.rb +229 -208
  126. data/lib/jiji/process_manager.rb +190 -96
  127. data/lib/jiji/registry.rb +87 -19
  128. data/lib/jiji/server.rb +1 -0
  129. data/lib/jiji/service/agent_service.rb +147 -48
  130. data/lib/jiji/service/output_service.rb +37 -17
  131. data/lib/jiji/service/process_service.rb +3 -5
  132. data/lib/jiji/service/trade_result_service.rb +4 -5
  133. data/lib/jiji/util/file_lock.rb +4 -4
  134. data/lib/jiji/util/include_proxy.rb +17 -0
  135. data/lib/jiji/util/json_broker.rb +6 -4
  136. data/lib/jiji/util/util.rb +1 -1
  137. data/swf/chart/fx/chart/Chart.as +7 -0
  138. data/swf/chart/fx/chart/ui/graph/GraphManager.as +15 -2
  139. data/test/ProcessTest/agents/foo.rb +10 -0
  140. data/test/ProcessTest/conf/configuration.yaml +3 -0
  141. data/test/agent/agent_tests.rb +10 -0
  142. data/test/agent/test_AgentManager.rb +28 -12
  143. data/test/agent/test_AgentRegistry.rb +194 -99
  144. data/test/agent/test_PeriodicallyAgent.rb +1 -2
  145. data/test/agent/test_Permitter.rb +1 -2
  146. data/test/all_tests.rb +7 -19
  147. data/test/dao/dao_tests.rb +9 -0
  148. data/test/dao/test_FileSystemDao.rb +431 -0
  149. data/test/dao/test_RateDao.rb +5 -7
  150. data/test/dao/test_TradeResultDao.rb +1 -2
  151. data/test/migration/migration_tests.rb +10 -0
  152. data/test/migration/migrator1_2_0test_data/basic/out/M2NlOTA2ODEtZDdlNi00NWU1LWIwNDQtMjBmODY2ZGNkNzBj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  153. data/test/migration/migrator1_2_0test_data/basic/out/MDVhYzcxMjYtMGFlMS00Mzk0LWEyNmUtYjVjZjgwNDA0ZmE2/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  154. data/test/migration/migrator1_2_0test_data/basic/out/MzA1YTk0NDgtNzhjNi00NDk3LTk2NTktYzE1ZjBhNzdiYjNj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  155. data/test/migration/migrator1_2_0test_data/basic/out/YjRkOTI1MzEtZTM4MS00YjQwLTg1ZTQtMWFmZDRlNDUwMzBm/56e75YuV5bmz5Z2H57ea/meta.yaml +9 -0
  156. data/test/migration/migrator1_2_0test_data/basic/props.yaml +85 -0
  157. data/test/migration/migrator1_2_0test_data/illegal_props/out/M2NlOTA2ODEtZDdlNi00NWU1LWIwNDQtMjBmODY2ZGNkNzBj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  158. data/test/migration/migrator1_2_0test_data/illegal_props/out/MDVhYzcxMjYtMGFlMS00Mzk0LWEyNmUtYjVjZjgwNDA0ZmE2/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  159. data/test/migration/migrator1_2_0test_data/illegal_props/out/MzA1YTk0NDgtNzhjNi00NDk3LTk2NTktYzE1ZjBhNzdiYjNj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  160. data/test/migration/migrator1_2_0test_data/illegal_props/out/YjRkOTI1MzEtZTM4MS00YjQwLTg1ZTQtMWFmZDRlNDUwMzBm/56e75YuV5bmz5Z2H57ea/meta.yaml +9 -0
  161. data/test/migration/migrator1_2_0test_data/illegal_props/props.yaml +1 -0
  162. data/test/migration/migrator1_2_0test_data/no_outs/props.yaml +85 -0
  163. data/test/migration/migrator1_2_0test_data/no_props/out/M2NlOTA2ODEtZDdlNi00NWU1LWIwNDQtMjBmODY2ZGNkNzBj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  164. data/test/migration/migrator1_2_0test_data/no_props/out/MDVhYzcxMjYtMGFlMS00Mzk0LWEyNmUtYjVjZjgwNDA0ZmE2/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  165. data/test/migration/migrator1_2_0test_data/no_props/out/MzA1YTk0NDgtNzhjNi00NDk3LTk2NTktYzE1ZjBhNzdiYjNj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  166. data/test/migration/migrator1_2_0test_data/no_props/out/YjRkOTI1MzEtZTM4MS00YjQwLTg1ZTQtMWFmZDRlNDUwMzBm/56e75YuV5bmz5Z2H57ea/meta.yaml +9 -0
  167. data/test/migration/test_Migrator.rb +1 -1
  168. data/test/migration/test_Migrator1_0_3.rb +1 -1
  169. data/test/migration/test_Migrator1_1_0.rb +1 -1
  170. data/test/migration/test_Migrator1_2_0.rb +94 -0
  171. data/test/plugin/embedded/test_SingleClickClient.rb +1 -2
  172. data/test/plugin/plugin_tests.rb +8 -0
  173. data/test/plugin/test_Loader.rb +1 -1
  174. data/test/shared/rate.csv +144 -0
  175. data/test/shared/shared_tests.rb +9 -0
  176. data/test/shared/test_Cross.rb +144 -0
  177. data/test/shared/test_PositionManager.rb +285 -0
  178. data/test/shared/test_Signal.rb +65 -0
  179. data/test/test_Output.rb +28 -21
  180. data/test/test_OutputManager.rb +162 -0
  181. data/test/test_Output_registry.rb +6 -17
  182. data/test/test_Process.rb +434 -222
  183. data/test/test_ProcessManager.rb +458 -101
  184. data/test/test_utils.rb +71 -8
  185. data/test/util/test_BlockToSession.rb +1 -2
  186. data/test/util/test_CSV.rb +1 -2
  187. data/test/util/test_SynchronizeInterceptor.rb +1 -2
  188. data/test/util/util_tests.rb +9 -0
  189. metadata +127 -47
  190. data/html/js/agent-editor-page.js +0 -440
  191. data/html/js/codepress/codepress.css +0 -21
  192. data/html/js/codepress/codepress.html +0 -35
  193. data/html/js/codepress/codepress.js +0 -138
  194. data/html/js/codepress/engines/gecko.js +0 -293
  195. data/html/js/codepress/engines/khtml.js +0 -0
  196. data/html/js/codepress/engines/msie.js +0 -304
  197. data/html/js/codepress/engines/older.js +0 -0
  198. data/html/js/codepress/engines/opera.js +0 -260
  199. data/html/js/codepress/images/line-numbers.gif +0 -0
  200. data/html/js/codepress/index.html +0 -443
  201. data/html/js/codepress/languages/asp.css +0 -71
  202. data/html/js/codepress/languages/asp.js +0 -117
  203. data/html/js/codepress/languages/autoit.css +0 -13
  204. data/html/js/codepress/languages/autoit.js +0 -32
  205. data/html/js/codepress/languages/csharp.css +0 -9
  206. data/html/js/codepress/languages/csharp.js +0 -25
  207. data/html/js/codepress/languages/css.css +0 -10
  208. data/html/js/codepress/languages/css.js +0 -23
  209. data/html/js/codepress/languages/generic.css +0 -9
  210. data/html/js/codepress/languages/generic.js +0 -25
  211. data/html/js/codepress/languages/html.css +0 -13
  212. data/html/js/codepress/languages/html.js +0 -59
  213. data/html/js/codepress/languages/java.css +0 -7
  214. data/html/js/codepress/languages/java.js +0 -24
  215. data/html/js/codepress/languages/javascript.css +0 -8
  216. data/html/js/codepress/languages/javascript.js +0 -30
  217. data/html/js/codepress/languages/perl.css +0 -11
  218. data/html/js/codepress/languages/perl.js +0 -27
  219. data/html/js/codepress/languages/php.css +0 -12
  220. data/html/js/codepress/languages/php.js +0 -61
  221. data/html/js/codepress/languages/ruby.css +0 -10
  222. data/html/js/codepress/languages/ruby.js +0 -26
  223. data/html/js/codepress/languages/sql.css +0 -10
  224. data/html/js/codepress/languages/sql.js +0 -30
  225. data/html/js/codepress/languages/text.css +0 -5
  226. data/html/js/codepress/languages/text.js +0 -9
  227. data/html/js/codepress/languages/vbscript.css +0 -71
  228. data/html/js/codepress/languages/vbscript.js +0 -117
  229. data/html/js/codepress/languages/xsl.css +0 -15
  230. data/html/js/codepress/languages/xsl.js +0 -103
  231. data/html/js/codepress/license.txt +0 -458
  232. data/html/js/edit_area/images/Thumbs.db +0 -0
  233. data/test/plugin/test_gem/a/lib/jiji_plugin_test.rb +0 -6
data/test/test_Process.rb CHANGED
@@ -6,11 +6,7 @@ require 'rubygems'
6
6
  require 'runit/testcase'
7
7
  require 'runit/cui/testrunner'
8
8
  require 'jiji/process'
9
- require 'jiji/agent/agent'
10
- require 'jiji/agent/agent_manager'
11
- require 'jiji/agent/agent_registry'
12
- require 'jiji/agent/permitter'
13
- require 'jiji/agent/util'
9
+ require 'jiji/registry'
14
10
  require 'logger'
15
11
  require 'test_utils'
16
12
 
@@ -20,326 +16,542 @@ class ProcessTest < RUNIT::TestCase
20
16
  include Test::Constants
21
17
 
22
18
  def setup
23
- @dir = File.dirname(__FILE__) + "/ProcessTest.tmp"
19
+ @dir = File.dirname(__FILE__) + "/ProcessTest"
24
20
  FileUtils.mkdir_p @dir
25
-
26
- @logger = Logger.new STDOUT
27
-
28
- # レジストリ
29
- @registry_mock = Object.new
30
- class << @registry_mock
31
- def output( agent_name, dir )
32
- return ["from_registry"]
33
- end
34
- end
21
+ @registry = JIJI::Registry.new(@dir , nil)
22
+ @registry.plugin_loader.load
35
23
  end
36
24
 
37
25
  def teardown
38
- FileUtils.rm_rf @dir
26
+ begin
27
+ Test.destry( @registry, @dir )
28
+ ensure
29
+ FileUtils.rm_rf "#{@dir}/process_info_test"
30
+ end
39
31
  end
40
32
 
41
- # 基本動作のテスト
42
- def test_basic
33
+ # ProcessInfoの基本操作のテスト
34
+ def test_process_info
43
35
 
44
- # 新規に作成
45
- agent_mng = new_agent_mang
36
+ dir = "#{@dir}/process_info_test"
46
37
 
47
- p1 = JIJI::Process.new( "1", @dir, agent_mng, @logger, {}, @registry_mock )
48
- assert_equals p1.id, "1"
49
- assert_equals p1.props, {"agents"=>[]}
38
+ p1 = JIJI::ProcessInfo.new( "1", dir )
39
+ assert_equals p1.process_id, "1"
40
+ assert_equals p1.props, {}
50
41
  assert_equals p1["x"], nil
51
- assert_equals p1.agent_manager, agent_mng
52
- assert_equals p1.outputs, {}
42
+ assert_equals p1.progress, 0
43
+ assert_equals p1.data_exist?, false
53
44
 
54
- p1["x"] = "xxx"
45
+ #プロパティを設定。データがファイルに保存される。
46
+ p1.props = {"x"=>"xxx", "y"=>"yyy"}
47
+ assert_equals p1.process_id, "1"
48
+ assert_equals p1.props, {"x"=>"xxx", "y"=>"yyy"}
55
49
  assert_equals p1["x"], "xxx"
50
+ assert_equals p1["y"], "yyy"
51
+ assert_equals p1.progress, 0
52
+ assert_equals p1.data_exist?, true
53
+
54
+
55
+ #再作成
56
+ p1 = JIJI::ProcessInfo.new( "1", dir )
57
+ assert_equals p1.process_id, "1"
58
+ assert_equals p1.props, {}
59
+ assert_equals p1["x"], nil
60
+ assert_equals p1.progress, 0
61
+ assert_equals p1.data_exist?, true
62
+
63
+ #保存されたデータを読み込み
64
+ p1.load
65
+ assert_equals p1.process_id, "1"
66
+ assert_equals p1.props, {"x"=>"xxx", "y"=>"yyy"}
67
+ assert_equals p1["x"], "xxx"
68
+ assert_equals p1["y"], "yyy"
69
+ assert_equals p1.progress, 0
70
+
71
+ #プロパティを変更
72
+ p1["x"] = "aaa"
73
+ p1["a"] = "aaa"
74
+ p1.progress = 20
75
+ assert_equals p1.process_id, "1"
76
+ assert_equals p1.props, {"x"=>"aaa", "y"=>"yyy", "a"=>"aaa"}
77
+ assert_equals p1["x"], "aaa"
78
+ assert_equals p1["y"], "yyy"
79
+ assert_equals p1["a"], "aaa"
80
+ assert_equals p1.progress, 20
81
+
82
+ #再作成
83
+ p1 = JIJI::ProcessInfo.new( "1", dir )
84
+ assert_equals p1.process_id, "1"
85
+ assert_equals p1.props, {}
86
+ assert_equals p1["x"], nil
87
+ assert_equals p1.progress, 0
88
+ assert_equals p1.data_exist?, true
89
+
90
+ #保存されたデータを読み込み
91
+ p1.load
92
+ assert_equals p1.process_id, "1"
93
+ assert_equals p1.props, {"x"=>"aaa", "y"=>"yyy", "a"=>"aaa"}
94
+ assert_equals p1["x"], "aaa"
95
+ assert_equals p1["y"], "yyy"
96
+ assert_equals p1["a"], "aaa"
97
+ assert_equals p1.progress, 0 #進捗は記録されない。
98
+
99
+
100
+ #別のProcessInfo
101
+ p1 = JIJI::ProcessInfo.new( "2", dir )
102
+ assert_equals p1.process_id, "2"
103
+ assert_equals p1.props, {}
104
+ assert_equals p1["x"], nil
105
+ assert_equals p1.progress, 0
106
+ assert_equals p1.data_exist?, false
107
+ end
108
+
109
+ # Processの基本動作のテスト
110
+ def test_backtest_process
111
+
112
+ # エージェント設定なし
113
+ pi1 = @registry.process_info( "1" )
114
+ pi1.props = {
115
+ "id"=>"pid1",
116
+ "name"=>"エージェントなし",
117
+ "start_date"=>0,
118
+ "end_date"=>100
119
+ }
120
+ p1 = @registry.backtest_process(pi1)
121
+ agent_mng = p1.agent_manager
122
+
123
+ #エージェントを読み込み → 何もロードされない
124
+ p1.load_agents( false )
125
+ assert_equals agent_mng.map, []
126
+
127
+ assert_equals agent_mng.operator.trade_enable, false
56
128
 
57
129
  # トレードのon/offを設定
58
- p1["trade_enable"] = false
59
- assert_equals p1["trade_enable"], false
60
- assert_equals p1.agent_manager.operator.trade_enable, false
61
- p1["trade_enable"] = true
62
- assert_equals p1["trade_enable"], true
63
- assert_equals p1.agent_manager.operator.trade_enable, true
64
- p1["trade_enable"] = false
65
- assert_equals p1["trade_enable"], false
66
- assert_equals p1.agent_manager.operator.trade_enable, false
67
-
68
- # エージェントの設定を変更
130
+ p1.trade_enable = true
131
+ pi1["trade_enable"] = true
132
+ assert_equals agent_mng.operator.trade_enable, true
133
+ p1.trade_enable = false
134
+ pi1["trade_enable"] = false
135
+ assert_equals agent_mng.operator.trade_enable, false
136
+ p1.trade_enable = true
137
+ pi1["trade_enable"] = true
138
+ assert_equals agent_mng.operator.trade_enable, true
139
+
140
+ #エージェントを追加
69
141
  agents = [
70
142
  {"id"=>"aaa",
71
143
  "name"=>"テストエージェント1",
72
- "class"=>"testclass@foo.rb",
73
- "class_name" => "testclass",
144
+ "class"=>"TestAgent@foo.rb",
145
+ "class_name" => "TestAgent",
74
146
  "file_name" => "foo.rb",
75
147
  "description" => "説明",
76
148
  "property_def" => {"id"=>"x", "default"=>85 },
77
149
  "properties" => {"x"=>30, "y"=>40 }},
78
150
  {"id"=>"bbb",
79
151
  "name"=>"テストエージェント2",
80
- "class"=>"testclass2@foo.rb",
81
- "class_name" => "testclass",
152
+ "class"=>"TestAgent2@foo.rb",
153
+ "class_name" => "TestAgent",
82
154
  "file_name" => "foo.rb",
83
155
  "description" => "説明2",
84
156
  "property_def" => {"id"=>"x", "default"=>85 },
85
157
  "properties" => {"x"=>30, "y"=>41 }}
86
158
  ]
87
-
88
- # 追加
89
- p1["agents"] = agents
90
- assert_equals p1["agents"], agents
91
- assert_equals agent_mng.get("aaa").agent.cl, "testclass@foo.rb"
159
+ pi1["agents"] = agents
160
+ p1.set_agents( agents )
161
+ assert_equals pi1["agents"], agents
92
162
  assert_equals agent_mng.get("aaa").agent.properties, {"x"=>30, "y"=>40 }
93
- assert_equals agent_mng.get("bbb").agent.cl, "testclass2@foo.rb"
94
163
  assert_equals agent_mng.get("bbb").agent.properties, {"x"=>30, "y"=>41 }
95
- assert_equals p1.outputs, { "aaa"=>["out1","out2"], "bbb"=>["out1","out2"] }
164
+
165
+ assert_equals agent_mng.get("aaa").operator.agent_name, "テストエージェント1"
166
+ assert_equals agent_mng.get("bbb").operator.agent_name, "テストエージェント2"
167
+
168
+ out1 = agent_mng.output_manager.get( "1", "aaa" )
169
+ assert_equals out1.agent_id, "aaa"
170
+ assert_equals out1.agent_name, "テストエージェント1"
171
+ out2 = agent_mng.output_manager.get( "1", "bbb" )
172
+ assert_equals out2.agent_id, "bbb"
173
+ assert_equals out2.agent_name, "テストエージェント2"
174
+
96
175
 
97
176
  # 変更
98
177
  agents = [
99
178
  {"id"=>"aaa",
100
179
  "name"=>"テストエージェント1",
101
- "class"=>"testclass@foo.rb",
102
- "class_name" => "testclass",
180
+ "class"=>"TestAgent@foo.rb",
181
+ "class_name" => "TestAgent",
103
182
  "file_name" => "foo.rb",
104
183
  "description" => "説明",
105
184
  "property_def" => {"id"=>"x", "default"=>85 },
106
185
  "properties" => {"x"=>50, "y"=>40 }},
107
186
  {"id"=>"bbb",
108
187
  "name"=>"テストエージェント4",
109
- "class"=>"testclass2@foo.rb",
110
- "class_name" => "testclass",
188
+ "class"=>"TestAgent2@foo.rb",
189
+ "class_name" => "TestAgent",
111
190
  "file_name" => "foo.rb",
112
191
  "description" => "説明2aaaaaa",
113
192
  "property_def" => {"id"=>"x", "default"=>85 },
114
193
  "properties" => {"x"=>60, "y"=>41 }}
115
194
  ]
116
- p1["agents"] = agents
117
- assert_equals p1["agents"], agents
118
- assert_equals agent_mng.get("aaa").agent.cl, "testclass@foo.rb"
195
+ pi1["agents"] = agents
196
+ p1.set_agents( agents )
197
+ assert_equals pi1["agents"], agents
119
198
  assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>40 }
120
- assert_equals agent_mng.get("bbb").agent.cl, "testclass2@foo.rb"
121
199
  assert_equals agent_mng.get("bbb").agent.properties, {"x"=>60, "y"=>41 }
122
- assert_equals p1.outputs, { "aaa"=>["out1","out2"], "bbb"=>["out1","out2"] }
200
+
201
+ assert_equals agent_mng.get("aaa").operator.agent_name, "テストエージェント1"
202
+ assert_equals agent_mng.get("bbb").operator.agent_name, "テストエージェント4"
203
+
204
+ out1 = agent_mng.output_manager.get( "1", "aaa" )
205
+ assert_equals out1.agent_id, "aaa"
206
+ assert_equals out1.agent_name, "テストエージェント1"
207
+ out2 = agent_mng.output_manager.get( "1", "bbb" )
208
+ assert_equals out2.agent_id, "bbb"
209
+ assert_equals out2.agent_name, "テストエージェント4"
123
210
 
124
211
  # 削除
125
212
  agents = [
126
213
  {"id"=>"aaa",
127
- "name"=>"テストエージェント1",
128
- "class"=>"testclass@foo.rb",
129
- "class_name" => "testclass",
214
+ "name"=>"テストエージェント11",
215
+ "class"=>"TestAgent@foo.rb",
216
+ "class_name" => "TestAgent",
130
217
  "file_name" => "foo.rb",
131
218
  "description" => "説明",
132
219
  "property_def" => {"id"=>"x", "default"=>85 },
133
220
  "properties" => {"x"=>50, "y"=>41 }}
134
221
  ]
135
- p1["agents"] = agents
136
- assert_equals p1["agents"], agents
137
- assert_equals agent_mng.get("aaa").agent.cl, "testclass@foo.rb"
222
+ p1.set_agents( agents )
223
+ pi1["agents"] = agents
224
+ assert_equals pi1["agents"], agents
138
225
  assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>41 }
139
226
  assert_equals agent_mng.get("bbb"), nil
140
- assert_equals p1.outputs, { "aaa"=>["out1","out2"] }
141
227
 
142
- # RMTモードで再読み込み
143
- # ファイルに保存された設定値が読み込まれる。また、エージェントがインスタンス化される
144
- agent_mng = new_agent_mang
145
- p1 = JIJI::Process.new( "1", @dir, agent_mng, @logger, nil, @registry_mock, true )
146
- assert_equals p1.id, "1"
228
+ assert_equals agent_mng.get("aaa").operator.agent_name, "テストエージェント11"
229
+
230
+ out1 = agent_mng.output_manager.get( "1", "aaa" )
231
+ assert_equals out1.agent_id, "aaa"
232
+ assert_equals out1.agent_name, "テストエージェント11"
233
+ out2 = agent_mng.output_manager.get( "1", "bbb" ) # outputは削除されない。
234
+ assert_equals out2.agent_id, "bbb"
235
+ assert_equals out2.agent_name, "テストエージェント4"
236
+
237
+
238
+ # 保存されたデータから再構築
239
+ pi1 = @registry.process_info( "1" )
240
+ pi1.load
241
+ p1 = @registry.backtest_process(pi1)
242
+ agent_mng = p1.agent_manager
243
+
244
+ p1.load_agents( false )
147
245
  assert_equals p1.agent_manager, agent_mng
148
- assert_equals p1["x"], "xxx"
149
- assert_equals p1["agents"], agents
150
- assert_equals agent_mng.get("aaa").agent.cl, "testclass@foo.rb"
246
+ assert_equals pi1["agents"], agents
247
+ assert_equals pi1["trade_enable"], false #バックテストは必ずfalseになる
248
+
249
+ assert_equals agent_mng.operator.trade_enable, false #バックテストは必ずfalseになる
250
+
151
251
  assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>41 }
152
252
  assert_equals agent_mng.get("bbb"), nil
153
- assert_equals p1["trade_enable"], false
154
- assert_equals p1.agent_manager.operator.trade_enable, false
155
- assert_equals p1.outputs, { "aaa"=>["out1","out2"] }
156
-
157
- # バックテストモードで再読み込み
158
- # ファイルに保存された設定値が読み込まれるが、エージェントはインスタンス化されない
159
- agent_mng = new_agent_mang
160
- p1 = JIJI::Process.new( "1", @dir, agent_mng, @logger, nil, @registry_mock, false )
161
- assert_equals p1.id, "1"
162
- assert_equals p1.agent_manager, agent_mng
163
- assert_equals p1["x"], "xxx"
164
- assert_equals p1["agents"], agents
165
- assert_equals agent_mng.get("aaa"), nil
166
- assert_equals agent_mng.get("bbb"), nil
167
- assert_equals p1["trade_enable"], false
168
- assert_equals p1.agent_manager.operator.trade_enable, false
169
- assert_equals p1.outputs, { "aaa"=> ["from_registry"] }
170
-
171
- # 別のプロセスを作成 / 設定値は別途保持される。
172
- agent_mng = new_agent_mang
173
- p2 = JIJI::Process.new( "2", @dir, agent_mng, @logger, {}, @registry_mock )
174
- assert_equals p2.id, "2"
175
- assert_equals p2.agent_manager, agent_mng
176
- assert_equals p2["x"], nil
177
- assert_equals p2["agents"], []
178
- assert_equals p2.outputs, { }
253
+
254
+ assert_equals agent_mng.get("aaa").operator.agent_name, "テストエージェント11"
255
+
256
+ out1 = agent_mng.output_manager.get( "1", "aaa" )
257
+ assert_equals out1.agent_id, "aaa"
258
+ assert_equals out1.agent_name, "テストエージェント11"
259
+ out2 = agent_mng.output_manager.get( "1", "bbb" )
260
+ assert_equals out2.agent_id, "bbb"
261
+ assert_equals out2.agent_name, "テストエージェント4"
262
+
263
+ p1.stop
179
264
 
180
265
  # 作成の段階でエージェントを指定する
181
- agent_mng = new_agent_mang
182
- p3 = JIJI::Process.new( "3", @dir, agent_mng, @logger, {"agents"=>agents}, @registry_mock )
183
- assert_equals p3.id, "3"
184
- assert_equals p3.agent_manager, agent_mng
185
- assert_equals p3["x"], nil
186
- assert_equals p3["agents"], agents
187
- assert_equals agent_mng.get("aaa").agent.cl, "testclass@foo.rb"
266
+ pi2 = @registry.process_info( "2" )
267
+ pi2.props = {
268
+ "id"=>"2",
269
+ "name"=>"エージェントあり",
270
+ "start_date"=>0,
271
+ "end_date"=>100,
272
+ "agents"=>agents
273
+ }
274
+ p2 = @registry.backtest_process(pi2)
275
+ agent_mng = p2.agent_manager
276
+
277
+ p2.load_agents( false )
278
+ assert_equals p2.agent_manager, agent_mng
279
+ assert_equals p2.info, pi2
280
+ assert_equals agent_mng.operator.trade_enable, false
281
+
188
282
  assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>41 }
189
283
  assert_equals agent_mng.get("bbb"), nil
190
- assert_equals p3.outputs, { "aaa"=>["out1","out2"] }
191
284
 
285
+ out1 = agent_mng.output_manager.get( "2", "aaa" )
286
+ assert_equals out1.agent_id, "aaa"
287
+ assert_equals out1.agent_name, "テストエージェント11"
288
+
289
+ p2.stop
192
290
  end
193
291
 
194
- # エージェントの作成でエラーになった場合のテスト
195
- def test_error
292
+ # Processの基本動作のテスト
293
+ def test_rmt_process
294
+
295
+ p1 = @registry.rmt_process
296
+ agent_mng = p1.agent_manager
297
+
298
+ #エージェントを読み込み → 何もロードされない
299
+ p1.load_agents( false )
300
+ assert_equals agent_mng.map, []
301
+
302
+ assert_equals agent_mng.operator.trade_enable, false
303
+
304
+ # トレードのon/offを設定
305
+ p1.trade_enable = true
306
+ p1.info["trade_enable"] = true
307
+ assert_equals agent_mng.operator.trade_enable, true
308
+ p1.trade_enable = false
309
+ p1.info["trade_enable"] = false
310
+ assert_equals agent_mng.operator.trade_enable, false
311
+ p1.trade_enable = true
312
+ p1.info["trade_enable"] = true
313
+ assert_equals agent_mng.operator.trade_enable, true
314
+
315
+ #エージェントを追加
196
316
  agents = [
197
317
  {"id"=>"aaa",
198
318
  "name"=>"テストエージェント1",
199
- "class"=>"testclass@foo.rb",
200
- "class_name" => "testclass",
319
+ "class"=>"TestAgent@foo.rb",
320
+ "class_name" => "TestAgent",
201
321
  "file_name" => "foo.rb",
202
322
  "description" => "説明",
203
323
  "property_def" => {"id"=>"x", "default"=>85 },
204
- "properties" => {"x"=>50, "y"=>41 }}
324
+ "properties" => {"x"=>30, "y"=>40 }},
325
+ {"id"=>"bbb",
326
+ "name"=>"テストエージェント2",
327
+ "class"=>"TestAgent2@foo.rb",
328
+ "class_name" => "TestAgent",
329
+ "file_name" => "foo.rb",
330
+ "description" => "説明2",
331
+ "property_def" => {"id"=>"x", "default"=>85 },
332
+ "properties" => {"x"=>30, "y"=>41 }}
205
333
  ]
334
+ p1.set_agents( agents )
335
+ p1.info["agents"] = agents
336
+ assert_equals p1.info["agents"], agents
337
+ assert_equals agent_mng.get("aaa").agent.properties, {"x"=>30, "y"=>40 }
338
+ assert_equals agent_mng.get("bbb").agent.properties, {"x"=>30, "y"=>41 }
206
339
 
207
- # RMTで生成時にエラー
208
- # 再起動で失敗するのを防ぐため、エラーはログに出力された後、無視される。
209
- agent_mng = new_agent_mang
210
- p1 = JIJI::Process.new( "1", @dir, agent_mng, @logger, {"agents"=>agents}, @registry_mock, true )
340
+ assert_equals agent_mng.get("aaa").operator.agent_name, "テストエージェント1"
341
+ assert_equals agent_mng.get("bbb").operator.agent_name, "テストエージェント2"
211
342
 
212
- error_registry = RegistryMock.new
213
- class << error_registry
214
- def create(*args); raise "test"; end
215
- end
216
- # 再作成
217
- agent_mng = new_agent_mang(error_registry)
218
- p1 = JIJI::Process.new( "1", @dir, agent_mng, @logger, nil, @registry_mock, true )
219
- assert_equals p1.id, "1"
343
+ out1 = agent_mng.output_manager.get( "rmt", "aaa" )
344
+ assert_equals out1.agent_id, "aaa"
345
+ assert_equals out1.agent_name, "テストエージェント1"
346
+ out2 = agent_mng.output_manager.get( "rmt", "bbb" )
347
+ assert_equals out2.agent_id, "bbb"
348
+ assert_equals out2.agent_name, "テストエージェント2"
349
+
350
+ p1.stop
351
+ Test.destry( @registry)
352
+ @registry = JIJI::Registry.new(@dir , nil)
353
+ @registry.plugin_loader.load
354
+
355
+ # 保存されたデータから再構築
356
+ p1 = @registry.rmt_process
357
+ agent_mng = p1.agent_manager
358
+
359
+ p1.load_agents( false )
220
360
  assert_equals p1.agent_manager, agent_mng
221
- assert_equals p1["agents"], agents
222
- assert_equals agent_mng.get("aaa"), nil
223
- assert_equals agent_mng.get("bbb"), nil
224
- assert_equals p1["trade_enable"], nil
225
- assert_equals p1.agent_manager.operator.trade_enable, false
226
- assert_equals p1.outputs, { "aaa"=>["from_registry"] }
361
+ assert_equals p1.info["agents"], agents
362
+ assert_equals p1.info["trade_enable"], true
227
363
 
228
- # RMTでエージェントの追加時にエラー
229
- agents << {"id"=>"bbb",
230
- "name"=>"テストエージェント4",
231
- "class"=>"testclass2@foo.rb",
232
- "class_name" => "testclass",
233
- "file_name" => "foo.rb",
234
- "description" => "説明2aaaaaa",
235
- "property_def" => {"id"=>"x", "default"=>85 },
236
- "properties" => {"x"=>60, "y"=>41 }}
237
- begin
238
- p1["agents"] = agents
239
- fail
240
- rescue
241
- end
364
+ assert_equals agent_mng.operator.trade_enable, true
365
+
366
+ assert_equals agent_mng.get("aaa").agent.properties, {"x"=>30, "y"=>40 }
367
+ assert_equals agent_mng.get("bbb").agent.properties, {"x"=>30, "y"=>41 }
368
+
369
+ assert_equals agent_mng.get("aaa").operator.agent_name, "テストエージェント1"
370
+ assert_equals agent_mng.get("bbb").operator.agent_name, "テストエージェント2"
242
371
 
243
- # RMTでエージェントのプロパティ更新時にエラー
244
- agents2 = [
372
+ out1 = agent_mng.output_manager.get( "rmt", "aaa" )
373
+ assert_equals out1.agent_id, "aaa"
374
+ assert_equals out1.agent_name, "テストエージェント1"
375
+ out2 = agent_mng.output_manager.get( "rmt", "bbb" )
376
+ assert_equals out2.agent_id, "bbb"
377
+ assert_equals out2.agent_name, "テストエージェント2"
378
+
379
+
380
+ # 削除
381
+ agents = [
245
382
  {"id"=>"aaa",
246
- "name"=>"テストエージェント1",
247
- "class"=>"testclass@foo.rb",
248
- "class_name" => "testclass",
383
+ "name"=>"テストエージェント11",
384
+ "class"=>"TestAgent@foo.rb",
385
+ "class_name" => "TestAgent",
249
386
  "file_name" => "foo.rb",
250
387
  "description" => "説明",
251
388
  "property_def" => {"id"=>"x", "default"=>85 },
252
389
  "properties" => {"x"=>50, "y"=>41 }}
253
390
  ]
254
- error_registry = RegistryMock.new
255
- class << error_registry
256
- def create( cl, property )
257
- a = Agent.new( cl, property )
258
- class << a
259
- def properties=(props)
260
- raise "test"
261
- end
262
- end
263
- return a
264
- end
265
- end
266
- agent_mng = new_agent_mang(error_registry)
267
- p1 = JIJI::Process.new( "2", @dir, agent_mng, @logger, {"agents"=>agents2}, @registry_mock, true )
268
- assert_equals p1["agents"], agents2
269
- assert_equals agent_mng.get("aaa").agent.cl, "testclass@foo.rb"
391
+ p1.set_agents( agents )
392
+ p1.info["agents"] = agents
393
+ assert_equals p1.info["agents"], agents
270
394
  assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>41 }
271
395
  assert_equals agent_mng.get("bbb"), nil
272
- assert_equals p1.outputs, { "aaa"=>["out1","out2"] }
273
396
 
274
- begin
275
- p1["agents"] = [
276
- {"id"=>"aaa",
277
- "name"=>"テストエージェント1",
278
- "class"=>"testclass@foo.rb",
279
- "class_name" => "testclass",
280
- "file_name" => "foo.rb",
281
- "description" => "説明",
282
- "property_def" => {"id"=>"x", "default"=>85 },
283
- "properties" => {"x"=>50, "y"=>31 }}
284
- ]
285
- fail
286
- rescue
287
- end
288
- assert_equals p1["agents"], agents2
289
- assert_equals agent_mng.get("aaa").agent.cl, "testclass@foo.rb"
397
+ assert_equals agent_mng.get("aaa").operator.agent_name, "テストエージェント11"
398
+
399
+ out1 = agent_mng.output_manager.get( "rmt", "aaa" )
400
+ assert_equals out1.agent_id, "aaa"
401
+ assert_equals out1.agent_name, "テストエージェント11"
402
+ out2 = agent_mng.output_manager.get( "rmt", "bbb" )
403
+ assert_equals out2.agent_id, "bbb"
404
+ assert_equals out2.agent_name, "テストエージェント2"
405
+
406
+
407
+ p1.info["trade_enable"] = false
408
+ p1.trade_enable = false
409
+ p1.stop
410
+ Test.destry( @registry)
411
+ @registry = JIJI::Registry.new(@dir , nil)
412
+ @registry.plugin_loader.load
413
+
414
+ # 保存されたデータから再構築
415
+ p1 = @registry.rmt_process
416
+ agent_mng = p1.agent_manager
417
+
418
+ p1.load_agents( false )
419
+ assert_equals p1.agent_manager, agent_mng
420
+ assert_equals p1.info["agents"], agents
421
+ assert_equals p1.info["trade_enable"], false
422
+
423
+ assert_equals agent_mng.operator.trade_enable, false
424
+ assert_equals p1.info["agents"], agents
290
425
  assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>41 }
291
426
  assert_equals agent_mng.get("bbb"), nil
292
- assert_equals p1.outputs, { "aaa"=>["out1","out2"] }
293
427
 
294
- # バックテストでエージェント生成時にエラー
295
- error_registry = RegistryMock.new
296
- class << error_registry
297
- def create; raise "test"; end
298
- end
299
- agent_mng = new_agent_mang(error_registry)
428
+ assert_equals agent_mng.get("aaa").operator.agent_name, "テストエージェント11"
429
+
430
+ out1 = agent_mng.output_manager.get( "rmt", "aaa" )
431
+ assert_equals out1.agent_id, "aaa"
432
+ assert_equals out1.agent_name, "テストエージェント11"
433
+ out2 = agent_mng.output_manager.get( "rmt", "bbb" )
434
+ assert_equals out2.agent_id, "bbb"
435
+ assert_equals out2.agent_name, "テストエージェント2"
436
+ end
437
+
438
+
439
+ # エージェントの作成でエラーになった場合のテスト
440
+ def test_error
441
+
442
+ agents = [
443
+ {"id"=>"aaa",
444
+ "name"=>"テストエージェント1",
445
+ "class"=>"TestAgent@foo.rb",
446
+ "class_name" => "TestAgent",
447
+ "file_name" => "foo.rb",
448
+ "description" => "説明",
449
+ "property_def" => {"id"=>"x", "default"=>85 },
450
+ "properties" => {"x"=>50, "y"=>41 }}
451
+ ]
452
+
453
+ pi1 = @registry.process_info( "1" )
454
+ pi1.props = {
455
+ "id"=>"pid1",
456
+ "name"=>"エージェントなし",
457
+ "start_date"=>0,
458
+ "end_date"=>100,
459
+ "agents"=>agents
460
+ }
461
+ p1 = @registry.backtest_process(pi1)
462
+ agent_mng = p1.agent_manager
463
+ error_registry = Test::RegistryMock.new # エージェントレジストリをモックに差し替え。
464
+ agent_mng.agent_registry = error_registry
465
+
466
+ # 生成時にエラー
467
+ Test::RegistryMock.set_fail_create {|cl,p| true }
300
468
  begin
301
- JIJI::Process.new( "1", @dir, agent_mng, @logger, {"agents"=>agents}, @registry_mock, false )
469
+ # エラーを無視しないモードで生成 / 例外が発生する
470
+ p1.load_agents( false )
302
471
  fail
303
- rescue
472
+ rescue RuntimeError
304
473
  end
305
- end
474
+ assert_equals agent_mng.get("aaa"), nil
306
475
 
307
- # エージェントマネージャを再作成する
308
- def new_agent_mang( agent_registory=RegistryMock.new )
309
- agent_mng = JIJI::AgentManager.new( "aaa", agent_registory, Logger.new(STDOUT))
310
- agent_mng.operator = Struct.new(:trade_enable).new(true)
311
- agent_mng.conf = CONF
312
- agent_mng.conf.set( [:agent,:safe_level], 0)
313
- agent_mng.registry = @registry_mock
314
- return agent_mng
315
- end
476
+ # エラーを無視するモードで生成 / 例外は発生しない
477
+ p1.load_agents( true )
478
+ assert_equals agent_mng.get("aaa"), nil
316
479
 
317
- class Agent
318
- include JIJI::Agent
319
480
 
320
- def initialize( cl, properties )
321
- @cl = cl
322
- @properties = properties
323
- end
481
+ # エージェントの追加時にエラー
482
+ agents << {"id"=>"bbb",
483
+ "name"=>"テストエージェント4",
484
+ "class"=>"TestAgent2@foo.rb",
485
+ "class_name" => "TestAgent",
486
+ "file_name" => "foo.rb",
487
+ "description" => "説明2aaaaaa",
488
+ "property_def" => {"id"=>"x", "default"=>85 },
489
+ "properties" => {"x"=>60, "y"=>41 }}
490
+ result = p1.set_agents(agents)
491
+ assert_not_nil result["aaa"][:cause]
492
+ assert_equals result["aaa"][:info], agents[0]
493
+ assert_equals result["aaa"][:operation], :add
494
+ assert_not_nil result["bbb"][:cause]
495
+ assert_equals result["bbb"][:info], agents[1]
496
+ assert_equals result["bbb"][:operation], :add
497
+ assert_equals agent_mng.get("aaa"), nil
498
+ assert_equals agent_mng.get("bbb"), nil
324
499
 
325
- # 設定されたプロパティを取得する
326
- def properties
327
- @properties
328
- end
329
- # プロパティを設定する
330
- def properties=( properties )
331
- @properties = properties
332
- end
333
- def output
334
- ["out1","out2"]
500
+ Test::RegistryMock.set_fail_create {|cl,p| false }
501
+
502
+ # エージェントのプロパティ更新時にエラー
503
+ Test::Agent.set_fail_propset {|a| a.cl == "TestAgent@foo.rb" }
504
+ p1.load_agents( false ) # ロードできるようになる。
505
+ assert_equals agent_mng.get("aaa").agent.cl, "TestAgent@foo.rb"
506
+ assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>41 }
507
+ assert_equals agent_mng.get("bbb").agent.cl, "TestAgent2@foo.rb"
508
+ assert_equals agent_mng.get("bbb").agent.properties, {"x"=>60, "y"=>41 }
509
+
510
+ agents[0]["properties"] = {"x"=>80, "y"=>81 }
511
+ agents[1]["properties"] = {"x"=>80, "y"=>81 }
512
+ result = p1.set_agents(agents)
513
+ assert_not_nil result["aaa"][:cause]
514
+ assert_equals result["aaa"][:info], agents[0]
515
+ assert_equals result["aaa"][:operation], :update
516
+ assert_nil result["bbb"]
517
+
518
+ #"aaa"のプロパティは更新されていない
519
+ assert_equals agent_mng.get("aaa").agent.cl, "TestAgent@foo.rb"
520
+ assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>41 }
521
+ assert_equals agent_mng.get("bbb").agent.cl, "TestAgent2@foo.rb"
522
+ assert_equals agent_mng.get("bbb").agent.properties, {"x"=>80, "y"=>81 }
523
+ Test::Agent.set_fail_propset {|a| false }
524
+
525
+ # エージェントの削除時にエラー
526
+ class << agent_mng
527
+ def remove( agent_id )
528
+ raise "test" if agent_id == "aaa"
529
+ super
530
+ end
335
531
  end
336
- attr :cl, true
532
+
533
+ result = p1.set_agents([])
534
+ assert_not_nil result["aaa"][:cause]
535
+ assert_equals result["aaa"][:info], agents[0]
536
+ assert_equals result["aaa"][:operation], :remove
537
+ assert_nil result["bbb"]
538
+
539
+ #エージェント"aaa"は健在
540
+ assert_equals agent_mng.get("aaa").agent.cl, "TestAgent@foo.rb"
541
+ assert_equals agent_mng.get("aaa").agent.properties, {"x"=>50, "y"=>41 }
542
+ assert_equals agent_mng.get("bbb"), nil
543
+
544
+ p1.stop
337
545
  end
338
546
 
339
- class RegistryMock
340
- def create( cl, property )
341
- Agent.new( cl, property )
342
- end
547
+ # エージェントマネージャを再作成する
548
+ def new_agent_mang( process_id, agent_registory=RegistryMock.new )
549
+ agent_mng = JIJI::AgentManager.new( process_id, agent_registory, Logger.new(STDOUT))
550
+ agent_mng.operator = Struct.new(:trade_enable, :agent_name).new(true)
551
+ agent_mng.conf = CONF
552
+ agent_mng.conf.set( [:agent,:safe_level], 0)
553
+ agent_mng.output_manager = JIJI::OutputManager.new( @registry_mock )
554
+ return agent_mng
343
555
  end
344
556
 
345
557
  end