scout-gear 7.1.0 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +65 -2
  3. data/VERSION +1 -1
  4. data/bin/scout +5 -1
  5. data/lib/rbbt-scout.rb +5 -0
  6. data/lib/scout/concurrent_stream.rb +13 -8
  7. data/lib/scout/config.rb +168 -0
  8. data/lib/scout/exceptions.rb +5 -3
  9. data/lib/scout/indiferent_hash/options.rb +1 -0
  10. data/lib/scout/indiferent_hash.rb +4 -2
  11. data/lib/scout/log/color.rb +3 -2
  12. data/lib/scout/log/progress/report.rb +1 -0
  13. data/lib/scout/log/progress/util.rb +66 -1
  14. data/lib/scout/log/progress.rb +5 -3
  15. data/lib/scout/log.rb +3 -2
  16. data/lib/scout/misc/helper.rb +31 -0
  17. data/lib/scout/misc/monitor.rb +4 -1
  18. data/lib/scout/misc/system.rb +15 -0
  19. data/lib/scout/misc.rb +2 -0
  20. data/lib/scout/named_array.rb +68 -0
  21. data/lib/scout/open/stream.rb +58 -33
  22. data/lib/scout/path/find.rb +27 -3
  23. data/lib/scout/path/util.rb +7 -4
  24. data/lib/scout/persist/serialize.rb +7 -14
  25. data/lib/scout/persist.rb +46 -12
  26. data/lib/scout/resource/produce.rb +7 -94
  27. data/lib/scout/resource/software.rb +176 -0
  28. data/lib/scout/semaphore.rb +8 -1
  29. data/lib/scout/tsv/dumper.rb +112 -0
  30. data/lib/scout/tsv/index.rb +161 -0
  31. data/lib/scout/tsv/open.rb +128 -0
  32. data/lib/scout/tsv/parser.rb +230 -30
  33. data/lib/scout/tsv/path.rb +13 -0
  34. data/lib/scout/tsv/persist/adapter.rb +367 -0
  35. data/lib/scout/tsv/persist/fix_width_table.rb +324 -0
  36. data/lib/scout/tsv/persist/serialize.rb +117 -0
  37. data/lib/scout/tsv/persist/tokyocabinet.rb +113 -0
  38. data/lib/scout/tsv/persist.rb +13 -0
  39. data/lib/scout/tsv/traverse.rb +143 -0
  40. data/lib/scout/tsv/util/filter.rb +303 -0
  41. data/lib/scout/tsv/util/process.rb +73 -0
  42. data/lib/scout/tsv/util/select.rb +220 -0
  43. data/lib/scout/tsv/util.rb +82 -0
  44. data/lib/scout/tsv.rb +16 -3
  45. data/lib/scout/work_queue/worker.rb +4 -4
  46. data/lib/scout/work_queue.rb +22 -7
  47. data/lib/scout/workflow/definition.rb +101 -4
  48. data/lib/scout/workflow/step/config.rb +18 -0
  49. data/lib/scout/workflow/step/dependencies.rb +40 -0
  50. data/lib/scout/workflow/step/file.rb +15 -0
  51. data/lib/scout/workflow/step/info.rb +35 -4
  52. data/lib/scout/workflow/step/progress.rb +14 -0
  53. data/lib/scout/workflow/step/provenance.rb +148 -0
  54. data/lib/scout/workflow/step.rb +71 -17
  55. data/lib/scout/workflow/task.rb +10 -5
  56. data/lib/scout/workflow/usage.rb +3 -1
  57. data/lib/scout/workflow.rb +11 -3
  58. data/lib/scout-gear.rb +1 -0
  59. data/lib/scout.rb +1 -0
  60. data/scout-gear.gemspec +64 -10
  61. data/scout_commands/find +1 -1
  62. data/scout_commands/workflow/task +16 -9
  63. data/scout_commands/workflow/task_old +2 -2
  64. data/share/software/install_helpers +523 -0
  65. data/test/scout/log/test_progress.rb +0 -2
  66. data/test/scout/misc/test_system.rb +21 -0
  67. data/test/scout/open/test_stream.rb +160 -1
  68. data/test/scout/path/test_find.rb +14 -7
  69. data/test/scout/resource/test_software.rb +24 -0
  70. data/test/scout/test_config.rb +66 -0
  71. data/test/scout/test_meta_extension.rb +10 -0
  72. data/test/scout/test_named_array.rb +19 -0
  73. data/test/scout/test_persist.rb +96 -0
  74. data/test/scout/test_tmpfile.rb +1 -1
  75. data/test/scout/test_tsv.rb +50 -1
  76. data/test/scout/test_work_queue.rb +41 -13
  77. data/test/scout/tsv/persist/test_adapter.rb +44 -0
  78. data/test/scout/tsv/persist/test_fix_width_table.rb +134 -0
  79. data/test/scout/tsv/persist/test_tokyocabinet.rb +92 -0
  80. data/test/scout/tsv/test_dumper.rb +44 -0
  81. data/test/scout/tsv/test_index.rb +156 -0
  82. data/test/scout/tsv/test_open.rb +9 -0
  83. data/test/scout/tsv/test_parser.rb +114 -3
  84. data/test/scout/tsv/test_persist.rb +43 -0
  85. data/test/scout/tsv/test_traverse.rb +116 -0
  86. data/test/scout/tsv/test_util.rb +23 -0
  87. data/test/scout/tsv/util/test_filter.rb +188 -0
  88. data/test/scout/tsv/util/test_process.rb +47 -0
  89. data/test/scout/tsv/util/test_select.rb +44 -0
  90. data/test/scout/work_queue/test_worker.rb +66 -9
  91. data/test/scout/workflow/step/test_dependencies.rb +25 -0
  92. data/test/scout/workflow/step/test_info.rb +15 -17
  93. data/test/scout/workflow/step/test_load.rb +19 -21
  94. data/test/scout/workflow/step/test_provenance.rb +25 -0
  95. data/test/scout/workflow/test_step.rb +206 -10
  96. data/test/scout/workflow/test_task.rb +0 -3
  97. data/test/test_helper.rb +9 -1
  98. metadata +50 -6
