]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/rb/spec/processor_spec.rb
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / lib / rb / spec / processor_spec.rb
1 #
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
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
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
17 # under the License.
18 #
19
20 require 'spec_helper'
21
22 describe 'Processor' do
23
24 class ProcessorSpec
25 include Thrift::Processor
26 end
27
28 describe Thrift::Processor do
29 before(:each) do
30 @processor = ProcessorSpec.new(double("MockHandler"))
31 @prot = double("MockProtocol")
32 end
33
34 def mock_trans(obj)
35 expect(obj).to receive(:trans).ordered do
36 double("trans").tap do |trans|
37 expect(trans).to receive(:flush).ordered
38 end
39 end
40 end
41
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)
46 end
47
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
57 mock_trans(@prot)
58 @processor.process(@prot, @prot)
59 end
60
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
65 end
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)
69 end
70
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
76 mock_trans(@prot)
77 @processor.write_result(result, @prot, 'testMessage', 23)
78 end
79 end
80 end