]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/rb/spec/processor_spec.rb
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
22 describe
'Processor' do
25 include Thrift
::Processor
28 describe Thrift
::Processor do
30 @processor = ProcessorSpec
. new ( double ( "MockHandler" ))
31 @prot = double ( "MockProtocol" )
35 expect ( obj
). to
receive ( :trans ). ordered
do
36 double ( "trans" ). tap
do | trans
|
37 expect ( trans
). to
receive ( :flush ). ordered
42 it
"should call process_<message> when it receives that message" do
43 expect ( @prot ). to
receive ( :read_message_begin ). ordered
. and_return
[ 'testMessage' , Thrift
::MessageTypes::CALL , 17 ]
44 expect ( @processor ). to
receive ( :process_testMessage ). with ( 17 , @prot , @prot ). ordered
45 expect ( @processor . process ( @prot , @prot )). to
eq ( true )
48 it
"should raise an ApplicationException when the received message cannot be processed" do
49 expect ( @prot ). to
receive ( :read_message_begin ). ordered
. and_return
[ 'testMessage' , Thrift
::MessageTypes::CALL , 4 ]
50 expect ( @prot ). to
receive ( :skip ). with ( Thrift
::Types::STRUCT ). ordered
51 expect ( @prot ). to
receive ( :read_message_end ). ordered
52 expect ( @prot ). to
receive ( :write_message_begin ). with ( 'testMessage' , Thrift
::MessageTypes::EXCEPTION , 4 ). ordered
53 e
= double ( Thrift
::ApplicationException )
54 expect ( e
). to
receive ( :write ). with ( @prot ). ordered
55 expect ( Thrift
::ApplicationException ). to
receive ( :new ). with ( Thrift
::ApplicationException::UNKNOWN_METHOD , "Unknown function testMessage" ). and_return ( e
)
56 expect ( @prot ). to
receive ( :write_message_end ). ordered
58 @processor . process ( @prot , @prot )
61 it
"should pass args off to the args class" do
62 args_class
= double ( "MockArgsClass" )
63 args
= double ( "#<MockArgsClass:mock>" ). tap
do | args
|
64 expect ( args
). to
receive ( :read ). with ( @prot ). ordered
66 expect ( args_class
). to
receive ( :new ). and_return args
67 expect ( @prot ). to
receive ( :read_message_end ). ordered
68 expect ( @processor . read_args ( @prot , args_class
)). to
eql ( args
)
71 it
"should write out a reply when asked" do
72 expect ( @prot ). to
receive ( :write_message_begin ). with ( 'testMessage' , Thrift
::MessageTypes::REPLY , 23 ). ordered
73 result
= double ( "MockResult" )
74 expect ( result
). to
receive ( :write ). with ( @prot ). ordered
75 expect ( @prot ). to
receive ( :write_message_end ). ordered
77 @processor . write_result ( result
, @prot , 'testMessage' , 23 )