@@ -5,7 +5,7 @@ require 'scout/path'
5
5
  require 'scout/open'
6
6
 
7
7
  class TestOpenStream < Test::Unit::TestCase
8
- def test_consume_stream
8
+ def test_stream
9
9
  content =<<-EOF
10
10
  1
11
11
  2
@@ -99,6 +99,32 @@ class TestOpenStream < Test::Unit::TestCase
99
99
  end
100
100
  end
101
101
 
102
+ def test_tee_stream_multiple
103
+ num = 2000
104
+ sout = Open.open_pipe do |sin|
105
+ num.times do |i|
106
+ sin.puts "line #{i} - #{rand(100000).to_s * 100}"
107
+ end
108
+ end
109
+
110
+ TmpFile.with_file do |tmp|
111
+ Path.setup tmp
112
+
113
+ s1, s2, s3 = Open.tee_stream_thread_multiple sout, 3
114
+
115
+ t1 = Open.consume_stream(s1, true, tmp.file1)
116
+ t2 = Open.consume_stream(s2, true, tmp.file2)
117
+ t3 = Open.consume_stream(s3, true, tmp.file3)
118
+ t1.join
119
+ t2.join
120
+ t3.join
121
+ assert_equal num, Open.read(tmp.file1).split("\n").length
122
+ assert_equal num, Open.read(tmp.file2).split("\n").length
123
+ assert_equal num, Open.read(tmp.file3).split("\n").length
124
+ end
125
+ end
126
+
127
+
102
128
  def test_tee_stream_source_error
103
129
  5.times do |i|
104
130
  num = 2000
@@ -137,6 +163,47 @@ class TestOpenStream < Test::Unit::TestCase
137
163
  end
138
164
  end
139
165
 
