You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2015/09/22 07:49:22 UTC

thrift git commit: THRIFT-3342 Improve ruby cross test client and server compatibility

Repository: thrift
Updated Branches:
  refs/heads/master cf63c95c1 -> 682382971


THRIFT-3342 Improve ruby cross test client and server compatibility

This closes #615


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/68238297
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/68238297
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/68238297

Branch: refs/heads/master
Commit: 68238297100517db0202a7f9698ac637bc8d1c35
Parents: cf63c95
Author: Nobuaki Sukegawa <ns...@gmail.com>
Authored: Mon Sep 21 23:28:22 2015 +0900
Committer: Roger Meier <r....@siemens.com>
Committed: Tue Sep 22 07:48:25 2015 +0200

----------------------------------------------------------------------
 test/known_failures_Linux.json    |  84 --------------------
 test/rb/integration/TestClient.rb | 136 +++++++++++++++++++++++++--------
 test/rb/integration/TestServer.rb |  60 ++++++++++-----
 3 files changed, 146 insertions(+), 134 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/68238297/test/known_failures_Linux.json
----------------------------------------------------------------------
diff --git a/test/known_failures_Linux.json b/test/known_failures_Linux.json
index 97551e2..bf05f93 100644
--- a/test/known_failures_Linux.json
+++ b/test/known_failures_Linux.json
@@ -180,12 +180,6 @@
   "go-nodejs_json_framed-ip-ssl",
   "go-perl_binary_buffered-ip-ssl",
   "go-perl_binary_framed-ip-ssl",
-  "go-rb_binary-accel_buffered-ip",
-  "go-rb_binary-accel_framed-ip",
-  "go-rb_binary_buffered-ip",
-  "go-rb_binary_framed-ip",
-  "go-rb_compact_buffered-ip",
-  "go-rb_compact_framed-ip",
   "go-rb_json_buffered-ip",
   "go-rb_json_framed-ip",
   "hs-c_glib_binary_buffered-ip",
@@ -290,11 +284,8 @@
   "hs-py_json_buffered-ip-ssl",
   "hs-py_json_framed-ip",
   "hs-py_json_framed-ip-ssl",
-  "hs-rb_binary-accel_buffered-ip",
   "hs-rb_binary-accel_framed-ip",
-  "hs-rb_binary_buffered-ip",
   "hs-rb_binary_framed-ip",
-  "hs-rb_compact_buffered-ip",
   "hs-rb_compact_framed-ip",
   "hs-rb_json_buffered-ip",
   "hs-rb_json_framed-ip",
@@ -324,15 +315,6 @@
   "java-hs_json_framed-ip-ssl",
   "java-nodejs_json_buffered-ip",
   "java-nodejs_json_buffered-ip-ssl",
-  "java-rb_binary-accel_buffered-ip",
-  "java-rb_binary-accel_fastframed-framed-ip",
-  "java-rb_binary-accel_framed-ip",
-  "java-rb_binary_buffered-ip",
-  "java-rb_binary_fastframed-framed-ip",
-  "java-rb_binary_framed-ip",
-  "java-rb_compact_buffered-ip",
-  "java-rb_compact_fastframed-framed-ip",
-  "java-rb_compact_framed-ip",
   "java-rb_json_buffered-ip",
   "java-rb_json_fastframed-framed-ip",
   "java-rb_json_framed-ip",
@@ -498,80 +480,14 @@
   "rb-c_glib_accel-binary_framed-ip",
   "rb-c_glib_binary_buffered-ip",
   "rb-c_glib_binary_framed-ip",
-  "rb-cpp_accel-binary_buffered-ip",
-  "rb-cpp_accel-binary_framed-ip",
-  "rb-cpp_binary_buffered-ip",
-  "rb-cpp_binary_framed-ip",
-  "rb-cpp_compact_buffered-ip",
-  "rb-cpp_compact_framed-ip",
-  "rb-cpp_json_buffered-ip",
-  "rb-cpp_json_framed-ip",
-  "rb-csharp_accel-binary_buffered-ip",
-  "rb-csharp_accel-binary_framed-ip",
-  "rb-csharp_binary_buffered-ip",
-  "rb-csharp_binary_framed-ip",
-  "rb-csharp_compact_buffered-ip",
-  "rb-csharp_compact_framed-ip",
   "rb-csharp_json_buffered-ip",
   "rb-csharp_json_framed-ip",
