sidekick-client 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/VERSION +1 -1
  2. data/lib/sidekick/client/sidekick_client.rb +0 -3
  3. data/lib/sidekick/shared/sidekick_queue_publisher.rb +1 -1
  4. data/sidekick-client.gemspec +1 -158
  5. metadata +1 -158
  6. data/lib/ext/eventmachine-0.12.10/.gitignore +0 -14
  7. data/lib/ext/eventmachine-0.12.10/README +0 -82
  8. data/lib/ext/eventmachine-0.12.10/Rakefile +0 -374
  9. data/lib/ext/eventmachine-0.12.10/docs/COPYING +0 -60
  10. data/lib/ext/eventmachine-0.12.10/docs/ChangeLog +0 -211
  11. data/lib/ext/eventmachine-0.12.10/docs/DEFERRABLES +0 -133
  12. data/lib/ext/eventmachine-0.12.10/docs/EPOLL +0 -141
  13. data/lib/ext/eventmachine-0.12.10/docs/GNU +0 -281
  14. data/lib/ext/eventmachine-0.12.10/docs/INSTALL +0 -13
  15. data/lib/ext/eventmachine-0.12.10/docs/KEYBOARD +0 -38
  16. data/lib/ext/eventmachine-0.12.10/docs/LEGAL +0 -25
  17. data/lib/ext/eventmachine-0.12.10/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
  18. data/lib/ext/eventmachine-0.12.10/docs/PURE_RUBY +0 -75
  19. data/lib/ext/eventmachine-0.12.10/docs/RELEASE_NOTES +0 -94
  20. data/lib/ext/eventmachine-0.12.10/docs/SMTP +0 -2
  21. data/lib/ext/eventmachine-0.12.10/docs/SPAWNED_PROCESSES +0 -89
  22. data/lib/ext/eventmachine-0.12.10/docs/TODO +0 -8
  23. data/lib/ext/eventmachine-0.12.10/eventmachine.gemspec +0 -40
  24. data/lib/ext/eventmachine-0.12.10/examples/ex_channel.rb +0 -43
  25. data/lib/ext/eventmachine-0.12.10/examples/ex_queue.rb +0 -2
  26. data/lib/ext/eventmachine-0.12.10/examples/helper.rb +0 -2
  27. data/lib/ext/eventmachine-0.12.10/ext/binder.cpp +0 -125
  28. data/lib/ext/eventmachine-0.12.10/ext/binder.h +0 -46
  29. data/lib/ext/eventmachine-0.12.10/ext/cmain.cpp +0 -827
  30. data/lib/ext/eventmachine-0.12.10/ext/cplusplus.cpp +0 -202
  31. data/lib/ext/eventmachine-0.12.10/ext/ed.cpp +0 -1893
  32. data/lib/ext/eventmachine-0.12.10/ext/ed.h +0 -424
  33. data/lib/ext/eventmachine-0.12.10/ext/em.cpp +0 -2282
  34. data/lib/ext/eventmachine-0.12.10/ext/em.h +0 -232
  35. data/lib/ext/eventmachine-0.12.10/ext/emwin.cpp +0 -300
  36. data/lib/ext/eventmachine-0.12.10/ext/emwin.h +0 -94
  37. data/lib/ext/eventmachine-0.12.10/ext/epoll.cpp +0 -26
  38. data/lib/ext/eventmachine-0.12.10/ext/epoll.h +0 -25
  39. data/lib/ext/eventmachine-0.12.10/ext/eventmachine.h +0 -122
  40. data/lib/ext/eventmachine-0.12.10/ext/eventmachine_cpp.h +0 -96
  41. data/lib/ext/eventmachine-0.12.10/ext/extconf.rb +0 -148
  42. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/extconf.rb +0 -83
  43. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.cpp +0 -214
  44. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.h +0 -59
  45. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/rubymain.cpp +0 -127
  46. data/lib/ext/eventmachine-0.12.10/ext/files.cpp +0 -94
  47. data/lib/ext/eventmachine-0.12.10/ext/files.h +0 -65
  48. data/lib/ext/eventmachine-0.12.10/ext/kb.cpp +0 -81
  49. data/lib/ext/eventmachine-0.12.10/ext/page.cpp +0 -107
  50. data/lib/ext/eventmachine-0.12.10/ext/page.h +0 -51
  51. data/lib/ext/eventmachine-0.12.10/ext/pipe.cpp +0 -349
  52. data/lib/ext/eventmachine-0.12.10/ext/project.h +0 -151
  53. data/lib/ext/eventmachine-0.12.10/ext/rubymain.cpp +0 -1166
  54. data/lib/ext/eventmachine-0.12.10/ext/sigs.cpp +0 -89
  55. data/lib/ext/eventmachine-0.12.10/ext/sigs.h +0 -32
  56. data/lib/ext/eventmachine-0.12.10/ext/ssl.cpp +0 -460
  57. data/lib/ext/eventmachine-0.12.10/ext/ssl.h +0 -94
  58. data/lib/ext/eventmachine-0.12.10/java/.classpath +0 -8
  59. data/lib/ext/eventmachine-0.12.10/java/.project +0 -17
  60. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactor.java +0 -570
  61. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactorException.java +0 -40
  62. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableChannel.java +0 -69
  63. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableDatagramChannel.java +0 -189
  64. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableSocketChannel.java +0 -364
  65. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Application.java +0 -194
  66. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Connection.java +0 -74
  67. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
  68. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
  69. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
  70. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Timer.java +0 -54
  71. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
  72. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
  73. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
  74. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
  75. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
  76. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
  77. data/lib/ext/eventmachine-0.12.10/lib/em/buftok.rb +0 -138
  78. data/lib/ext/eventmachine-0.12.10/lib/em/callback.rb +0 -26
  79. data/lib/ext/eventmachine-0.12.10/lib/em/channel.rb +0 -57
  80. data/lib/ext/eventmachine-0.12.10/lib/em/connection.rb +0 -564
  81. data/lib/ext/eventmachine-0.12.10/lib/em/deferrable.rb +0 -192
  82. data/lib/ext/eventmachine-0.12.10/lib/em/file_watch.rb +0 -54
  83. data/lib/ext/eventmachine-0.12.10/lib/em/future.rb +0 -61
  84. data/lib/ext/eventmachine-0.12.10/lib/em/messages.rb +0 -66
  85. data/lib/ext/eventmachine-0.12.10/lib/em/process_watch.rb +0 -44
  86. data/lib/ext/eventmachine-0.12.10/lib/em/processes.rb +0 -119
  87. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/header_and_content.rb +0 -138
  88. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient.rb +0 -263
  89. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient2.rb +0 -590
  90. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/line_and_text.rb +0 -125
  91. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/linetext2.rb +0 -161
  92. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/memcache.rb +0 -323
  93. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/object_protocol.rb +0 -45
  94. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/postgres3.rb +0 -247
  95. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/saslauth.rb +0 -175
  96. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpclient.rb +0 -357
  97. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpserver.rb +0 -547
  98. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/socks4.rb +0 -66
  99. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/stomp.rb +0 -200
  100. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/tcptest.rb +0 -53
  101. data/lib/ext/eventmachine-0.12.10/lib/em/protocols.rb +0 -36
  102. data/lib/ext/eventmachine-0.12.10/lib/em/queue.rb +0 -61
  103. data/lib/ext/eventmachine-0.12.10/lib/em/spawnable.rb +0 -85
  104. data/lib/ext/eventmachine-0.12.10/lib/em/streamer.rb +0 -130
  105. data/lib/ext/eventmachine-0.12.10/lib/em/timers.rb +0 -56
  106. data/lib/ext/eventmachine-0.12.10/lib/em/version.rb +0 -3
  107. data/lib/ext/eventmachine-0.12.10/lib/eventmachine.rb +0 -1592
  108. data/lib/ext/eventmachine-0.12.10/lib/evma/callback.rb +0 -32
  109. data/lib/ext/eventmachine-0.12.10/lib/evma/container.rb +0 -75
  110. data/lib/ext/eventmachine-0.12.10/lib/evma/factory.rb +0 -77
  111. data/lib/ext/eventmachine-0.12.10/lib/evma/protocol.rb +0 -87
  112. data/lib/ext/eventmachine-0.12.10/lib/evma/reactor.rb +0 -48
  113. data/lib/ext/eventmachine-0.12.10/lib/evma.rb +0 -32
  114. data/lib/ext/eventmachine-0.12.10/lib/jeventmachine.rb +0 -257
  115. data/lib/ext/eventmachine-0.12.10/lib/pr_eventmachine.rb +0 -1022
  116. data/lib/ext/eventmachine-0.12.10/setup.rb +0 -1585
  117. data/lib/ext/eventmachine-0.12.10/tasks/cpp.rake_example +0 -77
  118. data/lib/ext/eventmachine-0.12.10/tests/client.crt +0 -31
  119. data/lib/ext/eventmachine-0.12.10/tests/client.key +0 -51
  120. data/lib/ext/eventmachine-0.12.10/tests/test_attach.rb +0 -126
  121. data/lib/ext/eventmachine-0.12.10/tests/test_basic.rb +0 -284
  122. data/lib/ext/eventmachine-0.12.10/tests/test_channel.rb +0 -63
  123. data/lib/ext/eventmachine-0.12.10/tests/test_connection_count.rb +0 -35
  124. data/lib/ext/eventmachine-0.12.10/tests/test_defer.rb +0 -47
  125. data/lib/ext/eventmachine-0.12.10/tests/test_epoll.rb +0 -160
  126. data/lib/ext/eventmachine-0.12.10/tests/test_error_handler.rb +0 -35
  127. data/lib/ext/eventmachine-0.12.10/tests/test_errors.rb +0 -82
  128. data/lib/ext/eventmachine-0.12.10/tests/test_exc.rb +0 -55
  129. data/lib/ext/eventmachine-0.12.10/tests/test_file_watch.rb +0 -49
  130. data/lib/ext/eventmachine-0.12.10/tests/test_futures.rb +0 -198
  131. data/lib/ext/eventmachine-0.12.10/tests/test_get_sock_opt.rb +0 -30
  132. data/lib/ext/eventmachine-0.12.10/tests/test_handler_check.rb +0 -37
  133. data/lib/ext/eventmachine-0.12.10/tests/test_hc.rb +0 -218
  134. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb +0 -218
  135. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb +0 -153
  136. data/lib/ext/eventmachine-0.12.10/tests/test_inactivity_timeout.rb +0 -50
  137. data/lib/ext/eventmachine-0.12.10/tests/test_kb.rb +0 -60
  138. data/lib/ext/eventmachine-0.12.10/tests/test_ltp.rb +0 -182
  139. data/lib/ext/eventmachine-0.12.10/tests/test_ltp2.rb +0 -317
  140. data/lib/ext/eventmachine-0.12.10/tests/test_next_tick.rb +0 -133
  141. data/lib/ext/eventmachine-0.12.10/tests/test_object_protocol.rb +0 -37
  142. data/lib/ext/eventmachine-0.12.10/tests/test_pause.rb +0 -70
  143. data/lib/ext/eventmachine-0.12.10/tests/test_pending_connect_timeout.rb +0 -48
  144. data/lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb +0 -48
  145. data/lib/ext/eventmachine-0.12.10/tests/test_processes.rb +0 -128
  146. data/lib/ext/eventmachine-0.12.10/tests/test_proxy_connection.rb +0 -92
  147. data/lib/ext/eventmachine-0.12.10/tests/test_pure.rb +0 -125
  148. data/lib/ext/eventmachine-0.12.10/tests/test_queue.rb +0 -44
  149. data/lib/ext/eventmachine-0.12.10/tests/test_running.rb +0 -42
  150. data/lib/ext/eventmachine-0.12.10/tests/test_sasl.rb +0 -72
  151. data/lib/ext/eventmachine-0.12.10/tests/test_send_file.rb +0 -242
  152. data/lib/ext/eventmachine-0.12.10/tests/test_servers.rb +0 -76
  153. data/lib/ext/eventmachine-0.12.10/tests/test_smtpclient.rb +0 -83
  154. data/lib/ext/eventmachine-0.12.10/tests/test_smtpserver.rb +0 -85
  155. data/lib/ext/eventmachine-0.12.10/tests/test_spawn.rb +0 -322
  156. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_args.rb +0 -79
  157. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_methods.rb +0 -50
  158. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_verify.rb +0 -82
  159. data/lib/ext/eventmachine-0.12.10/tests/test_timers.rb +0 -162
  160. data/lib/ext/eventmachine-0.12.10/tests/test_ud.rb +0 -36
  161. data/lib/ext/eventmachine-0.12.10/tests/testem.rb +0 -31
  162. data/lib/ext/eventmachine-0.12.10/web/whatis +0 -7
