ntalbott-drbfire 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,138 @@
1
+ # Author:: Nathaniel Talbott.
2
+ # Copyright:: Copyright (c) 2004 Nathaniel Talbott. All rights reserved.
3
+ # License:: Ruby license.
4
+
5
+ require 'test/unit'
6
+ require 'socket'
7
+ require 'timeout'
8
+ require 'pp'
9
+ require 'ostruct'
10
+ require 'drb/drb'
11
+ require 'drb/ssl'
12
+
13
+ require 'drb/drbfire'
14
+
15
+ Thread.abort_on_exception = true
16
+
17
+ module DRbFire
18
+ class TC_Protocol < Test::Unit::TestCase
19
+ TEST_IP = "127.0.0.1"
20
+ TEST_PORT = 44324
21
+ TEST_URI = ["drbfire://", [TEST_IP, TEST_PORT].join(":")].join('')
22
+ TEST_SERVER_CONFIG = {ROLE => SERVER}
23
+ TEST_CLIENT_CONFIG = {ROLE => CLIENT}
24
+
25
+ def test_parse_uri
26
+ assert_raise(DRb::DRbBadScheme) do
27
+ Protocol.parse_uri("druby://localhost:0")
28
+ end
29
+ assert_raise(DRb::DRbBadURI) do
30
+ Protocol.parse_uri("drbfire://localhost")
31
+ end
32
+ assert_equal(['localhost', 0, 'option&stuff'], Protocol.parse_uri("drbfire://localhost:0?option&stuff"))
33
+ end
34
+
35
+ def test_uri_option
36
+ assert_equal(['drbfire://localhost:0', 'option&stuff'], Protocol.uri_option("drbfire://localhost:0?option&stuff", {}))
37
+ end
38
+
39
+ class Front
40
+ include DRbUndumped
41
+
42
+ class Param
43
+ include DRbUndumped
44
+
45
+ attr_reader :called
46
+
47
+ def initialize
48
+ @called = false
49
+ end
50
+
51
+ def n
52
+ @called = true
53
+ end
54
+ end
55
+
56
+ attr_reader :called, :param
57
+
58
+ def initialize
59
+ @called = 0
60
+ @param = Param.new
61
+ end
62
+
63
+ def param_called
64
+ @param.called
65
+ end
66
+
67
+ def m(args={})
68
+ @called += 1
69
+
70
+ args[:back].m(:param => @param) if(args[:back])
71
+ args[:param].n if(args[:param])
72
+ end
73
+ end
74
+
75
+ def check_communication
76
+ config = OpenStruct.new(
77
+ :start_server => true,
78
+ :stop_server => true,
79
+ :server => nil,
80
+ :front => Front.new,
81
+ :server_config => TEST_SERVER_CONFIG,
82
+ :client_config => TEST_CLIENT_CONFIG)
83
+ yield(config) if(block_given?)
84
+ begin
85
+ config.server = DRb.start_service(TEST_URI, config.front, config.server_config) if(config.start_server)
86
+ DRb.remove_server config.server # Hack to deal with running multiple servers in the same process - we always want the client server to be picked up.
87
+ client = nil
88
+ assert_nothing_raised do
89
+ timeout(1) do
90
+ client = DRb.start_service(TEST_URI, nil, config.client_config)
91
+ end
92
+ end
93
+ client_front = DRbObject.new(nil, TEST_URI)
94
+ back = Front.new
95
+ assert_nothing_raised do
96
+ timeout(1) do
97
+ client_front.m(:back => back)
98
+ end
99
+ end
100
+ assert(0 < config.front.called, "Server not called")
101
+ assert(config.front.param_called, "Server not called back")
102
+ assert_equal(1, back.called, "Client not called")
103
+ ensure
104
+ client.stop_service if(client)
105
+ config.server.stop_service if(config.server && config.stop_server)
106
+ end
107
+ assert_nothing_raised do
108
+ TCPServer.new(TEST_IP, TEST_PORT).close
109
+ end if(config.stop_server)
110
+ return config.server, config.front
111
+ end
112
+
113
+ def test_normal_communication
114
+ check_communication
115
+ end
116
+
117
+ def test_connect_twice
118
+ server, front = check_communication do |config|
119
+ config.start_server = true
120
+ config.stop_server = false
121
+ end
122
+ check_communication do |config|
123
+ config.start_server = false
124
+ config.stop_server = true
125
+ config.server = server
126
+ config.front = front
127
+ end
128
+ end
129
+
130
+ def test_ssl_communication
131
+ check_communication do |config|
132
+ config.server_config = TEST_SERVER_CONFIG.dup.update(DELEGATE => DRb::DRbSSLSocket,
133
+ :SSLCertName => [ ["C","US"], ["O","localhost"], ["CN", "Temporary"] ])
134
+ config.client_config = TEST_CLIENT_CONFIG.dup.update(DELEGATE => DRb::DRbSSLSocket)
135
+ end
136
+ end
137
+ end
138
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ntalbott-drbfire
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Nathaniel Talbott
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-07 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: DRbFire allows easy bidirectional DRb communication in the presence of a firewall.
17
+ email: drbfire@talbott.ws
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - ChangeLog
25
+ files:
26
+ - ChangeLog
27
+ - drbfire.gemspec
28
+ - INSTALL
29
+ - lib/drb/drbfire.rb
30
+ - README
31
+ - sample/client.rb
32
+ - sample/server.rb
33
+ - setup.rb
34
+ - test/test_drbfire.rb
35
+ has_rdoc: true
36
+ homepage: http://rubyforge.org/projects/drbfire
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --title
40
+ - DRbFire
41
+ - --main
42
+ - README
43
+ - --line-numbers
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project: drbfire
61
+ rubygems_version: 1.2.0
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: DRbFire allows easy bidirectional DRb communication in the presence of a firewall.
65
+ test_files: []
66
+