nera 0.1.2 → 0.2.0

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.
@@ -24,11 +24,20 @@ module NERA
24
24
  attr_accessor :keys
25
25
 
26
26
  # run record
27
- def initialize( table_file)
27
+ def initialize( table_file, param_recs, param_id)
28
+ raise ArgumentError unless param_recs.is_a?( NERA::ParameterRecords) and param_id.is_a?(Integer)
29
+
28
30
  @keys = ATTRIBUTES.map do |k| k[0] end
29
- @db = NERA::Database.new( table_file)
31
+ @db = NERA::Database.new( table_file, param_id)
32
+ @db.add_observer( param_recs)
30
33
  end
31
34
 
35
+ # argument is the path to runs.yml
36
+ def set_yaml_file( yaml_path)
37
+ @db.set_yaml_file( yaml_path)
38
+ end
39
+
40
+
32
41
  def self.create_table(table_file)
33
42
  NERA::Database.create_table( table_file)
34
43
  end
@@ -17,6 +17,7 @@ module NERA
17
17
  @db_folders = NERA::DbFolders.new( path_db_folds)
18
18
  table_path = @db_folders.path_to_simulators_table
19
19
  @sim_records = NERA::SimulatorRecords.new(table_path)
20
+ @sim_records.set_yaml_file( @db_folders.path_to_simulators_yaml )
20
21
 
21
22
  NERA::Simulator.inherited_simulators.each do |sim|
22
23
  next if list.find do |rec| rec[:name] == sim.to_s end
@@ -55,20 +56,13 @@ module NERA
55
56
  path = @db_folders.path_to_parameters_table( sim_klass)
56
57
  c = NERA::ParameterRecords.create_table( path, sim_klass)
57
58
  raise "The file #{path} already exists." unless c
59
+ @db_folders.logger.info(self.class.to_s) {
60
+ "registered the simulator (#{sim_klass.to_s})"
61
+ }
58
62
  }
59
- dump_in_yaml
60
63
  return a
61
64
  end
62
65
 
63
- private
64
- def dump_in_yaml
65
- ymlpath = @db_folders.path_to_simulators_yaml
66
- File.open( ymlpath, 'w') do |io|
67
- YAML::dump( @sim_records.list, io)
68
- io.flush
69
- end
70
- end
71
-
72
66
  end
73
67
 
74
68
  end
@@ -1,5 +1,6 @@
1
1
  require 'nera_database'
2
2
  require 'nera_simulator'
3
+ require 'observer'
3
4
 
4
5
  module NERA
5
6
 
@@ -17,6 +18,11 @@ module NERA
17
18
  @db = NERA::Database.new( db_file)
18
19
  end
19
20
 
21
+ # argument is the path to simulators.yml
22
+ def set_yaml_file( yaml_path)
23
+ @db.set_yaml_file( yaml_path)
24
+ end
25
+
20
26
  # if file already exists, returns false
21
27
  def self.create_table( db_file)
22
28
  NERA::Database.create_table( db_file)
@@ -69,6 +75,8 @@ module NERA
69
75
  @db.update( rec)
70
76
  end
71
77
 
78
+ alias :update :touch
79
+
72
80
  def destroy( id)
73
81
  raise ArgumentError unless id.is_a?(Integer)
74
82
  @db.destroy(id)
data/lib/nera.rb CHANGED
@@ -22,5 +22,5 @@ require 'nera_simulator_records'
22
22
  require 'nera_remote_connector'
23
23
 
24
24
  module NERA
25
- VERSION = '0.1.2'
25
+ VERSION = '0.2.0'
26
26
  end
@@ -8,7 +8,7 @@ class TC_NERA_DB < Test::Unit::TestCase
8
8
  FileUtils.chdir(@test_dir)
9
9
  @path_to_db = "./testdb"
10
10
  NERA::Database.create_table( @path_to_db)
11
- @db = NERA::Database.new( @path_to_db)
11
+ @db = NERA::Database.new( @path_to_db, 'arg')
12
12
  end
