content_server 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +15 -0
  2. data/bin/file_utils +118 -0
  3. data/lib/content_data/content_data.rb +114 -48
  4. data/lib/content_server/version.rb +1 -1
  5. data/lib/file_monitoring/file_monitoring.rb +94 -50
  6. data/lib/file_monitoring/monitor_path.rb +196 -113
  7. data/lib/file_utils/file_utils.rb +10 -49
  8. data/lib/networking/tcp.rb +4 -4
  9. data/spec/content_data/content_data_spec.rb +331 -0
  10. data/spec/content_data/validations_spec.rb +5 -0
  11. data/spec/content_server/content_server_spec.rb +5 -0
  12. data/spec/content_server/file_streamer_spec.rb +5 -0
  13. data/spec/file_copy/copy_spec.rb +5 -0
  14. data/spec/file_indexing/index_agent_spec.rb +5 -0
  15. data/spec/networking/tcp_spec.rb +5 -0
  16. data/spec/validations/index_validations_spec.rb +5 -0
  17. metadata +9 -89
  18. data/test/content_data/content_data_test.rb +0 -291
  19. data/test/file_generator/file_generator_spec.rb +0 -85
  20. data/test/file_monitoring/monitor_path_test.rb +0 -189
  21. data/test/file_monitoring/monitor_path_test/dir1000/test_file.1000 +0 -1000
  22. data/test/file_monitoring/monitor_path_test/dir1000/test_file.1000.0 +0 -1000
  23. data/test/file_monitoring/monitor_path_test/dir1000/test_file.1000.1 +0 -1000
  24. data/test/file_monitoring/monitor_path_test/dir1500/test_file.1500 +0 -1500
  25. data/test/file_monitoring/monitor_path_test/dir1500/test_file.1500.0 +0 -1500
  26. data/test/file_monitoring/monitor_path_test/dir1500/test_file.1500.1 +0 -1500
  27. data/test/file_monitoring/monitor_path_test/test_file.500 +0 -500
  28. data/test/file_monitoring/monitor_path_test/test_file.500.0 +0 -500
  29. data/test/file_monitoring/monitor_path_test/test_file.500.1 +0 -500
  30. data/test/file_utils/fileutil_mksymlink_test.rb +0 -134
  31. data/test/file_utils/fileutil_mksymlink_test/dir1000/dir1500/test_file.1500 +0 -1500
  32. data/test/file_utils/fileutil_mksymlink_test/dir1000/dir1500/test_file.1500.0 +0 -1500
  33. data/test/file_utils/fileutil_mksymlink_test/dir1000/dir1500/test_file.1500.1 +0 -1500
  34. data/test/file_utils/fileutil_mksymlink_test/dir1000/test_file.1000 +0 -1000
  35. data/test/file_utils/fileutil_mksymlink_test/dir1000/test_file.1000.0 +0 -1000
  36. data/test/file_utils/fileutil_mksymlink_test/dir1000/test_file.1000.1 +0 -1000
  37. data/test/file_utils/fileutil_mksymlink_test/test_file.500 +0 -500
  38. data/test/file_utils/fileutil_mksymlink_test/test_file.500.0 +0 -500
  39. data/test/file_utils/fileutil_mksymlink_test/test_file.500.1 +0 -500
  40. data/test/file_utils/time_modification_test.rb +0 -136
  41. data/test/params/params_spec.rb +0 -280
  42. data/test/params/params_test.rb +0 -43
  43. data/test/run_in_background/run_in_background_test.rb +0 -122
  44. data/test/run_in_background/test_app +0 -59
