From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/jaegertracing/thrift/test/rb/Gemfile | 7 + src/jaegertracing/thrift/test/rb/Makefile.am | 37 ++ .../test/rb/benchmarks/protocol_benchmark.rb | 174 ++++++++++ .../test/rb/core/test_backwards_compatability.rb | 30 ++ .../thrift/test/rb/core/test_exceptions.rb | 30 ++ .../test/rb/core/transport/test_transport.rb | 70 ++++ .../thrift/test/rb/fixtures/structs.rb | 298 ++++++++++++++++ .../thrift/test/rb/generation/test_enum.rb | 34 ++ .../thrift/test/rb/generation/test_recursive.rb | 41 +++ .../thrift/test/rb/generation/test_struct.rb | 48 +++ .../thrift/test/rb/integration/TestClient.rb | 381 +++++++++++++++++++++ .../thrift/test/rb/integration/TestServer.rb | 188 ++++++++++ src/jaegertracing/thrift/test/rb/test_helper.rb | 35 ++ src/jaegertracing/thrift/test/rb/test_suite.rb | 20 ++ 14 files changed, 1393 insertions(+) create mode 100644 src/jaegertracing/thrift/test/rb/Gemfile create mode 100644 src/jaegertracing/thrift/test/rb/Makefile.am create mode 100644 src/jaegertracing/thrift/test/rb/benchmarks/protocol_benchmark.rb create mode 100644 src/jaegertracing/thrift/test/rb/core/test_backwards_compatability.rb create mode 100644 src/jaegertracing/thrift/test/rb/core/test_exceptions.rb create mode 100644 src/jaegertracing/thrift/test/rb/core/transport/test_transport.rb create mode 100644 src/jaegertracing/thrift/test/rb/fixtures/structs.rb create mode 100644 src/jaegertracing/thrift/test/rb/generation/test_enum.rb create mode 100644 src/jaegertracing/thrift/test/rb/generation/test_recursive.rb create mode 100644 src/jaegertracing/thrift/test/rb/generation/test_struct.rb create mode 100755 src/jaegertracing/thrift/test/rb/integration/TestClient.rb create mode 100755 src/jaegertracing/thrift/test/rb/integration/TestServer.rb create mode 100644 src/jaegertracing/thrift/test/rb/test_helper.rb create mode 100644 src/jaegertracing/thrift/test/rb/test_suite.rb (limited to 'src/jaegertracing/thrift/test/rb') diff --git a/src/jaegertracing/thrift/test/rb/Gemfile b/src/jaegertracing/thrift/test/rb/Gemfile new file mode 100644 index 000000000..4ff0539fd --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/Gemfile @@ -0,0 +1,7 @@ +source "http://rubygems.org" + +require "rubygems" + +gem 'rack', '~> 2.0', '>= 2.0.4' +gem 'thin', '~> 1.7', '>= 1.7.2' +gem 'test-unit', '~> 3.2', '>= 3.2.7' diff --git a/src/jaegertracing/thrift/test/rb/Makefile.am b/src/jaegertracing/thrift/test/rb/Makefile.am new file mode 100644 index 000000000..39109340d --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/Makefile.am @@ -0,0 +1,37 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +stubs: $(THRIFT) ../ThriftTest.thrift ../SmallTest.thrift + $(THRIFT) --gen rb ../ThriftTest.thrift + $(THRIFT) --gen rb ../SmallTest.thrift + $(THRIFT) --gen rb ../Recursive.thrift + +precross: stubs + +check: stubs +if HAVE_BUNDLER + $(BUNDLER) install + $(BUNDLER) exec $(RUBY) -I. test_suite.rb +endif + +clean-local: + $(RM) -r gen-rb/ + +dist-hook: + $(RM) -r $(distdir)/gen-rb/ diff --git a/src/jaegertracing/thrift/test/rb/benchmarks/protocol_benchmark.rb b/src/jaegertracing/thrift/test/rb/benchmarks/protocol_benchmark.rb new file mode 100644 index 000000000..05a8ee534 --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/benchmarks/protocol_benchmark.rb @@ -0,0 +1,174 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. .. .. lib rb lib]) +$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. .. .. lib rb ext]) + +require 'thrift' + +require 'benchmark' +require 'rubygems' +require 'set' +require 'pp' + +# require 'ruby-debug' +# require 'ruby-prof' + +require File.join(File.dirname(__FILE__), '../fixtures/structs') + +transport1 = Thrift::MemoryBuffer.new +ruby_binary_protocol = Thrift::BinaryProtocol.new(transport1) + +transport2 = Thrift::MemoryBuffer.new +c_fast_binary_protocol = Thrift::BinaryProtocolAccelerated.new(transport2) + + +ooe = Fixtures::Structs::OneOfEach.new +ooe.im_true = true +ooe.im_false = false +ooe.a_bite = -42 +ooe.integer16 = 27000 +ooe.integer32 = 1<<24 +ooe.integer64 = 6000 * 1000 * 1000 +ooe.double_precision = Math::PI +ooe.some_characters = "Debug THIS!" +ooe.zomg_unicode = "\xd7\n\a\t" + +n1 = Fixtures::Structs::Nested1.new +n1.a_list = [] +n1.a_list << ooe << ooe << ooe << ooe +n1.i32_map = {} +n1.i32_map[1234] = ooe +n1.i32_map[46345] = ooe +n1.i32_map[-34264] = ooe +n1.i64_map = {} +n1.i64_map[43534986783945] = ooe +n1.i64_map[-32434639875122] = ooe +n1.dbl_map = {} +n1.dbl_map[324.65469834] = ooe +n1.dbl_map[-9458672340.4986798345112] = ooe +n1.str_map = {} +n1.str_map['sdoperuix'] = ooe +n1.str_map['pwoerxclmn'] = ooe + +n2 = Fixtures::Structs::Nested2.new +n2.a_list = [] +n2.a_list << n1 << n1 << n1 << n1 << n1 +n2.i32_map = {} +n2.i32_map[398345] = n1 +n2.i32_map[-2345] = n1 +n2.i32_map[12312] = n1 +n2.i64_map = {} +n2.i64_map[2349843765934] = n1 +n2.i64_map[-123234985495] = n1 +n2.i64_map[0] = n1 +n2.dbl_map = {} +n2.dbl_map[23345345.38927834] = n1 +n2.dbl_map[-1232349.5489345] = n1 +n2.dbl_map[-234984574.23498725] = n1 +n2.str_map = {} +n2.str_map[''] = n1 +n2.str_map['sdflkertpioux'] = n1 +n2.str_map['sdfwepwdcjpoi'] = n1 + +n3 = Fixtures::Structs::Nested3.new +n3.a_list = [] +n3.a_list << n2 << n2 << n2 << n2 << n2 +n3.i32_map = {} +n3.i32_map[398345] = n2 +n3.i32_map[-2345] = n2 +n3.i32_map[12312] = n2 +n3.i64_map = {} +n3.i64_map[2349843765934] = n2 +n3.i64_map[-123234985495] = n2 +n3.i64_map[0] = n2 +n3.dbl_map = {} +n3.dbl_map[23345345.38927834] = n2 +n3.dbl_map[-1232349.5489345] = n2 +n3.dbl_map[-234984574.23498725] = n2 +n3.str_map = {} +n3.str_map[''] = n2 +n3.str_map['sdflkertpioux'] = n2 +n3.str_map['sdfwepwdcjpoi'] = n2 + +n4 = Fixtures::Structs::Nested4.new +n4.a_list = [] +n4.a_list << n3 +n4.i32_map = {} +n4.i32_map[-2345] = n3 +n4.i64_map = {} +n4.i64_map[2349843765934] = n3 +n4.dbl_map = {} +n4.dbl_map[-1232349.5489345] = n3 +n4.str_map = {} +n4.str_map[''] = n3 + + +# prof = RubyProf.profile do +# n4.write(c_fast_binary_protocol) +# Fixtures::Structs::Nested4.new.read(c_fast_binary_protocol) +# end +# +# printer = RubyProf::GraphHtmlPrinter.new(prof) +# printer.print(STDOUT, :min_percent=>0) + +Benchmark.bmbm do |x| + x.report("ruby write large (1MB) structure once") do + n4.write(ruby_binary_protocol) + end + + x.report("ruby read large (1MB) structure once") do + Fixtures::Structs::Nested4.new.read(ruby_binary_protocol) + end + + x.report("c write large (1MB) structure once") do + n4.write(c_fast_binary_protocol) + end + + x.report("c read large (1MB) structure once") do + Fixtures::Structs::Nested4.new.read(c_fast_binary_protocol) + end + + + + x.report("ruby write 10_000 small structures") do + 10_000.times do + ooe.write(ruby_binary_protocol) + end + end + + x.report("ruby read 10_000 small structures") do + 10_000.times do + Fixtures::Structs::OneOfEach.new.read(ruby_binary_protocol) + end + end + + x.report("c write 10_000 small structures") do + 10_000.times do + ooe.write(c_fast_binary_protocol) + end + end + + x.report("c read 10_000 small structures") do + 10_000.times do + Fixtures::Structs::OneOfEach.new.read(c_fast_binary_protocol) + end + end + +end diff --git a/src/jaegertracing/thrift/test/rb/core/test_backwards_compatability.rb b/src/jaegertracing/thrift/test/rb/core/test_backwards_compatability.rb new file mode 100644 index 000000000..0577515d3 --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/core/test_backwards_compatability.rb @@ -0,0 +1,30 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require File.join(File.dirname(__FILE__), '../test_helper') + +require 'thrift' + +class TestThriftException < Test::Unit::TestCase + def test_has_accessible_message + msg = "hi there thrift" + assert_equal msg, Thrift::Exception.new(msg).message + end +end + diff --git a/src/jaegertracing/thrift/test/rb/core/test_exceptions.rb b/src/jaegertracing/thrift/test/rb/core/test_exceptions.rb new file mode 100644 index 000000000..f41587a7b --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/core/test_exceptions.rb @@ -0,0 +1,30 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require File.join(File.dirname(__FILE__), '../test_helper') + +require 'thrift' + +class TestException < Test::Unit::TestCase + def test_has_accessible_message + msg = "hi there thrift" + assert_equal msg, Thrift::Exception.new(msg).message + end +end + diff --git a/src/jaegertracing/thrift/test/rb/core/transport/test_transport.rb b/src/jaegertracing/thrift/test/rb/core/transport/test_transport.rb new file mode 100644 index 000000000..37afa858b --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/core/transport/test_transport.rb @@ -0,0 +1,70 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require File.join(File.dirname(__FILE__), '../../test_helper') + +require 'thrift' + +class DummyTransport < Thrift::BaseTransport + def initialize(data) + @data = data + end + + def read(size) + @data.slice!(0, size) + end +end + +# TTransport is basically an abstract class, but isn't raising NotImplementedError +class TestThriftTransport < Test::Unit::TestCase + def setup + @trans = Thrift::BaseTransport.new + end + + def test_open? + assert_nil @trans.open? + end + + def test_open + assert_nil @trans.open + end + + def test_close + assert_nil @trans.close + end + + # TODO: + # This doesn't necessarily test he right thing. + # It _looks_ like read isn't guaranteed to return the length + # you ask for and read_all is. This means our test needs to check + # for blocking. -- Kevin Clark 3/27/08 + def test_read_all + # Implements read + t = DummyTransport.new("hello") + assert_equal "hello", t.read_all(5) + end + + def test_write + assert_nil @trans.write(5) # arbitrary value + end + + def test_flush + assert_nil @trans.flush + end +end diff --git a/src/jaegertracing/thrift/test/rb/fixtures/structs.rb b/src/jaegertracing/thrift/test/rb/fixtures/structs.rb new file mode 100644 index 000000000..ebbeb0a7d --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/fixtures/structs.rb @@ -0,0 +1,298 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'thrift' + +module Fixtures + module Structs + class OneBool + include Thrift::Struct + attr_accessor :bool + FIELDS = { + 1 => {:type => Thrift::Types::BOOL, :name => 'bool'} + } + + def validate + end + end + + class OneByte + include Thrift::Struct + attr_accessor :byte + FIELDS = { + 1 => {:type => Thrift::Types::BYTE, :name => 'byte'} + } + + def validate + end + end + + class OneI16 + include Thrift::Struct + attr_accessor :i16 + FIELDS = { + 1 => {:type => Thrift::Types::I16, :name => 'i16'} + } + + def validate + end + end + + class OneI32 + include Thrift::Struct + attr_accessor :i32 + FIELDS = { + 1 => {:type => Thrift::Types::I32, :name => 'i32'} + } + + def validate + end + end + + class OneI64 + include Thrift::Struct + attr_accessor :i64 + FIELDS = { + 1 => {:type => Thrift::Types::I64, :name => 'i64'} + } + + def validate + end + end + + class OneDouble + include Thrift::Struct + attr_accessor :double + FIELDS = { + 1 => {:type => Thrift::Types::DOUBLE, :name => 'double'} + } + + def validate + end + end + + class OneString + include Thrift::Struct + attr_accessor :string + FIELDS = { + 1 => {:type => Thrift::Types::STRING, :name => 'string'} + } + + def validate + end + end + + class OneMap + include Thrift::Struct + attr_accessor :map + FIELDS = { + 1 => {:type => Thrift::Types::MAP, :name => 'map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRING}} + } + + def validate + end + end + + class NestedMap + include Thrift::Struct + attr_accessor :map + FIELDS = { + 0 => {:type => Thrift::Types::MAP, :name => 'map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::I32}}} + } + + def validate + end + end + + class OneList + include Thrift::Struct + attr_accessor :list + FIELDS = { + 1 => {:type => Thrift::Types::LIST, :name => 'list', :element => {:type => Thrift::Types::STRING}} + } + + def validate + end + end + + class NestedList + include Thrift::Struct + attr_accessor :list + FIELDS = { + 0 => {:type => Thrift::Types::LIST, :name => 'list', :element => {:type => Thrift::Types::LIST, :element => { :type => Thrift::Types::I32 } } } + } + + def validate + end + end + + class OneSet + include Thrift::Struct + attr_accessor :set + FIELDS = { + 1 => {:type => Thrift::Types::SET, :name => 'set', :element => {:type => Thrift::Types::STRING}} + } + + def validate + end + end + + class NestedSet + include Thrift::Struct + attr_accessor :set + FIELDS = { + 1 => {:type => Thrift::Types::SET, :name => 'set', :element => {:type => Thrift::Types::SET, :element => { :type => Thrift::Types::STRING } }} + } + + def validate + end + end + + # struct OneOfEach { + # 1: bool im_true, + # 2: bool im_false, + # 3: byte a_bite, + # 4: i16 integer16, + # 5: i32 integer32, + # 6: i64 integer64, + # 7: double double_precision, + # 8: string some_characters, + # 9: string zomg_unicode, + # 10: bool what_who, + # 11: binary base64, + # } + class OneOfEach + include Thrift::Struct + attr_accessor :im_true, :im_false, :a_bite, :integer16, :integer32, :integer64, :double_precision, :some_characters, :zomg_unicode, :what_who, :base64 + FIELDS = { + 1 => {:type => Thrift::Types::BOOL, :name => 'im_true'}, + 2 => {:type => Thrift::Types::BOOL, :name => 'im_false'}, + 3 => {:type => Thrift::Types::BYTE, :name => 'a_bite'}, + 4 => {:type => Thrift::Types::I16, :name => 'integer16'}, + 5 => {:type => Thrift::Types::I32, :name => 'integer32'}, + 6 => {:type => Thrift::Types::I64, :name => 'integer64'}, + 7 => {:type => Thrift::Types::DOUBLE, :name => 'double_precision'}, + 8 => {:type => Thrift::Types::STRING, :name => 'some_characters'}, + 9 => {:type => Thrift::Types::STRING, :name => 'zomg_unicode'}, + 10 => {:type => Thrift::Types::BOOL, :name => 'what_who'}, + 11 => {:type => Thrift::Types::STRING, :name => 'base64'} + } + + # Added for assert_equal + def ==(other) + [:im_true, :im_false, :a_bite, :integer16, :integer32, :integer64, :double_precision, :some_characters, :zomg_unicode, :what_who, :base64].each do |f| + var = "@#{f}" + return false if instance_variable_get(var) != other.instance_variable_get(var) + end + true + end + + def validate + end + end + + # struct Nested1 { + # 1: list a_list + # 2: map i32_map + # 3: map i64_map + # 4: map dbl_map + # 5: map str_map + # } + class Nested1 + include Thrift::Struct + attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map + FIELDS = { + 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => OneOfEach}}, + 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}}, + 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}}, + 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}}, + 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}} + } + + def validate + end + end + + # struct Nested2 { + # 1: list a_list + # 2: map i32_map + # 3: map i64_map + # 4: map dbl_map + # 5: map str_map + # } + class Nested2 + include Thrift::Struct + attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map + FIELDS = { + 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => Nested1}}, + 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}}, + 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}}, + 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}}, + 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}} + } + + def validate + end + end + + # struct Nested3 { + # 1: list a_list + # 2: map i32_map + # 3: map i64_map + # 4: map dbl_map + # 5: map str_map + # } + class Nested3 + include Thrift::Struct + attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map + FIELDS = { + 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => Nested2}}, + 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}}, + 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}}, + 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}}, + 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}} + } + + def validate + end + end + + # struct Nested4 { + # 1: list a_list + # 2: map i32_map + # 3: map i64_map + # 4: map dbl_map + # 5: map str_map + # } + class Nested4 + include Thrift::Struct + attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map + FIELDS = { + 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => Nested3}}, + 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}}, + 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}}, + 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}}, + 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}} + } + + def validate + end + end + end +end diff --git a/src/jaegertracing/thrift/test/rb/generation/test_enum.rb b/src/jaegertracing/thrift/test/rb/generation/test_enum.rb new file mode 100644 index 000000000..607ea66b9 --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/generation/test_enum.rb @@ -0,0 +1,34 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require File.join(File.dirname(__FILE__), '../test_helper') +require 'thrift_test' + +class TestEnumGeneration < Test::Unit::TestCase + include Thrift::Test + def test_enum_valid_values + assert_equal(Numberz::VALID_VALUES, Set.new([Numberz::ONE, Numberz::TWO, Numberz::THREE, Numberz::FIVE, Numberz::SIX, Numberz::EIGHT])) + end + + def test_enum_hash + Numberz::VALID_VALUES.each do |value| + assert_equal(Numberz.const_get(Numberz::VALUE_MAP[value].to_sym), value) + end + end +end \ No newline at end of file diff --git a/src/jaegertracing/thrift/test/rb/generation/test_recursive.rb b/src/jaegertracing/thrift/test/rb/generation/test_recursive.rb new file mode 100644 index 000000000..e912f72f5 --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/generation/test_recursive.rb @@ -0,0 +1,41 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require File.join(File.dirname(__FILE__), '../test_helper') +require 'recursive_types' + +class TestRecursiveGeneration < Test::Unit::TestCase + CHILD_ITEM = "child item" + PARENT_ITEM = "parent item" + + def test_can_create_recursive_tree + + child_tree = RecTree.new + child_tree.item = CHILD_ITEM + + parent_tree = RecTree.new + parent_tree.item = PARENT_ITEM + parent_tree.children = [child_tree] + + assert_equal(PARENT_ITEM, parent_tree.item) + assert_equal(1, parent_tree.children.length) + assert_equal(CHILD_ITEM, parent_tree.children.first.item) + assert_nil(parent_tree.children.first.children) + end +end diff --git a/src/jaegertracing/thrift/test/rb/generation/test_struct.rb b/src/jaegertracing/thrift/test/rb/generation/test_struct.rb new file mode 100644 index 000000000..3bd4fc9bb --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/generation/test_struct.rb @@ -0,0 +1,48 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require File.join(File.dirname(__FILE__), '../test_helper') +require 'small_service' + +class TestStructGeneration < Test::Unit::TestCase + + def test_default_values + hello = TestNamespace::Hello.new + + assert_kind_of(TestNamespace::Hello, hello) + assert_nil(hello.complexer) + + assert_equal(hello.simple, 53) + assert_equal(hello.words, 'words') + + assert_kind_of(TestNamespace::Goodbyez, hello.thinz) + assert_equal(hello.thinz.val, 36632) + + assert_kind_of(Hash, hello.complex) + assert_equal(hello.complex, { 6243 => 632, 2355 => 532, 23 => 532}) + + bool_passer = TestNamespace::BoolPasser.new(:value => false) + assert_equal false, bool_passer.value + end + + def test_goodbyez + assert_equal(TestNamespace::Goodbyez.new.val, 325) + end + +end diff --git a/src/jaegertracing/thrift/test/rb/integration/TestClient.rb b/src/jaegertracing/thrift/test/rb/integration/TestClient.rb new file mode 100755 index 000000000..639aca99e --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/integration/TestClient.rb @@ -0,0 +1,381 @@ +#!/usr/bin/env ruby +# encoding: utf-8 + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +$:.push File.dirname(__FILE__) + '/..' + +require 'test_helper' +require 'thrift' +require 'thrift_test' + +$domain_socket = nil +$host = "localhost" +$port = 9090 +$protocolType = "binary" +$ssl = false +$transport = "buffered" + +ARGV.each do|a| + if a == "--help" + puts "Allowed options:" + puts "\t -h [ --help ] \t produce help message" + puts "\t--domain-socket arg (=) \t Unix domain socket path" + puts "\t--host arg (=localhost) \t Host to connect \t not valid with domain-socket" + puts "\t--port arg (=9090) \t Port number to listen \t not valid with domain-socket" + puts "\t--protocol arg (=binary) \t protocol: accel, binary, compact, json" + puts "\t--ssl \t use ssl \t not valid with domain-socket" + puts "\t--transport arg (=buffered) transport: buffered, framed, http" + exit + elsif a.start_with?("--domain-socket") + $domain_socket = a.split("=")[1] + elsif a.start_with?("--host") + $host = a.split("=")[1] + elsif a.start_with?("--protocol") + $protocolType = a.split("=")[1] + elsif a == "--ssl" + $ssl = true + elsif a.start_with?("--transport") + $transport = a.split("=")[1] + elsif a.start_with?("--port") + $port = a.split("=")[1].to_i + end +end + +class SimpleClientTest < Test::Unit::TestCase + def setup + unless @socket + if $domain_socket.to_s.strip.empty? + if $ssl + # the working directory for ruby crosstest is test/rb/gen-rb + keysDir = File.join(File.dirname(File.dirname(Dir.pwd)), "keys") + ctx = OpenSSL::SSL::SSLContext.new + ctx.ca_file = File.join(keysDir, "CA.pem") + ctx.cert = OpenSSL::X509::Certificate.new(File.open(File.join(keysDir, "client.crt"))) + ctx.cert_store = OpenSSL::X509::Store.new + ctx.cert_store.add_file(File.join(keysDir, 'server.pem')) + ctx.key = OpenSSL::PKey::RSA.new(File.open(File.join(keysDir, "client.key"))) + ctx.options = OpenSSL::SSL::OP_NO_SSLv2 | OpenSSL::SSL::OP_NO_SSLv3 + ctx.ssl_version = :SSLv23 + ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER + @socket = Thrift::SSLSocket.new($host, $port, nil, ctx) + else + @socket = Thrift::Socket.new($host, $port) + end + else + @socket = Thrift::UNIXSocket.new($domain_socket) + end + + if $transport == "buffered" + transportFactory = Thrift::BufferedTransport.new(@socket) + elsif $transport == "framed" + transportFactory = Thrift::FramedTransport.new(@socket) + else + raise 'Unknown transport type' + end + + if $protocolType == "binary" + @protocol = Thrift::BinaryProtocol.new(transportFactory) + elsif $protocolType == "compact" + @protocol = Thrift::CompactProtocol.new(transportFactory) + elsif $protocolType == "json" + @protocol = Thrift::JsonProtocol.new(transportFactory) + elsif $protocolType == "accel" + @protocol = Thrift::BinaryProtocolAccelerated.new(transportFactory) + else + raise 'Unknown protocol type' + end + @client = Thrift::Test::ThriftTest::Client.new(@protocol) + @socket.open + end + end + + def teardown + @socket.close + end + + def test_void + p 'test_void' + @client.testVoid() + end + + def test_string + p 'test_string' + test_string = + 'quote: \" backslash:' + + ' forwardslash-escaped: \/ ' + + ' backspace: \b formfeed: \f newline: \n return: \r tab: ' + + ' now-all-of-them-together: "\\\/\b\n\r\t' + + ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><' + + ' char-to-test-json-parsing: ]] \"]] \\" }}}{ [[[ ' + test_string = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " + + "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " + + "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " + + "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, " + + "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, " + + "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, " + + "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, " + + "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, " + + "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, " + + "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, " + + "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, " + + "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, " + + "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, " + + "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa " + + "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa " + + "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪" + + "Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, " + + "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, " + + "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, " + + "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple " + + "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, " + + "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, " + + "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " + + "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " + + "Bân-lâm-gú, 粵語" + + result_string = @client.testString(test_string) + assert_equal(test_string, result_string.force_encoding(Encoding::UTF_8)) + end + + def test_bool + p 'test_bool' + assert_equal(@client.testBool(true), true) + assert_equal(@client.testBool(false), false) + end + + def test_byte + p 'test_byte' + val = 120 + assert_equal(@client.testByte(val), val) + assert_equal(@client.testByte(-val), -val) + end + + def test_i32 + p 'test_i32' + val = 2000000032 + assert_equal(@client.testI32(val), val) + assert_equal(@client.testI32(-val), -val) + end + + def test_i64 + 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.14159265358979323846 + assert_equal(@client.testDouble(val), val) + assert_equal(@client.testDouble(-val), -val) + assert_kind_of(Float, @client.testDouble(val)) + end + + def test_binary + p 'test_binary' + val = (0...256).reverse_each.to_a + 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) + + assert_equal(ret, 6) + assert_kind_of(Fixnum, ret) + 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)) + true + 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)) + end + + def get_struct + Thrift::Test::Xtruct.new({'string_thing' => 'hi!', 'i32_thing' => 4 }) + end + + def test_struct + p 'test_struct' + ret = @client.testStruct(get_struct) + + # 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) + + # 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) + + assert_kind_of(Thrift::Test::Xtruct, ret.struct_thing) + assert_kind_of(Thrift::Test::Xtruct2, ret) + end + + def test_insanity + p 'test_insanity' + insane = Thrift::Test::Insanity.new({ + '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' => 'Hello2', + 'byte_thing' => 2, + 'i32_thing' => 2, + 'i64_thing' => 2, + }) + ] + }) + + ret = @client.testInsanity(insane) + + assert_equal(insane, ret[1][2]) + assert_equal(insane, ret[1][3]) + + 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) + 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 + 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 + assert_raise Thrift::Test::Xception2 do + @client.testMultiException("Xception2", "test 2") + end + assert_equal( @client.testMultiException("Success", "test 3").string_thing, "test 3") + end + + def test_oneway + p 'test_oneway' + time1 = Time.now.to_f + @client.testOneway(1) + time2 = Time.now.to_f + assert_operator (time2-time1), :<, 0.1 + end + +end + diff --git a/src/jaegertracing/thrift/test/rb/integration/TestServer.rb b/src/jaegertracing/thrift/test/rb/integration/TestServer.rb new file mode 100755 index 000000000..7caf6a8cb --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/integration/TestServer.rb @@ -0,0 +1,188 @@ +#!/usr/bin/env ruby + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +$:.push File.dirname(__FILE__) + '/..' + +require 'test_helper' +require 'thrift' +require 'thrift_test' +require 'thrift_test_types' + +class SimpleHandler + [: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| + p meth + p thing + thing + end + + end + + def testVoid() + end + + def testInsanity(thing) + return { + 1 => { + 2 => thing, + 3 => thing + }, + 2 => { + 6 => Thrift::Test::Insanity::new() + } + } + end + + def testMapMap(thing) + return { + -4 => { + -4 => -4, + -3 => -3, + -2 => -2, + -1 => -1, + }, + 4 => { + 4 => 4, + 3 => 3, + 2 => 2, + 1 => 1, + } + } + end + + 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, :errorCode => 1001, :message => thing + elsif thing == "TException" + raise Thrift::Exception, :message => thing + else + # no-op + end + end + + def testMultiException(arg0, arg1) + if arg0 == "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, :errorCode => 1001, :message => 'This is an Xception' + else + return ::Thrift::Test::Xtruct.new({'string_thing' => arg1}) + end + end + + def testOneway(arg0) + sleep(arg0) + end + +end + +domain_socket = nil +port = 9090 +protocol = "binary" +@protocolFactory = nil +ssl = false +transport = "buffered" +@transportFactory = nil + +ARGV.each do|a| + if a == "--help" + puts "Allowed options:" + puts "\t -h [ --help ] \t produce help message" + puts "\t--domain-socket arg (=) \t Unix domain socket path" + puts "\t--port arg (=9090) \t Port number to listen \t not valid with domain-socket" + puts "\t--protocol arg (=binary) \t protocol: accel, binary, compact, json" + puts "\t--ssl \t use ssl \t not valid with domain-socket" + puts "\t--transport arg (=buffered) transport: buffered, framed, http" + exit + elsif a.start_with?("--domain-socket") + domain_socket = a.split("=")[1] + elsif a.start_with?("--protocol") + protocol = a.split("=")[1] + elsif a == "--ssl" + ssl = true + elsif a.start_with?("--transport") + transport = a.split("=")[1] + elsif a.start_with?("--port") + port = a.split("=")[1].to_i + end +end + +if protocol == "binary" || protocol.to_s.strip.empty? + @protocolFactory = Thrift::BinaryProtocolFactory.new +elsif protocol == "compact" + @protocolFactory = Thrift::CompactProtocolFactory.new +elsif protocol == "json" + @protocolFactory = Thrift::JsonProtocolFactory.new +elsif protocol == "accel" + @protocolFactory = Thrift::BinaryProtocolAcceleratedFactory.new +else + raise 'Unknown protocol type' +end + +if transport == "buffered" || transport.to_s.strip.empty? + @transportFactory = Thrift::BufferedTransportFactory.new +elsif transport == "framed" + @transportFactory = Thrift::FramedTransportFactory.new +else + raise 'Unknown transport type' +end + +@handler = SimpleHandler.new +@processor = Thrift::Test::ThriftTest::Processor.new(@handler) +@transport = nil +if domain_socket.to_s.strip.empty? + if ssl + # the working directory for ruby crosstest is test/rb/gen-rb + keysDir = File.join(File.dirname(File.dirname(Dir.pwd)), "keys") + ctx = OpenSSL::SSL::SSLContext.new + ctx.ca_file = File.join(keysDir, "CA.pem") + ctx.cert = OpenSSL::X509::Certificate.new(File.open(File.join(keysDir, "server.crt"))) + ctx.cert_store = OpenSSL::X509::Store.new + ctx.cert_store.add_file(File.join(keysDir, 'client.pem')) + ctx.key = OpenSSL::PKey::RSA.new(File.open(File.join(keysDir, "server.key"))) + ctx.options = OpenSSL::SSL::OP_NO_SSLv2 | OpenSSL::SSL::OP_NO_SSLv3 + ctx.ssl_version = :SSLv23 + ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER + @transport = Thrift::SSLServerSocket.new(nil, port, ctx) + else + @transport = Thrift::ServerSocket.new(port) + end +else + @transport = Thrift::UNIXServerSocket.new(domain_socket) +end + +@server = Thrift::ThreadedServer.new(@processor, @transport, @transportFactory, @protocolFactory) + +puts "Starting TestServer #{@server.to_s}" +@server.serve +puts "done." diff --git a/src/jaegertracing/thrift/test/rb/test_helper.rb b/src/jaegertracing/thrift/test/rb/test_helper.rb new file mode 100644 index 000000000..c1ed779ef --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/test_helper.rb @@ -0,0 +1,35 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +$:.unshift File.dirname(__FILE__) + '/gen-rb' +$:.unshift File.join(File.dirname(__FILE__), '../../lib/rb/lib') +$:.unshift File.join(File.dirname(__FILE__), '../../lib/rb/ext') + +require 'test/unit' + +module Thrift + module Struct + def ==(other) + return false unless other.is_a? self.class + self.class.const_get(:FIELDS).collect {|fid, data| data[:name] }.all? do |field| + send(field) == other.send(field) + end + end + end +end diff --git a/src/jaegertracing/thrift/test/rb/test_suite.rb b/src/jaegertracing/thrift/test/rb/test_suite.rb new file mode 100644 index 000000000..b157c2c50 --- /dev/null +++ b/src/jaegertracing/thrift/test/rb/test_suite.rb @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +Dir["{core,generation}/**/*.rb"].each {|f| require f } \ No newline at end of file -- cgit v1.2.3