13
13
 
14
14
  def teardown
@@ -20,6 +20,68 @@ class TC_NERA_DB < Test::Unit::TestCase
20
20
  assert_raise( RuntimeError ) { ( NERA::Database.new("Unknown") ) }
21
21
  end
22
22
 
23
+ def test_observable
24
+ a = 'a'
25
+ def a.update( arg)
26
+ upcase!
27
+ end
28
+ @db.add_observer( a)
29
+ record = { :key1 => 3, :key2 => 3.0}
30
+ @db.add( record)
31
+ assert_equal( 'A', a)
32
+
33
+ a.downcase!
34
+ rec = @db.find_by_id(1)
35
+ assert_equal( 'a', a)
36
+ rec[:key3] = 4.0
37
+ @db.update( rec)
38
+ assert_equal( 'A', a)
39
+
40
+ a.downcase!
41
+ @db.destroy(1)
42
+ assert_equal( 'A', a)
43
+
44
+ a.downcase!
45
+ @db.transaction do
46
+ @db.add(record)
47
+ assert_equal( 'a', a)
48
+ @db.destroy( 2)
49
+ assert_equal( 'a', a)
50
+ end
51
+ assert_equal( 'A', a)
52
+
53
+ a.downcase!
54
+ assert_raise(RuntimeError) {
55
+ @db.transaction do
56
+ @db.add( {:key1 => 99, :key2 => 2} )
57
+ raise
58
+ end
59
+ }
60
+ assert_equal( 'a', a)
61
+
62
+ end
63
+
64
+ def test_set_yaml_file
65
+ @db.set_yaml_file('rec.yml')
66
+
67
+ record = { :key1 => 3, :key2 => 3.0}
68
+ @db.add( record)
69
+ assert( File.exist?('rec.yml') )
70
+ loaded = YAML.load( File.open('rec.yml','r') )
71
+ rec2 = record.dup
72
+ rec2[:id] = 1
73
+ assert_equal( rec2, loaded[0])
74
+
75
+ assert_raise(RuntimeError) {
76
+ @db.transaction do
77
+ @db.add( {:key1 => 99, :key2 => 2} )
78
+ raise
79
+ end
80
+ }
81
+ loaded2 = YAML.load( File.open('rec.yml','r') )
82
+ assert_equal( loaded, loaded2)
83
+ end
84
+
23
85
  def test_create_table
24
86
  assert_nil( NERA::Database.create_table( @path_to_db) )
25
87
  end
@@ -210,5 +210,13 @@ class TC_NERA_DB_FOLDERS < Test::Unit::TestCase
210
210
  assert_equal( @db_folder+"/Tables/hosts.yml",p)
211
211
  end
212
212
 
213
+ def test_logger
214
+ @dbf.logger.info("controller") do "test_message" end
215
+ assert( File.exist?( @db_folder+"/Tables/logfile.txt") )
216
+ last_line = File.open( @db_folder+"/Tables/logfile.txt", 'r').readlines[-1]
217
+ assert( last_line =~ /^I,/)
218
+ assert( last_line =~ /controller: test_message$/)
219
+ end
220
+
213
221
  end
214
222
 
@@ -55,11 +55,16 @@ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase
55
55
  @jlc.cancel_jobs(1)
56
56
  }
57
57
 
58
+ logp = @db_folder+'/Tables/logfile.txt'
59
+ s1 = File.open(logp,'r').readlines.size
58
60
  f = @jlc.cancel_jobs( [1,2] )
59
61
  assert_equal([1,2], f)
60
62
  h, l = @jlc.not_finished_list_in_csv
61
63
  assert_equal( 1, l.size)
62
64
  assert_equal( 3, l[0].split(',')[0].to_i)
65
+ s2 = File.open(logp,'r').readlines.size
66
+ assert_equal( s1+2, s2)
67
+
63
68
 