@@ -1,122 +0,0 @@
1
- require 'test/unit'
2
- require 'run_in_background'
3
-
4
- # TODO break to number of small tests according to functionality
5
- # TODO rewrite with Shoulda/RSpec
6
- class TestRunInBackground < ::Test::Unit::TestCase
7
- Params.init([])
8
-
9
- if RUBY_PLATFORM =~ /linux/ or RUBY_PLATFORM =~ /darwin/
10
- OS = :LINUX
11
- elsif RUBY_PLATFORM =~ /mingw/ or RUBY_PLATFORM =~ /ms/ or RUBY_PLATFORM =~ /win/
12
- require 'sys/uname'
13
- OS = :WINDOWS
14
- else
15
- raise "Unsupported platform #{RUBY_PLATFORM}"
16
- end
17
-
18
- def setup
19
- @good_daemon = "good_daemon_test"
20
- @good_daemonize = "good_daemonize_test"
21
- @good_win32daemon = "good_win32daemon_test"
22
- @bad_daemon = "bad_daemon_test"
23
- @binary = File.join(File.dirname(File.expand_path(__FILE__)), 'test_app')
24
- @binary.tr!('/','\\') if OS == :WINDOWS
25
- File.chmod(0755, @binary) if OS == :LINUX && !File.executable?(@binary)
26
- @absent_binary = File.join(File.dirname(File.expand_path(__FILE__)), "test_app_absent")
27
- end
28
-
29
- def test_functionality
30
- if OS == :WINDOWS && Sys::Uname.sysname =~ /(Windows 7)/
31
- skip "This test shouldn't be run on #{$1}"
32
- end
33
-
34
- # test start
35
- # test application should actually start here
36
- assert_nothing_raised{ RunInBackground.start(@binary, ["1000"], @good_daemon) }
37
- assert_raise(ArgumentError) { RunInBackground.start(@absent_binary, ["1000"], @bad_daemon) }
38
-
39
- # start arguments have to be defined
40
- assert_raise(ArgumentError) { RunInBackground.start(["1000"], @bad_daemon) }
41
- assert_raise(ArgumentError) { RunInBackground.start(nil, ["1000"], @bad_daemon) }
42
- assert_raise(ArgumentError) { RunInBackground.start(@absent_binary, nil, @bad_daemon) }
43
- assert_raise(ArgumentError) { RunInBackground.start(@absent_binary, ["1000"], nil) }
44
-
45
- # test exists?
46
- assert_raise(ArgumentError) { RunInBackground.exists? }
47
- assert_equal(false, RunInBackground.exists?(@bad_daemon))
48
- assert_equal(true, RunInBackground.exists?(@good_daemon))
49
-
50
- # test running?
51
- # if stop method will be public need to add test checks actually stopped daemon
52
- assert_raise(ArgumentError) { RunInBackground.running? }
53
- assert_raise(ArgumentError) { RunInBackground.running?(@bad_daemon) }
54
- assert_equal(true, RunInBackground.running?(@good_daemon))
55
-
56
- # test daemonazing (start!)
57
- # from the nature of daemonization need to run it from another process that will be daemonized
58
- ruby = (OS == :WINDOWS ? RunInBackground::RUBY_INTERPRETER_PATH : "ruby")
59
- cmd = "#{ruby} -Ilib #{@binary} 50 #{@good_daemonize}"
60
- pid = spawn(cmd)
61
- Process.waitpid pid
62
- # checking that it indeed was daemonized
63
- # e.i. process was killed and code rerun in background
64
- # it takes time to the OS to remove process, so using a timeout here
65
- 0.upto(RunInBackground::TIMEOUT) do
66
- begin
67
- Process.kill(0, pid)
68
- rescue Errno::ESRCH
69
- break
70
- end
71
- sleep 1
72
- end
73
- assert_raise(Errno::ESRCH) { Process.kill(0, pid) }
74
- assert_equal(true, RunInBackground.exists?(@good_daemonize))
75
- assert_equal(true, RunInBackground.running?(@good_daemonize))
76
-
77
- # test running win32 specific daemon (start_win32service)
78
- # wrapper script will be run
79
- if OS == :WINDOWS
80
- win32service_arg = [RunInBackground::RUBY_INTERPRETER_PATH, @binary, 1000]
81
- assert_nothing_raised{
82
- RunInBackground.start_win32service(RunInBackground::WRAPPER_SCRIPT,
83
- win32service_arg, @good_win32daemon)
84
- }
85
- assert_equal(true, RunInBackground.exists?(@good_win32daemon))
86
- assert_equal(true, RunInBackground.running?(@good_win32daemon))
87
- else
88
- assert_raise(NotImplementedError) {
89
- RunInBackground.start_win32service(@absent_binary, [], @bad_daemon)
90
- }
91
- end
92
-
93
- # uncomment following lines if there is a suspicion that something gone wrong
94
- # inspired by bug caused by coworking of daemon_wrapper an logger
95
- #sleep 10
96
- #assert_equal(true, RunInBackground.running?(@good_daemon))
97
- #assert_equal(true, RunInBackground.running?(@good_daemonize))
98
- #assert_equal(true, RunInBackground.running?(@good_win32daemon))
99
-
100
- # test delete
101
- # test application should actually stop here
102
- assert_raise(ArgumentError) { RunInBackground.delete }
103
- assert_raise(ArgumentError) { RunInBackground.delete(@bad_daemon) }
104
- assert_nothing_raised { RunInBackground.delete(@good_daemon) }
105
- assert_equal(false, RunInBackground.exists?(@good_daemon))
106
-
107
- assert_nothing_raised { RunInBackground.delete(@good_daemonize) }
108
- assert_equal(false, RunInBackground.exists?(@good_daemonize))
109
-
110
- # actuall only for Windows platform
111
- if RunInBackground.exists?(@good_win32daemon)
112
- assert_nothing_raised { RunInBackground.delete(@good_win32daemon) }
113
- assert_equal(false, RunInBackground.exists?(@good_win32daemon))
114
- end
115
- end
116
-
117
- def teardown
118
- RunInBackground.delete @good_daemon if RunInBackground.exists? @good_daemon
119
- RunInBackground.delete @good_daemonize if RunInBackground.exists? @good_daemonize
120
- RunInBackground.delete @good_win32daemon if RunInBackground.exists? @good_win32daemon
121
- end
122
- end
@@ -1,59 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Toy script used for RunInBackground tests.
4
- # usage: $0 number_of_iterations [daemon_name_if_daemonized]
5
-
6
- DBG = false # NOTE be sure to disable it in production
7
-
8
- begin
9
-
10
- # On WindowsXP log can be found under:
11
- # C:/Documents and Settings/NetworkService/.bbfs/test_app_<pid>.log
12
- #Params['log_file_name'] = File.join(Dir.home, '.bbfs', "#{File.basename(__FILE__)}_#{Process.pid}.log")
13
- if DBG
14
- begin
15
- require 'params'
16
- require 'log'
17
- rescue LoadError
18
- $:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'lib'))
19
- $:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), '..', '..'))
20
- require 'params'
21
- require 'log'
22
- end
23
- Params.init Array.new
24
- Params['log_debug_level'] = 1
25
- Params['log_write_to_console'] = false
26
- Params['log_write_to_file'] = true
27
- Log.init
28
- end
29
-
30
- # app should be run in background
31
- if ARGV.size == 2
32
- begin
33
- require 'run_in_background'
34
- rescue LoadError
35
- $:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'lib'))
36
- $:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), '..', '..'))
37
- require 'run_in_background'
38
- end
39
-
40
- Log.debug1 "Before run in background: PID #{Process.pid}" if DBG
41
- # ARGV.pop returns frozen string and thus causes a failure of Service.create
42
- # to fix it new string with the same content created.
43
- RunInBackground.start!(String.new(ARGV.pop))
44
- # if got here then error
45
- Log.error "After run in background: ERROR" if DBG
46
- end
47
-
48
- max = (ARGV.size > 0 && ARGV[0] != nil && ARGV[0].to_i > 0)? ARGV[0].to_i : 200
49
-
50
- while max > 0
51
- Log.debug1 "#{max}" if DBG
52
- sleep 1
53
- max -= 1
54
- end
55
-
56
- rescue Exception => err
57
- Log.error "Wrapper error: #{err}" if DBG
58
- raise
59
- end