[ 
https://issues.apache.org/jira/browse/THRIFT-3473?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15052000#comment-15052000
 ] 

YU Chang edited comment on THRIFT-3473 at 12/11/15 1:54 AM:
------------------------------------------------------------

Sorry to response so late.

Actually, I am a newbie to thrift, and this is the first time I report bug to 
an open source project. So I really don't know how to "extend an existing test 
case within the Thrift code base", I'm even not sure what's that mean. Could 
you describe it more specifically?

If you mean the auto generated thrift code, I use this command to generate it:
> thrift -gen cpp test.thrift
then 
> mv gen-cpp/Test_server.skeleton.cpp Test_server.cpp
then I modified Test_server.cpp file. 

For reproducing the case, you can just remove the 
"gen-cpp/Test_server.skeleton.cpp" file. This is the directory tree:

.
├── gen-cpp
│   ├── test_constants.cpp
│   ├── test_constants.h
│   ├── Test.cpp
│   ├── Test.h
│   ├── test_types.cpp
│   └── test_types.h
├── gen-perl
│   └── thrifttest
│       ├── Constants.pm
│       ├── Test.pm
│       └── Types.pm
├── Test_client.pl
├── Test_server
├── Test_server.cpp
└── test.thrift

I'd like to email you all the codes if you need.




was (Author: huache):
Sorry to response so late.

Actually, I am a newbie to thrift, and this is the first time I report bug to 
an open source project. So I really don't know how to "extend an existing test 
case within the Thrift code base", I'm even not sure what's that mean. Could 
you describe it more specifically?

If you mean the auto generated thrift code, I use this command to generate it:
> thrift -gen cpp test.thrift
then 
> mv gen-cpp/Test_server.skeleton.cpp Test_server.cpp
and modify the Test_server.cpp file. 

For reproducing the case, you can just remove the 
"gen-cpp/Test_server.skeleton.cpp" file. The is the directory tree:

.
├── gen-cpp
│   ├── test_constants.cpp
│   ├── test_constants.h
│   ├── Test.cpp
│   ├── Test.h
│   ├── test_types.cpp
│   └── test_types.h
├── gen-perl
│   └── thrifttest
│       ├── Constants.pm
│       ├── Test.pm
│       └── Types.pm
├── Test_client.pl
├── Test_server
├── Test_server.cpp
└── test.thrift

I'd like to email you all the codes if you need.



> When use "optional' before a list, C++ server cannot return it correctly 
> -------------------------------------------------------------------------
>
>                 Key: THRIFT-3473
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3473
>             Project: Thrift
>          Issue Type: Bug
>          Components: C++ - Library
>    Affects Versions: 0.9.3
>         Environment: CentOS 7, GCC 4.8.3, Perl 5.16
>            Reporter: YU Chang
>
> Any "optional" modifier relates to a list will cause to a null/undef return 
> value.
> Here is thrift file:
> {code:title=test.thrift|borderStyle=solid}
> namespace cpp thrifttest
> namespace perl thrifttest
> struct Pair {
>     1: optional string a, 
>     2: optional string b
> }
> struct Result {
>     1: optional list<string> strList,
>     2: optional list<Pair> pairList
> }
> service Test {
>     Result listTest()
> }
> {code}
> Here is C++ code (server):
> {code:title=Test_server.cpp|borderStyle=solid}
> #include "gen-cpp/Test.h"
> #include <thrift/protocol/TBinaryProtocol.h>
> #include <thrift/server/TSimpleServer.h>
> #include <thrift/transport/TServerSocket.h>
> #include <thrift/transport/TBufferTransports.h>
> #include <iostream>
> using namespace std;
> using namespace ::apache::thrift;
> using namespace ::apache::thrift::protocol;
> using namespace ::apache::thrift::transport;
> using namespace ::apache::thrift::server;
> using boost::shared_ptr;
> using namespace  ::thrifttest;
> class TestHandler : virtual public TestIf {
>     public:
>         TestHandler() {
>             // Your initialization goes here
>         }
>         void listTest(Result& _return) {
>             _return.strList.push_back("Test");
>             _return.strList.push_back("one level list");
>             cout << "strList size: " << _return.strList.size() << endl;
>             Pair pair;
>             pair.a = "Test";
>             pair.b = "two level list";
>             _return.pairList.push_back(pair);
>             cout << "pairList size: " << _return.pairList.size() << endl;
>             printf("call listTest\n");
>         }
> };
> int main(int argc, char **argv) {
>     int port = 9595;
>     shared_ptr<TestHandler> handler(new TestHandler());
>     shared_ptr<TProcessor> processor(new TestProcessor(handler));
>     shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
>     shared_ptr<TTransportFactory> transportFactory(new 
> TBufferedTransportFactory());
>     shared_ptr<TProtocolFactory> protocolFactory(new 
> TBinaryProtocolFactory());
>     TSimpleServer server(processor, serverTransport, transportFactory, 
> protocolFactory);
>     server.serve();
>     return 0;
> }
> {code}
> Here is perl code (client):
> {code:title=Test_client.pl|borderStyle=solid}
> #!/usr/bin/perl
> use v5.12;
> use warnings;
> use autodie;
> use utf8;
> use Data::Dumper;
> use lib 'gen-perl';
> use thrifttest::Test;
> use thrifttest::Constants;
> use thrifttest::Types;
> use Thrift;
> use Thrift::BinaryProtocol;
> use Thrift::Socket;
> use Thrift::BufferedTransport;
> my $socket    = new Thrift::Socket('localhost', 9595);
> my $transport = new Thrift::BufferedTransport($socket, 1024, 1024);
> my $protocol  = new Thrift::BinaryProtocol($transport);
> my $client    = new thrifttest::TestClient($protocol);
> eval {
>     $transport->open();
>     my $result = $client->listTest;
>     say Dumper($result);
>     $transport->close();
> };
> say $@ if $@;
> {code}
> {code:title=C++ server output|borderStyle=solid}
> strList size: 2
> pairList size: 1
> call listTest
> {code}
> {code:title=perl client output|borderStyle=solid}
> $VAR1 = bless( {
>                  'pairList' => undef,
>                  'strList' => undef
>                }, 'thrifttest::Result' );
> {code}
> In this test case, every "optional" corresponding to a undef return value. 
> Only If I delete all the "optional" in the thrift file, I will get right 
> return value. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to