64
69
  flag = File.exist?( @dbf.path_to_job_script(1))
65
70
  assert_equal( false, flag)
@@ -71,9 +76,15 @@ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase
71
76
 
72
77
  f = @jlc.cancel_jobs( [1000] )
73
78
  assert_nil( f)
79
+ s3 = File.open(logp,'r').readlines.size
80
+ assert_equal( s2, s3)
81
+
74
82
 
75
83
  f = @jlc.cancel_jobs( [2,3] )
76
84
  assert_equal( [3], f)
85
+ s4 = File.open(logp,'r').readlines.size
86
+ assert_equal( s3+1, s4)
87
+
77
88
  end
78
89
 
79
90
  def test_include_list
@@ -93,9 +104,15 @@ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase
93
104
  def test_include
94
105
  prepare_zipped_file
95
106
  fname = "j000001.tar.bz2"
107
+ logp = @db_folder+'/Tables/logfile.txt'
108
+ s1 = File.open(logp,'r').readlines.size
109
+
96
110
  @jlc.include(fname)
97
111
  f = FileTest.exist?(fname)
98
112
  assert_equal( false, f)
113
+ s2 = File.open(logp,'r').readlines.size
114
+ assert_equal( s1+1, s2)
115
+
99
116
  count = 0
100
117
  File.open( @dbf.path_to_finished_jobs_file, 'r') do |io|
101
118
  YAML.load_documents( io) do |doc|
@@ -112,6 +129,9 @@ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase
112
129
 
113
130
  def test_include_all
114
131
  prepare_zipped_file
132
+
133
+ logp = @db_folder+'/Tables/logfile.txt'
134
+ s1 = File.open(logp,'r').readlines.size
115
135
  @jlc.include_all
116
136
  a = Dir.glob( @dbf.path_to_include_layer + "*" )
117
137
  assert_equal( [], a)
@@ -119,6 +139,8 @@ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase
119
139
  assert_equal( [], l)
120
140
  h, l = @rlc.not_finished_jobs_list_in_csv
121
141
  assert_equal( [], l)
142
+ s2 = File.open(logp,'r').readlines.size
143
+ assert_equal( s1+3, s2)
122
144
  end
123
145
 
124
146
  def prepare_zipped_file
@@ -27,6 +27,19 @@ class TC_NERA_JOB_RECS < Test::Unit::TestCase
27
27
  assert_nil( f)
28
28
  end
29
29
 
30
+ def test_set_yaml_file
31
+ @db.set_yaml_file( 'jobs.yml')
32
+ assert( ! File.exist?( 'jobs.yml') )
33
+
34
+ given_id = @db.add( Ising,5,3,4 )
35
+ assert( File.exist?( 'jobs.yml') )
36
+ loaded = YAML.load( File.open('jobs.yml','r') )
37
+
38
+ given_id = @db.add( XY,4,2,5 )
39
+ loaded2 = YAML.load( File.open('jobs.yml','r') )
40
+ assert( loaded.size < loaded2.size )
41
+ end
42
+
30
43
  def test_keys
31
44
  k = [ :id,:state,:simulator,:parameter_id,:run_id,
32
45
  :number_of_runs,:created_at,:updated_at,:host_name ]
@@ -93,8 +93,12 @@ class TC_NERA_PARAM_LAYER_CONTROLLER < Test::Unit::TestCase
93
93
  end
94
94
 
95
95
  def test_create_a_new_parameter_set
96
+ logp = @db_folder+'/Tables/logfile.txt'
97
+ s1 = File.open(logp,'r').readlines.size
96
98
  f = @plc.create_a_new_parameter_set( {:L => 32, :K => 0.01, :tmax => 1} )
97
99
  assert_equal( 1, f)
100
+ s2 = File.open(logp,'r').readlines.size
101
+ assert_equal( s1+1, s2)
98
102
  f = @plc.create_a_new_parameter_set( {:L => 64, :K => 0.02} )
