| 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 |
use Test::More tests => 2;
|
|
|
21 |
|
|
|
22 |
use strict;
|
|
|
23 |
use warnings;
|
|
|
24 |
|
|
|
25 |
use Thrift;
|
|
|
26 |
use Thrift::BinaryProtocol;
|
|
|
27 |
use Thrift::MemoryBuffer;
|
|
|
28 |
|
|
|
29 |
use ThriftTest::ThriftTest;
|
|
|
30 |
use ThriftTest::Types;
|
|
|
31 |
|
|
|
32 |
use Data::Dumper;
|
|
|
33 |
|
|
|
34 |
my $buffer = Thrift::MemoryBuffer->new(1024);
|
|
|
35 |
my $protocol = Thrift::BinaryProtocol->new($buffer);
|
|
|
36 |
my $client = ThriftTest::ThriftTestClient->new($protocol);
|
|
|
37 |
|
|
|
38 |
$buffer->open();
|
|
|
39 |
$client->send_testString("foo");
|
|
|
40 |
$client->{seqid}++;
|
|
|
41 |
$client->send_testString("bar");
|
|
|
42 |
|
|
|
43 |
my $client_command_binary = $buffer->getBuffer;
|
|
|
44 |
$buffer->resetBuffer;
|
|
|
45 |
|
|
|
46 |
# Process by server
|
|
|
47 |
|
|
|
48 |
my $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 |
|
|
|
69 |
foreach 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 |
|
|
|
87 |
package My::ThriftTest;
|
|
|
88 |
|
|
|
89 |
use strict;
|
|
|
90 |
use warnings;
|
|
|
91 |
use Data::Dumper;
|
|
|
92 |
|
|
|
93 |
sub new {
|
|
|
94 |
my $class = shift;
|
|
|
95 |
return bless {}, $class;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
sub testString {
|
|
|
99 |
my ($self, $string) = @_;
|
|
|
100 |
|
|
|
101 |
print __PACKAGE__ . "->testString()\n";
|
|
|
102 |
|
|
|
103 |
return "got ".$string;
|
|
|
104 |
}
|