sensu-em 2.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +12 -0
  4. data/.yardopts +7 -0
  5. data/CHANGELOG.md +33 -0
  6. data/GNU +281 -0
  7. data/Gemfile +2 -0
  8. data/LICENSE +60 -0
  9. data/README.md +109 -0
  10. data/Rakefile +20 -0
  11. data/docs/DocumentationGuidesIndex.md +27 -0
  12. data/docs/GettingStarted.md +521 -0
  13. data/docs/old/ChangeLog +211 -0
  14. data/docs/old/DEFERRABLES +246 -0
  15. data/docs/old/EPOLL +141 -0
  16. data/docs/old/INSTALL +13 -0
  17. data/docs/old/KEYBOARD +42 -0
  18. data/docs/old/LEGAL +25 -0
  19. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  20. data/docs/old/PURE_RUBY +75 -0
  21. data/docs/old/RELEASE_NOTES +94 -0
  22. data/docs/old/SMTP +4 -0
  23. data/docs/old/SPAWNED_PROCESSES +148 -0
  24. data/docs/old/TODO +8 -0
  25. data/eventmachine.gemspec +38 -0
  26. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  27. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  28. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  29. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  30. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  31. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  32. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  33. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  34. data/examples/old/ex_channel.rb +43 -0
  35. data/examples/old/ex_queue.rb +2 -0
  36. data/examples/old/ex_tick_loop_array.rb +15 -0
  37. data/examples/old/ex_tick_loop_counter.rb +32 -0
  38. data/examples/old/helper.rb +2 -0
  39. data/ext/binder.cpp +124 -0
  40. data/ext/binder.h +46 -0
  41. data/ext/cmain.cpp +887 -0
  42. data/ext/ed.cpp +1988 -0
  43. data/ext/ed.h +422 -0
  44. data/ext/em.cpp +2352 -0
  45. data/ext/em.h +253 -0
  46. data/ext/eventmachine.h +128 -0
  47. data/ext/extconf.rb +179 -0
  48. data/ext/fastfilereader/extconf.rb +103 -0
  49. data/ext/fastfilereader/mapper.cpp +214 -0
  50. data/ext/fastfilereader/mapper.h +59 -0
  51. data/ext/fastfilereader/rubymain.cpp +127 -0
  52. data/ext/kb.cpp +79 -0
  53. data/ext/page.cpp +107 -0
  54. data/ext/page.h +51 -0
  55. data/ext/pipe.cpp +347 -0
  56. data/ext/project.h +161 -0
  57. data/ext/rubymain.cpp +1318 -0
  58. data/ext/ssl.cpp +468 -0
  59. data/ext/ssl.h +94 -0
  60. data/java/.classpath +6 -0
  61. data/java/.gitignore +1 -0
  62. data/java/.project +17 -0
  63. data/java/src/com/rubyeventmachine/DatagramPacket.java +13 -0
  64. data/java/src/com/rubyeventmachine/EmReactor.java +529 -0
  65. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  66. data/java/src/com/rubyeventmachine/EventCallback.java +7 -0
  67. data/java/src/com/rubyeventmachine/EventCode.java +26 -0
  68. data/java/src/com/rubyeventmachine/EventableChannel.java +130 -0
  69. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +180 -0
  70. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +405 -0
  71. data/java/src/com/rubyeventmachine/SslBox.java +310 -0
  72. data/lib/em/buftok.rb +110 -0
  73. data/lib/em/callback.rb +58 -0
  74. data/lib/em/channel.rb +64 -0
  75. data/lib/em/completion.rb +304 -0
  76. data/lib/em/connection.rb +712 -0
  77. data/lib/em/deferrable/pool.rb +2 -0
  78. data/lib/em/deferrable.rb +210 -0
  79. data/lib/em/file_watch.rb +73 -0
  80. data/lib/em/future.rb +61 -0
  81. data/lib/em/iterator.rb +231 -0
  82. data/lib/em/messages.rb +66 -0
  83. data/lib/em/pool.rb +151 -0
  84. data/lib/em/process_watch.rb +45 -0
  85. data/lib/em/processes.rb +123 -0
  86. data/lib/em/protocols/header_and_content.rb +138 -0
  87. data/lib/em/protocols/httpclient.rb +279 -0
  88. data/lib/em/protocols/httpclient2.rb +600 -0
  89. data/lib/em/protocols/line_and_text.rb +125 -0
  90. data/lib/em/protocols/line_protocol.rb +29 -0
  91. data/lib/em/protocols/linetext2.rb +161 -0
  92. data/lib/em/protocols/memcache.rb +331 -0
  93. data/lib/em/protocols/object_protocol.rb +46 -0
  94. data/lib/em/protocols/postgres3.rb +246 -0
  95. data/lib/em/protocols/saslauth.rb +175 -0
  96. data/lib/em/protocols/smtpclient.rb +365 -0
  97. data/lib/em/protocols/smtpserver.rb +643 -0
  98. data/lib/em/protocols/socks4.rb +66 -0
  99. data/lib/em/protocols/stomp.rb +205 -0
  100. data/lib/em/protocols/tcptest.rb +54 -0
  101. data/lib/em/protocols.rb +37 -0
  102. data/lib/em/pure_ruby.rb +1017 -0
  103. data/lib/em/queue.rb +71 -0
  104. data/lib/em/resolver.rb +209 -0
  105. data/lib/em/spawnable.rb +84 -0
  106. data/lib/em/streamer.rb +118 -0
  107. data/lib/em/threaded_resource.rb +90 -0
  108. data/lib/em/tick_loop.rb +85 -0
  109. data/lib/em/timers.rb +61 -0
  110. data/lib/em/version.rb +3 -0
  111. data/lib/eventmachine.rb +1553 -0
  112. data/lib/jeventmachine.rb +321 -0
  113. data/lib/rubyeventmachine.jar +0 -0
  114. data/rakelib/cpp.rake_example +77 -0
  115. data/rakelib/package.rake +98 -0
  116. data/rakelib/test.rake +8 -0
  117. data/tests/client.crt +31 -0
  118. data/tests/client.key +51 -0
  119. data/tests/em_test_helper.rb +64 -0
  120. data/tests/server.crt +36 -0
  121. data/tests/server.key +51 -0
  122. data/tests/test_attach.rb +150 -0
  123. data/tests/test_basic.rb +294 -0
  124. data/tests/test_channel.rb +62 -0
  125. data/tests/test_completion.rb +177 -0
  126. data/tests/test_connection_count.rb +53 -0
  127. data/tests/test_defer.rb +18 -0
  128. data/tests/test_deferrable.rb +35 -0
  129. data/tests/test_epoll.rb +145 -0
  130. data/tests/test_error_handler.rb +38 -0
  131. data/tests/test_exc.rb +28 -0
  132. data/tests/test_file_watch.rb +65 -0
  133. data/tests/test_futures.rb +170 -0
  134. data/tests/test_get_sock_opt.rb +37 -0
  135. data/tests/test_handler_check.rb +35 -0
  136. data/tests/test_hc.rb +155 -0
  137. data/tests/test_httpclient.rb +190 -0
  138. data/tests/test_httpclient2.rb +133 -0
  139. data/tests/test_idle_connection.rb +25 -0
  140. data/tests/test_inactivity_timeout.rb +54 -0
  141. data/tests/test_iterator.rb +97 -0
  142. data/tests/test_kb.rb +34 -0
  143. data/tests/test_line_protocol.rb +33 -0
  144. data/tests/test_ltp.rb +138 -0
  145. data/tests/test_ltp2.rb +288 -0
  146. data/tests/test_next_tick.rb +104 -0
  147. data/tests/test_object_protocol.rb +36 -0
  148. data/tests/test_pause.rb +102 -0
  149. data/tests/test_pending_connect_timeout.rb +52 -0
  150. data/tests/test_pool.rb +194 -0
  151. data/tests/test_process_watch.rb +48 -0
  152. data/tests/test_processes.rb +128 -0
  153. data/tests/test_proxy_connection.rb +180 -0
  154. data/tests/test_pure.rb +88 -0
  155. data/tests/test_queue.rb +50 -0
  156. data/tests/test_resolver.rb +55 -0
  157. data/tests/test_running.rb +14 -0
  158. data/tests/test_sasl.rb +47 -0
  159. data/tests/test_send_file.rb +217 -0
  160. data/tests/test_servers.rb +33 -0
  161. data/tests/test_set_sock_opt.rb +37 -0
  162. data/tests/test_shutdown_hooks.rb +23 -0
  163. data/tests/test_smtpclient.rb +55 -0
  164. data/tests/test_smtpserver.rb +57 -0
  165. data/tests/test_spawn.rb +293 -0
  166. data/tests/test_ssl_args.rb +78 -0
  167. data/tests/test_ssl_echo_data.rb +60 -0
  168. data/tests/test_ssl_methods.rb +56 -0
  169. data/tests/test_ssl_verify.rb +82 -0
  170. data/tests/test_stomp.rb +37 -0
  171. data/tests/test_system.rb +42 -0
  172. data/tests/test_threaded_resource.rb +53 -0
  173. data/tests/test_tick_loop.rb +59 -0
  174. data/tests/test_timers.rb +123 -0
  175. data/tests/test_ud.rb +8 -0
  176. data/tests/test_unbind_reason.rb +48 -0
  177. metadata +297 -0