99
103
  assert_equal( 2, f)
100
104
  f = @plc.create_a_new_parameter_set( {:L => 96, :tmax => 3} )
@@ -120,8 +124,12 @@ class TC_NERA_PARAM_LAYER_CONTROLLER < Test::Unit::TestCase
120
124
 
121
125
  def test_move_a_parameter_set_into_trashbox
122
126
  add_three
127
+ logp = @db_folder+'/Tables/logfile.txt'
128
+ s1 = File.open(logp,'r').readlines.size
123
129
  f = @plc.move_a_parameter_set_into_trashbox(2)
124
130
  assert_equal( true, f)
131
+ s2 = File.open(logp,'r').readlines.size
132
+ assert_equal( s1+1,s2)
125
133
  header, list = @plc.parameters_list_in_csv
126
134
  assert_equal( 2, list.size)
127
135
  f = @plc.move_a_parameter_set_into_trashbox(2)
@@ -148,8 +156,12 @@ class TC_NERA_PARAM_LAYER_CONTROLLER < Test::Unit::TestCase
148
156
  add_three
149
157
  h_org, l_org = @plc.parameters_list_in_csv
150
158
  f = @plc.move_a_parameter_set_into_trashbox(2)
159
+ logp = @db_folder+'/Tables/logfile.txt'
160
+ s1 = File.open(logp,'r').readlines.size
151
161
  f = @plc.revert_a_parameter_set_in_trashbox(2)
152
162
  assert(f)
163
+ s2 = File.open(logp,'r').readlines.size
164
+ assert_equal( s1+1, s2)
153
165
  h2, l2 = @plc.parameters_list_in_csv
154
166
  assert_equal( l_org, l2)
155
167
  h3, l3 = @plc.trashbox_parameter_list_in_csv
@@ -169,8 +181,12 @@ class TC_NERA_PARAM_LAYER_CONTROLLER < Test::Unit::TestCase
169
181
  add_three
170
182
  h_org, l_org = @plc.parameters_list_in_csv
171
183
  @plc.move_a_parameter_set_into_trashbox(2)
184
+ logp = @db_folder+'/Tables/logfile.txt'
185
+ s1 = File.open(logp,'r').readlines.size
172
186
  s = @plc.delete_a_parameter_set(2)
173
187
  assert(s)
188
+ s2 = File.open(logp,'r').readlines.size
189
+ assert_equal( s1+1, s2)
174
190
  ht, lt = @plc.trashbox_parameter_list_in_csv
175
191
  assert_equal( [], lt)
176
192
 
@@ -7,9 +7,13 @@ class TC_NERA_PARAM_RECS < Test::Unit::TestCase
7
7
  @testdir = 'test_sim_recs'
8
8
  FileUtils.mkdir(@testdir)
9
9
  FileUtils.chdir(@testdir)
10
- @path_to_db = 'sim_recs_table.marshal'
10
+ @path_to_db_sim = 'sim_recs_table.marshal'
11
+ @path_to_db = 'param_recs_table.marshal'
12
+ NERA::SimulatorRecords.create_table( @path_to_db_sim)
13
+ @s_db = NERA::SimulatorRecords.new( @path_to_db_sim)
14
+ id = @s_db.add(Ising)
11
15
  NERA::ParameterRecords.create_table( @path_to_db, Ising)
12
- @db = NERA::ParameterRecords.new( @path_to_db, Ising)
16
+ @db = NERA::ParameterRecords.new( @path_to_db, @s_db, id)
13
17
  end
14
18
 
15
19
  def teardown
@@ -18,14 +22,17 @@ class TC_NERA_PARAM_RECS < Test::Unit::TestCase
18
22
  end
19
23
 
20
24
  def test_initialize
