| 30 |
ashish |
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 File.dirname(__FILE__) + '/spec_helper'
|
|
|
21 |
|
|
|
22 |
class ThriftProcessorSpec < Spec::ExampleGroup
|
|
|
23 |
include Thrift
|
|
|
24 |
|
|
|
25 |
class ProcessorSpec
|
|
|
26 |
include Thrift::Processor
|
|
|
27 |
end
|
|
|
28 |
|
|
|
29 |
describe "Processor" do
|
|
|
30 |
before(:each) do
|
|
|
31 |
@processor = ProcessorSpec.new(mock("MockHandler"))
|
|
|
32 |
@prot = mock("MockProtocol")
|
|
|
33 |
end
|
|
|
34 |
|
|
|
35 |
def mock_trans(obj)
|
|
|
36 |
obj.should_receive(:trans).ordered.and_return do
|
|
|
37 |
mock("trans").tee do |trans|
|
|
|
38 |
trans.should_receive(:flush).ordered
|
|
|
39 |
end
|
|
|
40 |
end
|
|
|
41 |
end
|
|
|
42 |
|
|
|
43 |
it "should call process_<message> when it receives that message" do
|
|
|
44 |
@prot.should_receive(:read_message_begin).ordered.and_return ['testMessage', MessageTypes::CALL, 17]
|
|
|
45 |
@processor.should_receive(:process_testMessage).with(17, @prot, @prot).ordered
|
|
|
46 |
@processor.process(@prot, @prot).should == true
|
|
|
47 |
end
|
|
|
48 |
|
|
|
49 |
it "should raise an ApplicationException when the received message cannot be processed" do
|
|
|
50 |
@prot.should_receive(:read_message_begin).ordered.and_return ['testMessage', MessageTypes::CALL, 4]
|
|
|
51 |
@prot.should_receive(:skip).with(Types::STRUCT).ordered
|
|
|
52 |
@prot.should_receive(:read_message_end).ordered
|
|
|
53 |
@prot.should_receive(:write_message_begin).with('testMessage', MessageTypes::EXCEPTION, 4).ordered
|
|
|
54 |
ApplicationException.should_receive(:new).with(ApplicationException::UNKNOWN_METHOD, "Unknown function testMessage").and_return do
|
|
|
55 |
mock(ApplicationException).tee do |e|
|
|
|
56 |
e.should_receive(:write).with(@prot).ordered
|
|
|
57 |
end
|
|
|
58 |
end
|
|
|
59 |
@prot.should_receive(:write_message_end).ordered
|
|
|
60 |
mock_trans(@prot)
|
|
|
61 |
@processor.process(@prot, @prot)
|
|
|
62 |
end
|
|
|
63 |
|
|
|
64 |
it "should pass args off to the args class" do
|
|
|
65 |
args_class = mock("MockArgsClass")
|
|
|
66 |
args = mock("#<MockArgsClass:mock>").tee do |args|
|
|
|
67 |
args.should_receive(:read).with(@prot).ordered
|
|
|
68 |
end
|
|
|
69 |
args_class.should_receive(:new).and_return args
|
|
|
70 |
@prot.should_receive(:read_message_end).ordered
|
|
|
71 |
@processor.read_args(@prot, args_class).should eql(args)
|
|
|
72 |
end
|
|
|
73 |
|
|
|
74 |
it "should write out a reply when asked" do
|
|
|
75 |
@prot.should_receive(:write_message_begin).with('testMessage', MessageTypes::REPLY, 23).ordered
|
|
|
76 |
result = mock("MockResult")
|
|
|
77 |
result.should_receive(:write).with(@prot).ordered
|
|
|
78 |
@prot.should_receive(:write_message_end).ordered
|
|
|
79 |
mock_trans(@prot)
|
|
|
80 |
@processor.write_result(result, @prot, 'testMessage', 23)
|
|
|
81 |
end
|
|
|
82 |
end
|
|
|
83 |
end
|