@@ -0,0 +1,82 @@
1
+ require 'em_test_helper'
2
+
3
+ if EM.ssl?
4
+ class TestSslVerify < Test::Unit::TestCase
5
+ def setup
6
+ $dir = File.dirname(File.expand_path(__FILE__)) + '/'
7
+ $cert_from_file = File.read($dir+'client.crt')
8
+ end
9
+
10
+ module Client
11
+ def connection_completed
12
+ start_tls(:private_key_file => $dir+'client.key', :cert_chain_file => $dir+'client.crt')
13
+ end
14
+
15
+ def ssl_handshake_completed
16
+ $client_handshake_completed = true
17
+ close_connection
18
+ end
19
+
20
+ def unbind
21
+ EM.stop_event_loop
22
+ end
23
+ end
24
+
25
+ module AcceptServer
26
+ def post_init
27
+ start_tls(:private_key_file => $dir+'server.key', :cert_chain_file => $dir+'server.crt', :verify_peer => true)
28
+ end
29
+
30
+ def ssl_verify_peer(cert)
31
+ $cert_from_server = cert
32
+ true
33
+ end
34
+
35
+ def ssl_handshake_completed
36
+ $server_handshake_completed = true
37
+ end
38
+ end
39
+
40
+ module DenyServer
41
+ def post_init
42
+ start_tls(:private_key_file => $dir+'server.key', :cert_chain_file => $dir+'server.crt', :verify_peer => true)
43
+ end
44
+
45
+ def ssl_verify_peer(cert)
46
+ $cert_from_server = cert
47
+ # Do not accept the peer. This should now cause the connection to shut down without the SSL handshake being completed.
48
+ false
49
+ end
50
+
51
+ def ssl_handshake_completed
52
+ $server_handshake_completed = true
53
+ end
54
+ end
55
+
56
+ def test_accept_server
57
+ $client_handshake_completed, $server_handshake_completed = false, false
58
+ EM.run {
59
+ EM.start_server("127.0.0.1", 16784, AcceptServer)
60
+ EM.connect("127.0.0.1", 16784, Client).instance_variable_get("@signature")
61
+ }
62
+
63
+ assert_equal($cert_from_file, $cert_from_server.gsub("\r", ""))
64
+ assert($client_handshake_completed)
65
+ assert($server_handshake_completed)
66
+ end
67
+
68
+ def test_deny_server
69
+ $client_handshake_completed, $server_handshake_completed = false, false
70
+ EM.run {
71
+ EM.start_server("127.0.0.1", 16784, DenyServer)
72
+ EM.connect("127.0.0.1", 16784, Client)
73
+ }
74
+
75
+ assert_equal($cert_from_file, $cert_from_server.gsub("\r", ""))
76
+ assert(!$client_handshake_completed)
77
+ assert(!$server_handshake_completed)
78
+ end
79
+ end
80
+ else
81
+ warn "EM built without SSL support, skipping tests in #{__FILE__}"
82
+ end
@@ -0,0 +1,37 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestStomp < Test::Unit::TestCase
4
+ CONTENT_LENGTH_REGEX = /^content-length: (\d+)$/
5
+
6
+ def bytesize(str)
7
+ str = str.to_s
8
+ size = str.bytesize if str.respond_to?(:bytesize) # bytesize added in 1.9
9
+ size || str.size
10
+ end
11
+
12
+ def test_content_length_in_bytes
13
+ connection = Object.new
14
+ connection.instance_eval do
15
+ extend EM::P::Stomp
16
+
17
+ def last_sent_content_length
18
+ @sent && Integer(@sent[CONTENT_LENGTH_REGEX, 1])
19
+ end
20
+
21
+ def send_data(string)
22
+ @sent = string
23
+ end
24
+ end
25
+
26
+ queue = "queue"
27
+ failure_message = "header content-length is not the byte size of last sent body"
28
+
29
+ body = "test"
30
+ connection.send queue, body
31
+ assert_equal bytesize(body), connection.last_sent_content_length, failure_message
32
+
33
+ body = "test\u221A"
34
+ connection.send queue, body
35
+ assert_equal bytesize(body), connection.last_sent_content_length, failure_message
36
+ end
37
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ require 'em_test_helper'
3
+
4
+ class TestSystem < Test::Unit::TestCase
5
+ def setup
6
+ @filename = File.expand_path("../я манал dump.txt", __FILE__)
7
+ @test_data = 'a' * 100
8
+ File.open(@filename, 'w'){|f| f.write(@test_data)}
9
+ end
10
+
11
+ def test_system
12
+ result = nil
13
+ status = nil
14
+ EM.run {
15
+ EM.system('cat', @filename){|out, state|
16
+ result = out
17
+ status = state.exitstatus
18
+ EM.stop
19
+ }
20
+ }
21
+ assert_equal(0, status)
22
+ assert_equal(@test_data, result)
23
+ end
24
+
25
+ def test_system_with_string
26
+ result = nil
27
+ status = nil
28
+ EM.run {
29
+ EM.system("cat '#@filename'"){|out, state|
30
+ result = out
31
+ status = state.exitstatus
32
+ EM.stop
33
+ }
34
+ }
35
+ assert_equal(0, status)
36
+ assert_equal(@test_data, result)
37
+ end
38
+
39
+ def teardown
40
+ File.unlink(@filename)
41
+ end
42
+ end
@@ -0,0 +1,53 @@
1
+ class TestThreadedResource < Test::Unit::TestCase
2
+ def object
3
+ @object ||= {}
4
+ end
5
+
6
+ def resource
7
+ @resource = EM::ThreadedResource.new do
8
+ object
9
+ end
10
+ end
11
+
12
+ def teardown
13
+ resource.shutdown
14
+ end
15
+
16
+ def test_dispatch_completion
17
+ EM.run do
18
+ completion = resource.dispatch do |o|
19
+ o[:foo] = :bar
20
+ :foo
21
+ end
22
+ completion.callback do |result|
23
+ assert_equal :foo, result
24
+ EM.stop
25
+ end
26
+ end
27
+ assert_equal :bar, object[:foo]
28
+ end
29
+
30
+ def test_dispatch_failure
31
+ completion = resource.dispatch do |o|
32
+ raise 'boom'
33
+ end
34
+ completion.errback do |error|
35
+ assert_kind_of RuntimeError, error
36
+ assert_equal 'boom', error.message
37
+ end
38
+ end
39
+
40
+ def test_dispatch_threading
41
+ main = Thread.current
42
+ resource.dispatch do |o|
43
+ o[:dispatch_thread] = Thread.current
44
+ end
45
+ assert_not_equal main, object[:dispatch_thread]
46
+ end
47
+
48
+ def test_shutdown
49
+ # This test should get improved sometime. The method returning thread is
50
+ # NOT an api that will be maintained.
51
+ assert !resource.shutdown.alive?
52
+ end
53
+ end
@@ -0,0 +1,59 @@
1
+ require "test/unit"
2
+ require 'em_test_helper'
3
+
4
+ class TestEmTickLoop < Test::Unit::TestCase
5
+ def test_em_tick_loop
6
+ i = 0
7
+ EM.tick_loop { i += 1; EM.stop if i == 10 }
8
+ EM.run { EM.add_timer(1) { EM.stop } }
9
+ assert_equal i, 10
10
+ end
11
+
12
+ def test_tick_loop_on_stop
13
+ t = nil
14
+ tick_loop = EM.tick_loop { :stop }
15
+ tick_loop.on_stop { t = true }
16
+ EM.run { EM.next_tick { EM.stop } }
17
+ assert t
18
+ end
19
+
20
+ def test_start_twice
21
+ i = 0
22
+ s = 0
23
+ tick_loop = EM.tick_loop { i += 1; :stop }
24
+ tick_loop.on_stop { s += 1; EM.stop }
25
+ EM.run { EM.next_tick { EM.stop } }
26
+ assert_equal 1, i
27
+ assert_equal 1, s
28
+ tick_loop.start
29
+ EM.run { EM.next_tick { EM.stop } }
30
+ assert_equal 2, i
31
+ assert_equal 1, s # stop callbacks are only called once
32
+ end
33
+
34
+ def test_stop
35
+ i, s = 0, 0
36
+ tick_loop = EM.tick_loop { i += 1 }
37
+ tick_loop.on_stop { s += 1 }
38
+ EM.run { EM.next_tick { tick_loop.stop; EM.next_tick { EM.stop } } }
39
+ assert tick_loop.stopped?
40
+ assert_equal 1, i
41
+ assert_equal 1, s
42
+ end
43
+
44
+ def test_immediate_stops
45
+ s = 0
46
+ tick_loop = EM::TickLoop.new { }
47
+ tick_loop.on_stop { s += 1 }
48
+ tick_loop.on_stop { s += 1 }
49
+ assert_equal 2, s
50
+ end
51
+
52
+ def test_stopped
53
+ tick_loop = EM::TickLoop.new { }
54
+ assert tick_loop.stopped?
55
+ tick_loop.start
56
+ assert !tick_loop.stopped?
57
+ end
58
+
59
+ end
@@ -0,0 +1,123 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestTimers < Test::Unit::TestCase
4
+
5
+ def test_timer_with_block
6
+ x = false
7
+ EM.run {
8
+ EM::Timer.new(0) {
9
+ x = true
10
+ EM.stop
11
+ }
12
+ }
13
+ assert x
14
+ end
15
+
16
+ def test_timer_with_proc
17
+ x = false
18
+ EM.run {
19
+ EM::Timer.new(0, proc {
20
+ x = true
21
+ EM.stop
22
+ })
23
+ }
24
+ assert x
25
+ end
26
+
27
+ def test_timer_cancel
28
+ assert_nothing_raised do
29
+ EM.run {
30
+ timer = EM::Timer.new(0.01) { flunk "Timer was not cancelled." }
31
+ timer.cancel
32
+
33
+ EM.add_timer(0.02) { EM.stop }
34
+ }
35
+ end
36
+ end
37
+
38
+ def test_periodic_timer
39
+ x = 0
40
+ EM.run {
41
+ EM::PeriodicTimer.new(0.01) do
42
+ x += 1
43
+ EM.stop if x == 4
44
+ end
45
+ }
46
+
47
+ assert_equal 4, x
48
+ end
49
+
50
+ def test_add_periodic_timer
51
+ x = 0
52
+ EM.run {
53
+ t = EM.add_periodic_timer(0.01) do
54
+ x += 1
55
+ EM.stop if x == 4
56
+ end
57
+ assert t.respond_to?(:cancel)
58
+ }
59
+ assert_equal 4, x
60
+ end
61
+
62
+ def test_periodic_timer_cancel
63
+ x = 0
64
+ EM.run {
65
+ pt = EM::PeriodicTimer.new(0.01) { x += 1 }
66
+ pt.cancel
67
+ EM::Timer.new(0.02) { EM.stop }
68
+ }
69
+ assert_equal 0, x
70
+ end
71
+
72
+ def test_add_periodic_timer_cancel
73
+ x = 0
74
+ EM.run {
75
+ pt = EM.add_periodic_timer(0.01) { x += 1 }
76
+ EM.cancel_timer(pt)
77
+ EM.add_timer(0.02) { EM.stop }
78
+ }
79
+ assert_equal 0, x
80
+ end
81
+
82
+ def test_periodic_timer_self_cancel
83
+ x = 0
84
+ EM.run {
85
+ pt = EM::PeriodicTimer.new(0) {
86
+ x += 1
87
+ if x == 4
88
+ pt.cancel
89
+ EM.stop
90
+ end
91
+ }
92
+ }
93
+ assert_equal 4, x
94
+ end
95
+
96
+
97
+ # This test is only applicable to compiled versions of the reactor.
98
+ # Pure ruby and java versions have no built-in limit on the number of outstanding timers.
99
+ unless [:pure_ruby, :java].include? EM.library_type
100
+ def test_timer_change_max_outstanding
101
+ defaults = EM.get_max_timers
102
+ EM.set_max_timers(100)
103
+
104
+ one_hundred_one_timers = lambda do
105
+ 101.times { EM.add_timer(0.01) {} }
106
+ EM.stop
107
+ end
108
+
109
+ assert_raises(RuntimeError) do
110
+ EM.run( &one_hundred_one_timers )
111
+ end
112
+
113
+ EM.set_max_timers( 101 )
114
+
115
+ assert_nothing_raised do
116
+ EM.run( &one_hundred_one_timers )
117
+ end
118
+ ensure
119
+ EM.set_max_timers(defaults)
120
+ end
121
+ end
122
+
123
+ end
data/tests/test_ud.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestUserDefinedEvents < Test::Unit::TestCase
4
+
5
+ def test_a
6
+ end
7
+
8
+ end
@@ -0,0 +1,48 @@
1
+ require 'em_test_helper'
2
+ require 'socket'
3
+
4
+ class TestUnbindReason < Test::Unit::TestCase
5
+
6
+ class StubConnection < EM::Connection
7
+ attr_reader :error
8
+ def unbind(reason = nil)
9
+ @error = reason
10
+ EM.stop
11
+ end
12
+ end
13
+
14
+ def test_connect_timeout
15
+ error = nil
16
+ EM.run {
17
+ conn = EM.connect 'google.com', 81, Module.new{ |m|
18
+ m.send(:define_method, :unbind) do |reason|
19
+ error = reason
20
+ EM.stop
21
+ end
22
+ }
23
+ conn.pending_connect_timeout = 0.1
24
+ }
25
+ assert_equal Errno::ETIMEDOUT, error
26
+ end
27
+
28
+ def test_connect_refused
29
+ error = nil
30
+ EM.run {
31
+ EM.connect '127.0.0.1', 12388, Module.new{ |m|
32
+ m.send(:define_method, :unbind) do |reason|
33
+ error = reason
34
+ EM.stop
35
+ end
36
+ }
37
+ }
38
+ assert_equal Errno::ECONNREFUSED, error
39
+ end
40
+
41
+ def test_optional_argument
42
+ conn = nil
43
+ EM.run {
44
+ conn = EM.connect '127.0.0.1', 12388, StubConnection
45
+ }
46
+ assert_equal Errno::ECONNREFUSED, conn.error
47
+ end
48
+ end