jubilee 2.1.0.Alpha1-java → 2.1.0.beta-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/CHANGELOG +9 -0
  4. data/README.md +12 -7
  5. data/jars/vertx-core-2.1.1.jar +0 -0
  6. data/java/src/jubilee/JubileeService.java +3 -3
  7. data/java/src/org/jruby/jubilee/Const.java +1 -1
  8. data/java/src/org/jruby/jubilee/JubileeVerticle.java +29 -4
  9. data/java/src/org/jruby/jubilee/RackApplication.java +38 -35
  10. data/java/src/org/jruby/jubilee/RackEnvironment.java +57 -23
  11. data/java/src/org/jruby/jubilee/RackEnvironmentHash.java +64 -11
  12. data/java/src/org/jruby/jubilee/RackInput.java +13 -10
  13. data/java/src/org/jruby/jubilee/RubyCallable.java +52 -0
  14. data/java/src/org/jruby/jubilee/RubyChannel.java +89 -0
  15. data/java/src/org/jruby/jubilee/RubyHttpServerResponse.java +72 -60
  16. data/java/src/org/jruby/jubilee/RubyNetSocket.java +169 -0
  17. data/java/src/org/jruby/jubilee/RubyPlatformManager.java +129 -113
  18. data/java/src/org/jruby/jubilee/impl/RubyIORackInput.java +9 -9
  19. data/java/src/org/jruby/jubilee/impl/RubyNullIO.java +1 -1
  20. data/java/src/org/jruby/jubilee/utils/RubyHelper.java +0 -6
  21. data/java/src/org/jruby/jubilee/vertx/JubileeVertx.java +12 -11
  22. data/jubilee.gemspec +43 -20
  23. data/lib/jubilee.rb +0 -1
  24. data/lib/jubilee/cli.rb +5 -3
  25. data/lib/jubilee/configuration.rb +2 -7
  26. data/lib/jubilee/const.rb +30 -28
  27. data/lib/jubilee/response.rb +40 -5
  28. data/lib/jubilee/server.rb +0 -3
  29. data/lib/jubilee/version.rb +1 -1
  30. data/spec/apps/rails4/basic/Gemfile +0 -2
  31. data/spec/apps/rails4/basic/Gemfile.lock +0 -7
  32. data/spec/integration/basic_rack_spec.rb +4 -3
  33. data/spec/integration/basic_rails4_spec.rb +4 -3
  34. data/spec/integration/basic_sinatra_spec.rb +4 -4
  35. data/spec/spec_helper.rb +1 -0
  36. data/test/{config → apps}/app.rb +0 -0
  37. data/test/apps/checker.ru +5 -10
  38. data/test/apps/chunked.ru +3 -0
  39. data/test/{config → apps}/config.ru +0 -0
  40. data/test/apps/content_length.ru +3 -0
  41. data/test/apps/hex.ru +4 -0
  42. data/test/apps/hijack.ru +7 -0
  43. data/test/apps/hijack2.ru +7 -0
  44. data/test/apps/huge.ru +4 -0
  45. data/test/apps/method_override.ru +1 -1
  46. data/test/apps/overwrite_check.ru +3 -2
  47. data/test/apps/persistent.rb +14 -0
  48. data/test/apps/persistent.ru +3 -0
  49. data/test/apps/rack_input.ru +5 -0
  50. data/test/apps/self_chunked.ru +6 -0
  51. data/test/apps/sha1.ru +2 -0
  52. data/test/apps/simple.ru +10 -1
  53. data/test/jubilee/test_cli.rb +1 -1
  54. data/test/jubilee/test_configuration.rb +1 -3
  55. data/test/jubilee/test_hijack.rb +27 -0
  56. data/test/jubilee/test_persistent.rb +208 -0
  57. data/test/jubilee/test_rack_server.rb +29 -68
  58. data/test/jubilee/test_server.rb +49 -15
  59. data/test/jubilee/test_upload.rb +13 -60
  60. data/test/test_helper.rb +2 -2
  61. metadata +19 -9
  62. data/java/src/org/jruby/jubilee/RubyServer.java +0 -159
  63. data/lib/jubilee/jubilee.jar +0 -0
  64. data/lib/rack/chunked.rb +0 -38
  65. data/test/config/app.ru +0 -3
  66. data/test/jubilee/test_response.rb +0 -270
