Rev 30 | Blame | Compare with Previous | Last modification | View Log | RSS feed
## 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'require 'ThriftTest'class AcceleratedBufferedClientTest < Test::Unit::TestCasedef setupunless @socket@socket = Thrift::Socket.new('localhost', 9090)@protocol = Thrift::BinaryProtocolAccelerated.new(Thrift::BufferedTransport.new(@socket))@client = Thrift::Test::ThriftTest::Client.new(@protocol)@socket.openendenddef test_stringassert_equal(@client.testString('string'), 'string')enddef test_byteval = 8assert_equal(@client.testByte(val), val)assert_equal(@client.testByte(-val), -val)enddef test_i32val = 32assert_equal(@client.testI32(val), val)assert_equal(@client.testI32(-val), -val)enddef test_i64val = 64assert_equal(@client.testI64(val), val)assert_equal(@client.testI64(-val), -val)enddef test_doubleval = 3.14assert_equal(@client.testDouble(val), val)assert_equal(@client.testDouble(-val), -val)assert_kind_of(Float, @client.testDouble(val))enddef test_mapval = {1 => 1, 2 => 2, 3 => 3}assert_equal(@client.testMap(val), val)assert_kind_of(Hash, @client.testMap(val))enddef test_listval = [1,2,3,4,5]assert_equal(@client.testList(val), val)assert_kind_of(Array, @client.testList(val))enddef test_enumval = Thrift::Test::Numberz::SIXret = @client.testEnum(val)assert_equal(ret, 6)assert_kind_of(Fixnum, ret)enddef test_typedef#UserId testTypedef(1: UserId thing),trueenddef test_setval = Set.new([1,2,3])assert_equal(@client.testSet(val), val)assert_kind_of(Set, @client.testSet(val))enddef get_structThrift::Test::Xtruct.new({'string_thing' => 'hi!', 'i32_thing' => 4 })enddef test_structret = @client.testStruct(get_struct)assert_nil(ret.byte_thing, nil)assert_nil(ret.i64_thing, nil)assert_equal(ret.string_thing, 'hi!')assert_equal(ret.i32_thing, 4)assert_kind_of(Thrift::Test::Xtruct, ret)enddef test_neststruct2 = 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)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)enddef test_insaneinsane = Thrift::Test::Insanity.new({'userMap' => { Thrift::Test::Numberz::ONE => 44 },'xtructs' => [get_struct,Thrift::Test::Xtruct.new({'string_thing' => 'hi again','i32_thing' => 12})]})ret = @client.testInsanity(insane)assert_not_nil(ret[44])assert_not_nil(ret[44][1])struct = ret[44][1]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)enddef test_map_mapret = @client.testMapMap(4)assert_kind_of(Hash, ret)assert_equal(ret, { 4 => { 4 => 4}})enddef test_exceptionassert_raise Thrift::Test::Xception do@client.testException('foo')endendend