eventmachine 0.8.0 → 0.8.1

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.
@@ -0,0 +1,236 @@
1
+ # $Id: test_send_file.rb 481 2007-07-28 18:41:17Z blackhedd $
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 8 April 2006
6
+ #
7
+ # See EventMachine and EventMachine::Connection for documentation and
8
+ # usage examples.
9
+ #
10
+ #----------------------------------------------------------------------------
11
+ #
12
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU General Public License
17
+ # as published by the Free Software Foundation; either version 2 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #---------------------------------------------------------------------------
23
+ #
24
+ #
25
+ #
26
+
27
+ $:.unshift "../lib"
28
+ require 'eventmachine'
29
+
30
+ class TestSendFile < Test::Unit::TestCase
31
+
32
+ module TestModule
33
+ def post_init
34
+ send_file_data TestFilename
35
+ close_connection_after_writing
36
+ end
37
+ end
38
+
39
+ TestHost = "0.0.0.0"
40
+ TestPort = 9055
41
+ TestFilename = "./xxxxxx"
42
+
43
+ def setup
44
+ end
45
+
46
+ def teardown
47
+ File.unlink( TestFilename ) if File.exist?( TestFilename )
48
+ end
49
+
50
+ def test_send_file
51
+ File.open( TestFilename, "w" ) {|f|
52
+ f << ("A" * 5000)
53
+ }
54
+
55
+ data = nil
56
+
57
+ EM.run {
58
+ EM.start_server TestHost, TestPort, TestModule
59
+ EM.add_timer(2) {EM.stop} # avoid hanging in case of error
60
+ EM.defer proc {
61
+ t = TCPSocket.new TestHost, TestPort
62
+ data = t.read
63
+ }, proc {
64
+ EM.stop
65
+ }
66
+ }
67
+
68
+ assert_equal( "A" * 5000, data )
69
+ File.unlink TestFilename
70
+ end
71
+
72
+ # EventMachine::Connection#send_file_data has a strict upper limit on the filesize it will work with.
73
+ def test_send_large_file
74
+ File.open( TestFilename, "w" ) {|f|
75
+ f << ("A" * 1000000)
76
+ }
77
+
78
+ data = nil
79
+
80
+ assert_raise(RuntimeError) {
81
+ EM.run {
82
+ EM.start_server TestHost, TestPort, TestModule
83
+ EM.add_timer(2) {EM.stop} # avoid hanging in case of error
84
+ EM.defer proc {
85
+ t = TCPSocket.new TestHost, TestPort
86
+ data = t.read
87
+ }, proc {
88
+ EM.stop
89
+ }
90
+ }
91
+ }
92
+
93
+ File.unlink TestFilename
94
+ end
95
+
96
+
97
+ module StreamTestModule
98
+ def post_init
99
+ EM::Deferrable.future( stream_file_data(TestFilename)) {
100
+ close_connection_after_writing
101
+ }
102
+ end
103
+ end
104
+
105
+ module ChunkStreamTestModule
106
+ def post_init
107
+ EM::Deferrable.future( stream_file_data(TestFilename, :http_chunks=>true)) {
108
+ close_connection_after_writing
109
+ }
110
+ end
111
+ end
112
+
113
+ def test_stream_file_data
114
+ File.open( TestFilename, "w" ) {|f|
115
+ f << ("A" * 1000)
116
+ }
117
+
118
+ data = nil
119
+
120
+ EM.run {
121
+ EM.start_server TestHost, TestPort, StreamTestModule
122
+ EM.add_timer(2) {EM.stop} # avoid hanging in case of error
123
+ EM.defer proc {
124
+ t = TCPSocket.new TestHost, TestPort
125
+ data = t.read
126
+ }, proc {
127
+ EM.stop
128
+ }
129
+ }
130
+
131
+ assert_equal( "A" * 1000, data )
132
+
133
+ File.unlink TestFilename
134
+ end
135
+
136
+ def test_stream_chunked_file_data
137
+ File.open( TestFilename, "w" ) {|f|
138
+ f << ("A" * 1000)
139
+ }
140
+
141
+ data = nil
142
+
143
+ EM.run {
144
+ EM.start_server TestHost, TestPort, ChunkStreamTestModule
145
+ EM.add_timer(2) {EM.stop} # avoid hanging in case of error
146
+ EM.defer proc {
147
+ t = TCPSocket.new TestHost, TestPort
148
+ data = t.read
149
+ }, proc {
150
+ EM.stop
151
+ }
152
+ }
153
+
154
+ assert_equal( "3e8\r\n#{"A" * 1000}\r\n0\r\n\r\n", data )
155
+
156
+ File.unlink TestFilename
157
+ end
158
+
159
+ module BadFileTestModule
160
+ def post_init
161
+ de = stream_file_data( TestFilename+"..." )
162
+ de.errback {|msg|
163
+ send_data msg
164
+ close_connection_after_writing
165
+ }
166
+ end
167
+ end
168
+ def test_stream_bad_file
169
+ data = nil
170
+ EM.run {
171
+ EM.start_server TestHost, TestPort, BadFileTestModule
172
+ EM.add_timer(2) {EM.stop} # avoid hanging in case of error
173
+ EM.defer proc {
174
+ t = TCPSocket.new TestHost, TestPort
175
+ data = t.read
176
+ }, proc {
177
+ EM.stop
178
+ }
179
+ }
180
+
181
+ assert_equal( "file not found", data )
182
+ end
183
+
184
+ def test_stream_large_file_data
185
+ File.open( TestFilename, "w" ) {|f|
186
+ f << ("A" * 10000)
187
+ }
188
+
189
+ data = nil
190
+
191
+ EM.run {
192
+ EM.start_server TestHost, TestPort, StreamTestModule
193
+ EM.add_timer(2) {EM.stop} # avoid hanging in case of error
194
+ EM.defer proc {
195
+ t = TCPSocket.new TestHost, TestPort
196
+ data = t.read
197
+ }, proc {
198
+ EM.stop
199
+ }
200
+ }
201
+
202
+ assert_equal( "A" * 10000, data )
203
+
204
+ File.unlink TestFilename
205
+ end
206
+
207
+ def test_stream_large_chunked_file_data
208
+ File.open( TestFilename, "w" ) {|f|
209
+ f << ("A" * 100000)
210
+ }
211
+
212
+ data = nil
213
+
214
+ EM.run {
215
+ EM.start_server TestHost, TestPort, ChunkStreamTestModule
216
+ EM.add_timer(2) {EM.stop} # avoid hanging in case of error
217
+ EM.defer proc {
218
+ t = TCPSocket.new TestHost, TestPort
219
+ data = t.read
220
+ }, proc {
221
+ EM.stop
222
+ }
223
+ }
224
+
225
+ expected = [
226
+ "4000\r\n#{"A" * 16384}\r\n" * 6,
227
+ "6a0\r\n#{"A" * 0x6a0}\r\n",
228
+ "0\r\n\r\n"
229
+ ].join
230
+ assert_equal( expected, data )
231
+
232
+ File.unlink TestFilename
233
+ end
234
+
235
+ end
236
+
@@ -0,0 +1,87 @@
1
+ # $Id: test_servers.rb 426 2007-07-17 16:54:08Z blackhedd $
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 8 April 2006
6
+ #
7
+ # See EventMachine and EventMachine::Connection for documentation and
8
+ # usage examples.
9
+ #
10
+ #----------------------------------------------------------------------------
11
+ #
12
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU General Public License
17
+ # as published by the Free Software Foundation; either version 2 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #---------------------------------------------------------------------------
23
+ #
24
+ #
25
+ #
26
+
27
+ $:.unshift "../lib"
28
+ require 'eventmachine'
29
+
30
+ class TestServers < Test::Unit::TestCase
31
+
32
+ Host = "127.0.0.1"
33
+ Port = 9550
34
+
35
+ def setup
36
+ end
37
+
38
+ def teardown
39
+ end
40
+
41
+
42
+ class TestStopServer < EM::Connection
43
+ def initialize *args
44
+ super
45
+ end
46
+ def post_init
47
+ # TODO,sucks that this isn't OOPy enough.
48
+ EM.stop_server @server_instance
49
+ end
50
+ end
51
+ def run_test_stop_server
52
+ succeed = false
53
+ err = false
54
+ EM.run {
55
+ sig = EM.start_server(Host, Port)
56
+ EM.defer proc {
57
+ if TCPSocket.new Host, Port
58
+ succeed = true
59
+ end
60
+ }, proc {
61
+ EM.stop_server sig
62
+ EM.defer proc {
63
+ # Wait for the acceptor to die, otherwise
64
+ # we'll probably get a conn-reset instead
65
+ # of a conn-refused.
66
+ sleep 0.1
67
+ begin
68
+ TCPSocket.new Host, Port
69
+ rescue
70
+ err = $!
71
+ end
72
+ }, proc {
73
+ EM.stop
74
+ }
75
+ }
76
+ }
77
+ assert_equal( true, succeed )
78
+ assert_equal( Errno::ECONNREFUSED, err.class )
79
+ end
80
+ def test_stop_server
81
+ 5.times {run_test_stop_server}
82
+ end
83
+
84
+
85
+ end
86
+
87
+
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: eventmachine
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.8.0
7
- date: 2007-07-11 00:00:00 -04:00
6
+ version: 0.8.1
7
+ date: 2007-07-30 00:00:00 -04:00
8
8
  summary: Ruby/EventMachine library