21
- assert_raise( RuntimeError) {
22
- NERA::ParameterRecords.new('unknown_file', Ising)
25
+ assert_raise( ArgumentError) {
26
+ NERA::ParameterRecords.new('unknown_file', Ising, "1")
27
+ }
28
+ assert_raise( ArgumentError) {
29
+ NERA::ParameterRecords.new('unknown_file', Ising, 1)
23
30
  }
24
31
  assert_raise( ArgumentError) {
25
- NERA::ParameterRecords.new( @path_to_db, XY)
32
+ NERA::ParameterRecords.new( @path_to_db, XY, 1)
26
33
  }
27
34
  assert_raise( ArgumentError) {
28
- NERA::ParameterRecords.new(@path_to_db, Temp)
35
+ NERA::ParameterRecords.new(@path_to_db, Temp, 1)
29
36
  }
30
37
  end
31
38
 
@@ -42,6 +49,46 @@ class TC_NERA_PARAM_RECS < Test::Unit::TestCase
42
49
  }
43
50
  end
44
51
 
52
+ def test_observer
53
+ @s_db.add(XY)
54
+
55
+ d1 = @s_db.list[0][:updated_at]
56
+ dx1 = @s_db.list[1][:updated_at]
57
+ sleep 2
58
+ param1 = { :L => 32, :K => 0.22, :tmax => 512 }
59
+ f = @db.add( param1)
60
+ d2 = @s_db.list[0][:updated_at]
61
+ dx2 = @s_db.list[1][:updated_at]
62
+ assert( d1 < d2)
63
+ assert_equal( dx1, dx2)
64
+
65
+ sleep 2
66
+ @db.transaction do
67
+ @db.update_to_state_trashbox(1)
68
+ d3 = @s_db.list[0][:updated_at]
69
+ assert_equal( d2, d3)
70
+ end
71
+ d4 = @s_db.list[0][:updated_at]
72
+ dx3 = @s_db.list[1][:updated_at]
73
+ assert( d2 < d4)
74
+ assert_equal( dx1, dx3)
75
+ end
76
+
77
+ def test_set_yaml_file
78
+ @db.set_yaml_file( 'parameters.yml')
79
+ assert( ! File.exist?( 'parameters.yml') )
80
+
81
+ param1 = { :L => 32, :K => 0.22, :tmax => 512 }
82
+ f = @db.add( param1)
83
+ assert( File.exist?( 'parameters.yml') )
84
+ loaded = YAML.load( File.open('parameters.yml','r') )
85
+
86
+ sleep 2
87
+ @db.touch(f)
88
+ loaded2 = YAML.load( File.open('parameters.yml','r') )
89
+ assert( loaded[0][:updated_at] < loaded2[0][:updated_at] )
90
+ end
91
+
45
92
  def test_keys
46
93
  assert_equal( [:id,:created_at,:updated_at,:in_trashbox?,:L,:K,:tmax], @db.keys)
47
94
  end
@@ -232,7 +279,7 @@ class TC_NERA_PARAM_RECS < Test::Unit::TestCase
232
279
  def test_touch
233
280
  add_three
234
281
  a = @db.find_by_id(1)
235
- sleep 3
282
+ sleep 2
236
283
  f = @db.touch( 1)
237
284
  assert_equal(true, f)
238
285
  b = @db.find_by_id(1)
@@ -244,6 +291,21 @@ class TC_NERA_PARAM_RECS < Test::Unit::TestCase
244
291
  assert_nil( f)
245
292
  end
246
293
 
294
+ def test_update
295
+ add_three
296
+ a = @db.find_by_id(1)
297
+ sleep 2
298
+ f = @db.update( 1)
299
+ assert_equal(true, f)
300
+ b = @db.find_by_id(1)
301
+ assert( a[:updated_at] < b[:updated_at] )
302
+ b[:updated_at] = a[:updated_at]
303
+ assert_equal( a, b)
304
+
305
+ f = @db.update(500)
306
+ assert_nil( f)
307
+ end
308
+
247
309
  def test_destroy
248
310
  add_three
249
311
  @db.update_to_state_trashbox(3)