@@ -2,6 +2,7 @@ require 'test_helper'
2
2
  require 'net/http'
3
3
 
4
4
  class TestJubileeServer < MiniTest::Unit::TestCase
5
+ include Helpers
5
6
  def setup
6
7
  @host, @port = "localhost", 8080
7
8
  @server = nil
@@ -13,27 +14,19 @@ class TestJubileeServer < MiniTest::Unit::TestCase
13
14
  end
14
15
 
15
16
  def test_server_embedded
16
- config = Jubilee::Configuration.new(rackup: File.expand_path("../../config/config.ru", __FILE__))
17
- @server = Jubilee::Server.new(config.options)
18
- @server.start
19
- sleep 0.5
20
- http, body = Net::HTTP.new(@host, @port), nil
21
- http.start do
22
- req = Net::HTTP::Get.new "/", {}
23
- http.request(req) do |resp|
24
- body = resp.body
25
- end
26
- end
27
- assert_equal "embedded app", body
17
+ start_server('config')
18
+ resp = GET("/")
19
+ assert_equal "embedded app", resp.body
28
20
  end
29
21
 
30
22
  def test_url_scheme_for_https
31
23
  config = Jubilee::Configuration.new(rackup: File.expand_path("../../apps/url_scheme.ru", __FILE__), port: @port, ssl: true,
32
24
  ssl_keystore: File.join(File.dirname(__FILE__), "../../examples/keystore.jks"),
33
- ssl_password: "hellojubilee")
25
+ ssl_password: "hellojubilee", instances: 1)
34
26
  @server = Jubilee::Server.new(config.options)
35
- @server.start
36
- sleep 0.5
27
+ q = Queue.new
28
+ @server.start{ q << 1 }
29
+ q.pop
37
30
  http = Net::HTTP.new @host, @port
38
31
  http.use_ssl = true
39
32
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -50,4 +43,45 @@ class TestJubileeServer < MiniTest::Unit::TestCase
50
43
  assert_equal "https", body
51
44
  end
52
45
 
46
+ def test_proper_rack_input_io
47
+ start_server('rack_input')
48
+ fifteen = "1" * 15
49
+
50
+ sock = TCPSocket.new @host, @port
51
+ sock << "PUT / HTTP/1.0\r\nContent-Length: 30\r\n\r\n#{fifteen}"
52
+ sleep 0.1 # important so that the previous data is sent as a packet
53
+ sock << fifteen
54
+
55
+ while true
56
+ line = sock.gets
57
+ break if line == "\r\n"
58
+ end
59
+ data = sock.read
60
+ assert_equal "#{fifteen}#{fifteen}", data
61
+ end
62
+
63
+ def test_huge_return
64
+ start_server('huge')
65
+ sock = TCPSocket.new @host, @port
66
+ sock << "GET / HTTP/1.0\r\n\r\n"
67
+
68
+ while true
69
+ line = sock.gets
70
+ break if line == "\r\n"
71
+ end
72
+
73
+ out = sock.read
74
+
75
+ giant = 2056610
76
+ assert_equal giant, out.bytesize
77
+ end
78
+
79
+ def start_server(rack, &block)
80
+ config = Jubilee::Configuration.new(rackup: File.expand_path("../../apps/#{rack}.ru", __FILE__), instances: 1)
81
+ @server = Jubilee::Server.new(config.options)
82
+ q = Queue.new
83
+ @server.start { q << 1 }
84
+ q.pop
85
+ sleep 0.1
86
+ end
53
87
  end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
2
 
3
3
  require 'test_helper'
4
- require 'digest/md5'
4
+ require 'digest'
5
5
 
6
6
  class TestUpload < MiniTest::Unit::TestCase
7
7
 