@@ -1,182 +0,0 @@
1
- # $Id$
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
-
28
- require 'eventmachine'
29
- require 'test/unit'
30
-
31
- class TestLineAndTextProtocol < Test::Unit::TestCase
32
-
33
- TestHost = "127.0.0.1"
34
- TestPort = 8905
35
-
36
-
37
- #--------------------------------------------------------------------
38
-
39
- class SimpleLineTest < EventMachine::Protocols::LineAndTextProtocol
40
- def receive_line line
41
- @line_buffer << line
42
- end
43
- end
44
-
45
- module StopClient
46
- def set_receive_data(&blk)
47
- @rdb = blk
48
- end
49
-
50
- def receive_data data
51
- @rdb.call(data) if @rdb
52
- end
53
-
54
- def unbind
55
- EM.add_timer(0.1) { EM.stop }
56
- end
57
- end
58
-
59
-
60
- def test_simple_lines
61
- lines_received = []
62
- EventMachine.run {
63
- EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
64
- conn.instance_eval "@line_buffer = lines_received"
65
- end
66
- EventMachine.add_timer(4) {assert(false, "test timed out")}
67
-
68
- EventMachine.connect TestHost, TestPort, StopClient do |c|
69
- c.send_data "aaa\nbbb\r\nccc\n"
70
- c.close_connection_after_writing
71
- end
72
- }
73
- assert_equal( %w(aaa bbb ccc), lines_received )
74
- end
75
-
76
- #--------------------------------------------------------------------
77
-
78
- class SimpleLineTest < EventMachine::Protocols::LineAndTextProtocol
79
- def receive_error text
80
- @error_message << text
81
- end
82
- end
83
-
84
- def test_overlength_lines
85
- lines_received = []
86
- EventMachine.run {
87
- EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
88
- conn.instance_eval "@error_message = lines_received"
89
- end
90
- EventMachine.add_timer(4) {assert(false, "test timed out")}
91
-
92
- EventMachine.connect TestHost, TestPort, StopClient do |c|
93
- c.send_data "a" * (16*1024 + 1)
94
- c.send_data "\n"
95
- c.close_connection_after_writing
96
- end
97
-
98
- }
99
- assert_equal( ["overlength line"], lines_received )
100
- end
101
-
102
-
103
- #--------------------------------------------------------------------
104
-
105
- class LineAndTextTest < EventMachine::Protocols::LineAndTextProtocol
106
- def post_init
107
- end
108
- def receive_line line
109
- if line =~ /content-length:\s*(\d+)/i
110
- @content_length = $1.to_i
111
- elsif line.length == 0
112
- set_binary_mode @content_length
113
- end
114
- end
115
- def receive_binary_data text
116
- send_data "received #{text.length} bytes"
117
- close_connection_after_writing
118
- end
119
- end
120
-
121
- def test_lines_and_text
122
- output = ''
123
- lines_received = []
124
- text_received = []
125
- EventMachine.run {
126
- EventMachine.start_server( TestHost, TestPort, LineAndTextTest ) do |conn|
127
- conn.instance_eval "@lines = lines_received; @text = text_received"
128
- end
129
- EventMachine.add_timer(4) {assert(false, "test timed out")}
130
-
131
- EventMachine.connect TestHost, TestPort, StopClient do |c|
132
- c.set_receive_data { |data| output << data }
133
- c.send_data "Content-length: 400\n"
134
- c.send_data "\n"
135
- c.send_data "A" * 400
136
- EM.add_timer(0.1) { c.close_connection_after_writing }
137
- end
138
- }
139
- assert_equal( "received 400 bytes", output )
140
- end
141
-
142
- #--------------------------------------------------------------------
143
-
144
-
145
- class BinaryTextTest < EventMachine::Protocols::LineAndTextProtocol
146
- def post_init
147
- end
148
- def receive_line line
149
- if line =~ /content-length:\s*(\d+)/i
150
- set_binary_mode $1.to_i
151
- else
152
- raise "protocol error"
153
- end
154
- end
155
- def receive_binary_data text
156
- send_data "received #{text.length} bytes"
157
- close_connection_after_writing
158
- end
159
- end
160
-
161
- def test_binary_text
162
- output = ''
163
- lines_received = []
164
- text_received = []
165
- EventMachine.run {
166
- EventMachine.start_server( TestHost, TestPort, BinaryTextTest ) do |conn|
167
- conn.instance_eval "@lines = lines_received; @text = text_received"
168
- end
169
- EventMachine.add_timer(4) {assert(false, "test timed out")}
170
-
171
- EventMachine.connect TestHost, TestPort, StopClient do |c|
172
- c.set_receive_data { |data| output << data }
173
- c.send_data "Content-length: 10000\n"
174
- c.send_data "A" * 10000
175
- EM.add_timer(0.2) { c.close_connection_after_writing }
176
- end
177
- }
178
- assert_equal( "received 10000 bytes", output )
179
- end
180
-
181
- #--------------------------------------------------------------------
182
- end
@@ -1,317 +0,0 @@
1
- # $Id$
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
-
28
- $:.unshift "../lib"
29
- require 'eventmachine'
30
- require 'test/unit'
31
-
32
- # TODO!!! Need tests for overlength headers and text bodies.
33
-
34
- class TestLineText2 < Test::Unit::TestCase
35
-
36
- # Run each of these tests two ways: passing in the whole test-dataset in one chunk,
37
- # and passing it in one character at a time.
38
-
39
- class Basic
40
- include EM::Protocols::LineText2
41
- attr_reader :lines
42
- def receive_line line
43
- (@lines ||= []) << line
44
- end
45
- end
46
- def test_basic
47
- testdata = "Line 1\nLine 2\r\nLine 3\n"
48
-
49
- a = Basic.new
50
- a.receive_data testdata
51
- assert_equal( ["Line 1", "Line 2", "Line 3"], a.lines )
52
-
53
- a = Basic.new
54
- testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
55
- assert_equal( ["Line 1", "Line 2", "Line 3"], a.lines )
56
- end
57
-
58
- class ChangeDelimiter
59
- include EM::Protocols::LineText2
60
- attr_reader :lines
61
- def initialize *args
62
- super
63
- @delim = "A"
64
- set_delimiter @delim
65
- end
66
- def receive_line line
67
- (@lines ||= []) << line
68
- set_delimiter( @delim.succ! )
69
- end
70
- end
71
-
72
- def test_change_delimiter
73
- testdata = %Q(LineaALinebBLinecCLinedD)
74
-
75
- a = ChangeDelimiter.new
76
- a.receive_data testdata
77
- assert_equal( ["Linea", "Lineb", "Linec", "Lined"], a.lines )
78
-
79
- a = ChangeDelimiter.new
80
- testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
81
- assert_equal( ["Linea", "Lineb", "Linec", "Lined"], a.lines )
82
- end
83
-
84
-
85
- #--
86
- # Test two lines followed by an empty line, ten bytes of binary data, then
87
- # two more lines.
88
-
89
- class Binary
90
- include EM::Protocols::LineText2
91
- attr_reader :lines, :body
92
- def initialize *args
93
- super
94
- @lines = []
95
- @body = nil
96
- end
97
- def receive_line ln
98
- if ln == ""
99
- set_text_mode 10
100
- else
101
- @lines << ln
102
- end
103
- end
104
- def receive_binary_data data
105
- @body = data
106
- end
107
- end
108
-
109
- def test_binary
110
- testdata = %Q(Line 1
111
- Line 2
112
-
113
- 0000000000Line 3
114
- Line 4
115
- )
116
-
117
- a = Binary.new
118
- a.receive_data testdata
119
- assert_equal( ["Line 1", "Line 2", "Line 3", "Line 4"], a.lines)
120
- assert_equal( "0000000000", a.body )
121
-
122
- a = Binary.new
123
- testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
124
- assert_equal( ["Line 1", "Line 2", "Line 3", "Line 4"], a.lines)
125
- assert_equal( "0000000000", a.body )
126
- end
127
-
128
-
129
- # Test unsized binary data. The expectation is that each chunk of it
130
- # will be passed to us as it it received.
131
- class UnsizedBinary
132
- include EM::Protocols::LineText2
133
- attr_reader :n_calls, :body
134
- def initialize *args
135
- super
136
- set_text_mode
137
- end
138
- def receive_binary_data data
139
- @n_calls ||= 0
140
- @n_calls += 1
141
- (@body ||= "") << data
142
- end
143
- end
144
-
145
- def test_unsized_binary
146
- testdata = "X\0" * 1000
147
-
148
- a = UnsizedBinary.new
149
- a.receive_data testdata
150
- assert_equal( 1, a.n_calls )
151
- assert_equal( testdata, a.body )
152
-
153
- a = UnsizedBinary.new
154
- testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
155
- assert_equal( 2000, a.n_calls )
156
- assert_equal( testdata, a.body )
157
- end
158
-
159
-
160
- # Test binary data with a "throw back" into line-mode.
161
- class ThrowBack
162
- include EM::Protocols::LineText2
163
- attr_reader :headers
164
- def initialize *args
165
- super
166
- @headers = []
167
- @n_bytes = 0
168
- set_text_mode
169
- end
170
- def receive_binary_data data
171
- wanted = 25 - @n_bytes
172
- will_take = if data.length > wanted
173
- data.length - wanted
174
- else
175
- data.length
176
- end
177
- @n_bytes += will_take
178
-
179
- if @n_bytes == 25
180
- set_line_mode( data[will_take..-1] )
181
- end
182
- end
183
- def receive_line ln
184
- @headers << ln
185
- end
186
- end
187
- def test_throw_back
188
- testdata = "Line\n" * 10
189
-
190
- a = ThrowBack.new
191
- a.receive_data testdata
192
- assert_equal( ["Line"] * 5, a.headers )
193
-
194
- a = ThrowBack.new
195
- testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
196
- assert_equal( ["Line"] * 5, a.headers )
197
- end
198
-
199
- # Test multi-character line delimiters.
200
- # Also note that the test data has a "tail" with no delimiter, that will be
201
- # discarded, but cf. the BinaryTail test.
202
- # TODO!!! This test doesn't work in the byte-by-byte case.
203
- class Multichar
204
- include EM::Protocols::LineText2
205
- attr_reader :lines
206
- def initialize *args
207
- super
208
- @lines = []
209
- set_delimiter "012"
210
- end
211
- def receive_line ln
212
- @lines << ln
213
- end
214
- end
215
- def test_multichar
216
- testdata = "Line012Line012Line012Line"
217
-
218
- a = Multichar.new
219
- a.receive_data testdata
220
- assert_equal( ["Line"]*3, a.lines )
221
-
222
- a = Multichar.new
223
- testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
224
- # DOESN'T WORK in this case. Multi-character delimiters are broken.
225
- #assert_equal( ["Line"]*3, a.lines )
226
- end
227
-
228
- # Test a binary "tail," when a sized binary transfer doesn't complete because
229
- # of an unbind. We get a partial result.
230
- class BinaryTail
231
- include EM::Protocols::LineText2
232
- attr_reader :data
233
- def initialize *args
234
- super
235
- @data = ""
236
- set_text_mode 1000
237
- end
238
- def receive_binary_data data
239
- # we expect to get all the data in one chunk, even in the byte-by-byte case,
240
- # because sized transfers by definition give us exactly one call to
241
- # #receive_binary_data.
242
- @data = data
243
- end
244
- end
245
- def test_binary_tail
246
- testdata = "0" * 500
247
-
248
- a = BinaryTail.new
249
- a.receive_data testdata
250
- a.unbind
251
- assert_equal( "0" * 500, a.data )
252
-
253
- a = BinaryTail.new
254
- testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
255
- a.unbind
256
- assert_equal( "0" * 500, a.data )
257
- end
258
-
259
-
260
- # Test an end-of-binary call. Arrange to receive binary data but don't bother counting it
261
- # as it comes. Rely on getting receive_end_of_binary_data to signal the transition back to
262
- # line mode.
263
- # At the present time, this isn't strictly necessary with sized binary chunks because by
264
- # definition we accumulate them and make exactly one call to receive_binary_data, but
265
- # we may want to support a mode in the future that would break up large chunks into multiple
266
- # calls.
267
- class LazyBinary
268
- include EM::Protocols::LineText2
269
- attr_reader :data, :end
270
- def initialize *args
271
- super
272
- @data = ""
273
- set_text_mode 1000
274
- end
275
- def receive_binary_data data
276
- # we expect to get all the data in one chunk, even in the byte-by-byte case,
277
- # because sized transfers by definition give us exactly one call to
278
- # #receive_binary_data.
279
- @data = data
280
- end
281
- def receive_end_of_binary_data
282
- @end = true
283
- end
284
- end
285
- def test_receive_end_of_binary_data
286
- testdata = "_" * 1000
287
- a = LazyBinary.new
288
- testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
289
- assert_equal( "_" * 1000, a.data )
290
- assert( a.end )
291
- end
292
-
293
-
294
- # This tests a bug fix in which calling set_text_mode failed when called
295
- # inside receive_binary_data.
296
- #
297
- class BinaryPair
298
- include EM::Protocols::LineText2
299
- attr_reader :sizes
300
- def initialize *args
301
- super
302
- set_text_mode 1
303
- @sizes = []
304
- end
305
- def receive_binary_data dt
306
- @sizes << dt.length
307
- set_text_mode( (dt.length == 1) ? 2 : 1 )
308
- end
309
- end
310
- def test_binary_pairs
311
- test_data = "123" * 5
312
- a = BinaryPair.new
313
- a.receive_data test_data
314
- assert_equal( [1,2,1,2,1,2,1,2,1,2], a.sizes )
315
- end
316
-
317
- end
@@ -1,133 +0,0 @@
1
- # $Id$
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
-
28
- $:.unshift "../lib"
29
- require 'eventmachine'
30
- require 'test/unit'
31
-
32
- class TestNextTick < Test::Unit::TestCase
33
-
34
- def test_tick_arg
35
- pr = proc {EM.stop}
36
- EM.run {
37
- EM.next_tick pr
38
- }
39
- assert true
40
- end
41
-
42
- def test_tick_block
43
- EM.run {
44
- EM.next_tick {EM.stop}
45
- }
46
- assert true
47
- end
48
-
49
- # This illustrates the solution to a long-standing problem.
50
- # It's now possible to correctly nest calls to EM#run.
51
- # See the source code commentary for EM#run for more info.
52
- #
53
- def test_run_run
54
- EM.run {
55
- EM.run {
56
- EM.next_tick {EM.stop}
57
- }
58
- }
59
- end
60
-
61
- def test_pre_run_queue
62
- x = false
63
- EM.next_tick { EM.stop; x = true }
64
- EM.run { EM.add_timer(0.2) { EM.stop } }
65
- assert x
66
- end
67
-
68
- def test_cleanup_after_stop
69
- x = true
70
- EM.run{
71
- EM.next_tick{
72
- EM.stop
73
- EM.next_tick{ x=false }
74
- }
75
- }
76
- EM.run{
77
- EM.next_tick{ EM.stop }
78
- }
79
- assert x
80
- end
81
-
82
- # We now support an additional parameter for EM#run.
83
- # You can pass two procs to EM#run now. The first is executed as the normal
84
- # run block. The second (if given) is scheduled for execution after the
85
- # reactor loop completes.
86
- # The reason for supporting this is subtle. There has always been an expectation
87
- # that EM#run doesn't return until after the reactor loop ends. But now it's
88
- # possible to nest calls to EM#run, which means that a nested call WILL
89
- # RETURN. In order to write code that will run correctly either way, it's
90
- # recommended to put any code which must execute after the reactor completes
91
- # in the second parameter.
92
- #
93
- def test_run_run_2
94
- a = proc {EM.stop}
95
- b = proc {assert true}
96
- EM.run a, b
97
- end
98
-
99
-
100
- # This illustrates that EM#run returns when it's called nested.
101
- # This isn't a feature, rather it's something to be wary of when writing code
102
- # that must run correctly even if EM#run is called while a reactor is already
103
- # running.
104
- def test_run_run_3
105
- a = []
106
- EM.run {
107
- EM.run proc {EM.stop}, proc {a << 2}
108
- a << 1
109
- }
110
- assert_equal( [1,2], a )
111
- end
112
-
113
-
114
- def test_schedule_on_reactor_thread
115
- x = false
116
- EM.run do
117
- EM.schedule { x = true }
118
- EM.stop
119
- end
120
- assert x
121
- end
122
-
123
- def test_schedule_from_thread
124
- x = false
125
- EM.run do
126
- Thread.new { EM.schedule { x = true } }.join
127
- assert !x
128
- EM.next_tick { EM.stop }
129
- end
130
- assert x
131
- end
132
-
133
- end
@@ -1,37 +0,0 @@
1
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
4
-
5
- class TestObjectProtocol < Test::Unit::TestCase
6
- Host = "127.0.0.1"
7
- Port = 9550
8
-
9
- module Server
10
- include EM::P::ObjectProtocol
11
- def post_init
12
- send_object :hello=>'world'
13
- end
14
- def receive_object obj
15
- $server = obj
16
- EM.stop
17
- end
18
- end
19
-
20
- module Client
21
- include EM::P::ObjectProtocol
22
- def receive_object obj
23
- $client = obj
24
- send_object 'you_said'=>obj
25
- end
26
- end
27
-
28
- def test_send_receive
29
- EM.run{
30
- EM.start_server Host, Port, Server
31
- EM.connect Host, Port, Client
32
- }
33
-
34
- assert($client == {:hello=>'world'})
35
- assert($server == {'you_said'=>{:hello=>'world'}})
36
- end
37
- end