backnob 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/test/backnob.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ workers: test/worker.rb
3
+ listen: 127.0.0.1:64000
@@ -0,0 +1,108 @@
1
+ require 'pathname'
2
+ require File.dirname(__FILE__) + '/test_helper.rb'
3
+ require File.dirname(__FILE__) + '/../lib/backnob/client'
4
+ require 'drb/drb'
5
+
6
+ module MockClass
7
+ def self.method; @method; end
8
+ def self.args; @args; end
9
+ def self.return=(n); @return = n; end
10
+
11
+ def self.method_missing(method, *args)
12
+ @method = method.to_s
13
+ @args = args
14
+ @return
15
+ end
16
+ end
17
+
18
+ class MockObject
19
+ include MockClass
20
+ include Test::Unit::Assertions
21
+ include DRb::DRbUndumped
22
+
23
+ attr_reader :method, :args
24
+ attr_accessor :return
25
+
26
+ def method_missing(method, *args)
27
+ @method = method.to_s
28
+ @args = args
29
+ @return
30
+ end
31
+ end
32
+
33
+ module Backnob
34
+ class Server < MockObject
35
+ end
36
+ end
37
+
38
+ class TestClient < Test::Unit::TestCase
39
+ include DRb::DRbUndumped
40
+
41
+ SERVER_URI = 'druby://127.0.0.1:'
42
+
43
+ def setup
44
+ @server = MockObject.new
45
+
46
+ @port = 6444
47
+ while true
48
+ begin
49
+ DRb.start_service(SERVER_URI + @port.to_s, @server)
50
+ break
51
+ rescue
52
+ @port += 1
53
+ end
54
+ end
55
+ @uri = SERVER_URI + @port.to_s
56
+ @client = Backnob::Client.new(@uri)
57
+ end
58
+
59
+ def teardown
60
+ DRb.stop_service
61
+ end
62
+
63
+ def test_available
64
+ @server.return = false
65
+ assert_equal false, @client.available?
66
+ assert @server.method == 'ping'
67
+ @server.return = true
68
+ assert_equal true, @client.available?
69
+
70
+ @client = Backnob::Client.new('druby://127.0.0.1:64000')
71
+ assert_equal false, @client.available?
72
+ end
73
+
74
+ def test_add_worker
75
+ @server.return = nil
76
+ file = File.dirname(__FILE__) + '/worker.rb'
77
+ @client.add_worker(file)
78
+ assert_equal 'add_file', @server.method
79
+ assert_equal [Pathname.new(file).realpath.to_s], @server.args
80
+ end
81
+
82
+ def test_create_worker
83
+ key = '12345678'
84
+ @server.return = key
85
+ returned = @client.create_worker 'test'
86
+
87
+ assert_equal key, returned
88
+ assert_equal 'create_worker', @server.method
89
+ assert_equal 'test', @server.args.first
90
+
91
+ returned = @client.create_worker 'test', {:test_option => 'string'}
92
+ assert_equal key, returned
93
+ assert_equal 'create_worker', @server.method
94
+ assert_equal ['test', {:test_option => 'string'}], @server.args
95
+ end
96
+
97
+ def test_results
98
+ results = {:running => true}
99
+ key = '12345678'
100
+
101
+ @server.return = results
102
+ returned = @client.results(key)
103
+
104
+ assert_equal results, returned
105
+ assert_equal 'results', @server.method
106
+ assert_equal key, @server.args.first
107
+ end
108
+ end
@@ -0,0 +1,60 @@
1
+ # require 'test/unit'
2
+ #
3
+ # class MockStdout
4
+ # attr_reader :output
5
+ #
6
+ # def initialize
7
+ # clear
8
+ # end
9
+ #
10
+ # def clear
11
+ # @output = ''
12
+ # end
13
+ #
14
+ # def puts(*args)
15
+ # @output << args.join
16
+ # end
17
+ #
18
+ # def write(*args)
19
+ # @output << args.join
20
+ # end
21
+ #
22
+ # def redirect
23
+ # @old = $stdout
24
+ # clear
25
+ #
26
+ # begin
27
+ # $stdout = self
28
+ # yield
29
+ # ensure
30
+ # $stdout = @old
31
+ # end
32
+ #
33
+ # @output
34
+ # end
35
+ #
36
+ # def self.redirect
37
+ # MockStdout.new.redirect do
38
+ # yield
39
+ # end
40
+ # end
41
+ # end
42
+
43
+ # class TestController < Test::Unit::TestCase
44
+ # def setup
45
+ # @path = 'lib/backnob_control.rb'
46
+ # ARGV.clear
47
+ # end
48
+ #
49
+ # def test_help
50
+ # ARGV << '-h'
51
+ # assert MockStdout.redirect{ load @path } =~ /usage/i
52
+ # end
53
+ #
54
+ # def test_version
55
+ # ARGV << '-v'
56
+ # output = MockStdout.redirect{ load @path }
57
+ # assert output =~ /version \d+/
58
+ # assert output !~ /usage/i
59
+ # end
60
+ # end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/backnob'
@@ -0,0 +1,59 @@
1
+ require 'pathname'
2
+ require File.dirname(__FILE__) + '/test_helper.rb'
3
+ require File.dirname(__FILE__) + '/../lib/backnob/client'
4
+
5
+ $running = false
6
+ $control = File.dirname(__FILE__) + '/../lib/backnob_control.rb'
7
+
8
+ class TestServer < Test::Unit::TestCase
9
+ def setup
10
+ unless $running
11
+ $running = true
12
+ system("ruby #{$control} -c test/backnob.yml start")
13
+ sleep 2
14
+
15
+ $client = Backnob::Client.new('druby://127.0.0.1:64000')
16
+ $server = $client.server
17
+ end
18
+ end
19
+
20
+ def add_worker
21
+ $client.add_worker(File.dirname(__FILE__) + '/worker.rb')
22
+ end
23
+
24
+ def test_defaults
25
+ test_workers = $client.add_worker('')
26
+ assert test_workers.detect{|f| f =~ /test\/worker.rb/ }
27
+ end
28
+
29
+ def test_available
30
+ assert_equal true, $client.available?
31
+ end
32
+
33
+ def test_add_worker
34
+ file = Pathname.new(File.dirname(__FILE__) + '/worker.rb').realpath.to_s
35
+ workers = $client.add_worker(file)
36
+ assert workers.include?(file)
37
+ end
38
+
39
+ def test_create_worker
40
+ add_worker
41
+ key = $client.create_worker('test')
42
+ assert key != nil
43
+ end
44
+
45
+ def test_results
46
+ add_worker
47
+ key = $client.create_worker('test')
48
+
49
+ running = $client.results(key, :running)
50
+ assert_equal true, running
51
+
52
+ while $client.results(key, :running)
53
+ sleep 0.25
54
+ end
55
+
56
+ data = $client.results(key, :data)
57
+ assert_equal "bye now", data
58
+ end
59
+ end
@@ -0,0 +1,15 @@
1
+ require 'lib/backnob/worker'
2
+
3
+ class TestServer < Test::Unit::TestCase
4
+ def test_rails_method
5
+ eval('class NonRailsWorker < Backnob::Worker; end')
6
+ non_rails_worker = NonRailsWorker.new('key')
7
+ assert non_rails_worker
8
+ assert_equal false, non_rails_worker.rails
9
+
10
+ eval('class RailsWorker < Backnob::Worker; rails true; end')
11
+ rails_worker = RailsWorker.new('key')
12
+ assert rails_worker
13
+ assert_equal true, rails_worker.rails
14
+ end
15
+ end
data/test/worker.rb ADDED
@@ -0,0 +1,11 @@
1
+ class TestWorker < Backnob::Worker
2
+ def execute
3
+ results(:data, 'Hello there')
4
+ sleep 2
5
+ results(:data, 'booha')
6
+ sleep 2
7
+ results(:data, 'bye now')
8
+ end
9
+ end
10
+
11
+ Backnob::Server.register(TestWorker)
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: backnob
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-09-20 00:00:00 +12:00
8
+ summary: Background workers
9
+ require_paths:
10
+ - lib
11
+ email: jeremy@boost.co.nz
12
+ homepage: http://backnob.rubyforge.org
13
+ rubyforge_project: backnob
14
+ description: Background workers
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ - |
29
+ -----BEGIN CERTIFICATE-----
30
+ MIIDVDCCAjygAwIBAgIBADANBgkqhkiG9w0BAQUFADBQMQ8wDQYDVQQDDAZqZXJl
31
+ bXkxFTATBgoJkiaJk/IsZAEZFgVib29zdDESMBAGCgmSJomT8ixkARkWAmNvMRIw
32
+ EAYKCZImiZPyLGQBGRYCbnowHhcNMDcwOTE5MjM1NTMzWhcNMDgwOTE4MjM1NTMz
33
+ WjBQMQ8wDQYDVQQDDAZqZXJlbXkxFTATBgoJkiaJk/IsZAEZFgVib29zdDESMBAG
34
+ CgmSJomT8ixkARkWAmNvMRIwEAYKCZImiZPyLGQBGRYCbnowggEiMA0GCSqGSIb3
35
+ DQEBAQUAA4IBDwAwggEKAoIBAQC9iE/TR1B0kVe6hE+VvgppAEXJyZFmRmq7v3Hz
36
+ FcQhFBqiIvtduBnVMvgl/U2AHXju/T9LTxDFNuv98QFX3pk3/TKy7wUnIgY3cfPF
37
+ 2ujAA4bLJLbJ4I3BEoIfMlvutYrlQIIMZyQMUb+mi/lRnGulgdcwgzKdphYlGRDH
38
+ vBAZgwhKCE2WpPN3MmaO+8dmkqEwaBhYPW7X3UeEZx6QSWal9pApcuuHcqh55i7o
39
+ pjDrkvuXJxw3IgKgRHPh2ExlRJ6jbFzql/tRBBryncdc4L8KtguZEHgjLy9j6HB/
40
+ XoM7n7NUaFye0OvOL7YAlfrLM3y7hTkJ4hVMa1BYaRx92X5vAgMBAAGjOTA3MAkG
41
+ A1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBRlMOKrIxERnYcTZTu/WY1o
42
+ EQGV3DANBgkqhkiG9w0BAQUFAAOCAQEAZgbhZViPjKgk1GuLVH5EshvvyODLFzye
43
+ tCdlYDkGc3FkQHQqOrvmUHL6GNBSAKNf7j045sTaV0m7BNu29DE6e/3Xxu236f6U
44
+ tj3z28i9lkShnSTruYRyJK1ZpTpyrWxhZVgmD1pxE3t451QfAPZvPu2uMK/vDNaf
45
+ seyfJwaP9mTdavkD/raHXHwrP6opy0L03KTNdG6kBuQgo6GZvPa5J+DNYJzkMtP8
46
+ Ei2mFeyNJL5ubHFX2gqNm47R408ONNNI6P0VBwFHnqarsIGv3M7IOparZKM5xjHk
47
+ wvrcwzFpoPtz0WqUckGUehomGsOVX04Qb2cPfXaqaJHGTa+64j9Jlg==
48
+ -----END CERTIFICATE-----
49
+
50
+ post_install_message:
51
+ authors:
52
+ - Jeremy Wells
53
+ files:
54
+ - History.txt
55
+ - License.txt
56
+ - Manifest.txt
57
+ - README.txt
58
+ - Rakefile
59
+ - bin/backnob
60
+ - examples/backnob.yml
61
+ - lib/backnob.rb
62
+ - lib/backnob/client.rb
63
+ - lib/backnob/hash.rb
64
+ - lib/backnob/options.rb
65
+ - lib/backnob/server.rb
66
+ - lib/backnob/version.rb
67
+ - lib/backnob/worker.rb
68
+ - lib/backnob_control.rb
69
+ - scripts/txt2html
70
+ - setup.rb
71
+ - test/backnob.yml
72
+ - test/test_client.rb
73
+ - test/test_controller.rb
74
+ - test/test_helper.rb
75
+ - test/test_server.rb
76
+ - test/worker.rb
77
+ test_files:
78
+ - test/test_client.rb
79
+ - test/test_controller.rb
80
+ - test/test_helper.rb
81
+ - test/test_server.rb
82
+ - test/test_worker.rb
83
+ rdoc_options:
84
+ - --main
85
+ - README.txt
86
+ extra_rdoc_files:
87
+ - History.txt
88
+ - License.txt
89
+ - Manifest.txt
90
+ - README.txt
91
+ executables:
92
+ - backnob
93
+ extensions: []
94
+
95
+ requirements: []
96
+
97
+ dependencies: []
98
+
metadata.gz.sig ADDED
@@ -0,0 +1 @@
1
+ ��0@�� <J�c7#ݪ��H��*���[$�g`%�*�C��4�k��\�Y�Pdj�Ẏ�6 DW����xKò��I|����q:�U����"�/�3�ܾ�S/�y���C���؇��'���e�'���Ԑ���ۙҁ�j�JYKV~hN����miY���}�ڗZ����r�q�36��a+'�>l���(i{i�xb�yN�OFap���Gڠ��iv`�:g��3���iԃ!R0���������d�3�x�W