166
+ def test_tee_stream_source_error_multiple
167
+ 5.times do |i|
168
+ num = 2000
169
+ sout = Open.open_pipe do |sin|
170
+ num.times do |i|
171
+ sin.puts "line #{i} - #{rand(100000).to_s * 100}"
172
+ end
173
+ raise ScoutException
174
+ end
175
+
176
+ TmpFile.with_file do |tmp|
177
+ Path.setup tmp
178
+
179
+ s1, s2, s3 = Open.tee_stream_thread_multiple sout, 3
180
+
181
+ t1 = Open.consume_stream(s1, true, tmp.file1)
182
+ t2 = Open.consume_stream(s2, true, tmp.file2)
183
+ t3 = Open.consume_stream(s3, true, tmp.file3)
184
+ assert_raise ScoutException do
185
+ begin
186
+ t1.join
187
+ t2.join
188
+ t3.join
189
+ rescue
190
+ raise
191
+ ensure
192
+ [t1, t2, t2].each do |t|
193
+ begin
194
+ t.join if t.alive?
195
+ rescue ScoutException
196
+ end
197
+ end
198
+ end
199
+ end
200
+ refute Open.exist?(tmp.file1)
201
+ refute Open.exist?(tmp.file2)
202
+ refute Open.exist?(tmp.file3)
203
+ end
204
+ end
205
+ end
206
+
140
207
  def test_tee_stream_save_error
141
208
  Log.with_severity 6 do
142
209
  50.times do |i|
@@ -175,6 +242,98 @@ class TestOpenStream < Test::Unit::TestCase
175
242
  end
176
243
  end
177
244
 