-  "rb-go_accel-binary_buffered-ip",
-  "rb-go_accel-binary_framed-ip",
-  "rb-go_binary_buffered-ip",
-  "rb-go_binary_framed-ip",
-  "rb-go_compact_buffered-ip",
-  "rb-go_compact_framed-ip",
-  "rb-go_json_buffered-ip",
-  "rb-go_json_framed-ip",
-  "rb-hs_accel-binary_buffered-ip",
   "rb-hs_accel-binary_framed-ip",
-  "rb-hs_binary_buffered-ip",
   "rb-hs_binary_framed-ip",
-  "rb-hs_compact_buffered-ip",
   "rb-hs_compact_framed-ip",
-  "rb-hs_json_buffered-ip",
   "rb-hs_json_framed-ip",
-  "rb-java_accel-binary_buffered-ip",
-  "rb-java_accel-binary_framed-fastframed-ip",
-  "rb-java_accel-binary_framed-ip",
-  "rb-java_binary_buffered-ip",
-  "rb-java_binary_framed-fastframed-ip",
-  "rb-java_binary_framed-ip",
-  "rb-java_compact_buffered-ip",
-  "rb-java_compact_framed-fastframed-ip",
-  "rb-java_compact_framed-ip",
-  "rb-java_json_buffered-ip",
-  "rb-java_json_framed-fastframed-ip",
-  "rb-java_json_framed-ip",
-  "rb-nodejs_accel-binary_buffered-ip",
-  "rb-nodejs_accel-binary_framed-ip",
-  "rb-nodejs_binary_buffered-ip",
-  "rb-nodejs_binary_framed-ip",
-  "rb-nodejs_compact_buffered-ip",
-  "rb-nodejs_compact_framed-ip",
   "rb-nodejs_json_buffered-ip",
   "rb-nodejs_json_framed-ip",
-  "rb-py_accel-binary_buffered-ip",
-  "rb-py_accel-binary_framed-ip",
-  "rb-py_accel_buffered-ip",
-  "rb-py_accel_framed-ip",
-  "rb-py_binary-accel_buffered-ip",
-  "rb-py_binary-accel_framed-ip",
-  "rb-py_binary_buffered-ip",
-  "rb-py_binary_framed-ip",
-  "rb-py_compact_buffered-ip",
-  "rb-py_compact_framed-ip",
-  "rb-py_json_buffered-ip",
-  "rb-py_json_framed-ip",
-  "rb-rb_accel-binary_buffered-ip",
-  "rb-rb_accel-binary_framed-ip",
-  "rb-rb_accel_buffered-ip",
-  "rb-rb_accel_framed-ip",
-  "rb-rb_binary-accel_buffered-ip",
-  "rb-rb_binary-accel_framed-ip",
-  "rb-rb_binary_buffered-ip",
-  "rb-rb_binary_framed-ip",
-  "rb-rb_compact_buffered-ip",
-  "rb-rb_compact_framed-ip",
   "rb-rb_json_buffered-ip",
   "rb-rb_json_framed-ip"
 ]

http://git-wip-us.apache.org/repos/asf/thrift/blob/68238297/test/rb/integration/TestClient.rb
----------------------------------------------------------------------
diff --git a/test/rb/integration/TestClient.rb b/test/rb/integration/TestClient.rb
index 3659ccb..b31a024 100755
--- a/test/rb/integration/TestClient.rb
+++ b/test/rb/integration/TestClient.rb
@@ -54,11 +54,8 @@ class SimpleClientTest < Test::Unit::TestCase
   def setup 
     unless @socket
       @socket   = Thrift::Socket.new($host, $port)
-      transportFactory = Thrift::BufferedTransport.new(@socket)
       if $transport == "buffered"
         transportFactory = Thrift::BufferedTransport.new(@socket)
-      elsif $transport == ""
-        transportFactory = Thrift::BufferedTransport.new(@socket)
       elsif $transport == "framed"
         transportFactory = Thrift::FramedTransport.new(@socket)
       else