@@ -68,17 +68,27 @@ class TC_NERA_RM_CONNECTOR < Test::Unit::TestCase
68
68
  @rc.transfer( [1,2], 1)
69
69
  }
70
70
 
71
+ logp = @db_folder+'/Tables/logfile.txt'
72
+ s1 = File.open(logp,'r').readlines.size
71
73
  ret = @rc.transfer( [999,1000], "localhost")
72
74
  assert_equal( :no_such_jobs, ret)
75
+ s2 = File.open(logp,'r').readlines.size
76
+ assert_equal( s1, s2)
77
+
73
78
 
74
79
  ret = @rc.transfer( [1,2], "unknown_host")
75
80
  assert_equal( :connection_failed, ret)
76
81
 
77
82
  ret = @rc.transfer( [1], "unconnectable")
78
83
  assert_equal( :connection_failed, ret)
84
+ s3 = File.open(logp,'r').readlines.size
85
+ assert_equal( s2+1, s3)
79
86
 
80
87
  ret = @rc.transfer( [1,2], "localhost")
81
88
  assert_equal( :succeeded, ret)
89
+ s3 = File.open(logp,'r').readlines.size
90
+ assert_equal( s2+3, s3)
91
+
82
92
  h,l = @jlc.not_finished_list_in_csv
83
93
  stat = l[0].split(',')[1].strip
84
94
  assert_equal( :copied.to_s, stat)
@@ -120,11 +130,17 @@ class TC_NERA_RM_CONNECTOR < Test::Unit::TestCase
120
130
  ret = @rc.submit( [1,2], "unknown_host")
121
131
  assert_equal( :connection_failed, ret)
122
132
 
133
+ logp = @db_folder+'/Tables/logfile.txt'
134
+ s1 = File.open(logp,'r').readlines.size
123
135
  ret = @rc.submit( [1], "unconnectable")
124
136
  assert_equal( :connection_failed, ret)
137
+ s2 = File.open(logp,'r').readlines.size
138
+ assert_equal( s1+1, s2)
125
139
 
126
140
  ret = @rc.submit( [1,2], "localhost_submittable")
127
141
  assert_equal( :succeeded, ret)
142
+ s2 = File.open(logp,'r').readlines.size
143
+ assert_equal( s1+3, s2)
128
144
 
129
145
  h,l = @jlc.not_finished_list_in_csv
130
146
  stat = l[0].split(',')[1].strip
@@ -198,17 +214,26 @@ class TC_NERA_RM_CONNECTOR < Test::Unit::TestCase
198
214
  ret = @rc.download( ["j000001.tar.bz2"], "unknown_host")
199
215
  assert_equal( :connection_failed, ret)
200
216
 
217
+ logp = @db_folder+'/Tables/logfile.txt'
218
+ s1 = File.open(logp,'r').readlines.size
201
219
  ret = @rc.download( ["j000001.tar.bz2"], "unconnectable")
202
220
  assert_equal( :connection_failed, ret)
221
+ s2 = File.open(logp,'r').readlines.size
222
+ assert_equal( s1+1,s2)
203
223
 
204
224
  ret = @rc.download( ["j000001.tar.bz2"], "localhost_submittable")
205
225
  assert_equal( [], ret)
226
+ s2 = File.open(logp,'r').readlines.size
227
+ assert_equal( s1+1,s2)
206
228
 
207
229
  ret = @rc.submit( [1,2], "localhost_submittable")
208
230
  sleep 3 # wait for completion
209
231
  downloadable = @rc.check_completion("localhost_submittable")
210
232
  ret = @rc.download( downloadable, "localhost_submittable")
211
233
  assert_equal( ["j000001.tar.bz2", "j000002.tar.bz2"], ret)
234
+ s2 = File.open(logp,'r').readlines.size
235
+ assert_equal( s1+5,s2)
236
+
212
237
 
213
238
  downloadable = @rc.check_completion("localhost_submittable")
214
239
  assert_equal( downloadable, [])
