rb: Make a few of the NonblockingServer specs pass under jruby


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@669036 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/spec/ThriftSpec.thrift b/lib/rb/spec/ThriftSpec.thrift
index 1012e51..4309829 100644
--- a/lib/rb/spec/ThriftSpec.thrift
+++ b/lib/rb/spec/ThriftSpec.thrift
@@ -20,7 +20,7 @@
 service NonblockingService {
   Hello greeting(1:bool english)
   bool block()
-  async void unblock()
+  async void unblock(1:i32 n)
   async void shutdown()
   void sleep(1:double seconds)
 }
diff --git a/lib/rb/spec/gen-rb/NonblockingService.rb b/lib/rb/spec/gen-rb/NonblockingService.rb
index 411a6f0..ba6b3e4 100644
--- a/lib/rb/spec/gen-rb/NonblockingService.rb
+++ b/lib/rb/spec/gen-rb/NonblockingService.rb
@@ -43,12 +43,12 @@
             raise Thrift::ApplicationException.new(Thrift::ApplicationException::MISSING_RESULT, 'block failed: unknown result')
           end
 
-          def unblock()
-            send_unblock()
+          def unblock(n)
+            send_unblock(n)
           end
 
-          def send_unblock()
-            send_message('unblock', Unblock_args)
+          def send_unblock(n)
+            send_message('unblock', Unblock_args, :n => n)
           end
           def shutdown()
             send_shutdown()
@@ -92,7 +92,7 @@
 
           def process_unblock(seqid, iprot, oprot)
             args = read_args(iprot, Unblock_args)
-            @handler.unblock()
+            @handler.unblock(args.n)
             return
           end
 
@@ -146,8 +146,9 @@
 
         class Unblock_args
           include Thrift::Struct
+          Thrift::Struct.field_accessor self, :n
           FIELDS = {
-
+            1 => {:type => Thrift::Types::I32, :name => 'n'}
           }
         end
 
diff --git a/lib/rb/spec/nonblockingserver_spec.rb b/lib/rb/spec/nonblockingserver_spec.rb
index 04c569a..fd0fb64 100644
--- a/lib/rb/spec/nonblockingserver_spec.rb
+++ b/lib/rb/spec/nonblockingserver_spec.rb
@@ -25,8 +25,8 @@
       @queue.pop
     end
 
-    def unblock
-      @queue.num_waiting.times { @queue.push true }
+    def unblock(n)
+      n.times { @queue.push true }
     end
 
     def sleep(time)
@@ -72,12 +72,25 @@
     end
   end
 
+  class SpecServerSocket < ServerSocket
+    def initialize(host, port, queue)
+      super(host, port)
+      @queue = queue
+    end
+
+    def listen
+      super
+      @queue.push :listen
+    end
+  end
+
   describe Thrift::NonblockingServer do
     before(:each) do
       @port = 43251
       handler = Handler.new
       processor = NonblockingService::Processor.new(handler)
-      @transport = ServerSocket.new('localhost', @port)
+      queue = Queue.new
+      @transport = SpecServerSocket.new('localhost', @port, queue)
       transportFactory = FramedTransportFactory.new
       logger = Logger.new(STDERR)
       logger.level = Logger::WARN
@@ -92,7 +105,7 @@
           master_thread.raise e
         end
       end
-      Thread.pass
+      queue.pop
 
       @clients = []
       @catch_exceptions = false
@@ -119,12 +132,13 @@
       Thread.new do
         begin
           client = setup_client
-          while (msg = queue.pop)
+          while (cmd = queue.pop)
+            msg, *args = cmd
             case msg
             when :block
               result << client.block
             when :unblock
-              client.unblock
+              client.unblock(args.first)
             when :hello
               result << client.greeting(true) # ignore result
             when :sleep
@@ -154,9 +168,17 @@
     it "should handle concurrent clients" do
       queue = Queue.new
       trans_queue = Queue.new
-      4.times { Thread.new { queue.push setup_client(trans_queue).block } }
+      4.times do
+        Thread.new(Thread.current) do |main_thread|
+          begin
+            queue.push setup_client(trans_queue).block
+          rescue => e
+            main_thread.raise e
+          end
+        end
+      end
       4.times { trans_queue.pop }
-      setup_client.unblock
+      setup_client.unblock(4)
       4.times { queue.pop.should be_true }
     end
 
@@ -175,7 +197,7 @@
       queues[6] << :hello
       3.times { result.pop.should == Hello.new }
       client.greeting(true).should == Hello.new
-      queues[5] << :unblock
+      queues[5] << [:unblock, 4]
       4.times { result.pop.should be_true }
       queues[2] << :hello
       result.pop.should == Hello.new