@@ -67,8 +64,6 @@ class SimpleClientTest < Test::Unit::TestCase
 
       if $protocolType == "binary"
         @protocol = Thrift::BinaryProtocol.new(transportFactory)
-      elsif $protocolType == ""
-        @protocol = Thrift::BinaryProtocol.new(transportFactory)
       elsif $protocolType == "compact"
         @protocol = Thrift::CompactProtocol.new(transportFactory)
       elsif $protocolType == "json"
@@ -84,53 +79,81 @@ class SimpleClientTest < Test::Unit::TestCase
   end
   
   def test_void
+    p 'test_void'
     @client.testVoid()
   end
 
   def test_string
+    p 'test_string'
     assert_equal(@client.testString('string'), 'string')
   end
 
+  def test_bool
+    p 'test_bool'
+    assert_equal(@client.testBool(true), true)
+    assert_equal(@client.testBool(false), false)
+  end
+
   def test_byte
-    val = 8
+    p 'test_byte'
+    val = 120
     assert_equal(@client.testByte(val), val)
     assert_equal(@client.testByte(-val), -val)
   end
 
   def test_i32
-    val = 32
+    p 'test_i32'
+    val = 2000000032
     assert_equal(@client.testI32(val), val)
     assert_equal(@client.testI32(-val), -val)
   end
 
   def test_i64
-    val = 64
+    p 'test_i64'
+    val = 9000000000000000064
     assert_equal(@client.testI64(val), val)
     assert_equal(@client.testI64(-val), -val)
   end
 
   def test_double
+    p 'test_double'
     val = 3.14
     assert_equal(@client.testDouble(val), val)
     assert_equal(@client.testDouble(-val), -val)
     assert_kind_of(Float, @client.testDouble(val))
   end
 
-  # TODO: testBinary
+  def test_binary
+    p 'test_binary'
+    val = [42, 0, 142, 242]
+    ret = @client.testBinary(val.pack('C*'))
+    assert_equal(val, ret.bytes.to_a)
+  end
   
   def test_map
+    p 'test_map'
     val = {1 => 1, 2 => 2, 3 => 3}
     assert_equal(@client.testMap(val), val)
     assert_kind_of(Hash, @client.testMap(val))
   end
 
+  def test_string_map
+    p 'test_string_map'
+    val = {'a' => '2', 'b' => 'blah', 'some' => 'thing'}
+    ret = @client.testStringMap(val)
+    assert_equal(val, ret)
+    assert_kind_of(Hash, ret)
+  end
+
   def test_list
+    p 'test_list'
     val = [1,2,3,4,5]
     assert_equal(@client.testList(val), val)
     assert_kind_of(Array, @client.testList(val))
   end
 
   def test_enum
+    p 'test_enum'
     val = Thrift::Test::Numberz::SIX
     ret = @client.testEnum(val)
 
@@ -139,6 +162,7 @@ class SimpleClientTest < Test::Unit::TestCase
   end
 
   def test_typedef
+    p 'test_typedef'
     #UserId  testTypedef(1: UserId thing),
     assert_equal(@client.testTypedef(309858235082523), 309858235082523)
     assert_kind_of(Fixnum, @client.testTypedef(309858235082523))
@@ -146,6 +170,7 @@ class SimpleClientTest < Test::Unit::TestCase
   end
 
   def test_set
+    p 'test_set'
     val = Set.new([1,2,3])
     assert_equal(@client.testSet(val), val)
     assert_kind_of(Set, @client.testSet(val))
@@ -156,22 +181,28 @@ class SimpleClientTest < Test::Unit::TestCase
   end
 
   def test_struct
+    p 'test_struct'
     ret = @client.testStruct(get_struct)
 
-    assert_nil(ret.byte_thing, nil)
-    assert_nil(ret.i64_thing, nil)
+    # TODO: not sure what unspecified "default" requiredness values should be
+    assert(ret.byte_thing == nil || ret.byte_thing == 0)
+    assert(ret.i64_thing == nil || ret.i64_thing == 0)
+
     assert_equal(ret.string_thing, 'hi!')
     assert_equal(ret.i32_thing, 4)
     assert_kind_of(Thrift::Test::Xtruct, ret)
   end
 
   def test_nest