245
+ def test_tee_stream_save_error_multiple
246
+ Log.with_severity 6 do
247
+ 50.times do |i|
248
+ TmpFile.with_file do |tmp|
249
+ Path.setup tmp
250
+ assert_raise ScoutException do
251
+ num = 2000
252
+ begin
253
+ sout = Open.open_pipe do |sin|
254
+ num.times do |i|
255
+ sin.puts "line #{i} - #{rand(100000).to_s * 100}"
256
+ end
257
+ end
258
+
259
+ begin
260
+ s1, s2, s3 = Open.tee_stream_thread_multiple sout, 3
261
+
262
+ s2.abort ScoutException.new
263
+ t1 = Open.consume_stream(s1, true, tmp.file1)
264
+ t2 = Open.consume_stream(s2, true, tmp.file2)
265
+
266
+ t1.join
267
+ t2.join
268
+ ensure
269
+ s1.close if s1.respond_to?(:close) && ! s1.closed?
270
+ s1.join if s1.respond_to?(:join) && ! s1.joined?
271
+ s2.close if s2.respond_to?(:close) && ! s2.closed?
272
+ s2.join if s2.respond_to?(:join) && ! s2.joined?
273
+ s3.close if s3.respond_to?(:close) && ! s3.closed?
274
+ s3.join if s3.respond_to?(:join) && ! s3.joined?
275
+ end
276
+ ensure
277
+ sout.close if sout.respond_to?(:close) && ! sout.closed?
278
+ sout.join if sout.respond_to?(:join) && ! sout.joined?
279
+ end
280
+ end
281
+ refute Open.exist?(tmp.file1)
282
+ refute Open.exist?(tmp.file2)
283
+ end
284
+ end
285
+ end
286
+ end
287
+
288
+ def test_sort_stream
289
+ text =<<-EOF
290
+ ##
291
+ ##
292
+ ##
293
+ #Row LabelA LabelB LabelC
294
+ row2 AA BB CC
295
+ row3 AAA BBB CCC
296
+ row1 A B C
297
+ EOF
298
+ s = StringIO.new text
299
+ sorted = Open.sort_stream(s)
300
+ assert_equal %w(## ## ## #Row row2 row3 row1), text.split("\n").collect{|l| l.split(" ").first}
301
+ assert_equal %w(## ## ## #Row row1 row2 row3), sorted.read.split("\n").collect{|l| l.split(" ").first}
302
+ end
303
+
304
+ def test_sort_long_stream
305
+ text =<<-EOF
306
+ ##
307
+ ##
308
+ ##
309
+ #Row LabelA LabelB LabelC
310
+ row2 AA BB CC
311
+ row3 AAA BBB CCC
312
+ row1 A B C
313
+ EOF
314
+
315
+ s = StringIO.new text + (text.split("\n")[-3..-1] * "\n" + "\n") * 10000
316
+ sorted = Open.sort_stream(s)
317
+ assert_equal %w(## ## ## #Row row2 row3 row1), text.split("\n").collect{|l| l.split(" ").first}
318
+ assert_equal %w(## ## ## #Row row1 row2 row3), sorted.read.split("\n").collect{|l| l.split(" ").first}
319
+ end
320
+
321
+ def test_sort_stream2
322
+ text =<<-EOF
323
+ ##
324
+ ##
325
+ ##
326
+ #Row LabelA LabelB LabelC
327
+ row2 AA BB CC
328
+ row3 AAA BBB CCC
329
+ row1 A B C
330
+ EOF
331
+ s = StringIO.new text
332
+ sorted = Open.sort_stream(Open.sort_stream(s))
333
+ assert_equal %w(## ## ## #Row row2 row3 row1), text.split("\n").collect{|l| l.split(" ").first}
334
+ assert_equal %w(## ## ## #Row row1 row2 row3), sorted.read.split("\n").collect{|l| l.split(" ").first}
335
+ end
336
+
178
337
  # def test_collapse_stream
179
338
  # text=<<-EOF
180
339
  #row1 A B C
@@ -29,7 +29,7 @@ class TestPathFind < Test::Unit::TestCase
29
29
  def test_current
30
30
  path = Path.setup("share/data/some_file", 'scout')
31
31
  TmpFile.in_dir do |tmpdir|
32
- assert_equal File.join(tmpdir,"share/data/some_file"), path.find(:current)
32
+ assert_equal_path File.join(tmpdir,"share/data/some_file"), path.find(:current)
33
33
  end
34
34
  end
35
35
 
@@ -38,7 +38,7 @@ class TestPathFind < Test::Unit::TestCase
38
38
  TmpFile.in_dir do |tmpdir|
39
39
  FileUtils.mkdir_p(File.dirname(File.join(tmpdir, path)))
40
40
  File.write(File.join(tmpdir, path), 'string')
41
- assert_equal File.join(tmpdir,"share/data/some_file"), path.find
41
+ assert_equal_path File.join(tmpdir,"share/data/some_file"), path.find
42
42
  assert_equal :current, path.find.where
43
43
  assert_equal "share/data/some_file", path.find.original
44
44
  end
@@ -67,7 +67,7 @@ class TestPathFind < Test::Unit::TestCase
67
67
 
68
68
  p = Path.setup("/tmp/foo/bar")
69
69
  assert p.located?
70
- assert_equal p, p.find
70
+ assert_equal_path p, p.find
71
71
 
72
72
  end
73
73
 
@@ -75,10 +75,10 @@ class TestPathFind < Test::Unit::TestCase
75
75
  path = Path.setup("share/data/some_file", 'scout')
76
76
  TmpFile.with_file do |tmpdir|
77
77
  path.path_maps[:custom] = [tmpdir, '{PATH}'] * "/"
78
- assert_equal File.join(tmpdir,"share/data/some_file"), path.find(:custom)
78
+ assert_equal_path File.join(tmpdir,"share/data/some_file"), path.find(:custom)
79
79
 
80
80
  path.path_maps[:custom] = [tmpdir, '{TOPLEVEL}/{PKGDIR}/{SUBPATH}'] * "/"
81
- assert_equal File.join(tmpdir,"share/scout/data/some_file"), path.find(:custom)
81
+ assert_equal_path File.join(tmpdir,"share/scout/data/some_file"), path.find(:custom)
82
82
  end
83
83
  end
84
84
 
@@ -87,7 +87,7 @@ class TestPathFind < Test::Unit::TestCase
87
87
  TmpFile.with_file do |tmpdir|
88
88
  path.pkgdir = 'scout_alt'
89
89
  path.path_maps[:custom] = [tmpdir, '{TOPLEVEL}/{PKGDIR}/{SUBPATH}'] * "/"
90
- assert_equal File.join(tmpdir,"share/scout_alt/data/some_file"), path.find(:custom)
90
+ assert_equal_path File.join(tmpdir,"share/scout_alt/data/some_file"), path.find(:custom)
91
91
  end
92
92
  end
93
93
 
@@ -98,6 +98,13 @@ class TestPathFind < Test::Unit::TestCase
98
98
  assert_equal "/some_dir/scout_commands/find", Path.follow(path, '/some_dir/{PATH/bin\/scout/scout_commands}')
99
99
  end
100
100
 
101
-
101
+ def test_gz
102
+ TmpFile.with_file do |tmpdir|
103
+ Path.setup(tmpdir)
104
+ Open.write(tmpdir.somefile + '.gz', "FOO")
105
+ assert_equal_path tmpdir.somefile + '.gz', tmpdir.somefile.find
106
+ assert Open.exist?(tmpdir.somefile)
107
+ end
108
+ end
102
109
  end
103
110
 
@@ -0,0 +1,24 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestResourceSoftware < Test::Unit::TestCase
5
+ module TestResource
6
+ extend Resource
7
+
8
+ self.subdir = Path.setup('tmp/test-resource')
9
+ end
10
+
11
+ def test_install
12
+ Resource.install nil, "scout_install_example", tmpdir.software do
13
+ <<-EOF
14
+ echo "#!/bin/bash\necho WORKING" > $OPT_BIN_DIR/scout_install_example
15
+ chmod +x $OPT_BIN_DIR/scout_install_example
16
+ EOF
17
+ end
18
+ assert_nothing_raised do
19
+ CMD.cmd(tmpdir.software.opt.bin.scout_install_example).read
20
+ end
21
+ assert_equal "WORKING", CMD.cmd('scout_install_example').read.strip
22
+ end
23
+ end
24
+
@@ -0,0 +1,66 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestConfig < Test::Unit::TestCase
5
+ setup do
6
+ Scout::Config.set({:cpus => 30}, :test_config, :test)
7
+ Scout::Config.set(:cpus, 5, "slow::2", :test)
8
+ Scout::Config.set({:token => "token"}, "token")
9
+ Scout::Config.set(:notoken, "no_token")
10
+ Scout::Config.set({:emptytoken => "empty"})
11
+ end
12
+
13
+ def test_simple
14
+ assert_equal 30, Scout::Config.get(:cpus, :test_config)
15
+ end
16
+
17
+ def test_match
18
+ assert_equal({20 => ["token"]}, Scout::Config.match({["key:token"] => "token"}, "key:token"))
19
+ end
20
+
21
+ def test_simple_no_token
22
+ assert_equal "token", Scout::Config.get("token", "token")
23
+ assert_equal "no_token", Scout::Config.get("notoken", "key:notoken")
24
+ assert_equal 'token', Scout::Config.get("token", "key:token")
25
+ assert_equal 'token', Scout::Config.get("token")
26
+ assert_equal nil, Scout::Config.get("token", "someotherthing")
27
+ assert_equal "default_token", Scout::Config.get("token", 'unknown', :default => 'default_token')
28
+ assert_equal 'empty', Scout::Config.get("emptytoken", 'key:emptytoken')
29
+ end
30
+
31
+ def test_prio
32
+ assert_equal 5, Scout::Config.get(:cpus, :slow, :test)
33
+ end
34
+
35
+ def test_with_config
36
+ Scout::Config.add_entry 'key', 'valueA', 'token'
37
+ assert_equal "valueA", Scout::Config.get('key', 'token')
38
+ assert_equal "default", Scout::Config.get('key2', 'token', :default => 'default')
39
+
40
+ Scout::Config.with_config do
41
+ Scout::Config.add_entry 'key', 'valueB', 'token'
42
+ Scout::Config.add_entry 'key2', 'valueB2', 'token'
43
+ assert_equal "valueB", Scout::Config.get('key', 'token')
44
+ assert_equal "valueB2", Scout::Config.get('key2', 'token', :default => 'default')
45
+ end
46
+
47
+ assert_equal "valueA", Scout::Config.get('key', 'token')
48
+ assert_equal "default", Scout::Config.get('key2', 'token', :default => 'default')
49
+ end
50
+
51
+ def test_order
52
+ Scout::Config.add_entry 'key', 'V1', 'token1'
53
+ Scout::Config.add_entry 'key', 'V2', 'token2'
54
+ Scout::Config.add_entry 'key', 'V3', 'token2'
55
+
56
+ assert_equal "V3", Scout::Config.get('key', 'token2')
57
+ assert_equal "V1", Scout::Config.get('key', 'token1')
58
+ assert_equal "V3", Scout::Config.get('key', 'token2', 'token1')
59
+ assert_equal "V1", Scout::Config.get('key', 'token1', 'token2')
60
+ end
61
+
62
+ def test_default
63
+ Scout::Config.add_entry 'key', 'V1', 'token1'
64
+ assert_equal "V3", Scout::Config.get('key', 'token2', :default => 'V3')
65
+ end
66
+ end
@@ -19,6 +19,16 @@ class TestMetaExtension < Test::Unit::TestCase
19
19
  assert_equal :code, str2.code
20
20
  end
21
21
 
22
+ def test_marshal
23
+ str = "String"
24
+ ExtensionClass.setup(str, :code)
25
+ assert ExtensionClass === str
26
+ assert_equal :code, str.code
27
+
28
+ str2 = Marshal.load(Marshal.dump(str))
29
+ assert_equal :code, str2.code
30
+ end
31
+
22
32
  def test_setup_alternatives
23
33
  str = "String"
24
34
 
@@ -0,0 +1,19 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestNamedArray < Test::Unit::TestCase
5
+ def test_identify_names
6
+ names =<<-EOF.split("\n")
7
+ ValueA
8
+ ValueB (Entity type)
9
+ 15
10
+ EOF
11
+ assert_equal 0, NamedArray.identify_name(names, "ValueA")
12
+ assert_equal :key, NamedArray.identify_name(names, :key)
13
+ assert_equal 0, NamedArray.identify_name(names, nil)
14
+ assert_equal 1, NamedArray.identify_name(names, "ValueB (Entity type)")
15
+ assert_equal 1, NamedArray.identify_name(names, "ValueB")
16
+ assert_equal 1, NamedArray.identify_name(names, 1)
17
+ end
18
+ end
19
+
@@ -56,6 +56,21 @@ class TestPersist < Test::Unit::TestCase
56
56
  end
57
57
  end
58
58
 
59
+ def test_stream_multiple
60
+ TmpFile.with_file do |tmpfile|
61
+ Path.setup(tmpfile)
62
+ obj = "TEST\nTEST"
63
+ stream = StringIO.new obj
64
+ stream.rewind
65
+ res1 = Persist.persist(tmpfile, :string, :dir => tmpdir.persist, :tee_copies => 2){ stream }
66
+ res2 = res1.next
67
+ assert IO === res1
68
+ assert_equal obj, res1.read
69
+ assert_equal obj, res2.read
70
+ assert_equal obj, Persist.persist(tmpfile, :string, :dir => tmpdir.persist){ raise ScoutException }
71
+ end
72
+ end
73
+
59
74
  def test_update_time
60
75
  TmpFile.with_file do |dir|
61
76
  Path.setup(dir)
@@ -79,5 +94,86 @@ class TestPersist < Test::Unit::TestCase
79
94
  assert_equal "TEST2", Persist.persist(dir.cache, type, :dir => tmpdir.persist, :update => dir.file3){ Open.read(dir.file3) }
80
95
  end
81
96
  end
97
+
98
+ def test_concurrent
99
+ num = 10
100
+
101
+ s = 0.01
102
+ 10.times do
103
+ TmpFile.with_file do |file|
104
+ output1 = file + '.output1'
105
+ output2 = file + '.output2'
106
+ pid1 = Process.fork do
107
+ Open.purge_pipes
108
+ sleep rand/10.0
109
+ io = Persist.persist("test", :string, :path => file) do
110
+ Open.open_pipe do |sin|
111
+ num.times do |i|
112
+ sin.puts "line-#{i}-#{Process.pid}"
113
+ sleep s
114
+ end
115
+ end
116
+ end
117
+ if IO === io
118
+ Open.consume_stream(io, false)
119
+ else
120
+ Open.write(output1, io)
121
+ end
122
+ end
123
+ pid2 = Process.fork do
124
+ Open.purge_pipes
125
+ sleep rand/10.0
126
+ io = Persist.persist("test", :string, :path => file) do
127
+ Open.open_pipe do |sin|
128
+ num.times do |i|
129
+ sin.puts "line-#{i}-#{Process.pid}"
130
+ sleep s
131
+ end
132
+ end
133
+ end
134
+ if IO === io
135
+ Open.consume_stream(io, false)
136
+ else
137
+ Open.write(output2, io)
138
+ end
139
+ end
140
+ Process.wait
141
+ Process.wait
142
+
143
+ assert File.exist?(output1) || File.exist?(output2)
144
+ [pid1, pid2].zip([output2, output1]).each do |pid, found|
145
+ next unless File.exist?(found)
146
+ assert Open.read(found).include? "-#{pid}\n"
147
+ end
148
+ [pid1, pid2].zip([output1, output2]).each do |pid, found|
149
+ next unless File.exist?(found)
150
+ refute Open.read(found).include? "-#{pid}\n"
151
+ end
152
+ Open.rm file
153
+ Open.rm output1
154
+ Open.rm output2
155
+ end
156
+ end
157
+ end
158
+
159
+ def __test_speed
160
+ times = 100_000
161
+ TmpFile.with_file do |tmpfile|
162
+ sout = Persist.persist(tmpfile, :string, :path => tmpfile) do
163
+ Open.open_pipe do |sin|
164
+ times.times do |i|
165
+ sin.puts "line-#{i}"
166
+ end
167
+ end
168
+ end
169
+
170
+ Log::ProgressBar.with_bar do |bar|
171
+ while l = sout.gets
172
+ bar.tick
173
+ end
174
+ end
175
+ end
176
+ end
177
+
82
178
  end
83
179
 
@@ -45,7 +45,7 @@ class TestTmpFile < Test::Unit::TestCase
45
45
 
46
46
  def test_in_dir
47
47
  TmpFile.in_dir do |dir|
48
- assert_equal dir, FileUtils.pwd
48
+ assert_equal_path dir, FileUtils.pwd
49
49
  end
50
50
  end
51
51
 
@@ -20,7 +20,7 @@ row4 a a id3
20
20
  EOF
21
21
 
22
22
  tsv = TmpFile.with_file(content) do |filename|
23
- TSV.open(filename)
23
+ TSV.open(filename, :persist => false)
24
24
  end
25
25
 
26
26
  TmpFile.with_file(content2) do |filename|
@@ -30,5 +30,54 @@ row4 a a id3
30
30
  assert_include tsv.keys, 'row4'
31
31
  assert_include tsv.keys, 'row1'
32
32
  end
33
+
34
+ def test_open_persist
35
+ content =<<-'EOF'
36
+ #: :sep=/\s+/#:type=:double#:merge=:concat
37
+ #Id ValueA ValueB OtherID
38
+ row1 a|aa|aaa b Id1|Id2
39
+ row2 A B Id3
40
+ row2 a a id3
41
+ EOF
42
+
43
+ tsv = TmpFile.with_file(content) do |filename|
44
+ TSV.open(filename, :persist => true)
45
+ end
46
+
47
+ assert tsv.respond_to?(:persistence_class)
48
+ assert_equal TokyoCabinet::HDB, tsv.persistence_class
49
+
50
+ assert_include tsv.keys, 'row1'
51
+ assert_include tsv.keys, 'row2'
52
+ end
53
+
54
+ def test_open_persist_in_situ
55
+ content =<<-'EOF'
56
+ #: :sep=/\s+/#:type=:double#:merge=:concat
57
+ #Id ValueA ValueB OtherID
58
+ row1 a|aa|aaa b Id1|Id2
59
+ row2 A B Id3
60
+ row2 a a id3
61
+ EOF
62
+
63
+ tsv = TmpFile.with_file(content) do |filename|
64
+ TSV.open(filename, :persist => false)
65
+ end
66
+
67
+ assert_include tsv.keys, 'row1'
68
+ assert_include tsv.keys, 'row2'
69
+ assert_equal %w(A a), tsv["row2"][0]
70
+
71
+ tsv = TmpFile.with_file(content) do |filename|
72
+ TSV.open(filename, :persist => true, :merge => true)
73
+ end
74
+
75
+ assert tsv.respond_to?(:persistence_class)
76
+ assert_equal TokyoCabinet::HDB, tsv.persistence_class
77
+
78
+ assert_include tsv.keys, 'row1'
79
+ assert_include tsv.keys, 'row2'
80
+ assert_equal %w(A a), tsv["row2"][0]
81
+ end
33
82
  end
34
83
 
@@ -3,7 +3,7 @@ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1
3
3
 
4
4
  require 'scout/log'
5
5
  class TestWorkQueue < Test::Unit::TestCase
6
- def test_queue_remove_workers
6
+ def test_a_queue_remove_workers
7
7
  num = 10
8
8
  reps = 10_000
9
9
  q = WorkQueue.new num do |obj|
@@ -19,7 +19,9 @@ class TestWorkQueue < Test::Unit::TestCase
19
19
  q.write i
20
20
  end
21
21
 
22
- num.times do q.remove_one_worker end
22
+ (num - 1).times do q.remove_one_worker end
23
+
24
+ Thread.pass until q.workers.length == 1
23
25
 
24
26
  w = q.add_worker do |obj|
25
27
  "HEY"
@@ -38,7 +40,7 @@ class TestWorkQueue < Test::Unit::TestCase
38
40
 
39
41
  def test_queue
40
42
  num = 10
41
- reps = 10_000
43
+ reps = 1_000
42
44
  q = WorkQueue.new num do |obj|
43
45
  [Process.pid.to_s, obj.to_s] * " "
44
46
  end
@@ -55,8 +57,8 @@ class TestWorkQueue < Test::Unit::TestCase
55
57
  end
56
58
 
57
59
  Process.wait pid
58
-
59
60
  q.close
61
+
60
62
  q.join
61
63
 
62
64
  assert_equal reps, res.length
@@ -67,6 +69,7 @@ class TestWorkQueue < Test::Unit::TestCase
67
69
  reps = 10_000
68
70
  q = WorkQueue.new num do |obj|
69
71
  [Process.pid.to_s, obj.to_s] * " "
72
+ :ignore
70
73
  end
71
74
 
72
75
  q.ignore_ouput
@@ -76,14 +79,10 @@ class TestWorkQueue < Test::Unit::TestCase
76
79
  res << out
77
80
  end
78
81
 
79
- pid = Process.fork do
80
- reps.times do |i|
81
- q.write i
82
- end
82
+ reps.times do |i|
83
+ q.write i
83
84
  end
84
85
 
85
- Process.wait pid
86
-
87
86
  q.close
88
87
  q.join
89
88
 
@@ -91,11 +90,12 @@ class TestWorkQueue < Test::Unit::TestCase
91
90
  end
92
91
 
93
92
  def test_queue_error
94
- num = 10
93
+ num = 100
95
94
  reps = 10_000
96
95
 
96
+ sss 0
97
97
  q = WorkQueue.new num do |obj|
98
- raise ScoutException if rand < 1
98
+ raise ScoutException if rand < 0.1
99
99
  [Process.pid.to_s, obj.to_s] * " "
100
100
  end
101
101
 
@@ -110,11 +110,39 @@ class TestWorkQueue < Test::Unit::TestCase
110
110
  end
111
111
  end
112
112
 
113
- Process.wait pid
113
+ Process.waitpid pid
114
+ q.close
114
115
 
115
116
  assert_raise ScoutException do
117
+ q.join
118
+ t.join
119
+ end
120
+ end
121
+
122
+ def test_queue_error_in_input
123
+ num = 100
124
+ reps = 10_000
125
+
126
+ q = WorkQueue.new num do |obj|
127
+ [Process.pid.to_s, obj.to_s] * " "
128
+ end
129
+
130
+ res = []
131
+ q.process do |out|
132
+ raise ScoutException if rand < 0.01
133
+ res << out
134
+ end
135
+
136
+ pid = Process.fork do
137
+ reps.times do |i|
138
+ q.write i
139
+ end
116
140
  q.close
141
+ end
142
+
143
+ assert_raise ScoutException do
117
144
  q.join
145
+ t.join
118
146
  end
119
147
  end
120
148
  end