@@ -73,11 +73,16 @@ class TC_NERA_RUN_LAYER_CONTROLLER < Test::Unit::TestCase
73
73
  end
74
74
 
75
75
  def test_create_jobs
76
+ logp = @db_folder+'/Tables/logfile.txt'
77
+ s1 = File.open(logp,'r').readlines.size
78
+
76
79
  jid = @rlc.create_jobs(1)
77
80
  header, list = @rlc.all_runs_list_in_csv
78
81
  assert_equal( 1, list.size)
79
82
  assert_equal( [1], jid)
80
83
  assert( list[0].split(', ')[3].to_i > 0) # check job id
84
+ s2 = File.open(logp,'r').readlines.size
85
+ assert_equal( s1+1,s2)
81
86
 
82
87
  jobs_table = NERA::JobRecords.new( @dbf.path_to_jobs_table)
83
88
  l = jobs_table.list_all
@@ -87,6 +92,9 @@ class TC_NERA_RUN_LAYER_CONTROLLER < Test::Unit::TestCase
87
92
 
88
93
  # -------------------------------------
89
94
  jid = @rlc.create_jobs(3)
95
+ s3 = File.open(logp,'r').readlines.size
96
+ assert_equal( s2+3,s3)
97
+
90
98
  header, list = @rlc.all_runs_list_in_csv
91
99
  assert_equal( 4, list.size)
92
100
  assert_equal( [2,3,4], jid)
@@ -107,6 +115,9 @@ class TC_NERA_RUN_LAYER_CONTROLLER < Test::Unit::TestCase
107
115
  header, list = @rlc.all_runs_list_in_csv
108
116
  assert_equal( 8, list.size)
109
117
  assert_equal( [5,6], jid)
118
+ s4 = File.open(logp,'r').readlines.size
119
+ assert_equal( s3+2,s4)
120
+
110
121
 
111
122
  jobs_table = NERA::JobRecords.new( @dbf.path_to_jobs_table)
112
123
  l = jobs_table.list_all
@@ -139,10 +150,15 @@ class TC_NERA_RUN_LAYER_CONTROLLER < Test::Unit::TestCase
139
150
  def test_cancel_jobs
140
151
  jids = @rlc.create_jobs(3)
141
152
  p jids
153
+
154
+ logp = @db_folder+'/Tables/logfile.txt'
155
+ s1 = File.open(logp,'r').readlines.size
142
156
  canceled = @rlc.cancel_jobs( jids)
143
157
  assert_equal( jids, canceled)
144
158
  h, l = @rlc.all_runs_list_in_csv
145
159
  assert_equal( 0, l.size)
160
+ s2 = File.open(logp,'r').readlines.size
161
+ assert_equal( s1+3, s2)
146
162
 
147
163
  l = NERA::JobRecords.new( @dbf.path_to_jobs_table).list_all
148
164
  assert_equal( 0, l.size)
@@ -165,16 +181,27 @@ class TC_NERA_RUN_LAYER_CONTROLLER < Test::Unit::TestCase
165
181
  end
166
182
 
167
183
  def test_analyze
184
+ logp = @db_folder+'/Tables/logfile.txt'
185
+ s1 = File.open(logp,'r').readlines.size
186
+
168
187
  @rlc.analyze( "analyze_test1")
169
188
  assert( FileTest.exist?( @dbf.path_to_run_layer(Ising,1) + "test1") )
189
+ s2 = File.open(logp,'r').readlines.size
190
+ assert_equal( s1+1, s2)
170
191
 
171
192
  assert_nil( @rlc.analyze( "hoge") )
172
193
  end
173
194
 
174
195
  def test_analyze_all
196
+ logp = @db_folder+'/Tables/logfile.txt'
197
+ s1 = File.open(logp,'r').readlines.size
198
+
175
199
  @rlc.analyze_all
176
200
  assert( FileTest.exist?( @dbf.path_to_run_layer(Ising,1) + "test1") )