@@ -15,12 +15,12 @@ class TestUpload < MiniTest::Unit::TestCase
15
15
 
16
16
  # we want random binary data to test 1.9 encoding-aware IO craziness
17
17
  @random = File.open('/dev/urandom','rb')
18
- sleep 1
19
18
  end
20
19
 
21
20
  def teardown
22
21
  @server.stop
23
22
  @random.close
23
+ sleep 0.1
24
24
  end
25
25
 
26
26
  def test_put
@@ -41,10 +41,10 @@ class TestUpload < MiniTest::Unit::TestCase
41
41
 
42
42
  def test_put_content_md5
43
43
  start_server
44
- skip "Vert.x doesn't hendle trailing headers"
45
44
  md5 = Digest::MD5.new
46
45
  sock = TCPSocket.new(@addr, @port)
47
46
  sock.syswrite("PUT / HTTP/1.0\r\nTransfer-Encoding: chunked\r\n" \
47
+ "X-Expect-Size: #{length}\r\n" \
48
48
  "Trailer: Content-MD5\r\n\r\n")
49
49
  @count.times do |i|
50
50
  buf = @random.sysread(@bs)
@@ -60,8 +60,10 @@ class TestUpload < MiniTest::Unit::TestCase
60
60
  read = sock.read.split(/\r\n/)
61
61
  assert_equal "HTTP/1.0 200 OK", read[0]
62
62
  resp = eval(read.grep(/^X-Resp: /).first.sub!(/X-Resp: /, ''))
63
+ assert_equal length, resp[:size]
63
64
  assert_equal @sha1.hexdigest, resp[:sha1]
64
- assert_equal content_md5, resp[:content_md5]
65
+ #Vert.x doesn't handle trailing headers
66
+ #assert_equal content_md5, resp[:content_md5]
65
67
  end
66
68
 
67
69
  def test_put_trickle_small
@@ -113,6 +115,9 @@ class TestUpload < MiniTest::Unit::TestCase
113
115
  def test_put_excessive_overwrite_closed
114
116
  config = Jubilee::Configuration.new(rackup: File.expand_path("../../apps/overwrite_check.ru", __FILE__))
115
117
  @server = Jubilee::Server.new(config.options)
118
+ q = Queue.new
119
+ @server.start { q << 1 }
120
+ q.pop
116
121
 
117
122
  sock = TCPSocket.new(@addr, @port)
118
123
  # buf = ' ' * @bs # Something is wrong with the vertx http compression
@@ -168,59 +173,6 @@ class TestUpload < MiniTest::Unit::TestCase
168
173
  assert_match(/sysread_read_byte_match/, resp)
169
174
  end
170
175
 