+    p 'test_nest'
     struct2 = Thrift::Test::Xtruct2.new({'struct_thing' => get_struct, 'i32_thing' => 10})
 
     ret = @client.testNest(struct2)
 
-    assert_nil(ret.struct_thing.byte_thing, nil)
-    assert_nil(ret.struct_thing.i64_thing, nil)
+    # TODO: not sure what unspecified "default" requiredness values should be
+    assert(ret.struct_thing.byte_thing == nil || ret.struct_thing.byte_thing == 0)
+    assert(ret.struct_thing.i64_thing == nil || ret.struct_thing.i64_thing == 0)
+
     assert_equal(ret.struct_thing.string_thing, 'hi!')
     assert_equal(ret.struct_thing.i32_thing, 4)
     assert_equal(ret.i32_thing, 10)
@@ -181,49 +212,87 @@ class SimpleClientTest < Test::Unit::TestCase
   end
 
   def test_insanity
+    p 'test_insanity'
     insane = Thrift::Test::Insanity.new({
-      'userMap' => { Thrift::Test::Numberz::ONE => 44 },
-      'xtructs' => [get_struct,
+      'userMap' => {
+        Thrift::Test::Numberz::FIVE => 5,
+        Thrift::Test::Numberz::EIGHT => 8,
+      },
+      'xtructs' => [
+        Thrift::Test::Xtruct.new({
+          'string_thing' => 'Goodbye4',
+          'byte_thing' => 4,
+          'i32_thing' => 4,
+          'i64_thing' => 4,
+        }),
         Thrift::Test::Xtruct.new({
-          'string_thing' => 'hi again',
-          'i32_thing' => 12
+          'string_thing' => 'Hello2',
+          'byte_thing' => 2,
+          'i32_thing' => 2,
+          'i64_thing' => 2,
         })
       ]
     })
 
     ret = @client.testInsanity(insane)
 
-    assert_not_nil(ret[44])
-    assert_not_nil(ret[44][1])
-
-    struct = ret[44][1]
+    assert_equal(insane, ret[1][2])
+    assert_equal(insane, ret[1][3])
 
-    assert_equal(struct.userMap[Thrift::Test::Numberz::ONE], 44)
-    assert_equal(struct.xtructs[1].string_thing, 'hi again')
-    assert_equal(struct.xtructs[1].i32_thing, 12)
-
-    assert_kind_of(Hash, struct.userMap)
-    assert_kind_of(Array, struct.xtructs)
-    assert_kind_of(Thrift::Test::Insanity, struct)
+    assert(ret[2][6].userMap == nil || ret[2][6].userMap.length == 0)
+    assert(ret[2][6].xtructs == nil || ret[2][6].xtructs.length == 0)
   end
 
   def test_map_map
+    p 'test_map_map'
     ret = @client.testMapMap(4)
     assert_kind_of(Hash, ret)
-    assert_equal(ret, { 4 => { 4 => 4}})
+    expected = {
+      -4 => {
+        -4 => -4,
+        -3 => -3,
+        -2 => -2,
+        -1 => -1,
+      },
+      4 => {
+        4 => 4,
+        3 => 3,
+        2 => 2,
+        1 => 1,
+      }
+    }
+    assert_equal(expected, ret)
+  end
+
+  def test_multi
+    p 'test_multi'
+    ret = @client.testMulti(42, 4242, 424242, {1 => 'blah', 2 => 'thing'}, Thrift::Test::Numberz::EIGHT, 24)
+    expected = Thrift::Test::Xtruct.new({
+      :string_thing => 'Hello2',
+      :byte_thing =>   42,
+      :i32_thing =>    4242,
+      :i64_thing =>    424242
+    })
+    assert_equal(expected, ret)
   end
 
   def test_exception
+    p 'test_exception'
     assert_raise Thrift::Test::Xception do
       @client.testException('Xception')
     end
-#    assert_raise Thrift::TException do
-#      @client.testException('TException')
-#    end
-    assert_equal( @client.testException('test'), "test")
+    begin
+      @client.testException('TException')
+    rescue => e
+      assert e.class.ancestors.include?(Thrift::Exception)
+    end
+    assert_nothing_raised do
+      @client.testException('test')
+    end
   end
 
   def test_multi_exception
+    p 'test_multi_exception'
     assert_raise Thrift::Test::Xception do
       @client.testMultiException("Xception", "test 1")
     end
@@ -234,6 +303,7 @@ class SimpleClientTest < Test::Unit::TestCase
   end
 
   def test_oneway
+    p 'test_oneway'
     time1 = Time.now.to_f
     @client.testOneway(3)
     time2 = Time.now.to_f

http://git-wip-us.apache.org/repos/asf/thrift/blob/68238297/test/rb/integration/TestServer.rb
----------------------------------------------------------------------
diff --git a/test/rb/integration/TestServer.rb b/test/rb/integration/TestServer.rb
index 64949bc..0021e2a 100755
--- a/test/rb/integration/TestServer.rb
+++ b/test/rb/integration/TestServer.rb
@@ -24,10 +24,11 @@ $:.push File.dirname(__FILE__) + '/..'
 require 'test_helper'
 require 'thrift'
 require 'thrift_test'
+require 'thrift_test_types'
 
 class SimpleHandler
-  [:testVoid, :testString, :testByte, :testI32, :testI64, :testDouble, :testBinary,
-   :testStruct, :testMap, :testSet, :testList, :testNest,
+  [:testVoid, :testString, :testBool, :testByte, :testI32, :testI64, :testDouble, :testBinary,
+   :testStruct, :testMap, :testStringMap, :testSet, :testList, :testNest, :testEnum, :testTypedef,
    :testEnum, :testTypedef, :testMultiException].each do |meth|
 
     define_method(meth) do |thing|
@@ -40,42 +41,67 @@ class SimpleHandler
   end
 
   def testInsanity(thing)
-    num, uid = thing.userMap.find { true }
-    return {uid => {num => thing}}
+    return {
+      1 => {
+        2 => thing,
+        3 => thing
+      },
+      2 => {
+        6 => Thrift::Test::Insanity::new()
+      }
+    }
   end
 
   def testMapMap(thing)
-    return {thing => {thing => thing}}
+    return {
+      -4 => {
+        -4 => -4,
+        -3 => -3,
+        -2 => -2,
+        -1 => -1,
+      },
+      4 => {
+        4 => 4,
+        3 => 3,
+        2 => 2,
+        1 => 1,
+      }
+    }
   end
 
-  def testEnum(thing)
-    return thing
-  end
-
-  def testTypedef(thing)
-    return thing
+  def testMulti(arg0, arg1, arg2, arg3, arg4, arg5)
+    return Thrift::Test::Xtruct.new({
+      'string_thing' => 'Hello2',
+      'byte_thing' => arg0,
+      'i32_thing' => arg1,
+      'i64_thing' => arg2,
+    })
   end
 
   def testException(thing)
     if thing == "Xception"
-      raise Thrift::Test::Xception, :message => thing
+      raise Thrift::Test::Xception, :errorCode => 1001, :message => thing
     elsif thing == "TException"
-      raise Thrift::Test::TException, :message => thing
+      raise Thrift::Exception, :message => thing
     else
-      return arg1
+      # no-op
     end
   end
 
   def testMultiException(arg0, arg1)
     if arg0 == "Xception2"
-      raise Thrift::Test::Xception2, :message => 'This is an Xception2'
+      raise Thrift::Test::Xception2, :errorCode => 2002, :struct_thing => ::Thrift::Test::Xtruct.new({ :string_thing => 'This is an Xception2' })
     elsif arg0 == "Xception"
-      raise Thrift::Test::Xception, :message => 'This is an Xception'
+      raise Thrift::Test::Xception, :errorCode => 1001, :message => 'This is an Xception'
     else
-      return arg1
+      return ::Thrift::Test::Xtruct.new({'string_thing' => arg1})
     end
   end
 
+  def testOneway(arg0)
+    sleep(arg0)
+  end
+
 end
 
 protocol = "binary"