Upgrading dependency to Thrift 0.12.0

This commit is contained in:
Renan DelValle 2018-11-27 18:03:50 -08:00
parent 3e4590dcc0
commit 356978cb42
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
1302 changed files with 101701 additions and 26784 deletions

View file

@ -17,8 +17,6 @@
# under the License.
#
THRIFT = $(top_builddir)/compiler/cpp/thrift
stubs: ../ThriftTest.thrift
$(THRIFT) --gen perl ../ThriftTest.thrift

View file

@ -19,7 +19,7 @@
# under the License.
#
require 5.6.0;
use 5.10.0;
use strict;
use warnings;
use Data::Dumper;
@ -33,10 +33,12 @@ use Thrift;
use Thrift::BinaryProtocol;
use Thrift::BufferedTransport;
use Thrift::FramedTransport;
use Thrift::MultiplexedProtocol;
use Thrift::SSLSocket;
use Thrift::Socket;
use Thrift::UnixSocket;
use ThriftTest::SecondService;
use ThriftTest::ThriftTest;
use ThriftTest::Types;
@ -47,15 +49,19 @@ sub usage {
Usage: $0 [OPTIONS]
Options: (default)
--ca CA to validate server with.
--cert Certificate to use.
Required if using --ssl.
--ciphers Acceptable cipher list.
--domain-socket <file> Use a unix domain socket.
--help Show usage.
--key Certificate key.
Required if using --ssl.
--port <portnum> 9090 Port to use.
--protocol {binary} binary Protocol to use.
--ssl If present, use SSL.
--transport {buffered|framed} buffered Transport to use.
EOF
}
@ -66,7 +72,10 @@ my %opts = (
);
GetOptions(\%opts, qw (
ca=s
cert=s
ciphers=s
key=s
domain-socket=s
help
host=s
@ -81,18 +90,13 @@ if ($opts{help}) {
exit 0;
}
if ($opts{ssl} and not defined $opts{cert}) {
usage();
exit 1;
}
my $socket = undef;
if ($opts{"domain-socket"}) {
$socket = new Thrift::UnixSocket($opts{"domain-socket"});
} elsif ($opts{ssl}) {
$socket = new Thrift::SSLSocket($opts{host}, $opts{port});
$socket = new Thrift::SSLSocket(\%opts);
} else {
$socket = new Thrift::Socket($opts{host}, $opts{port});
$socket = new Thrift::Socket($opts{host}, $opts{port});
}
my $transport;
@ -106,21 +110,37 @@ if ($opts{transport} eq 'buffered') {
}
my $protocol;
if ($opts{protocol} eq 'binary') {
my $protocol2;
if ($opts{protocol} eq 'binary' || $opts{protocol} eq 'multi') {
$protocol = new Thrift::BinaryProtocol($transport);
} else {
usage();
exit 1;
}
my $secondService = undef;
if (index($opts{protocol}, 'multi') == 0) {
$protocol2 = new Thrift::MultiplexedProtocol($protocol, "SecondService");
$protocol = new Thrift::MultiplexedProtocol($protocol, "ThriftTest");
$secondService = new ThriftTest::SecondServiceClient($protocol2);
}
my $testClient = new ThriftTest::ThriftTestClient($protocol);
eval {
$transport->open();
};
};
if($@){
die(Dumper($@));
}
use constant ERR_BASETYPES => 1;
use constant ERR_STRUCTS => 2;
use constant ERR_CONTAINERS => 4;
use constant ERR_EXCEPTIONS => 8;
use constant ERR_PROTOCOL => 16;
use constant ERR_UNKNOWN => 64;
my $start = gettimeofday();
#
@ -136,6 +156,17 @@ print(" = void\n");
print("testString(\"Test\")");
my $s = $testClient->testString("Test");
print(" = \"$s\"\n");
exit(ERR_BASETYPES) if ($s ne 'Test');
#
# MULTIPLEXED TEST
#
if (index($opts{protocol}, 'multi') == 0) {
print("secondtestString(\"Test2\")");
$s = $secondService->secondtestString("Test2");
print(" = \"$s\"\n");
exit(ERR_PROTOCOL) if ($s ne 'testString("Test2")');
}
#
# BOOL TEST
@ -143,9 +174,11 @@ print(" = \"$s\"\n");
print("testBool(1)");
my $t = $testClient->testBool(1);
print(" = $t\n");
exit(ERR_BASETYPES) if ($t ne 1);
print("testBool(0)");
my $f = $testClient->testBool(0);
print(" = $f\n");
exit(ERR_BASETYPES) if ($f ne "");
#
@ -161,13 +194,15 @@ print(" = $u8\n");
print("testI32(-1)");
my $i32 = $testClient->testI32(-1);
print(" = $i32\n");
exit(ERR_BASETYPES) if ($i32 ne -1);
#
#I64 TEST
# I64 TEST
#
print("testI64(-34359738368)");
my $i64 = $testClient->testI64(-34359738368);
print(" = $i64\n");
exit(ERR_BASETYPES) if ($i64 ne -34359738368);
#
# DOUBLE TEST
@ -175,6 +210,7 @@ print(" = $i64\n");
print("testDouble(-852.234234234)");
my $dub = $testClient->testDouble(-852.234234234);
print(" = $dub\n");
exit(ERR_BASETYPES) if ($dub ne -852.234234234);
#
# BINARY TEST --- TODO

View file

@ -19,13 +19,15 @@
# under the License.
#
require 5.6.0;
use 5.10.0;
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long qw(GetOptions);
use Time::HiRes qw(gettimeofday);
$SIG{INT} = \&sigint_handler;
use lib '../../lib/perl/lib';
use lib 'gen-perl';
@ -33,11 +35,13 @@ use Thrift;
use Thrift::BinaryProtocol;
use Thrift::BufferedTransport;
use Thrift::FramedTransport;
use Thrift::MultiplexedProcessor;
use Thrift::SSLServerSocket;
use Thrift::ServerSocket;
use Thrift::Server;
use Thrift::UnixServerSocket;
use ThriftTest::SecondService;
use ThriftTest::ThriftTest;
use ThriftTest::Types;
@ -50,7 +54,8 @@ Usage: $0 [OPTIONS]
Options: (default)
--ca Certificate authority file (optional).
--cert Certificate file.
Required if using --ssl.
Required if using --ssl.
--ciphers Acceptable cipher list.
--domain-socket <file> Use a unix domain socket.
--help Show usage.
--key Private key file for certificate.
@ -60,7 +65,7 @@ Options: (default)
--protocol {binary} binary Protocol to use.
--ssl If present, use SSL/TLS.
--transport {buffered|framed} buffered Transport to use.
EOF
}
@ -73,6 +78,7 @@ my %opts = (
GetOptions(\%opts, qw (
ca=s
cert=s
ciphers=s
domain-socket=s
help
host=s
@ -94,7 +100,9 @@ if ($opts{ssl} and not defined $opts{cert}) {
}
my $handler = new ThriftTestHandler();
my $handler2 = new SecondServiceHandler();
my $processor = new ThriftTest::ThriftTestProcessor($handler);
my $processor2 = new ThriftTest::SecondServiceProcessor($handler2);
my $serversocket;
if ($opts{"domain-socket"}) {
unlink($opts{"domain-socket"});
@ -114,13 +122,21 @@ if ($opts{transport} eq 'buffered') {
exit 1;
}
my $protocol;
if ($opts{protocol} eq 'binary') {
if ($opts{protocol} eq 'binary' || $opts{protocol} eq 'multi') {
$protocol = new Thrift::BinaryProtocolFactory();
} else {
usage();
exit 1;
}
if (index($opts{protocol}, 'multi') == 0) {
my $newProcessor = new Thrift::MultiplexedProcessor($protocol);
$newProcessor->defaultProcessor($processor);
$newProcessor->registerProcessor("ThriftTest", $processor);
$newProcessor->registerProcessor("SecondService", $processor2);
$processor = $newProcessor;
}
my $ssltag = '';
if ($opts{ssl}) {
$ssltag = "(SSL)";
@ -132,8 +148,14 @@ if ($opts{"domain-socket"}) {
my $server = new Thrift::SimpleServer($processor, $serversocket, $transport, $protocol);
print "Starting \"simple\" server ($opts{transport}/$opts{protocol}) listen on: $listening_on\n";
$server->serve();
print "done.\n";
###
sub sigint_handler {
print "received SIGINT, stopping...\n";
$server->stop();
}
###
### Test server implementation
###
@ -148,7 +170,7 @@ sub new {
}
sub testVoid() {
print("testVoid()\n");
print("testVoid()\n");
}
sub testString() {
@ -280,7 +302,7 @@ sub testSet() {
print(", ");
}
print("$key");
push($result, $key);
push(@arr, $key);
}
print("})\n");
return $result;
@ -320,7 +342,7 @@ sub testTypedef() {
sub testMapMap() {
my $self = shift;
my $hello = shift;
printf("testMapMap(%d)\n", $hello);
my $result = { 4 => { 1 => 1, 2 => 2, 3 => 3, 4 => 4 }, -4 => { -1 => -1, -2 => -2, -3 => -3, -4 => -4 } };
return $result;
@ -352,7 +374,7 @@ sub testMulti() {
my $arg3 = shift;
my $arg4 = shift;
my $arg5 = shift;
print("testMulti()\n");
return new ThriftTest::Xtruct({string_thing => "Hello2", byte_thing => $arg0, i32_thing => $arg1, i64_thing => $arg2});
}
@ -388,11 +410,29 @@ sub testMultiException() {
sub testOneway() {
my $self = shift;
my $sleepFor = shift;
print("testOneway($sleepFor): Sleeping...\n");
sleep $sleepFor;
print("testOneway($sleepFor): done sleeping!\n");
my $num = shift;
print("testOneway($num): received\n");
}
###
### Test server implementation
###
package SecondServiceHandler;
use base qw( ThriftTest::SecondServiceIf );
sub new {
my $classname = shift;
my $self = {};
return bless($self, $classname);
}
sub secondtestString() {
my $self = shift;
my $thing = shift;
print("testString($thing)\n");
return "testString(\"" . $thing . "\")";
}
1;