9
9
  require_paths:
10
10
  - lib
@@ -41,6 +41,9 @@ files:
41
41
  - tests/test_timers.rb
42
42
  - tests/test_epoll.rb
43
43
  - tests/test_next_tick.rb
44
+ - tests/test_servers.rb
45
+ - tests/test_send_file.rb
46
+ - tests/test_ltp2.rb
44
47
  - lib/em
45
48
  - lib/protocols
46
49
  - lib/evma
@@ -48,15 +51,19 @@ files:
48
51
  - lib/pr_eventmachine.rb
49
52
  - lib/evma.rb
50
53
  - lib/eventmachine_version.rb
54
+ - lib/jeventmachine.rb
51
55
  - lib/em/eventable.rb
52
56
  - lib/em/deferrable.rb
53
57
  - lib/em/future.rb
54
58
  - lib/em/messages.rb
59
+ - lib/em/streamer.rb
55
60
  - lib/protocols/httpclient.rb
56
61
  - lib/protocols/tcptest.rb
57
62
  - lib/protocols/line_and_text.rb
58
63
  - lib/protocols/header_and_content.rb
59
64
  - lib/protocols/buftok.rb
65
+ - lib/protocols/stomp.rb
66
+ - lib/protocols/linetext2.rb
60
67
  - lib/evma/reactor.rb
61
68
  - lib/evma/protocol.rb
62
69
  - lib/evma/container.rb
@@ -83,9 +90,12 @@ files:
83
90
  - ext/cmain.cpp
84
91
  - ext/ed.cpp
85
92
  - ext/ed.h
93
+ - ext/autoscan.log
86
94
  - ext/pipe.cpp
87
95
  - ext/epoll.cpp
88
96
  - ext/epoll.h
97
+ - ext/cplusplus.cpp
98
+ - ext/eventmachine_cpp.h
89
99
  - README
90
100
  - RELEASE_NOTES
91
101
  - COPYING