blob: 1d8be73be04987b8e94a6c6a084c084c42f7d557 [file] [log] [blame]
T Jake Lucianifdcb7102009-07-17 01:37:01 +00001#
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
20use Test::More tests => 2;
21
22use strict;
23use warnings;
24
25use Thrift;
26use Thrift::BinaryProtocol;
27use Thrift::MemoryBuffer;
28
29use ThriftTest::ThriftTest;
30use ThriftTest::Types;
31
32use Data::Dumper;
33
34my $buffer = Thrift::MemoryBuffer->new(1024);
35my $protocol = Thrift::BinaryProtocol->new($buffer);
36my $client = ThriftTest::ThriftTestClient->new($protocol);
37
38$buffer->open();
39$client->send_testString("foo");
40$client->{seqid}++;
41$client->send_testString("bar");
42
43my $client_command_binary = $buffer->getBuffer;
44$buffer->resetBuffer;
45
46# Process by server
47
48my $server_output_binary;
49{
50 my $protocol_factory = Thrift::BinaryProtocolFactory->new();
51
52 my $input_buffer = Thrift::MemoryBuffer->new();
53 $input_buffer->write($client_command_binary);
54 my $input_protocol = $protocol_factory->getProtocol($input_buffer);
55
56 my $output_buffer = Thrift::MemoryBuffer->new();
57 my $output_protocol = $protocol_factory->getProtocol($output_buffer);
58
59 my $processor = ThriftTest::ThriftTestProcessor->new( My::ThriftTest->new() );
60 my $result = $processor->process($input_protocol, $output_protocol);
61 print "process resulted in $result\n";
62 $result = $processor->process($input_protocol, $output_protocol);
63 print "process resulted in $result\n";
64 $server_output_binary = $output_buffer->getBuffer();
65}
66
67$buffer->write($server_output_binary);
68
69foreach my $val (("got foo","got bar")){
70 my ($function_name, $message_type, $sequence_id);
71
72 $protocol->readMessageBegin(\$function_name, \$message_type, \$sequence_id);
73 print " $function_name, $message_type, $sequence_id\n";
74
75 if ($message_type == TMessageType::EXCEPTION) {
76 die;
77 }
78
79 my $result = ThriftTest::ThriftTest_testString_result->new();
80 $result->read($protocol);
81 $protocol->readMessageEnd();
82
83 is($result->success(),$val);
84}
85
86
87package My::ThriftTest;
88
89use strict;
90use warnings;
91use Data::Dumper;
92
93sub new {
94 my $class = shift;
95 return bless {}, $class;
96}
97
98sub testString {
99 my ($self, $string) = @_;
100
101 print __PACKAGE__ . "->testString()\n";
102
103 return "got ".$string;
104}