171
- =begin
172
- def test_chunked_upload_via_curl
173
- # POSIX doesn't require all of these to be present on a system
174
- which('curl') or return
175
- which('sha1sum') or return
176
- which('dd') or return
177
-
178
- start_server
179
-
180
- tmp = Tempfile.new('dd_dest')
181
- assert(system("dd", "if=#{@random.path}", "of=#{tmp.path}",
182
- "bs=#{@bs}", "count=#{@count}"),
183
- "dd #@random to #{tmp}")
184
- sha1_re = %r!\b([a-f0-9]{40})\b!
185
- sha1_out = `sha1sum #{tmp.path}`
186
- assert $?.success?, 'sha1sum ran OK'
187
-
188
- assert_match(sha1_re, sha1_out)
189
- sha1 = sha1_re.match(sha1_out)[1]
190
- cmd = "curl -H 'X-Expect-Size: #{tmp.size}' --tcp-nodelay \
191
- -isSf --no-buffer -T- " \
192
- "http://#@addr:#@port/"
193
- resp = Tempfile.new('resp')
194
- resp.sync = true
195
-
196
- rd, wr = IO.pipe
197
- wr.sync = rd.sync = true
198
- pid = fork {
199
- STDIN.reopen(rd)
200
- rd.close
201
- wr.close
202
- STDOUT.reopen(resp)
203
- exec cmd
204
- }
205
- rd.close
206
-
207
- tmp.rewind
208
- @count.times { |i|
209
- wr.write(tmp.read(@bs))
210
- sleep(rand / 10) if 0 == i % 8
211
- }
212
- wr.close
213
- pid, status = Process.waitpid2(pid)
214
-
215
- resp.rewind
216
- resp = resp.read
217
- assert status.success?, 'curl ran OK'
218
- assert_match(%r!\b#{sha1}\b!, resp)
219
- assert_match(/sysread_read_byte_match/, resp)
220
- assert_match(/expect_size_match/, resp)
221
- end
222
- =end
223
-
224
176
  def test_curl_chunked_small
225
177
  # POSIX doesn't require all of these to be present on a system
226
178
  which('curl') or return
@@ -255,10 +207,11 @@ class TestUpload < MiniTest::Unit::TestCase
255
207
  end
256
208
 
257
209
  def start_server
258
- config = Jubilee::Configuration.new(rackup: File.expand_path("../../apps/sha1.ru", __FILE__))
210
+ config = Jubilee::Configuration.new(rackup: File.expand_path("../../apps/sha1.ru", __FILE__), instances: 1)
259
211
  @server = Jubilee::Server.new(config.options)
260
- @server.start
212
+ q = Queue.new
213
+ @server.start{ q << 1 }
214
+ q.pop
261
215
  sleep 0.1
262
216
  end
263
-
264
217
  end
@@ -52,7 +52,7 @@ module Helpers
52
52
 
53
53
  def GET(path, header={})
54
54
  sleep 0.1
55
- Net::HTTP.start(@host, @port) { |http|
55
+ Net::HTTP.start("localhost", 8080) { |http|
56
56
  user = header.delete(:user)
57
57
  passwd = header.delete(:passwd)
58
58
 
@@ -71,7 +71,7 @@ module Helpers
71
71
 
72
72
  def POST(path, formdata={}, header={})
73
73
  sleep 0.1
74
- Net::HTTP.start(@host, @port) { |http|
74
+ Net::HTTP.start("localhost", 8080) { |http|
75
75
  user = header.delete(:user)
76
76
  passwd = header.delete(:passwd)
77
77
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jubilee
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.Alpha1
4
+ version: 2.1.0.beta
5
5
  platform: java
6
6
  authors:
7
7
  - Isaiah Peng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-17 00:00:00.000000000 Z
11
+ date: 2014-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -107,9 +107,11 @@ files:
107
107
  - java/src/org/jruby/jubilee/RackEnvironmentHash.java
108
108
  - java/src/org/jruby/jubilee/RackInput.java
109
109
  - java/src/org/jruby/jubilee/RackResponse.java
110
+ - java/src/org/jruby/jubilee/RubyCallable.java
111
+ - java/src/org/jruby/jubilee/RubyChannel.java
110
112
  - java/src/org/jruby/jubilee/RubyHttpServerResponse.java
113
+ - java/src/org/jruby/jubilee/RubyNetSocket.java
111
114
  - java/src/org/jruby/jubilee/RubyPlatformManager.java
112
- - java/src/org/jruby/jubilee/RubyServer.java
113
115
  - java/src/org/jruby/jubilee/impl/RubyIORackInput.java
114
116
  - java/src/org/jruby/jubilee/impl/RubyNullIO.java
115
117
  - java/src/org/jruby/jubilee/utils/RubyHelper.java
@@ -120,11 +122,9 @@ files:
120
122
  - lib/jubilee/cli.rb
121
123
  - lib/jubilee/configuration.rb
122
124
  - lib/jubilee/const.rb
123
- - lib/jubilee/jubilee.jar
124
125
  - lib/jubilee/response.rb
125
126
  - lib/jubilee/server.rb
126
127
  - lib/jubilee/version.rb
127
- - lib/rack/chunked.rb
128
128
  - lib/rack/handler/jubilee.rb
129
129
  - lib/vertx.rb
130
130
  - lib/vertx/README.md
@@ -211,20 +211,30 @@ files:
211
211
  - spec/integration/basic_sinatra_spec.rb
212
212
  - spec/spec_helper.rb
213
213
  - test/.ruby-version
214
+ - test/apps/app.rb
214
215
  - test/apps/checker.ru
216
+ - test/apps/chunked.ru
217
+ - test/apps/config.ru
218
+ - test/apps/content_length.ru
219
+ - test/apps/hex.ru
220
+ - test/apps/hijack.ru
221
+ - test/apps/hijack2.ru
222
+ - test/apps/huge.ru
215
223
  - test/apps/method_override.ru
216
224
  - test/apps/overwrite_check.ru
225
+ - test/apps/persistent.rb
226
+ - test/apps/persistent.ru
217
227
  - test/apps/rack_crasher.ru
228
+ - test/apps/rack_input.ru
229
+ - test/apps/self_chunked.ru
218
230
  - test/apps/sha1.ru
219
231
  - test/apps/simple.ru
220
232
  - test/apps/url_scheme.ru
221
- - test/config/app.rb
222
- - test/config/app.ru
223
- - test/config/config.ru
224
233
  - test/jubilee/test_cli.rb
225
234
  - test/jubilee/test_configuration.rb
235
+ - test/jubilee/test_hijack.rb
236
+ - test/jubilee/test_persistent.rb
226
237
  - test/jubilee/test_rack_server.rb
227
- - test/jubilee/test_response.rb
228
238
  - test/jubilee/test_server.rb
229
239
  - test/jubilee/test_upload.rb
230
240
  - test/test_helper.rb
@@ -1,159 +0,0 @@
1
- package org.jruby.jubilee;
2
-
3
- import org.jruby.*;
4
- import org.jruby.anno.JRubyMethod;
5
- import org.jruby.jubilee.vertx.JubileeVertx;
6
- import org.jruby.runtime.Block;
7
- import org.jruby.runtime.ObjectAllocator;
8
- import org.jruby.runtime.ThreadContext;
9
- import org.jruby.runtime.builtin.IRubyObject;
10
- import org.vertx.java.core.Handler;
11
- import org.vertx.java.core.Vertx;
12
- import org.vertx.java.core.http.HttpServer;
13
- import org.vertx.java.core.http.HttpServerRequest;
14
- import org.vertx.java.core.json.JsonArray;
15
- import org.vertx.java.core.json.JsonObject;
16
- import org.vertx.java.platform.impl.WrappedVertx;
17
-
18
- import java.io.IOException;
19
-
20
- public class RubyServer extends RubyObject {
21
- private Vertx vertx;
22
- private HttpServer httpServer;
23
- private RackApplication app;
24
- private boolean running = false;
25
- private boolean ssl = false;
26
- private String keyStorePath;
27
- private String keyStorePassword;
28
- private String eventBusPrefix;
29
- private int port;
30
- private String host;
31
-
32
- public static void createServerClass(Ruby runtime) {
33
- RubyModule mJubilee = runtime.defineModule("Jubilee");
34
- RubyClass serverClass = mJubilee.defineClassUnder("VertxServer", runtime.getObject(), ALLOCATOR);
35
- serverClass.defineAnnotatedMethods(RubyServer.class);
36
- }
37
-
38
- private static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
39
- public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) {
40
- return new RubyServer(ruby, rubyClass);
41
- }
42
- };
43
-
44
- public RubyServer(Ruby ruby, RubyClass rubyClass) {
45
- super(ruby, rubyClass);
46
- }
47
-
48
- /**
49
- * Initialize jubilee server, take a rack application and a configuration hash as parameter
50
- *
51
- * @param context
52
- * @param app
53
- * @param config
54
- * @param block
55
- * @return
56
- */
57
- @JRubyMethod(name = "initialize")
58
- public IRubyObject initialize(ThreadContext context, IRubyObject app, IRubyObject config, Block block) {
59
- Ruby runtime = getRuntime();
60
- /* configuration keys */
61
- RubyHash options = config.convertToHash();
62
- RubySymbol port_k = runtime.newSymbol("Port");
63
- RubySymbol host_k = runtime.newSymbol("Host");
64
- RubySymbol ssl_k = runtime.newSymbol("ssl");
65
- RubySymbol ssl_keystore_k = runtime.newSymbol("ssl_keystore");
66
- RubySymbol ssl_password_k = runtime.newSymbol("ssl_password");
67
- RubySymbol eventbus_prefix_k = runtime.newSymbol("eventbus_prefix");
68
-
69
- /* retrieve from passed in options */
70
- this.port = RubyNumeric.num2int(options.op_aref(context, port_k));
71
- this.host = options.op_aref(context, host_k).asJavaString();
72
-
73
- this.ssl = options.op_aref(context, ssl_k).isTrue();
74
- if (this.ssl) {
75
- this.keyStorePath = options.op_aref(context, ssl_keystore_k).asJavaString();
76
- if (options.has_key_p(ssl_password_k).isTrue())
77
- this.keyStorePassword = options.op_aref(context, ssl_password_k).asJavaString();
78
- }
79
- if (options.has_key_p(eventbus_prefix_k).isTrue())
80
- this.eventBusPrefix = options.op_aref(context, eventbus_prefix_k).asJavaString();
81
-
82
- this.vertx = JubileeVertx.vertx();
83
-
84
- httpServer = vertx.createHttpServer();
85
- try {
86
- this.app = new RackApplication((WrappedVertx) vertx, context, app, this.ssl);
87
- if (block.isGiven()) block.yieldSpecific(context, this);
88
- } catch (IOException e) {
89
- // noop
90
- }
91
- return this;
92
- }
93
-
94
- /**
95
- * Start http server, initialize states
96
- *
97
- * @param context
98
- * @param block
99
- * @return
100
- */
101
- @JRubyMethod(name = "start")
102
- public IRubyObject start(final ThreadContext context, final Block block) {
103
- httpServer.setAcceptBacklog(10000);
104
- httpServer.requestHandler(new Handler<HttpServerRequest>() {
105
- public void handle(final HttpServerRequest req) {
106
- app.call(req);
107
- }
108
- });
109
- if (eventBusPrefix != null) {
110
- JsonObject config = new JsonObject().putString("prefix", eventBusPrefix);
111
- JsonArray allowAll = new JsonArray();
112
- allowAll.add(new JsonObject());
113
- // TODO read inbounds and outbounds from config file
114
- vertx.createSockJSServer(httpServer).bridge(config, allowAll, allowAll);
115
- }
116
- if (ssl) httpServer.setSSL(true).setKeyStorePath(this.keyStorePath)
117
- .setKeyStorePassword(this.keyStorePassword);
118
- httpServer.listen(this.port, this.host);
119
- this.running = true;
120
- if (block.isGiven()) block.yieldSpecific(context, this);
121
- return this;
122
- }
123
-
124
- /**
125
- * Set timeout for keep alive connection
126
- *
127
- * @param context
128
- * @param timeout (in TimeUnit.SECONDS)
129
- * @return this
130
- */
131
- @JRubyMethod(name = "persistent_timeout=")
132
- public IRubyObject setPersistentTimeout(final ThreadContext context, final IRubyObject timeout) {
133
- // FIXME
134
- //httpServer.setPersistentTimeout(RubyInteger.fix2long(timeout) * 1000);
135
- return this;
136
- }
137
-
138
- /**
139
- * Stop the HttpServer
140
- *
141
- * @param context
142
- * @param args if shutdown abruptly
143
- * @param block callback on close
144
- * @return
145
- */
146
- @JRubyMethod(name = {"stop", "close"}, optional = 1)
147
- public IRubyObject close(ThreadContext context, IRubyObject[] args, Block block) {
148
- if (running) {
149
- this.running = false;
150
- httpServer.close();
151
- // DO I need to stop?
152
- //vertx.stop();
153
- if (block.isGiven()) block.yieldSpecific(context);
154
- } else {
155
- getRuntime().getOutputStream().println("jubilee server not running?");
156
- }
157
- return getRuntime().getNil();
158
- }
159
- }