177
201
  assert( FileTest.exist?( @dbf.path_to_run_layer(Ising,1) + "test2") )
202
+ s2 = File.open(logp,'r').readlines.size
203
+ assert_equal( s1+2, s2)
204
+
178
205
  end
179
206
 
180
207
  end
@@ -8,8 +8,20 @@ class TC_NERA_RUN_RECORDS < Test::Unit::TestCase
8
8
  FileUtils.mkdir( @testdir)
9
9
  FileUtils.chdir( @testdir)
10
10
  @table_file = 'run_recs.pstore'
11
+
12
+ @path_to_db_sim = 'sim_recs_table.marshal'
13
+ @path_to_db_param = 'param_recs_table.marshal'
14
+ NERA::SimulatorRecords.create_table( @path_to_db_sim)
15
+ @s_recs = NERA::SimulatorRecords.new( @path_to_db_sim)
16
+ id = @s_recs.add( Ising)
17
+ NERA::ParameterRecords.create_table( @path_to_db_param, Ising)
18
+ @p_recs = NERA::ParameterRecords.new( @path_to_db_param, @s_recs, id)
19
+ param1 = { :L => 32, :K => 0.22, :tmax => 512 }
20
+ f = @p_recs.add( param1)
21
+
22
+
11
23
  NERA::RunRecords.create_table( @table_file)
12
- @rrecs = NERA::RunRecords.new( @table_file)
24
+ @rrecs = NERA::RunRecords.new( @table_file, @p_recs, f)
13
25
  end
14
26
 
15
27
  def teardown
@@ -19,10 +31,52 @@ class TC_NERA_RUN_RECORDS < Test::Unit::TestCase
19
31
 
20
32
  def test_initialize
21
33
  assert_raise( RuntimeError) {
22
- NERA::RunRecords.new( 'unknown')
34
+ NERA::RunRecords.new( 'unknown', @p_recs, 1)
35
+ }
36
+ assert_raise( ArgumentError) {
37
+ NERA::RunRecords.new( @table_file, Ising, 1)
38
+ }
39
+ assert_raise( ArgumentError) {
40
+ NERA::RunRecords.new( @table_file, @p_recs, '1')
23
41
  }
24
42
  end
25
43
 
44
+ def test_observer
45
+ @s_recs.add(XY)
46
+ @p_recs.add( { :L => 64, :K => 0.25, :tmax => 512 })
47
+
48
+ da1 = @s_recs.list[0][:updated_at]
49
+ db1 = @s_recs.list[1][:updated_at]
50
+ dc1 = @p_recs.list_all[0][:updated_at]
51
+ dd1 = @p_recs.list_all[1][:updated_at]
52
+ sleep 2
53
+
54
+ @rrecs.add(1)
55
+ de1 = @s_recs.list[0][:updated_at]
56
+ df1 = @s_recs.list[1][:updated_at]
57
+ dg1 = @p_recs.list_all[0][:updated_at]
58
+ dh1 = @p_recs.list_all[1][:updated_at]
59
+ assert( da1 < de1)
60
+ assert( dc1 < dg1)
61
+ assert_equal( db1, df1)
62
+ assert_equal( dd1, dh1)
63
+ end
64
+
65
+ def test_set_yaml_file
66
+ @rrecs.set_yaml_file( 'runs.yml')
67
+ assert( ! File.exist?( 'runs.yml') )
68
+
69
+ @rrecs.add( 1)
70
+ assert( File.exist?( 'runs.yml') )
71
+ loaded = YAML.load( File.open('runs.yml','r') )
72
+
73
+ sleep 2
74
+ @rrecs.add(1)
75
+ loaded2 = YAML.load( File.open('runs.yml','r') )
76
+ assert( loaded.size < loaded2.size )
77
+ end
78
+
79
+
26
80
  def test_create_a_new_table
27
81
  n = NERA::RunRecords.create_table( @table_file)
28
82
  assert_nil(n)