You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2016/09/04 09:50:28 UTC
[01/10] thrift git commit: THRIFT-3046: Allow PSR4 class loading for
generated classes (PHP)
Repository: thrift
Updated Branches:
refs/heads/master aa4312ef5 -> d2b4f2483
THRIFT-3046: Allow PSR4 class loading for generated classes (PHP)
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/7b0cb9a6
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/7b0cb9a6
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/7b0cb9a6
Branch: refs/heads/master
Commit: 7b0cb9a63aff78c03e6ff2cd1d266b408a22df7f
Parents: aa4312e
Author: fduch <al...@gmail.com>
Authored: Wed Mar 18 15:01:20 2015 +0300
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sat Sep 3 15:57:47 2016 +0900
----------------------------------------------------------------------
compiler/cpp/src/generate/t_php_generator.cc | 625 +++++++++++++---------
1 file changed, 374 insertions(+), 251 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/7b0cb9a6/compiler/cpp/src/generate/t_php_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc
index 9f79337..2fa9b24 100644
--- a/compiler/cpp/src/generate/t_php_generator.cc
+++ b/compiler/cpp/src/generate/t_php_generator.cc
@@ -62,23 +62,26 @@ public:
validate_ = false;
json_serializable_ = false;
nsglobal_ = ""; // by default global namespace is empty
- for( iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
- if( iter->first.compare("inlined") == 0) {
+ psr4_ = false;
+ for (iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
+ if (iter->first.compare("inlined") == 0) {
binary_inline_ = true;
- } else if( iter->first.compare("rest") == 0) {
+ } else if (iter->first.compare("rest") == 0) {
rest_ = true;
- } else if( iter->first.compare("server") == 0) {
+ } else if (iter->first.compare("server") == 0) {
phps_ = true;
- } else if( iter->first.compare("oop") == 0) {
+ } else if (iter->first.compare("oop") == 0) {
oop_ = true;
- } else if( iter->first.compare("validate") == 0) {
+ } else if (iter->first.compare("validate") == 0) {
validate_ = true;
- } else if( iter->first.compare("json") == 0) {
+ } else if (iter->first.compare("json") == 0) {
json_serializable_ = true;
- } else if( iter->first.compare("nsglobal") == 0) {
+ } else if (iter->first.compare("nsglobal") == 0) {
nsglobal_ = iter->second;
+ } else if (iter->first.compare("psr4") == 0) {
+ psr4_ = true;
} else {
- throw "unknown option php:" + iter->first;
+ throw "unknown option php:" + iter->first;
}
}
@@ -105,7 +108,6 @@ public:
void generate_typedef(t_typedef* ttypedef);
void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
void generate_consts(vector<t_const*> consts);
void generate_struct(t_struct* tstruct);
void generate_xception(t_struct* txception);
@@ -124,7 +126,7 @@ public:
bool is_result = false);
void generate_php_struct_reader(std::ofstream& out, t_struct* tstruct, bool is_result);
void generate_php_struct_writer(std::ofstream& out, t_struct* tstruct, bool is_result);
- void generate_php_function_helpers(t_function* tfunction);
+ void generate_php_function_helpers(t_service* tservice, t_function* tfunction);
void generate_php_struct_required_validator(ofstream& out,
t_struct* tstruct,
std::string method_name,
@@ -148,7 +150,9 @@ public:
void generate_service_rest(t_service* tservice);
void generate_service_client(t_service* tservice);
void generate_service_processor(t_service* tservice);
- void generate_process_function(t_service* tservice, t_function* tfunction);
+ void generate_process_function(std::ofstream& out, t_service* tservice, t_function* tfunction);
+ void generate_service_header(t_service* tservice, std::ofstream& file);
+ void generate_program_header(std::ofstream& file);
/**
* Serialization constructs
@@ -330,7 +334,6 @@ private:
* File streams
*/
std::ofstream f_types_;
- std::ofstream f_helpers_;
std::ofstream f_service_;
std::string package_dir_;
@@ -355,6 +358,11 @@ private:
bool oop_;
/**
+ * Whether to hold each class in separate file to allow PSR4-autoloading
+ */
+ bool psr4_;
+
+ /**
* Whether to generate validator code
*/
bool validate_;
@@ -393,18 +401,13 @@ void t_php_generator::init_generator() {
MKDIR(package_dir_.c_str());
}
- // Make output file
- string f_types_name = package_dir_ + "Types.php";
- f_types_.open(f_types_name.c_str());
-
- // Print header
- f_types_ << "<?php" << endl;
- if ( ! php_namespace_suffix(get_program()).empty() ) {
- f_types_ << "namespace " << php_namespace_suffix(get_program()) << ";" << endl << endl;
+ // Prepare output file for all the types in non-psr4 mode
+ if (!psr4_) {
+ // Make output file
+ string f_types_name = package_dir_ + "Types.php";
+ f_types_.open(f_types_name.c_str());
+ generate_program_header(f_types_);
}
- f_types_ << autogen_comment() << php_includes();
-
- f_types_ << endl;
}
/**
@@ -432,9 +435,11 @@ string t_php_generator::php_includes() {
* Close up (or down) some filez.
*/
void t_php_generator::close_generator() {
- // Close types file
- f_types_ << endl;
- f_types_.close();
+ if (!psr4_) {
+ // Close types file
+ f_types_ << endl;
+ f_types_.close();
+ }
}
/**
@@ -447,37 +452,74 @@ void t_php_generator::generate_typedef(t_typedef* ttypedef) {
}
/**
+ * Generates service header contains namespace suffix and includes inside file specified
+ */
+void t_php_generator::generate_service_header(t_service* tservice, std::ofstream& file) {
+ file << "<?php" << endl;
+ if (!php_namespace_suffix(tservice->get_program()).empty()) {
+ file << "namespace " << php_namespace_suffix(tservice->get_program()) << ";" << endl;
+ }
+ file << autogen_comment() << php_includes();
+
+ file << endl;
+}
+
+/**
+ * Generates program header contains namespace suffix and includes inside file specified
+ */
+void t_php_generator::generate_program_header(std::ofstream& file) {
+ file << "<?php" << endl;
+ if (!php_namespace_suffix(get_program()).empty()) {
+ file << "namespace " << php_namespace_suffix(get_program()) << ";" << endl << endl;
+ }
+ file << autogen_comment() << php_includes();
+
+ file << endl;
+}
+
+/**
* Generates code for an enumerated type. Since define is expensive to lookup
* in PHP, we use a global array for this.
*
* @param tenum The enumeration
*/
void t_php_generator::generate_enum(t_enum* tenum) {
+ std::ofstream& f_enum = f_types_;
+ if (psr4_) {
+ string f_enum_name = package_dir_ + tenum->get_name() + ".php";
+ f_enum.open(f_enum_name.c_str());
+ generate_program_header(f_enum);
+ }
+
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
// We're also doing it this way to see how it performs. It's more legible
// code but you can't do things like an 'extract' on it, which is a bit of
// a downer.
- generate_php_doc(f_types_, tenum);
- f_types_ << "final class " << tenum->get_name() << " {" << endl;
+ generate_php_doc(f_enum, tenum);
+ f_enum << "final class " << tenum->get_name() << " {" << endl;
indent_up();
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
int value = (*c_iter)->get_value();
- generate_php_doc(f_types_, *c_iter);
- indent(f_types_) << "const " << (*c_iter)->get_name() << " = " << value << ";" << endl;
+ generate_php_doc(f_enum, *c_iter);
+ indent(f_enum) << "const " << (*c_iter)->get_name() << " = " << value << ";" << endl;
}
- indent(f_types_) << "static public $__names = array(" << endl;
+ indent(f_enum) << "static public $__names = array(" << endl;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
int value = (*c_iter)->get_value();
- indent(f_types_) << " " << value << " => '" << (*c_iter)->get_name() << "'," << endl;
+ indent(f_enum) << " " << value << " => '" << (*c_iter)->get_name() << "'," << endl;
}
- indent(f_types_) << ");" << endl;
+ indent(f_enum) << ");" << endl;
indent_down();
- f_types_ << "}" << endl << endl;
+
+ f_enum << "}" << endl << endl;
+ if (psr4_) {
+ f_enum.close();
+ }
}
/**
@@ -490,50 +532,51 @@ void t_php_generator::generate_consts(vector<t_const*> consts) {
// Create class only if needed
if (consts.size() > 0) {
- f_types_ << "final class Constant extends \\Thrift\\Type\\TConstant {" << endl;
+
+ std::ofstream& f_consts = f_types_;
+ if (psr4_) {
+ string f_consts_name = package_dir_ + "Constant.php";
+ f_consts.open(f_consts_name.c_str());
+ generate_program_header(f_consts);
+ }
+ f_consts << "final class Constant extends \\Thrift\\Type\\TConstant {" << endl;
+
indent_up();
// Create static property
for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
string name = (*c_iter)->get_name();
- indent(f_types_) << "static protected $" << name << ";" << endl;
+ indent(f_consts) << "static protected $" << name << ";" << endl;
}
// Create init function
for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
string name = (*c_iter)->get_name();
- f_types_ << endl;
+ f_consts << endl;
- indent(f_types_) << "static protected function init_" << name << "() {" << endl;
+ indent(f_consts) << "static protected function init_" << name << "() {" << endl;
indent_up();
- indent(f_types_) << "return ";
- generate_const(*c_iter);
- f_types_ << ";" << endl;
+ indent(f_consts) << "return ";
+ generate_php_doc(f_consts, *c_iter);
+ f_consts << render_const_value((*c_iter)->get_type(), (*c_iter)->get_value());
+ f_consts << ";" << endl;
indent_down();
- indent(f_types_) << "}" << endl;
+ indent(f_consts) << "}" << endl;
}
indent_down();
- f_types_ << "}" << endl << endl;
+ f_consts << "}" << endl << endl;
+ if (psr4_) {
+ f_consts.close();
+ }
}
}
/**
- * Generate a constant value
- */
-void t_php_generator::generate_const(t_const* tconst) {
- t_type* type = tconst->get_type();
- t_const_value* value = tconst->get_value();
-
- generate_php_doc(f_types_, tconst);
- f_types_ << render_const_value(type, value);
-}
-
-/**
* Prints the value of a constant with the given type. Note that type checking
* is NOT performed in this function as it is always run beforehand using the
* validate_types method in main.cc
@@ -655,7 +698,16 @@ void t_php_generator::generate_xception(t_struct* txception) {
* Structs can be normal or exceptions.
*/
void t_php_generator::generate_php_struct(t_struct* tstruct, bool is_exception) {
- generate_php_struct_definition(f_types_, tstruct, is_exception);
+ std::ofstream& f_struct = f_types_;
+ if (psr4_) {
+ string f_struct_name = package_dir_ + tstruct->get_name() + ".php";
+ f_struct.open(f_struct_name.c_str());
+ generate_program_header(f_struct);
+ }
+ generate_php_struct_definition(f_struct, tstruct, is_exception);
+ if (psr4_) {
+ f_struct.close();
+ }
}
void t_php_generator::generate_php_type_spec(ofstream& out, t_type* t) {
@@ -1145,16 +1197,11 @@ bool t_php_generator::needs_php_read_validator(t_struct* tstruct, bool is_result
* @param tservice The service definition
*/
void t_php_generator::generate_service(t_service* tservice) {
- string f_service_name = package_dir_ + service_name_ + ".php";
- f_service_.open(f_service_name.c_str());
-
- f_service_ << "<?php" << endl;
- if ( ! php_namespace_suffix(tservice->get_program()).empty() ) {
- f_service_ << "namespace " << php_namespace_suffix(tservice->get_program()) << ";" << endl;
+ if(!psr4_) {
+ string f_service_name = package_dir_ + service_name_ + ".php";
+ f_service_.open(f_service_name.c_str());
+ generate_service_header(tservice, f_service_);
}
- f_service_ << autogen_comment() << php_includes();
-
- f_service_ << endl;
// Generate the three main parts of the service (well, two for now in PHP)
generate_service_interface(tservice);
@@ -1167,9 +1214,11 @@ void t_php_generator::generate_service(t_service* tservice) {
generate_service_processor(tservice);
}
- // Close service file
- f_service_ << endl;
- f_service_.close();
+ if(!psr4_) {
+ // Close service file
+ f_service_ << endl;
+ f_service_.close();
+ }
}
/**
@@ -1178,6 +1227,13 @@ void t_php_generator::generate_service(t_service* tservice) {
* @param tservice The service to generate a server for.
*/
void t_php_generator::generate_service_processor(t_service* tservice) {
+ std::ofstream& f_service_processor = f_service_;
+ if (psr4_) {
+ string f_service_processor_name = package_dir_ + service_name_ + "Processor.php";
+ f_service_processor.open(f_service_processor_name.c_str());
+ generate_service_header(tservice, f_service_processor);
+ }
+
// Generate the dispatch methods
vector<t_function*> functions = tservice->get_functions();
vector<t_function*>::iterator f_iter;
@@ -1191,70 +1247,74 @@ void t_php_generator::generate_service_processor(t_service* tservice) {
}
// Generate the header portion
- f_service_ << "class " << service_name_ << "Processor" << extends_processor << " {" << endl;
+ f_service_processor << "class " << service_name_ << "Processor" << extends_processor << " {" << endl;
indent_up();
if (extends.empty()) {
- f_service_ << indent() << "protected $handler_ = null;" << endl;
+ f_service_processor << indent() << "protected $handler_ = null;" << endl;
}
- f_service_ << indent() << "public function __construct($handler) {" << endl;
+ f_service_processor << indent() << "public function __construct($handler) {" << endl;
if (extends.empty()) {
- f_service_ << indent() << " $this->handler_ = $handler;" << endl;
+ f_service_processor << indent() << " $this->handler_ = $handler;" << endl;
} else {
- f_service_ << indent() << " parent::__construct($handler);" << endl;
+ f_service_processor << indent() << " parent::__construct($handler);" << endl;
}
- f_service_ << indent() << "}" << endl << endl;
+ f_service_processor << indent() << "}" << endl << endl;
// Generate the server implementation
- indent(f_service_) << "public function process($input, $output) {" << endl;
+ indent(f_service_processor) << "public function process($input, $output) {" << endl;
indent_up();
- f_service_ << indent() << "$rseqid = 0;" << endl << indent() << "$fname = null;" << endl
- << indent() << "$mtype = 0;" << endl << endl;
+ f_service_processor << indent() << "$rseqid = 0;" << endl << indent() << "$fname = null;" << endl
+ << indent() << "$mtype = 0;" << endl << endl;
if (binary_inline_) {
t_field ffname(g_type_string, "fname");
t_field fmtype(g_type_i8, "mtype");
t_field fseqid(g_type_i32, "rseqid");
- generate_deserialize_field(f_service_, &ffname, "", true);
- generate_deserialize_field(f_service_, &fmtype, "", true);
- generate_deserialize_field(f_service_, &fseqid, "", true);
+ generate_deserialize_field(f_service_processor, &ffname, "", true);
+ generate_deserialize_field(f_service_processor, &fmtype, "", true);
+ generate_deserialize_field(f_service_processor, &fseqid, "", true);
} else {
- f_service_ << indent() << "$input->readMessageBegin($fname, $mtype, $rseqid);" << endl;
+ f_service_processor << indent() << "$input->readMessageBegin($fname, $mtype, $rseqid);" << endl;
}
// HOT: check for method implementation
- f_service_ << indent() << "$methodname = 'process_'.$fname;" << endl << indent()
- << "if (!method_exists($this, $methodname)) {" << endl;
+ f_service_processor << indent() << "$methodname = 'process_'.$fname;" << endl << indent()
+ << "if (!method_exists($this, $methodname)) {" << endl;
if (binary_inline_) {
- f_service_ << indent() << " throw new \\Exception('Function '.$fname.' not implemented.');"
- << endl;
+ f_service_processor << indent() << " throw new \\Exception('Function '.$fname.' not implemented.');"
+ << endl;
} else {
- f_service_ << indent() << " $input->skip("
- << "TType::STRUCT);" << endl << indent() << " $input->readMessageEnd();" << endl
- << indent() << " $x = new "
- << "TApplicationException('Function '.$fname.' not implemented.', "
- << "TApplicationException::UNKNOWN_METHOD);" << endl << indent()
- << " $output->writeMessageBegin($fname, "
- << "TMessageType::EXCEPTION, $rseqid);" << endl << indent()
- << " $x->write($output);" << endl << indent() << " $output->writeMessageEnd();"
- << endl << indent() << " $output->getTransport()->flush();" << endl << indent()
- << " return;" << endl;
- }
- f_service_ << indent() << "}" << endl << indent()
- << "$this->$methodname($rseqid, $input, $output);" << endl << indent()
- << "return true;" << endl;
+ f_service_processor << indent() << " $input->skip("
+ << "TType::STRUCT);" << endl << indent() << " $input->readMessageEnd();" << endl
+ << indent() << " $x = new "
+ << "TApplicationException('Function '.$fname.' not implemented.', "
+ << "TApplicationException::UNKNOWN_METHOD);" << endl << indent()
+ << " $output->writeMessageBegin($fname, "
+ << "TMessageType::EXCEPTION, $rseqid);" << endl << indent()
+ << " $x->write($output);" << endl << indent() << " $output->writeMessageEnd();"
+ << endl << indent() << " $output->getTransport()->flush();" << endl << indent()
+ << " return;" << endl;
+ }
+ f_service_processor << indent() << "}" << endl << indent()
+ << "$this->$methodname($rseqid, $input, $output);" << endl << indent()
+ << "return true;" << endl;
indent_down();
- f_service_ << indent() << "}" << endl << endl;
+ f_service_processor << indent() << "}" << endl << endl;
// Generate the process subfunctions
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- generate_process_function(tservice, *f_iter);
+ generate_process_function(f_service_processor, tservice, *f_iter);
}
indent_down();
- f_service_ << "}" << endl;
+ f_service_processor << "}" << endl;
+
+ if (psr4_) {
+ f_service_processor.close();
+ }
}
/**
@@ -1262,9 +1322,9 @@ void t_php_generator::generate_service_processor(t_service* tservice) {
*
* @param tfunction The function to write a dispatcher for
*/
-void t_php_generator::generate_process_function(t_service* tservice, t_function* tfunction) {
+void t_php_generator::generate_process_function(std::ofstream& out, t_service* tservice, t_function* tfunction) {
// Open function
- indent(f_service_) << "protected function process_" << tfunction->get_name()
+ indent(out) << "protected function process_" << tfunction->get_name()
<< "($seqid, $input, $output) {" << endl;
indent_up();
@@ -1273,10 +1333,10 @@ void t_php_generator::generate_process_function(t_service* tservice, t_function*
string resultname = php_namespace(tservice->get_program()) + service_name_ + "_"
+ tfunction->get_name() + "_result";
- f_service_ << indent() << "$args = new " << argsname << "();" << endl << indent()
+ out << indent() << "$args = new " << argsname << "();" << endl << indent()
<< "$args->read($input);" << endl;
if (!binary_inline_) {
- f_service_ << indent() << "$input->readMessageEnd();" << endl;
+ out << indent() << "$input->readMessageEnd();" << endl;
}
t_struct* xs = tfunction->get_xceptions();
@@ -1285,12 +1345,12 @@ void t_php_generator::generate_process_function(t_service* tservice, t_function*
// Declare result for non oneway function
if (!tfunction->is_oneway()) {
- f_service_ << indent() << "$result = new " << resultname << "();" << endl;
+ out << indent() << "$result = new " << resultname << "();" << endl;
}
// Try block for a function with exceptions
if (xceptions.size() > 0) {
- f_service_ << indent() << "try {" << endl;
+ out << indent() << "try {" << endl;
indent_up();
}
@@ -1299,83 +1359,83 @@ void t_php_generator::generate_process_function(t_service* tservice, t_function*
const std::vector<t_field*>& fields = arg_struct->get_members();
vector<t_field*>::const_iterator f_iter;
- f_service_ << indent();
+ out << indent();
if (!tfunction->is_oneway() && !tfunction->get_returntype()->is_void()) {
- f_service_ << "$result->success = ";
+ out << "$result->success = ";
}
- f_service_ << "$this->handler_->" << tfunction->get_name() << "(";
+ out << "$this->handler_->" << tfunction->get_name() << "(";
bool first = true;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if (first) {
first = false;
} else {
- f_service_ << ", ";
+ out << ", ";
}
- f_service_ << "$args->" << (*f_iter)->get_name();
+ out << "$args->" << (*f_iter)->get_name();
}
- f_service_ << ");" << endl;
+ out << ");" << endl;
if (!tfunction->is_oneway() && xceptions.size() > 0) {
indent_down();
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
- f_service_ << indent() << "} catch ("
+ out << indent() << "} catch ("
<< php_namespace(get_true_type((*x_iter)->get_type())->get_program())
<< (*x_iter)->get_type()->get_name() << " $" << (*x_iter)->get_name() << ") {"
<< endl;
if (!tfunction->is_oneway()) {
indent_up();
- f_service_ << indent() << "$result->" << (*x_iter)->get_name() << " = $"
+ out << indent() << "$result->" << (*x_iter)->get_name() << " = $"
<< (*x_iter)->get_name() << ";" << endl;
indent_down();
- f_service_ << indent();
+ out << indent();
}
}
- f_service_ << "}" << endl;
+ out << "}" << endl;
}
// Shortcut out here for oneway functions
if (tfunction->is_oneway()) {
- f_service_ << indent() << "return;" << endl;
+ out << indent() << "return;" << endl;
indent_down();
- f_service_ << indent() << "}" << endl;
+ out << indent() << "}" << endl;
return;
}
- f_service_ << indent() << "$bin_accel = ($output instanceof "
+ out << indent() << "$bin_accel = ($output instanceof "
<< "TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');"
<< endl;
- f_service_ << indent() << "if ($bin_accel)" << endl;
- scope_up(f_service_);
+ out << indent() << "if ($bin_accel)" << endl;
+ scope_up(out);
- f_service_ << indent() << "thrift_protocol_write_binary($output, '" << tfunction->get_name()
+ out << indent() << "thrift_protocol_write_binary($output, '" << tfunction->get_name()
<< "', "
<< "TMessageType::REPLY, $result, $seqid, $output->isStrictWrite());" << endl;
- scope_down(f_service_);
- f_service_ << indent() << "else" << endl;
- scope_up(f_service_);
+ scope_down(out);
+ out << indent() << "else" << endl;
+ scope_up(out);
// Serialize the request header
if (binary_inline_) {
- f_service_ << indent() << "$buff = pack('N', (0x80010000 | "
- << "TMessageType::REPLY)); " << endl << indent() << "$buff .= pack('N', strlen('"
- << tfunction->get_name() << "'));" << endl << indent() << "$buff .= '"
- << tfunction->get_name() << "';" << endl << indent() << "$buff .= pack('N', $seqid);"
- << endl << indent() << "$result->write($buff);" << endl << indent()
- << "$output->write($buff);" << endl << indent() << "$output->flush();" << endl;
+ out << indent() << "$buff = pack('N', (0x80010000 | "
+ << "TMessageType::REPLY)); " << endl << indent() << "$buff .= pack('N', strlen('"
+ << tfunction->get_name() << "'));" << endl << indent() << "$buff .= '"
+ << tfunction->get_name() << "';" << endl << indent() << "$buff .= pack('N', $seqid);"
+ << endl << indent() << "$result->write($buff);" << endl << indent()
+ << "$output->write($buff);" << endl << indent() << "$output->flush();" << endl;
} else {
- f_service_ << indent() << "$output->writeMessageBegin('" << tfunction->get_name() << "', "
- << "TMessageType::REPLY, $seqid);" << endl << indent() << "$result->write($output);"
- << endl << indent() << "$output->writeMessageEnd();" << endl << indent()
- << "$output->getTransport()->flush();" << endl;
+ out << indent() << "$output->writeMessageBegin('" << tfunction->get_name() << "', "
+ << "TMessageType::REPLY, $seqid);" << endl << indent() << "$result->write($output);"
+ << endl << indent() << "$output->writeMessageEnd();" << endl << indent()
+ << "$output->getTransport()->flush();" << endl;
}
- scope_down(f_service_);
+ scope_down(out);
// Close function
indent_down();
- f_service_ << indent() << "}" << endl;
+ out << indent() << "}" << endl;
}
/**
@@ -1387,14 +1447,28 @@ void t_php_generator::generate_service_helpers(t_service* tservice) {
vector<t_function*> functions = tservice->get_functions();
vector<t_function*>::iterator f_iter;
- f_service_ << "// HELPER FUNCTIONS AND STRUCTURES" << endl << endl;
+ std::ofstream& f_struct_definition = f_service_;
+ if (!psr4_) {
+ f_struct_definition << "// HELPER FUNCTIONS AND STRUCTURES" << endl << endl;
+ }
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
t_struct* ts = (*f_iter)->get_arglist();
string name = ts->get_name();
ts->set_name(service_name_ + "_" + name);
- generate_php_struct_definition(f_service_, ts);
- generate_php_function_helpers(*f_iter);
+
+ if (psr4_) {
+ string f_struct_definition_name = package_dir_ + service_name_ + "_" + name + ".php";
+ f_struct_definition.open(f_struct_definition_name.c_str());
+ generate_service_header(tservice, f_struct_definition);
+ }
+
+ generate_php_struct_definition(f_struct_definition, ts);
+ if (psr4_) {
+ f_struct_definition.close();
+ }
+
+ generate_php_function_helpers(tservice, *f_iter);
ts->set_name(name);
}
}
@@ -1404,7 +1478,7 @@ void t_php_generator::generate_service_helpers(t_service* tservice) {
*
* @param tfunction The function
*/
-void t_php_generator::generate_php_function_helpers(t_function* tfunction) {
+void t_php_generator::generate_php_function_helpers(t_service* tservice, t_function* tfunction) {
if (!tfunction->is_oneway()) {
t_struct result(program_, service_name_ + "_" + tfunction->get_name() + "_result");
t_field success(tfunction->get_returntype(), "success", 0);
@@ -1419,7 +1493,16 @@ void t_php_generator::generate_php_function_helpers(t_function* tfunction) {
result.append(*f_iter);
}
- generate_php_struct_definition(f_service_, &result, false, true);
+ std::ofstream& f_struct_helper = f_service_;
+ if (psr4_) {
+ string f_struct_helper_name = package_dir_ + result.get_name() + ".php";
+ f_struct_helper.open(f_struct_helper_name.c_str());
+ generate_service_header(tservice, f_struct_helper);
+ }
+ generate_php_struct_definition(f_struct_helper, &result, false, true);
+ if (psr4_) {
+ f_struct_helper.close();
+ }
}
}
@@ -1429,6 +1512,13 @@ void t_php_generator::generate_php_function_helpers(t_function* tfunction) {
* @param tservice The service to generate a header definition for
*/
void t_php_generator::generate_service_interface(t_service* tservice) {
+ std::ofstream& f_service_interface = f_service_;
+ if (psr4_) {
+ string f_service_interface_name = package_dir_ + service_name_ + "If.php";
+ f_service_interface.open(f_service_interface_name.c_str());
+ generate_service_header(tservice, f_service_interface);
+ }
+
string extends = "";
string extends_if = "";
if (tservice->get_extends() != NULL) {
@@ -1437,24 +1527,37 @@ void t_php_generator::generate_service_interface(t_service* tservice) {
extends_if = " extends " + php_namespace(tservice->get_extends()->get_program())
+ tservice->get_extends()->get_name() + "If";
}
- generate_php_doc(f_service_, tservice);
- f_service_ << "interface " << php_namespace_declaration(tservice) << "If" << extends_if << " {"
+ generate_php_doc(f_service_interface, tservice);
+ f_service_interface << "interface " << php_namespace_declaration(tservice) << "If" << extends_if << " {"
<< endl;
indent_up();
vector<t_function*> functions = tservice->get_functions();
vector<t_function*>::iterator f_iter;
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- generate_php_doc(f_service_, *f_iter);
- indent(f_service_) << "public function " << function_signature(*f_iter) << ";" << endl;
+ generate_php_doc(f_service_interface, *f_iter);
+ indent(f_service_interface) << "public function " << function_signature(*f_iter) << ";" << endl;
}
indent_down();
- f_service_ << "}" << endl << endl;
+ f_service_interface << "}" << endl << endl;
+
+ // Close service interface file
+ f_service_interface << endl;
+ if (psr4_) {
+ f_service_interface.close();
+ }
}
/**
* Generates a REST interface
*/
void t_php_generator::generate_service_rest(t_service* tservice) {
+ std::ofstream& f_service_rest = f_service_;
+ if (psr4_) {
+ string f_service_rest_name = package_dir_ + service_name_ + "Rest.php";
+ f_service_rest.open(f_service_rest_name.c_str());
+ generate_service_header(tservice, f_service_rest);
+ }
+
string extends = "";
string extends_if = "";
if (tservice->get_extends() != NULL) {
@@ -1463,20 +1566,20 @@ void t_php_generator::generate_service_rest(t_service* tservice) {
extends_if = " extends " + php_namespace(tservice->get_extends()->get_program())
+ tservice->get_extends()->get_name() + "Rest";
}
- f_service_ << "class " << service_name_ << "Rest" << extends_if << " {" << endl;
+ f_service_rest << "class " << service_name_ << "Rest" << extends_if << " {" << endl;
indent_up();
if (extends.empty()) {
- f_service_ << indent() << "protected $impl_;" << endl << endl;
+ f_service_rest << indent() << "protected $impl_;" << endl << endl;
}
- f_service_ << indent() << "public function __construct($impl) {" << endl << indent()
+ f_service_rest << indent() << "public function __construct($impl) {" << endl << indent()
<< " $this->impl_ = $impl;" << endl << indent() << "}" << endl << endl;
vector<t_function*> functions = tservice->get_functions();
vector<t_function*>::iterator f_iter;
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- indent(f_service_) << "public function " << (*f_iter)->get_name() << "($request) {" << endl;
+ indent(f_service_rest) << "public function " << (*f_iter)->get_name() << "($request) {" << endl;
indent_up();
const vector<t_field*>& args = (*f_iter)->get_arglist()->get_members();
vector<t_field*>::const_iterator a_iter;
@@ -1485,35 +1588,41 @@ void t_php_generator::generate_service_rest(t_service* tservice) {
string cast = type_to_cast(atype);
string req = "$request['" + (*a_iter)->get_name() + "']";
if (atype->is_bool()) {
- f_service_ << indent() << "$" << (*a_iter)->get_name() << " = " << cast << "(!empty(" << req
+ f_service_rest << indent() << "$" << (*a_iter)->get_name() << " = " << cast << "(!empty(" << req
<< ") && (" << req << " !== 'false'));" << endl;
} else {
- f_service_ << indent() << "$" << (*a_iter)->get_name() << " = isset(" << req << ") ? "
+ f_service_rest << indent() << "$" << (*a_iter)->get_name() << " = isset(" << req << ") ? "
<< cast << req << " : null;" << endl;
}
if (atype->is_string() && ((t_base_type*)atype)->is_string_list()) {
- f_service_ << indent() << "$" << (*a_iter)->get_name() << " = explode(',', $"
- << (*a_iter)->get_name() << ");" << endl;
+ f_service_rest << indent() << "$" << (*a_iter)->get_name() << " = explode(',', $"
+ << (*a_iter)->get_name() << ");" << endl;
} else if (atype->is_map() || atype->is_list()) {
- f_service_ << indent() << "$" << (*a_iter)->get_name() << " = json_decode($"
- << (*a_iter)->get_name() << ", true);" << endl;
+ f_service_rest << indent() << "$" << (*a_iter)->get_name() << " = json_decode($"
+ << (*a_iter)->get_name() << ", true);" << endl;
} else if (atype->is_set()) {
- f_service_ << indent() << "$" << (*a_iter)->get_name() << " = array_fill_keys(json_decode($"
- << (*a_iter)->get_name() << ", true), 1);" << endl;
+ f_service_rest << indent() << "$" << (*a_iter)->get_name() << " = array_fill_keys(json_decode($"
+ << (*a_iter)->get_name() << ", true), 1);" << endl;
} else if (atype->is_struct() || atype->is_xception()) {
- f_service_ << indent() << "if ($" << (*a_iter)->get_name() << " !== null) {" << endl
- << indent() << " $" << (*a_iter)->get_name() << " = new "
- << php_namespace(atype->get_program()) << atype->get_name() << "(json_decode($"
- << (*a_iter)->get_name() << ", true));" << endl << indent() << "}" << endl;
+ f_service_rest << indent() << "if ($" << (*a_iter)->get_name() << " !== null) {" << endl
+ << indent() << " $" << (*a_iter)->get_name() << " = new "
+ << php_namespace(atype->get_program()) << atype->get_name() << "(json_decode($"
+ << (*a_iter)->get_name() << ", true));" << endl << indent() << "}" << endl;
}
}
- f_service_ << indent() << "return $this->impl_->" << (*f_iter)->get_name() << "("
+ f_service_rest << indent() << "return $this->impl_->" << (*f_iter)->get_name() << "("
<< argument_list((*f_iter)->get_arglist(), false) << ");" << endl;
indent_down();
- indent(f_service_) << "}" << endl << endl;
+ indent(f_service_rest) << "}" << endl << endl;
}
indent_down();
- f_service_ << "}" << endl << endl;
+ f_service_rest << "}" << endl << endl;
+
+ // Close service rest file
+ f_service_rest << endl;
+ if (psr4_) {
+ f_service_rest.close();
+ }
}
/**
@@ -1522,6 +1631,13 @@ void t_php_generator::generate_service_rest(t_service* tservice) {
* @param tservice The service to generate a server for.
*/
void t_php_generator::generate_service_client(t_service* tservice) {
+ std::ofstream& f_service_client = f_service_;
+ if (psr4_) {
+ string f_service_client_name = package_dir_ + service_name_ + "Client.php";
+ f_service_client.open(f_service_client_name.c_str());
+ generate_service_header(tservice, f_service_client);
+ }
+
string extends = "";
string extends_client = "";
if (tservice->get_extends() != NULL) {
@@ -1530,27 +1646,27 @@ void t_php_generator::generate_service_client(t_service* tservice) {
+ "Client";
}
- f_service_ << "class " << php_namespace_declaration(tservice) << "Client" << extends_client
+ f_service_client << "class " << php_namespace_declaration(tservice) << "Client" << extends_client
<< " implements " << php_namespace(tservice->get_program()) << service_name_ << "If {"
<< endl;
indent_up();
// Private members
if (extends.empty()) {
- f_service_ << indent() << "protected $input_ = null;" << endl << indent()
+ f_service_client << indent() << "protected $input_ = null;" << endl << indent()
<< "protected $output_ = null;" << endl << endl;
- f_service_ << indent() << "protected $seqid_ = 0;" << endl << endl;
+ f_service_client << indent() << "protected $seqid_ = 0;" << endl << endl;
}
// Constructor function
- f_service_ << indent() << "public function __construct($input, $output=null) {" << endl;
+ f_service_client << indent() << "public function __construct($input, $output=null) {" << endl;
if (!extends.empty()) {
- f_service_ << indent() << " parent::__construct($input, $output);" << endl;
+ f_service_client << indent() << " parent::__construct($input, $output);" << endl;
} else {
- f_service_ << indent() << " $this->input_ = $input;" << endl << indent()
+ f_service_client << indent() << " $this->input_ = $input;" << endl << indent()
<< " $this->output_ = $output ? $output : $input;" << endl;
}
- f_service_ << indent() << "}" << endl << endl;
+ f_service_client << indent() << "}" << endl << endl;
// Generate client method implementations
vector<t_function*> functions = tservice->get_functions();
@@ -1562,86 +1678,86 @@ void t_php_generator::generate_service_client(t_service* tservice) {
string funname = (*f_iter)->get_name();
// Open function
- indent(f_service_) << "public function " << function_signature(*f_iter) << endl;
- scope_up(f_service_);
- indent(f_service_) << "$this->send_" << funname << "(";
+ indent(f_service_client) << "public function " << function_signature(*f_iter) << endl;
+ scope_up(f_service_client);
+ indent(f_service_client) << "$this->send_" << funname << "(";
bool first = true;
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
if (first) {
first = false;
} else {
- f_service_ << ", ";
+ f_service_client << ", ";
}
- f_service_ << "$" << (*fld_iter)->get_name();
+ f_service_client << "$" << (*fld_iter)->get_name();
}
- f_service_ << ");" << endl;
+ f_service_client << ");" << endl;
if (!(*f_iter)->is_oneway()) {
- f_service_ << indent();
+ f_service_client << indent();
if (!(*f_iter)->get_returntype()->is_void()) {
- f_service_ << "return ";
+ f_service_client << "return ";
}
- f_service_ << "$this->recv_" << funname << "();" << endl;
+ f_service_client << "$this->recv_" << funname << "();" << endl;
}
- scope_down(f_service_);
- f_service_ << endl;
+ scope_down(f_service_client);
+ f_service_client << endl;
- indent(f_service_) << "public function send_" << function_signature(*f_iter) << endl;
- scope_up(f_service_);
+ indent(f_service_client) << "public function send_" << function_signature(*f_iter) << endl;
+ scope_up(f_service_client);
std::string argsname = php_namespace(tservice->get_program()) + service_name_ + "_"
+ (*f_iter)->get_name() + "_args";
- f_service_ << indent() << "$args = new " << argsname << "();" << endl;
+ f_service_client << indent() << "$args = new " << argsname << "();" << endl;
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
- f_service_ << indent() << "$args->" << (*fld_iter)->get_name() << " = $"
+ f_service_client << indent() << "$args->" << (*fld_iter)->get_name() << " = $"
<< (*fld_iter)->get_name() << ";" << endl;
}
- f_service_ << indent() << "$bin_accel = ($this->output_ instanceof "
+ f_service_client << indent() << "$bin_accel = ($this->output_ instanceof "
<< "TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');"
<< endl;
- f_service_ << indent() << "if ($bin_accel)" << endl;
- scope_up(f_service_);
+ f_service_client << indent() << "if ($bin_accel)" << endl;
+ scope_up(f_service_client);
string messageType = (*f_iter)->is_oneway() ? "TMessageType::ONEWAY" : "TMessageType::CALL";
- f_service_ << indent() << "thrift_protocol_write_binary($this->output_, '"
+ f_service_client << indent() << "thrift_protocol_write_binary($this->output_, '"
<< (*f_iter)->get_name() << "', " << messageType
<< ", $args, $this->seqid_, $this->output_->isStrictWrite());" << endl;
- scope_down(f_service_);
- f_service_ << indent() << "else" << endl;
- scope_up(f_service_);
+ scope_down(f_service_client);
+ f_service_client << indent() << "else" << endl;
+ scope_up(f_service_client);
// Serialize the request header
if (binary_inline_) {
- f_service_ << indent() << "$buff = pack('N', (0x80010000 | " << messageType << "));" << endl
- << indent() << "$buff .= pack('N', strlen('" << funname << "'));" << endl
- << indent() << "$buff .= '" << funname << "';" << endl << indent()
- << "$buff .= pack('N', $this->seqid_);" << endl;
+ f_service_client << indent() << "$buff = pack('N', (0x80010000 | " << messageType << "));" << endl
+ << indent() << "$buff .= pack('N', strlen('" << funname << "'));" << endl
+ << indent() << "$buff .= '" << funname << "';" << endl << indent()
+ << "$buff .= pack('N', $this->seqid_);" << endl;
} else {
- f_service_ << indent() << "$this->output_->writeMessageBegin('" << (*f_iter)->get_name()
- << "', " << messageType << ", $this->seqid_);" << endl;
+ f_service_client << indent() << "$this->output_->writeMessageBegin('" << (*f_iter)->get_name()
+ << "', " << messageType << ", $this->seqid_);" << endl;
}
// Write to the stream
if (binary_inline_) {
- f_service_ << indent() << "$args->write($buff);" << endl << indent()
- << "$this->output_->write($buff);" << endl << indent()
- << "$this->output_->flush();" << endl;
+ f_service_client << indent() << "$args->write($buff);" << endl << indent()
+ << "$this->output_->write($buff);" << endl << indent()
+ << "$this->output_->flush();" << endl;
} else {
- f_service_ << indent() << "$args->write($this->output_);" << endl << indent()
- << "$this->output_->writeMessageEnd();" << endl << indent()
- << "$this->output_->getTransport()->flush();" << endl;
+ f_service_client << indent() << "$args->write($this->output_);" << endl << indent()
+ << "$this->output_->writeMessageEnd();" << endl << indent()
+ << "$this->output_->getTransport()->flush();" << endl;
}
- scope_down(f_service_);
+ scope_down(f_service_client);
- scope_down(f_service_);
+ scope_down(f_service_client);
if (!(*f_iter)->is_oneway()) {
std::string resultname = php_namespace(tservice->get_program()) + service_name_ + "_"
@@ -1652,55 +1768,55 @@ void t_php_generator::generate_service_client(t_service* tservice) {
string("recv_") + (*f_iter)->get_name(),
&noargs);
// Open function
- f_service_ << endl << indent() << "public function " << function_signature(&recv_function)
- << endl;
- scope_up(f_service_);
+ f_service_client << endl << indent() << "public function " << function_signature(&recv_function)
+ << endl;
+ scope_up(f_service_client);
- f_service_ << indent() << "$bin_accel = ($this->input_ instanceof "
- << "TBinaryProtocolAccelerated)"
- << " && function_exists('thrift_protocol_read_binary');" << endl;
+ f_service_client << indent() << "$bin_accel = ($this->input_ instanceof "
+ << "TBinaryProtocolAccelerated)"
+ << " && function_exists('thrift_protocol_read_binary');" << endl;
- f_service_ << indent()
- << "if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '"
- << resultname << "', $this->input_->isStrictRead());" << endl;
- f_service_ << indent() << "else" << endl;
- scope_up(f_service_);
+ f_service_client << indent()
+ << "if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '"
+ << resultname << "', $this->input_->isStrictRead());" << endl;
+ f_service_client << indent() << "else" << endl;
+ scope_up(f_service_client);
- f_service_ << indent() << "$rseqid = 0;" << endl << indent() << "$fname = null;" << endl
+ f_service_client << indent() << "$rseqid = 0;" << endl << indent() << "$fname = null;" << endl
<< indent() << "$mtype = 0;" << endl << endl;
if (binary_inline_) {
t_field ffname(g_type_string, "fname");
t_field fseqid(g_type_i32, "rseqid");
- f_service_ << indent() << "$ver = unpack('N', $this->input_->readAll(4));" << endl
- << indent() << "$ver = $ver[1];" << endl << indent() << "$mtype = $ver & 0xff;"
- << endl << indent() << "$ver = $ver & 0xffff0000;" << endl << indent()
- << "if ($ver != 0x80010000) throw new "
- << "TProtocolException('Bad version identifier: '.$ver, "
- << "TProtocolException::BAD_VERSION);" << endl;
- generate_deserialize_field(f_service_, &ffname, "", true);
- generate_deserialize_field(f_service_, &fseqid, "", true);
+ f_service_client << indent() << "$ver = unpack('N', $this->input_->readAll(4));" << endl
+ << indent() << "$ver = $ver[1];" << endl << indent() << "$mtype = $ver & 0xff;"
+ << endl << indent() << "$ver = $ver & 0xffff0000;" << endl << indent()
+ << "if ($ver != 0x80010000) throw new "
+ << "TProtocolException('Bad version identifier: '.$ver, "
+ << "TProtocolException::BAD_VERSION);" << endl;
+ generate_deserialize_field(f_service_client, &ffname, "", true);
+ generate_deserialize_field(f_service_client, &fseqid, "", true);
} else {
- f_service_ << indent() << "$this->input_->readMessageBegin($fname, $mtype, $rseqid);"
- << endl << indent() << "if ($mtype == "
- << "TMessageType::EXCEPTION) {" << endl << indent() << " $x = new "
- << "TApplicationException();" << endl << indent() << " $x->read($this->input_);"
- << endl << indent() << " $this->input_->readMessageEnd();" << endl << indent()
- << " throw $x;" << endl << indent() << "}" << endl;
+ f_service_client << indent() << "$this->input_->readMessageBegin($fname, $mtype, $rseqid);"
+ << endl << indent() << "if ($mtype == "
+ << "TMessageType::EXCEPTION) {" << endl << indent() << " $x = new "
+ << "TApplicationException();" << endl << indent() << " $x->read($this->input_);"
+ << endl << indent() << " $this->input_->readMessageEnd();" << endl << indent()
+ << " throw $x;" << endl << indent() << "}" << endl;
}
- f_service_ << indent() << "$result = new " << resultname << "();" << endl << indent()
- << "$result->read($this->input_);" << endl;
+ f_service_client << indent() << "$result = new " << resultname << "();" << endl << indent()
+ << "$result->read($this->input_);" << endl;
if (!binary_inline_) {
- f_service_ << indent() << "$this->input_->readMessageEnd();" << endl;
+ f_service_client << indent() << "$this->input_->readMessageEnd();" << endl;
}
- scope_down(f_service_);
+ scope_down(f_service_client);
// Careful, only return result if not a void function
if (!(*f_iter)->get_returntype()->is_void()) {
- f_service_ << indent() << "if ($result->success !== null) {" << endl << indent()
+ f_service_client << indent() << "if ($result->success !== null) {" << endl << indent()
<< " return $result->success;" << endl << indent() << "}" << endl;
}
@@ -1708,27 +1824,33 @@ void t_php_generator::generate_service_client(t_service* tservice) {
const std::vector<t_field*>& xceptions = xs->get_members();
vector<t_field*>::const_iterator x_iter;
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
- f_service_ << indent() << "if ($result->" << (*x_iter)->get_name() << " !== null) {" << endl
- << indent() << " throw $result->" << (*x_iter)->get_name() << ";" << endl
- << indent() << "}" << endl;
+ f_service_client << indent() << "if ($result->" << (*x_iter)->get_name() << " !== null) {" << endl
+ << indent() << " throw $result->" << (*x_iter)->get_name() << ";" << endl
+ << indent() << "}" << endl;
}
// Careful, only return _result if not a void function
if ((*f_iter)->get_returntype()->is_void()) {
- indent(f_service_) << "return;" << endl;
+ indent(f_service_client) << "return;" << endl;
} else {
- f_service_ << indent() << "throw new \\Exception(\"" << (*f_iter)->get_name()
- << " failed: unknown result\");" << endl;
+ f_service_client << indent() << "throw new \\Exception(\"" << (*f_iter)->get_name()
+ << " failed: unknown result\");" << endl;
}
// Close function
- scope_down(f_service_);
- f_service_ << endl;
+ scope_down(f_service_client);
+ f_service_client << endl;
}
}
indent_down();
- f_service_ << "}" << endl << endl;
+ f_service_client << "}" << endl << endl;
+
+ // Close service client file
+ f_service_client << endl;
+ if (psr4_) {
+ f_service_client.close();
+ }
}
/**
@@ -2524,6 +2646,7 @@ THRIFT_REGISTER_GENERATOR(
" inlined: Generate PHP inlined files\n"
" server: Generate PHP server stubs\n"
" oop: Generate PHP with object oriented subclasses\n"
+ " psr4: Generate each PHP class in separate file (allows PSR4 autoloading)\n"
" rest: Generate PHP REST processors\n"
" nsglobal=NAME: Set global namespace\n"
" validate: Generate PHP validator methods\n"
[06/10] thrift git commit: THRIFT-3908 Remove redundant dependencies
from Dockerfile
Posted by ns...@apache.org.
THRIFT-3908 Remove redundant dependencies from Dockerfile
This closes #1071
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/080041c3
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/080041c3
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/080041c3
Branch: refs/heads/master
Commit: 080041c3855fdcdd372240e6a4c4deb5e2da16a9
Parents: 88c5ee7
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sun Sep 4 18:49:19 2016 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Sep 4 18:49:19 2016 +0900
----------------------------------------------------------------------
build/docker/debian/Dockerfile | 10 ++--------
build/docker/ubuntu/Dockerfile | 10 ++--------
2 files changed, 4 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/080041c3/build/docker/debian/Dockerfile
----------------------------------------------------------------------
diff --git a/build/docker/debian/Dockerfile b/build/docker/debian/Dockerfile
index 5ec956e..22dd3b5 100644
--- a/build/docker/debian/Dockerfile
+++ b/build/docker/debian/Dockerfile
@@ -121,10 +121,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
RUN apt-get update && apt-get install -y --no-install-recommends \
`# CSharp dependencies` \
libmono-system-web2.0-cil \
- mono-complete \
- mono-devel \
- mono-gmcs \
- mono-xbuild
+ mono-devel
RUN apt-get update && apt-get install -y --no-install-recommends \
`# D dependencies` \
@@ -145,11 +142,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
rm -rf /tmp/* && \
rm -rf /var/tmp/*
-# Java
-RUN update-java-alternatives -s java-1.7.0-openjdk-amd64
-
# Ruby
-RUN gem install bundler rake
+RUN gem install bundler --no-ri --no-rdoc
# Go
RUN curl -sSL https://storage.googleapis.com/golang/go1.4.3.linux-amd64.tar.gz | tar -C /usr/local/ -xz
http://git-wip-us.apache.org/repos/asf/thrift/blob/080041c3/build/docker/ubuntu/Dockerfile
----------------------------------------------------------------------
diff --git a/build/docker/ubuntu/Dockerfile b/build/docker/ubuntu/Dockerfile
index 4f09538..99f0a8f 100644
--- a/build/docker/ubuntu/Dockerfile
+++ b/build/docker/ubuntu/Dockerfile
@@ -139,10 +139,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
RUN apt-get update && apt-get install -y --no-install-recommends \
`# CSharp dependencies` \
libmono-system-web2.0-cil \
- mono-complete \
- mono-devel \
- mono-gmcs \
- mono-xbuild
+ mono-devel
RUN apt-get update && apt-get install -y --no-install-recommends \
`# D dependencies` \
@@ -163,11 +160,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
rm -rf /tmp/* && \
rm -rf /var/tmp/*
-# Java
-RUN update-java-alternatives -s java-1.7.0-openjdk-amd64
-
# Ruby
-RUN gem install bundler rake
+RUN gem install bundler --no-ri --no-rdoc
# Go
RUN curl -sSL https://storage.googleapis.com/golang/go1.4.3.linux-amd64.tar.gz | tar -C /usr/local/ -xz
[03/10] thrift git commit: THRIFT-3904 Fix typo in node tutorial.
Posted by ns...@apache.org.
THRIFT-3904 Fix typo in node tutorial.
This closes #1067
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/c2256fc7
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/c2256fc7
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/c2256fc7
Branch: refs/heads/master
Commit: c2256fc751f61bb364e9e5f0fe3b5747adf4970c
Parents: d1ceba4
Author: Mark Sonnabaum <ma...@sonnabaum.com>
Authored: Thu Aug 25 09:08:47 2016 -0500
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sat Sep 3 17:20:06 2016 +0900
----------------------------------------------------------------------
tutorial/nodejs/NodeClient.js | 4 ++--
tutorial/nodejs/NodeClientPromise.js | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/c2256fc7/tutorial/nodejs/NodeClient.js
----------------------------------------------------------------------
diff --git a/tutorial/nodejs/NodeClient.js b/tutorial/nodejs/NodeClient.js
index 475e304..130ba57 100644
--- a/tutorial/nodejs/NodeClient.js
+++ b/tutorial/nodejs/NodeClient.js
@@ -22,8 +22,8 @@ var Calculator = require('./gen-nodejs/Calculator');
var ttypes = require('./gen-nodejs/tutorial_types');
-var transport = thrift.TBufferedTransport();
-var protocol = thrift.TBinaryProtocol();
+var transport = thrift.TBufferedTransport;
+var protocol = thrift.TBinaryProtocol;
var connection = thrift.createConnection("localhost", 9090, {
transport : transport,
http://git-wip-us.apache.org/repos/asf/thrift/blob/c2256fc7/tutorial/nodejs/NodeClientPromise.js
----------------------------------------------------------------------
diff --git a/tutorial/nodejs/NodeClientPromise.js b/tutorial/nodejs/NodeClientPromise.js
index d0245c5..fac12ba 100644
--- a/tutorial/nodejs/NodeClientPromise.js
+++ b/tutorial/nodejs/NodeClientPromise.js
@@ -22,8 +22,8 @@ var Calculator = require('./gen-nodejs/Calculator');
var ttypes = require('./gen-nodejs/tutorial_types');
-var transport = thrift.TBufferedTransport();
-var protocol = thrift.TBinaryProtocol();
+var transport = thrift.TBufferedTransport;
+var protocol = thrift.TBinaryProtocol;
var connection = thrift.createConnection("localhost", 9090, {
transport : transport,
[05/10] thrift git commit: THRIFT-3906 Run C# tests with make check
Posted by ns...@apache.org.
THRIFT-3906 Run C# tests with make check
This closes #1069
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/88c5ee71
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/88c5ee71
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/88c5ee71
Branch: refs/heads/master
Commit: 88c5ee71db1cc25c37a1c66e5dde0d5ce6f55096
Parents: c2256fc
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sun Sep 4 18:49:18 2016 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Sep 4 18:49:18 2016 +0900
----------------------------------------------------------------------
configure.ac | 3 +-
lib/Makefile.am | 1 -
lib/csharp/Makefile.am | 20 +-
.../Multiplex/Client/Multiplex.Test.Client.cs | 43 +-
lib/csharp/test/Multiplex/Makefile.am | 52 ++
.../Multiplex/Server/Multiplex.Test.Server.cs | 98 +--
lib/csharp/test/Multiplex/maketest.sh | 34 -
lib/csharp/test/ThriftTest/Makefile.am | 36 -
lib/csharp/test/ThriftTest/Program.cs | 71 --
.../test/ThriftTest/Properties/AssemblyInfo.cs | 55 --
lib/csharp/test/ThriftTest/TestClient.cs | 833 ------------------
lib/csharp/test/ThriftTest/TestServer.cs | 547 ------------
lib/csharp/test/ThriftTest/ThriftTest.csproj | 141 ----
lib/csharp/test/ThriftTest/maketest.sh | 30 -
test/Makefile.am | 5 +
test/csharp/Makefile.am | 87 ++
test/csharp/Program.cs | 71 ++
test/csharp/Properties/AssemblyInfo.cs | 55 ++
test/csharp/TestClient.cs | 836 +++++++++++++++++++
test/csharp/TestServer.cs | 547 ++++++++++++
test/csharp/ThriftTest.csproj | 141 ++++
test/csharp/ThriftTest.sln | 17 +
test/tests.json | 4 +-
23 files changed, 1877 insertions(+), 1850 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index c72dd43..fb22699 100755
--- a/configure.ac
+++ b/configure.ac
@@ -721,7 +721,7 @@ AC_CONFIG_FILES([
lib/c_glib/thrift_c_glib.pc
lib/c_glib/test/Makefile
lib/csharp/Makefile
- lib/csharp/test/ThriftTest/Makefile
+ lib/csharp/test/Multiplex/Makefile
lib/d/Makefile
lib/d/test/Makefile
lib/erl/Makefile
@@ -749,6 +749,7 @@ AC_CONFIG_FILES([
test/features/Makefile
test/c_glib/Makefile
test/cpp/Makefile
+ test/csharp/Makefile
test/erl/Makefile
test/go/Makefile
test/haxe/Makefile
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/Makefile.am b/lib/Makefile.am
index d8d9b47..f12e092 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -30,7 +30,6 @@ endif
if WITH_MONO
SUBDIRS += csharp
-PRECROSS_TARGET += precross-csharp
endif
if WITH_JAVA
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/csharp/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/csharp/Makefile.am b/lib/csharp/Makefile.am
index 824a872..bf02c87 100644
--- a/lib/csharp/Makefile.am
+++ b/lib/csharp/Makefile.am
@@ -17,9 +17,9 @@
# under the License.
#
-SUBDIRS = . test/ThriftTest
+SUBDIRS = . test/Multiplex
-THRIFTCODE= \
+THRIFTCODE = \
src/Collections/THashSet.cs \
src/Collections/TCollections.cs \
src/Properties/AssemblyInfo.cs \
@@ -74,31 +74,23 @@ THRIFTCODE= \
src/TApplicationException.cs
if MONO_MCS
-CSC=mcs
+export CSC = mcs
else
-CSC=gmcs
+export CSC = gmcs
endif
if NET_2_0
-MONO_DEFINES=/d:NET_2_0
+export CSC_DEFINES = -d:NET_2_0
endif
all-local: Thrift.dll
Thrift.dll: $(THRIFTCODE)
- $(CSC) $(THRIFTCODE) /out:Thrift.dll /target:library /reference:System.Web $(MONO_DEFINES)
+ $(CSC) $(CSC_DEFINES) -out:$@ -target:library -reference:System.Web $(THRIFTCODE)
clean-local:
$(RM) Thrift.dll
-precross: all-local
- $(MAKE) -C test/ThriftTest precross
-
-# run csharp tests?
-# check:
-# cd test/ThriftTest && ./maketest.sh
-# cd test/Multiplex && ./maketest.sh
-
EXTRA_DIST = \
$(THRIFTCODE) \
ThriftMSBuildTask \
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs b/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs
index ccfe21d..c810a08 100644
--- a/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs
+++ b/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs
@@ -26,17 +26,16 @@ using Thrift.Server;
using Thrift;
using Test.Multiplex;
-
namespace Test.Multiplex.Client
{
public class TestClient
{
- private void Run()
+ static void Execute(int port)
{
try
{
TTransport trans;
- trans = new TSocket("localhost", 9090);
+ trans = new TSocket("localhost", port);
trans = new TFramedTransport(trans);
trans.Open();
@@ -44,44 +43,40 @@ namespace Test.Multiplex.Client
TMultiplexedProtocol multiplex;
- multiplex = new TMultiplexedProtocol( Protocol, Constants.NAME_BENCHMARKSERVICE);
- BenchmarkService.Iface bench = new BenchmarkService.Client( multiplex);
+ multiplex = new TMultiplexedProtocol(Protocol, Constants.NAME_BENCHMARKSERVICE);
+ BenchmarkService.Iface bench = new BenchmarkService.Client(multiplex);
- multiplex = new TMultiplexedProtocol( Protocol, Constants.NAME_AGGR);
- Aggr.Iface aggr = new Aggr.Client( multiplex);
+ multiplex = new TMultiplexedProtocol(Protocol, Constants.NAME_AGGR);
+ Aggr.Iface aggr = new Aggr.Client(multiplex);
- sbyte i;
- for( i = 1; 10 >= i; ++i)
+ for (sbyte i = 1; 10 >= i; ++i)
{
- aggr.addValue( bench.fibonacci(i));
+ aggr.addValue(bench.fibonacci(i));
}
- foreach( int k in aggr.getValues())
+ foreach (int k in aggr.getValues())
{
- Console.Write(k.ToString()+" ");
+ Console.Write(k.ToString() + " ");
Console.WriteLine("");
}
+ trans.Close();
}
- catch( Exception e)
+ catch (Exception e)
{
- Console.WriteLine( e.Message);
+ Console.WriteLine(e.Message);
}
}
-
- public static void Execute()
- {
- TestClient client = new TestClient();
- client.Run();
- }
-
static void Main(string[] args)
{
- Execute();
+ int port = 9090;
+ if (args.Length > 0)
+ {
+ port = ushort.Parse(args[0]);
+ }
+ Execute(port);
Console.WriteLine("done.");
- Console.ReadLine();
}
-
}
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/csharp/test/Multiplex/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/csharp/test/Multiplex/Makefile.am b/lib/csharp/test/Multiplex/Makefile.am
new file mode 100644
index 0000000..57253d6
--- /dev/null
+++ b/lib/csharp/test/Multiplex/Makefile.am
@@ -0,0 +1,52 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+GENERATED = \
+ gen-csharp/Aggr.cs \
+ gen-csharp/BenchmarkService.cs \
+ gen-csharp/Error.cs
+
+BUILT_SOURCES = $(GENERATED)
+
+THRIFT = $(top_builddir)/compiler/cpp/thrift
+
+gen-csharp/Aggr.cs: $(top_srcdir)/contrib/async-test/aggr.thrift
+ $(THRIFT) --gen csharp $<
+
+gen-csharp/BenchmarkService.cs gen-csharp/Error.cs: $(top_srcdir)/lib/rb/benchmark/Benchmark.thrift
+ $(THRIFT) --gen csharp $<
+
+ThriftImpl.dll: Multiplex.Test.Common.cs $(GENERATED) ../../Thrift.dll
+ $(CSC) $(CSC_DEFINES) -t:library -out:./ThriftImpl.dll -reference:../../Thrift.dll $(GENERATED) $<
+
+MultiplexClient.exe: Client/Multiplex.Test.Client.cs ThriftImpl.dll
+ $(CSC) $(CSC_DEFINES) -out:$@ -reference:../../Thrift.dll -reference:ThriftImpl.dll $<
+
+MultiplexServer.exe: Server/Multiplex.Test.Server.cs ThriftImpl.dll
+ $(CSC) $(CSC_DEFINES) -out:$@ -reference:../../Thrift.dll -reference:ThriftImpl.dll $<
+
+clean-local:
+ $(RM) -rf gen-csharp *.exe *.dll
+
+TESTPORT = 9501
+check-local: MultiplexServer.exe MultiplexClient.exe
+ echo $(TESTPORT)
+ MONO_PATH=../../ timeout 10 mono MultiplexServer.exe $(TESTPORT) &
+ sleep 1
+ MONO_PATH=../../ mono MultiplexClient.exe $(TESTPORT)
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs b/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs
index 61c2d7c..9786189 100644
--- a/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs
+++ b/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs
@@ -30,30 +30,14 @@ namespace Test.Multiplex.Server
{
public class TestServer
{
- public interface ITestHandler
- {
- void SetServer( TServer aServer);
- }
-
- protected class TestHandlerImpl : ITestHandler
- {
- private TServer Server;
-
- public void SetServer( TServer aServer)
- {
- Server = aServer;
- }
- }
-
-
- protected class BenchmarkServiceImpl : TestHandlerImpl, BenchmarkService.Iface
+ class BenchmarkServiceImpl : BenchmarkService.Iface
{
public int fibonacci(sbyte n)
{
int prev, next, result;
prev = 0;
result = 1;
- while( n > 0)
+ while (n > 0)
{
next = result + prev;
prev = result;
@@ -64,14 +48,13 @@ namespace Test.Multiplex.Server
}
}
-
- protected class AggrServiceImpl : TestHandlerImpl, Aggr.Iface
+ class AggrServiceImpl : Aggr.Iface
{
List<int> values = new List<int>();
public void addValue(int value)
{
- values.Add( value);
+ values.Add(value);
}
public List<int> getValues()
@@ -80,52 +63,45 @@ namespace Test.Multiplex.Server
}
}
- static void Execute()
- {
- try
- {
- // create protocol factory, default to BinaryProtocol
- TProtocolFactory ProtocolFactory = new TBinaryProtocol.Factory(true,true);
- TServerTransport servertrans = new TServerSocket( 9090, 0, false);
- TTransportFactory TransportFactory = new TFramedTransport.Factory();
-
- BenchmarkService.Iface benchHandler = new BenchmarkServiceImpl();
- TProcessor benchProcessor = new BenchmarkService.Processor( benchHandler);
-
- Aggr.Iface aggrHandler = new AggrServiceImpl();
- TProcessor aggrProcessor = new Aggr.Processor( aggrHandler);
-
- TMultiplexedProcessor multiplex = new TMultiplexedProcessor();
- multiplex.RegisterProcessor(Constants.NAME_BENCHMARKSERVICE, benchProcessor);
- multiplex.RegisterProcessor(Constants.NAME_AGGR, aggrProcessor);
-
- TServer ServerEngine = new TSimpleServer( multiplex, servertrans, TransportFactory, ProtocolFactory);
+ static void Execute(int port)
+ {
+ try
+ {
+ // create protocol factory, default to BinaryProtocol
+ TProtocolFactory ProtocolFactory = new TBinaryProtocol.Factory(true,true);
+ TServerTransport servertrans = new TServerSocket(port, 0, false);
+ TTransportFactory TransportFactory = new TFramedTransport.Factory();
- (benchHandler as ITestHandler).SetServer( ServerEngine);
- (aggrHandler as ITestHandler).SetServer( ServerEngine);
+ BenchmarkService.Iface benchHandler = new BenchmarkServiceImpl();
+ TProcessor benchProcessor = new BenchmarkService.Processor(benchHandler);
- Console.WriteLine("Starting the server ...");
- ServerEngine.Serve();
+ Aggr.Iface aggrHandler = new AggrServiceImpl();
+ TProcessor aggrProcessor = new Aggr.Processor(aggrHandler);
- (benchHandler as ITestHandler).SetServer(null);
- (aggrHandler as ITestHandler).SetServer(null);
+ TMultiplexedProcessor multiplex = new TMultiplexedProcessor();
+ multiplex.RegisterProcessor(Constants.NAME_BENCHMARKSERVICE, benchProcessor);
+ multiplex.RegisterProcessor(Constants.NAME_AGGR, aggrProcessor);
- }
- catch( Exception e)
- {
- Console.WriteLine( e.Message);
- }
- Console.WriteLine( "done.");
- }
+ TServer ServerEngine = new TSimpleServer(multiplex, servertrans, TransportFactory, ProtocolFactory);
+ Console.WriteLine("Starting the server ...");
+ ServerEngine.Serve();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
- static void Main(string[] args)
- {
- Execute();
- }
+ static void Main(string[] args)
+ {
+ int port = 9090;
+ if (args.Length > 0)
+ {
+ port = ushort.Parse(args[0]);
+ }
+ Execute(port);
+ }
}
-
-
-
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/csharp/test/Multiplex/maketest.sh
----------------------------------------------------------------------
diff --git a/lib/csharp/test/Multiplex/maketest.sh b/lib/csharp/test/Multiplex/maketest.sh
deleted file mode 100755
index 1f29ee2..0000000
--- a/lib/csharp/test/Multiplex/maketest.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/sh
-
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-../../../../compiler/cpp/thrift --gen csharp ../../../../contrib/async-test/aggr.thrift
-../../../../compiler/cpp/thrift --gen csharp ../../../rb/benchmark/Benchmark.thrift
-gmcs /t:library /out:./ThriftImpl.dll /recurse:./gen-csharp/* /reference:../../Thrift.dll Multiplex.Test.Common.cs
-gmcs /out:MultiplexClient.exe /reference:../../Thrift.dll /reference:ThriftImpl.dll Client/Multiplex.Test.Client.cs
-gmcs /out:MultiplexServer.exe /reference:../../Thrift.dll /reference:ThriftImpl.dll Server/Multiplex.Test.Server.cs
-
-
-
-export MONO_PATH=../../
-
-timeout 120 ./MultiplexServer.exe &
-sleep 3;
-./MultiplexClient.exe
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/csharp/test/ThriftTest/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/csharp/test/ThriftTest/Makefile.am b/lib/csharp/test/ThriftTest/Makefile.am
deleted file mode 100644
index c0014e6..0000000
--- a/lib/csharp/test/ThriftTest/Makefile.am
+++ /dev/null
@@ -1,36 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-THRIFT = $(top_builddir)/compiler/cpp/thrift
-if MONO_MCS
-CSC=mcs
-else
-CSC=gmcs
-endif
-
-stubs: $(top_srcdir)/test/ThriftTest.thrift
- $(THRIFT) --gen csharp -o . $(top_srcdir)/test/ThriftTest.thrift
-
-precross: TestClientServer.exe
-
-ThriftImpl.dll: stubs
- $(CSC) /t:library /out:./ThriftImpl.dll /recurse:./gen-csharp/Thrift/Test/*.cs /reference:../../Thrift.dll
-
-TestClientServer.exe: TestClient.cs TestServer.cs Program.cs ThriftImpl.dll
- $(CSC) /out:TestClientServer.exe /reference:../../Thrift.dll /reference:ThriftImpl.dll TestClient.cs TestServer.cs Program.cs
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/csharp/test/ThriftTest/Program.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/test/ThriftTest/Program.cs b/lib/csharp/test/ThriftTest/Program.cs
deleted file mode 100644
index 8ec00e3..0000000
--- a/lib/csharp/test/ThriftTest/Program.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-// Distributed under the Thrift Software License
-//
-// See accompanying file LICENSE or visit the Thrift site at:
-// http://developers.facebook.com/thrift/
-
-using System;
-using Thrift.Transport;
-using Thrift.Protocol;
-using Thrift.Test; //generated code
-
-namespace Test
-{
- class Program
- {
- static int Main(string[] args)
- {
- if (args.Length == 0)
- {
- Console.WriteLine("must provide 'server' or 'client' arg");
- return -1;
- }
-
- try
- {
- Console.SetBufferSize(Console.BufferWidth, 4096);
- }
- catch (Exception)
- {
- Console.WriteLine("Failed to grow scroll-back buffer");
- }
-
- string[] subArgs = new string[args.Length - 1];
- for(int i = 1; i < args.Length; i++)
- {
- subArgs[i-1] = args[i];
- }
- if (args[0] == "client")
- {
- return TestClient.Execute(subArgs);
- }
- else if (args[0] == "server")
- {
- return TestServer.Execute(subArgs) ? 0 : 1;
- }
- else
- {
- Console.WriteLine("first argument must be 'server' or 'client'");
- }
- return 0;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/csharp/test/ThriftTest/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/test/ThriftTest/Properties/AssemblyInfo.cs b/lib/csharp/test/ThriftTest/Properties/AssemblyInfo.cs
deleted file mode 100644
index 504ca8d..0000000
--- a/lib/csharp/test/ThriftTest/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("ThriftTest")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("ThriftTest")]
-[assembly: AssemblyCopyright("Copyright � 2009 The Apache Software Foundation")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("f41b193b-f1ab-48ee-8843-f88e43084e26")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/csharp/test/ThriftTest/TestClient.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/test/ThriftTest/TestClient.cs b/lib/csharp/test/ThriftTest/TestClient.cs
deleted file mode 100644
index cb73597..0000000
--- a/lib/csharp/test/ThriftTest/TestClient.cs
+++ /dev/null
@@ -1,833 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-using System;
-using System.Linq;
-using System.Diagnostics;
-using System.Collections.Generic;
-using System.Threading;
-using System.Security.Cryptography.X509Certificates;
-using Thrift.Collections;
-using Thrift.Protocol;
-using Thrift.Transport;
-using Thrift.Test;
-using System.Security.Authentication;
-
-namespace Test
-{
- public class TestClient
- {
- private class TestParams
- {
- public int numIterations = 1;
- public string host = "localhost";
- public int port = 9090;
- public string url;
- public string pipe;
- public bool buffered;
- public bool framed;
- public string protocol;
- public bool encrypted = false;
- protected bool _isFirstTransport = true;
-
-
- public TTransport CreateTransport()
- {
- if (url == null)
- {
- // endpoint transport
- TTransport trans = null;
- if (pipe != null)
- trans = new TNamedPipeClientTransport(pipe);
- else
- {
- if (encrypted)
- {
- string certPath = "../../../../test/keys/client.p12";
- X509Certificate cert = new X509Certificate2(certPath, "thrift");
- trans = new TTLSSocket(host, port, 0, cert, (o, c, chain, errors) => true, null, SslProtocols.Tls);
- }
- else
- {
- trans = new TSocket(host, port);
- }
- }
-
- // layered transport
- if (buffered)
- trans = new TBufferedTransport(trans);
- if (framed)
- trans = new TFramedTransport(trans);
-
- if (_isFirstTransport)
- {
- //ensure proper open/close of transport
- trans.Open();
- trans.Close();
- _isFirstTransport = false;
- }
- return trans;
- }
- else
- {
- return new THttpClient(new Uri(url));
- }
- }
-
- public TProtocol CreateProtocol(TTransport transport)
- {
- if (protocol == "compact")
- return new TCompactProtocol(transport);
- else if (protocol == "json")
- return new TJSONProtocol(transport);
- else
- return new TBinaryProtocol(transport);
- }
- };
-
- private const int ErrorBaseTypes = 1;
- private const int ErrorStructs = 2;
- private const int ErrorContainers = 4;
- private const int ErrorExceptions = 8;
- private const int ErrorUnknown = 64;
-
- private class ClientTest
- {
- private readonly TTransport transport;
- private readonly ThriftTest.Client client;
- private readonly int numIterations;
- private bool done;
-
- public int ReturnCode { get; set; }
-
- public ClientTest(TestParams param)
- {
- transport = param.CreateTransport();
- client = new ThriftTest.Client(param.CreateProtocol(transport));
- numIterations = param.numIterations;
- }
- public void Execute()
- {
- if (done)
- {
- Console.WriteLine("Execute called more than once");
- throw new InvalidOperationException();
- }
-
- for (int i = 0; i < numIterations; i++)
- {
- try
- {
- if (!transport.IsOpen)
- transport.Open();
- }
- catch (TTransportException ex)
- {
- Console.WriteLine("*** FAILED ***");
- Console.WriteLine("Connect failed: " + ex.Message);
- ReturnCode |= ErrorUnknown;
- Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
- continue;
- }
-
- try
- {
- ReturnCode |= ExecuteClientTest(client);
- }
- catch (Exception ex)
- {
- Console.WriteLine("*** FAILED ***");
- Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
- ReturnCode |= ErrorUnknown;
- }
- }
- try
- {
- transport.Close();
- }
- catch(Exception ex)
- {
- Console.WriteLine("Error while closing transport");
- Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
- }
- done = true;
- }
- }
-
- public static int Execute(string[] args)
- {
- try
- {
- TestParams param = new TestParams();
- int numThreads = 1;
- try
- {
- for (int i = 0; i < args.Length; i++)
- {
- if (args[i] == "-u")
- {
- param.url = args[++i];
- }
- else if (args[i] == "-n")
- {
- param.numIterations = Convert.ToInt32(args[++i]);
- }
- else if (args[i] == "-pipe") // -pipe <name>
- {
- param.pipe = args[++i];
- Console.WriteLine("Using named pipes transport");
- }
- else if (args[i].Contains("--host="))
- {
- param.host = args[i].Substring(args[i].IndexOf("=") + 1);
- }
- else if (args[i].Contains("--port="))
- {
- param.port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1));
- }
- else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered")
- {
- param.buffered = true;
- Console.WriteLine("Using buffered sockets");
- }
- else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed")
- {
- param.framed = true;
- Console.WriteLine("Using framed transport");
- }
- else if (args[i] == "-t")
- {
- numThreads = Convert.ToInt32(args[++i]);
- }
- else if (args[i] == "--compact" || args[i] == "--protocol=compact")
- {
- param.protocol = "compact";
- Console.WriteLine("Using compact protocol");
- }
- else if (args[i] == "--json" || args[i] == "--protocol=json")
- {
- param.protocol = "json";
- Console.WriteLine("Using JSON protocol");
- }
- else if (args[i] == "--ssl")
- {
- param.encrypted = true;
- Console.WriteLine("Using encrypted transport");
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("*** FAILED ***");
- Console.WriteLine("Error while parsing arguments");
- Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
- return ErrorUnknown;
- }
-
- var tests = Enumerable.Range(0, numThreads).Select(_ => new ClientTest(param)).ToArray();
- //issue tests on separate threads simultaneously
- var threads = tests.Select(test => new Thread(test.Execute)).ToArray();
- DateTime start = DateTime.Now;
- foreach (var t in threads)
- t.Start();
- foreach (var t in threads)
- t.Join();
- Console.WriteLine("Total time: " + (DateTime.Now - start));
- Console.WriteLine();
- return tests.Select(t => t.ReturnCode).Aggregate((r1, r2) => r1 | r2);
- }
- catch (Exception outerEx)
- {
- Console.WriteLine("*** FAILED ***");
- Console.WriteLine("Unexpected error");
- Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace);
- return ErrorUnknown;
- }
- }
-
- public static string BytesToHex(byte[] data) {
- return BitConverter.ToString(data).Replace("-", string.Empty);
- }
-
- public static byte[] PrepareTestData(bool randomDist)
- {
- byte[] retval = new byte[0x100];
- int initLen = Math.Min(0x100,retval.Length);
-
- // linear distribution, unless random is requested
- if (!randomDist) {
- for (var i = 0; i < initLen; ++i) {
- retval[i] = (byte)i;
- }
- return retval;
- }
-
- // random distribution
- for (var i = 0; i < initLen; ++i) {
- retval[i] = (byte)0;
- }
- var rnd = new Random();
- for (var i = 1; i < initLen; ++i) {
- while( true) {
- int nextPos = rnd.Next() % initLen;
- if (retval[nextPos] == 0) {
- retval[nextPos] = (byte)i;
- break;
- }
- }
- }
- return retval;
- }
-
- public static int ExecuteClientTest(ThriftTest.Client client)
- {
- int returnCode = 0;
-
- Console.Write("testVoid()");
- client.testVoid();
- Console.WriteLine(" = void");
-
- Console.Write("testString(\"Test\")");
- string s = client.testString("Test");
- Console.WriteLine(" = \"" + s + "\"");
- if ("Test" != s)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorBaseTypes;
- }
-
- Console.Write("testBool(true)");
- bool t = client.testBool((bool)true);
- Console.WriteLine(" = " + t);
- if (!t)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorBaseTypes;
- }
- Console.Write("testBool(false)");
- bool f = client.testBool((bool)false);
- Console.WriteLine(" = " + f);
- if (f)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorBaseTypes;
- }
-
- Console.Write("testByte(1)");
- sbyte i8 = client.testByte((sbyte)1);
- Console.WriteLine(" = " + i8);
- if (1 != i8)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorBaseTypes;
- }
-
- Console.Write("testI32(-1)");
- int i32 = client.testI32(-1);
- Console.WriteLine(" = " + i32);
- if (-1 != i32)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorBaseTypes;
- }
-
- Console.Write("testI64(-34359738368)");
- long i64 = client.testI64(-34359738368);
- Console.WriteLine(" = " + i64);
- if (-34359738368 != i64)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorBaseTypes;
- }
-
- // TODO: Validate received message
- Console.Write("testDouble(5.325098235)");
- double dub = client.testDouble(5.325098235);
- Console.WriteLine(" = " + dub);
- if (5.325098235 != dub)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorBaseTypes;
- }
- Console.Write("testDouble(-0.000341012439638598279)");
- dub = client.testDouble(-0.000341012439638598279);
- Console.WriteLine(" = " + dub);
- if (-0.000341012439638598279 != dub)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorBaseTypes;
- }
-
- byte[] binOut = PrepareTestData(true);
- Console.Write("testBinary(" + BytesToHex(binOut) + ")");
- try
- {
- byte[] binIn = client.testBinary(binOut);
- Console.WriteLine(" = " + BytesToHex(binIn));
- if (binIn.Length != binOut.Length)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorBaseTypes;
- }
- for (int ofs = 0; ofs < Math.Min(binIn.Length, binOut.Length); ++ofs)
- if (binIn[ofs] != binOut[ofs])
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorBaseTypes;
- }
- }
- catch (Thrift.TApplicationException ex)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorBaseTypes;
- Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
- }
-
- // binary equals? only with hashcode option enabled ...
- Console.WriteLine("Test CrazyNesting");
- if( typeof(CrazyNesting).GetMethod("Equals").DeclaringType == typeof(CrazyNesting))
- {
- CrazyNesting one = new CrazyNesting();
- CrazyNesting two = new CrazyNesting();
- one.String_field = "crazy";
- two.String_field = "crazy";
- one.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF };
- two.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF };
- if (!one.Equals(two))
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorContainers;
- throw new Exception("CrazyNesting.Equals failed");
- }
- }
-
- // TODO: Validate received message
- Console.Write("testStruct({\"Zero\", 1, -3, -5})");
- Xtruct o = new Xtruct();
- o.String_thing = "Zero";
- o.Byte_thing = (sbyte)1;
- o.I32_thing = -3;
- o.I64_thing = -5;
- Xtruct i = client.testStruct(o);
- Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}");
-
- // TODO: Validate received message
- Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})");
- Xtruct2 o2 = new Xtruct2();
- o2.Byte_thing = (sbyte)1;
- o2.Struct_thing = o;
- o2.I32_thing = 5;
- Xtruct2 i2 = client.testNest(o2);
- i = i2.Struct_thing;
- Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}");
-
- Dictionary<int, int> mapout = new Dictionary<int, int>();
- for (int j = 0; j < 5; j++)
- {
- mapout[j] = j - 10;
- }
- Console.Write("testMap({");
- bool first = true;
- foreach (int key in mapout.Keys)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- Console.Write(", ");
- }
- Console.Write(key + " => " + mapout[key]);
- }
- Console.Write("})");
-
- Dictionary<int, int> mapin = client.testMap(mapout);
-
- Console.Write(" = {");
- first = true;
- foreach (int key in mapin.Keys)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- Console.Write(", ");
- }
- Console.Write(key + " => " + mapin[key]);
- }
- Console.WriteLine("}");
-
- // TODO: Validate received message
- List<int> listout = new List<int>();
- for (int j = -2; j < 3; j++)
- {
- listout.Add(j);
- }
- Console.Write("testList({");
- first = true;
- foreach (int j in listout)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- Console.Write(", ");
- }
- Console.Write(j);
- }
- Console.Write("})");
-
- List<int> listin = client.testList(listout);
-
- Console.Write(" = {");
- first = true;
- foreach (int j in listin)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- Console.Write(", ");
- }
- Console.Write(j);
- }
- Console.WriteLine("}");
-
- //set
- // TODO: Validate received message
- THashSet<int> setout = new THashSet<int>();
- for (int j = -2; j < 3; j++)
- {
- setout.Add(j);
- }
- Console.Write("testSet({");
- first = true;
- foreach (int j in setout)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- Console.Write(", ");
- }
- Console.Write(j);
- }
- Console.Write("})");
-
- THashSet<int> setin = client.testSet(setout);
-
- Console.Write(" = {");
- first = true;
- foreach (int j in setin)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- Console.Write(", ");
- }
- Console.Write(j);
- }
- Console.WriteLine("}");
-
-
- Console.Write("testEnum(ONE)");
- Numberz ret = client.testEnum(Numberz.ONE);
- Console.WriteLine(" = " + ret);
- if (Numberz.ONE != ret)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorStructs;
- }
-
- Console.Write("testEnum(TWO)");
- ret = client.testEnum(Numberz.TWO);
- Console.WriteLine(" = " + ret);
- if (Numberz.TWO != ret)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorStructs;
- }
-
- Console.Write("testEnum(THREE)");
- ret = client.testEnum(Numberz.THREE);
- Console.WriteLine(" = " + ret);
- if (Numberz.THREE != ret)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorStructs;
- }
-
- Console.Write("testEnum(FIVE)");
- ret = client.testEnum(Numberz.FIVE);
- Console.WriteLine(" = " + ret);
- if (Numberz.FIVE != ret)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorStructs;
- }
-
- Console.Write("testEnum(EIGHT)");
- ret = client.testEnum(Numberz.EIGHT);
- Console.WriteLine(" = " + ret);
- if (Numberz.EIGHT != ret)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorStructs;
- }
-
- Console.Write("testTypedef(309858235082523)");
- long uid = client.testTypedef(309858235082523L);
- Console.WriteLine(" = " + uid);
- if (309858235082523L != uid)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorStructs;
- }
-
- // TODO: Validate received message
- Console.Write("testMapMap(1)");
- Dictionary<int, Dictionary<int, int>> mm = client.testMapMap(1);
- Console.Write(" = {");
- foreach (int key in mm.Keys)
- {
- Console.Write(key + " => {");
- Dictionary<int, int> m2 = mm[key];
- foreach (int k2 in m2.Keys)
- {
- Console.Write(k2 + " => " + m2[k2] + ", ");
- }
- Console.Write("}, ");
- }
- Console.WriteLine("}");
-
- // TODO: Validate received message
- Insanity insane = new Insanity();
- insane.UserMap = new Dictionary<Numberz, long>();
- insane.UserMap[Numberz.FIVE] = 5000L;
- Xtruct truck = new Xtruct();
- truck.String_thing = "Truck";
- truck.Byte_thing = (sbyte)8;
- truck.I32_thing = 8;
- truck.I64_thing = 8;
- insane.Xtructs = new List<Xtruct>();
- insane.Xtructs.Add(truck);
- Console.Write("testInsanity()");
- Dictionary<long, Dictionary<Numberz, Insanity>> whoa = client.testInsanity(insane);
- Console.Write(" = {");
- foreach (long key in whoa.Keys)
- {
- Dictionary<Numberz, Insanity> val = whoa[key];
- Console.Write(key + " => {");
-
- foreach (Numberz k2 in val.Keys)
- {
- Insanity v2 = val[k2];
-
- Console.Write(k2 + " => {");
- Dictionary<Numberz, long> userMap = v2.UserMap;
-
- Console.Write("{");
- if (userMap != null)
- {
- foreach (Numberz k3 in userMap.Keys)
- {
- Console.Write(k3 + " => " + userMap[k3] + ", ");
- }
- }
- else
- {
- Console.Write("null");
- }
- Console.Write("}, ");
-
- List<Xtruct> xtructs = v2.Xtructs;
-
- Console.Write("{");
- if (xtructs != null)
- {
- foreach (Xtruct x in xtructs)
- {
- Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, ");
- }
- }
- else
- {
- Console.Write("null");
- }
- Console.Write("}");
-
- Console.Write("}, ");
- }
- Console.Write("}, ");
- }
- Console.WriteLine("}");
-
- sbyte arg0 = 1;
- int arg1 = 2;
- long arg2 = long.MaxValue;
- Dictionary<short, string> multiDict = new Dictionary<short, string>();
- multiDict[1] = "one";
- Numberz arg4 = Numberz.FIVE;
- long arg5 = 5000000;
- Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
- Xtruct multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);
- Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing
- + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n");
-
- try
- {
- Console.WriteLine("testException(\"Xception\")");
- client.testException("Xception");
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- }
- catch (Xception ex)
- {
- if (ex.ErrorCode != 1001 || ex.Message != "Xception")
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
- }
- try
- {
- Console.WriteLine("testException(\"TException\")");
- client.testException("TException");
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- }
- catch (Thrift.TException)
- {
- // OK
- }
- catch (Exception ex)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
- }
- try
- {
- Console.WriteLine("testException(\"ok\")");
- client.testException("ok");
- // OK
- }
- catch (Exception ex)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
- }
-
- try
- {
- Console.WriteLine("testMultiException(\"Xception\", ...)");
- client.testMultiException("Xception", "ignore");
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- }
- catch (Xception ex)
- {
- if (ex.ErrorCode != 1001 || ex.Message != "This is an Xception")
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
- }
- try
- {
- Console.WriteLine("testMultiException(\"Xception2\", ...)");
- client.testMultiException("Xception2", "ignore");
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- }
- catch (Xception2 ex)
- {
- if (ex.ErrorCode != 2002 || ex.Struct_thing.String_thing != "This is an Xception2")
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
- }
- try
- {
- Console.WriteLine("testMultiException(\"success\", \"OK\")");
- if ("OK" != client.testMultiException("success", "OK").String_thing)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorExceptions;
- Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
- }
-
- Stopwatch sw = new Stopwatch();
- sw.Start();
- Console.WriteLine("Test Oneway(1)");
- client.testOneway(1);
- sw.Stop();
- if (sw.ElapsedMilliseconds > 1000)
- {
- Console.WriteLine("*** FAILED ***");
- returnCode |= ErrorBaseTypes;
- }
-
- Console.Write("Test Calltime()");
- var startt = DateTime.UtcNow;
- for ( int k=0; k<1000; ++k )
- client.testVoid();
- Console.WriteLine(" = " + (DateTime.UtcNow - startt).TotalSeconds.ToString() + " ms a testVoid() call" );
- return returnCode;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/csharp/test/ThriftTest/TestServer.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/test/ThriftTest/TestServer.cs b/lib/csharp/test/ThriftTest/TestServer.cs
deleted file mode 100644
index e51ae92..0000000
--- a/lib/csharp/test/ThriftTest/TestServer.cs
+++ /dev/null
@@ -1,547 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-// Distributed under the Thrift Software License
-//
-// See accompanying file LICENSE or visit the Thrift site at:
-// http://developers.facebook.com/thrift/
-using System;
-using System.Collections.Generic;
-using System.Security.Cryptography.X509Certificates;
-using Thrift.Collections;
-using Thrift.Test; //generated code
-using Thrift.Transport;
-using Thrift.Protocol;
-using Thrift.Server;
-using Thrift;
-using System.Threading;
-using System.Text;
-using System.Security.Authentication;
-
-namespace Test
-{
- public class TestServer
- {
- public static int _clientID = -1;
- public delegate void TestLogDelegate(string msg, params object[] values);
-
- public class TradeServerEventHandler : TServerEventHandler
- {
- public int callCount = 0;
- public void preServe()
- {
- callCount++;
- }
- public Object createContext(Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output)
- {
- callCount++;
- return null;
- }
- public void deleteContext(Object serverContext, Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output)
- {
- callCount++;
- }
- public void processContext(Object serverContext, Thrift.Transport.TTransport transport)
- {
- callCount++;
- }
- };
-
- public class TestHandler : ThriftTest.Iface, Thrift.TControllingHandler
- {
- public TServer server { get; set; }
- private int handlerID;
- private StringBuilder reusableStringBuilder = new StringBuilder();
- private TestLogDelegate testLogDelegate;
-
- public TestHandler()
- {
- handlerID = Interlocked.Increment(ref _clientID);
- testLogDelegate += testConsoleLogger;
- testLogDelegate.Invoke("New TestHandler instance created");
- }
-
- public void testConsoleLogger(string msg, params object[] values)
- {
- reusableStringBuilder.Clear();
- reusableStringBuilder.AppendFormat("handler{0:D3}:",handlerID);
- reusableStringBuilder.AppendFormat(msg, values);
- reusableStringBuilder.AppendLine();
- Console.Write( reusableStringBuilder.ToString() );
- }
-
- public void testVoid()
- {
- testLogDelegate.Invoke("testVoid()");
- }
-
- public string testString(string thing)
- {
- testLogDelegate.Invoke("testString({0})", thing);
- return thing;
- }
-
- public bool testBool(bool thing)
- {
- testLogDelegate.Invoke("testBool({0})", thing);
- return thing;
- }
-
- public sbyte testByte(sbyte thing)
- {
- testLogDelegate.Invoke("testByte({0})", thing);
- return thing;
- }
-
- public int testI32(int thing)
- {
- testLogDelegate.Invoke("testI32({0})", thing);
- return thing;
- }
-
- public long testI64(long thing)
- {
- testLogDelegate.Invoke("testI64({0})", thing);
- return thing;
- }
-
- public double testDouble(double thing)
- {
- testLogDelegate.Invoke("testDouble({0})", thing);
- return thing;
- }
-
- public byte[] testBinary(byte[] thing)
- {
- string hex = BitConverter.ToString(thing).Replace("-", string.Empty);
- testLogDelegate.Invoke("testBinary({0:X})", hex);
- return thing;
- }
-
- public Xtruct testStruct(Xtruct thing)
- {
- testLogDelegate.Invoke("testStruct({{\"{0}\", {1}, {2}, {3}}})", thing.String_thing, thing.Byte_thing, thing.I32_thing, thing.I64_thing);
- return thing;
- }
-
- public Xtruct2 testNest(Xtruct2 nest)
- {
- Xtruct thing = nest.Struct_thing;
- testLogDelegate.Invoke("testNest({{{0}, {{\"{1}\", {2}, {3}, {4}, {5}}}}})",
- nest.Byte_thing,
- thing.String_thing,
- thing.Byte_thing,
- thing.I32_thing,
- thing.I64_thing,
- nest.I32_thing);
- return nest;
- }
-
- public Dictionary<int, int> testMap(Dictionary<int, int> thing)
- {
- reusableStringBuilder.Clear();
- reusableStringBuilder.Append("testMap({{");
- bool first = true;
- foreach (int key in thing.Keys)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- reusableStringBuilder.Append(", ");
- }
- reusableStringBuilder.AppendFormat("{0} => {1}", key, thing[key]);
- }
- reusableStringBuilder.Append("}})");
- testLogDelegate.Invoke(reusableStringBuilder.ToString());
- return thing;
- }
-
- public Dictionary<string, string> testStringMap(Dictionary<string, string> thing)
- {
- reusableStringBuilder.Clear();
- reusableStringBuilder.Append("testStringMap({{");
- bool first = true;
- foreach (string key in thing.Keys)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- reusableStringBuilder.Append(", ");
- }
- reusableStringBuilder.AppendFormat("{0} => {1}", key, thing[key]);
- }
- reusableStringBuilder.Append("}})");
- testLogDelegate.Invoke(reusableStringBuilder.ToString());
- return thing;
- }
-
- public THashSet<int> testSet(THashSet<int> thing)
- {
- reusableStringBuilder.Clear();
- reusableStringBuilder.Append("testSet({{");
- bool first = true;
- foreach (int elem in thing)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- reusableStringBuilder.Append(", ");
- }
- reusableStringBuilder.AppendFormat("{0}", elem);
- }
- reusableStringBuilder.Append("}})");
- testLogDelegate.Invoke(reusableStringBuilder.ToString());
- return thing;
- }
-
- public List<int> testList(List<int> thing)
- {
- reusableStringBuilder.Clear();
- reusableStringBuilder.Append("testList({{");
- bool first = true;
- foreach (int elem in thing)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- reusableStringBuilder.Append(", ");
- }
- reusableStringBuilder.AppendFormat("{0}", elem);
- }
- reusableStringBuilder.Append("}})");
- testLogDelegate.Invoke(reusableStringBuilder.ToString());
- return thing;
- }
-
- public Numberz testEnum(Numberz thing)
- {
- testLogDelegate.Invoke("testEnum({0})", thing);
- return thing;
- }
-
- public long testTypedef(long thing)
- {
- testLogDelegate.Invoke("testTypedef({0})", thing);
- return thing;
- }
-
- public Dictionary<int, Dictionary<int, int>> testMapMap(int hello)
- {
- testLogDelegate.Invoke("testMapMap({0})", hello);
- Dictionary<int, Dictionary<int, int>> mapmap =
- new Dictionary<int, Dictionary<int, int>>();
-
- Dictionary<int, int> pos = new Dictionary<int, int>();
- Dictionary<int, int> neg = new Dictionary<int, int>();
- for (int i = 1; i < 5; i++)
- {
- pos[i] = i;
- neg[-i] = -i;
- }
-
- mapmap[4] = pos;
- mapmap[-4] = neg;
-
- return mapmap;
- }
-
- public Dictionary<long, Dictionary<Numberz, Insanity>> testInsanity(Insanity argument)
- {
- testLogDelegate.Invoke("testInsanity()");
-
- Xtruct hello = new Xtruct();
- hello.String_thing = "Hello2";
- hello.Byte_thing = 2;
- hello.I32_thing = 2;
- hello.I64_thing = 2;
-
- Xtruct goodbye = new Xtruct();
- goodbye.String_thing = "Goodbye4";
- goodbye.Byte_thing = (sbyte)4;
- goodbye.I32_thing = 4;
- goodbye.I64_thing = (long)4;
-
- Insanity crazy = new Insanity();
- crazy.UserMap = new Dictionary<Numberz, long>();
- crazy.UserMap[Numberz.EIGHT] = (long)8;
- crazy.Xtructs = new List<Xtruct>();
- crazy.Xtructs.Add(goodbye);
-
- Insanity looney = new Insanity();
- crazy.UserMap[Numberz.FIVE] = (long)5;
- crazy.Xtructs.Add(hello);
-
- Dictionary<Numberz, Insanity> first_map = new Dictionary<Numberz, Insanity>();
- Dictionary<Numberz, Insanity> second_map = new Dictionary<Numberz, Insanity>(); ;
-
- first_map[Numberz.TWO] = crazy;
- first_map[Numberz.THREE] = crazy;
-
- second_map[Numberz.SIX] = looney;
-
- Dictionary<long, Dictionary<Numberz, Insanity>> insane =
- new Dictionary<long, Dictionary<Numberz, Insanity>>();
- insane[(long)1] = first_map;
- insane[(long)2] = second_map;
-
- return insane;
- }
-
- public Xtruct testMulti(sbyte arg0, int arg1, long arg2, Dictionary<short, string> arg3, Numberz arg4, long arg5)
- {
- testLogDelegate.Invoke("testMulti()");
-
- Xtruct hello = new Xtruct(); ;
- hello.String_thing = "Hello2";
- hello.Byte_thing = arg0;
- hello.I32_thing = arg1;
- hello.I64_thing = arg2;
- return hello;
- }
-
- /**
- * Print 'testException(%s)' with arg as '%s'
- * @param string arg - a string indication what type of exception to throw
- * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
- * elsen if arg == "TException" throw TException
- * else do not throw anything
- */
- public void testException(string arg)
- {
- testLogDelegate.Invoke("testException({0})", arg);
- if (arg == "Xception")
- {
- Xception x = new Xception();
- x.ErrorCode = 1001;
- x.Message = arg;
- throw x;
- }
- if (arg == "TException")
- {
- throw new Thrift.TException();
- }
- return;
- }
-
- public Xtruct testMultiException(string arg0, string arg1)
- {
- testLogDelegate.Invoke("testMultiException({0}, {1})", arg0,arg1);
- if (arg0 == "Xception")
- {
- Xception x = new Xception();
- x.ErrorCode = 1001;
- x.Message = "This is an Xception";
- throw x;
- }
- else if (arg0 == "Xception2")
- {
- Xception2 x = new Xception2();
- x.ErrorCode = 2002;
- x.Struct_thing = new Xtruct();
- x.Struct_thing.String_thing = "This is an Xception2";
- throw x;
- }
-
- Xtruct result = new Xtruct();
- result.String_thing = arg1;
- return result;
- }
-
- public void testStop()
- {
- if (server != null)
- {
- server.Stop();
- }
- }
-
- public void testOneway(int arg)
- {
- testLogDelegate.Invoke("testOneway({0}), sleeping...", arg);
- System.Threading.Thread.Sleep(arg * 1000);
- testLogDelegate.Invoke("testOneway finished");
- }
-
- } // class TestHandler
-
- private enum ServerType
- {
- TSimpleServer,
- TThreadedServer,
- TThreadPoolServer,
- }
-
- private enum ProcessorFactoryType
- {
- TSingletonProcessorFactory,
- TPrototypeProcessorFactory,
- }
-
- public static bool Execute(string[] args)
- {
- try
- {
- bool useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false;
- ServerType serverType = ServerType.TSimpleServer;
- ProcessorFactoryType processorFactoryType = ProcessorFactoryType.TSingletonProcessorFactory;
- int port = 9090;
- string pipe = null;
- for (int i = 0; i < args.Length; i++)
- {
- if (args[i] == "-pipe") // -pipe name
- {
- pipe = args[++i];
- }
- else if (args[i].Contains("--port="))
- {
- port = int.Parse(args[i].Substring(args[i].IndexOf("=") + 1));
- }
- else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered")
- {
- useBufferedSockets = true;
- }
- else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed")
- {
- useFramed = true;
- }
- else if (args[i] == "--compact" || args[i] == "--protocol=compact")
- {
- compact = true;
- }
- else if (args[i] == "--json" || args[i] == "--protocol=json")
- {
- json = true;
- }
- else if (args[i] == "--threaded" || args[i] == "--server-type=threaded")
- {
- serverType = ServerType.TThreadedServer;
- }
- else if (args[i] == "--threadpool" || args[i] == "--server-type=threadpool")
- {
- serverType = ServerType.TThreadPoolServer;
- }
- else if (args[i] == "--prototype" || args[i] == "--processor=prototype")
- {
- processorFactoryType = ProcessorFactoryType.TPrototypeProcessorFactory;
- }
- else if (args[i] == "--ssl")
- {
- useEncryption = true;
- }
- }
-
- // Transport
- TServerTransport trans;
- if (pipe != null)
- {
- trans = new TNamedPipeServerTransport(pipe);
- }
- else
- {
- if (useEncryption)
- {
- string certPath = "../../../../test/keys/server.p12";
- trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2(certPath, "thrift"), null, null, SslProtocols.Tls);
- }
- else
- {
- trans = new TServerSocket(port, 0, useBufferedSockets);
- }
- }
-
- TProtocolFactory proto;
- if (compact)
- proto = new TCompactProtocol.Factory();
- else if (json)
- proto = new TJSONProtocol.Factory();
- else
- proto = new TBinaryProtocol.Factory();
-
- TProcessorFactory processorFactory;
- if (processorFactoryType == ProcessorFactoryType.TPrototypeProcessorFactory)
- {
- processorFactory = new TPrototypeProcessorFactory<ThriftTest.Processor, TestHandler>();
- }
- else
- {
- // Processor
- TestHandler testHandler = new TestHandler();
- ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler);
- processorFactory = new TSingletonProcessorFactory(testProcessor);
- }
-
- TTransportFactory transFactory;
- if (useFramed)
- transFactory = new TFramedTransport.Factory();
- else
- transFactory = new TTransportFactory();
-
- TServer serverEngine;
- switch (serverType)
- {
- case ServerType.TThreadPoolServer:
- serverEngine = new TThreadPoolServer(processorFactory, trans, transFactory, proto);
- break;
- case ServerType.TThreadedServer:
- serverEngine = new TThreadedServer(processorFactory, trans, transFactory, proto);
- break;
- default:
- serverEngine = new TSimpleServer(processorFactory, trans, transFactory, proto);
- break;
- }
-
- //Server event handler
- TradeServerEventHandler serverEvents = new TradeServerEventHandler();
- serverEngine.setEventHandler(serverEvents);
-
- // Run it
- string where = (pipe != null ? "on pipe " + pipe : "on port " + port);
- Console.WriteLine("Starting the " + serverType.ToString() + " " + where +
- (processorFactoryType == ProcessorFactoryType.TPrototypeProcessorFactory ? " with processor prototype factory " : "") +
- (useBufferedSockets ? " with buffered socket" : "") +
- (useFramed ? " with framed transport" : "") +
- (useEncryption ? " with encryption" : "") +
- (compact ? " with compact protocol" : "") +
- (json ? " with json protocol" : "") +
- "...");
- serverEngine.Serve();
-
- }
- catch (Exception x)
- {
- Console.Error.Write(x);
- return false;
- }
- Console.WriteLine("done.");
- return true;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/csharp/test/ThriftTest/ThriftTest.csproj
----------------------------------------------------------------------
diff --git a/lib/csharp/test/ThriftTest/ThriftTest.csproj b/lib/csharp/test/ThriftTest/ThriftTest.csproj
deleted file mode 100644
index d671997..0000000
--- a/lib/csharp/test/ThriftTest/ThriftTest.csproj
+++ /dev/null
@@ -1,141 +0,0 @@
-\ufeff<?xml version="1.0" encoding="utf-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.21022</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}</ProjectGuid>
- <OutputType>Exe</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>ThriftTest</RootNamespace>
- <AssemblyName>ThriftTest</AssemblyName>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- <IsWebBootstrapper>false</IsWebBootstrapper>
- <FileUpgradeFlags>
- </FileUpgradeFlags>
- <OldToolsVersion>3.5</OldToolsVersion>
- <UpgradeBackupLocation />
- <PublishUrl>publish\</PublishUrl>
- <Install>true</Install>
- <InstallFrom>Disk</InstallFrom>
- <UpdateEnabled>false</UpdateEnabled>
- <UpdateMode>Foreground</UpdateMode>
- <UpdateInterval>7</UpdateInterval>
- <UpdateIntervalUnits>Days</UpdateIntervalUnits>
- <UpdatePeriodically>false</UpdatePeriodically>
- <UpdateRequired>false</UpdateRequired>
- <MapFileExtensions>true</MapFileExtensions>
- <ApplicationRevision>0</ApplicationRevision>
- <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
- <UseApplicationTrust>false</UseApplicationTrust>
- <BootstrapperEnabled>true</BootstrapperEnabled>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="System" />
- <Reference Include="ThriftImpl, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>.\ThriftImpl.dll</HintPath>
- </Reference>
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Program.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="TestClient.cs" />
- <Compile Include="TestServer.cs" />
- </ItemGroup>
- <ItemGroup>
- <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
- <Visible>False</Visible>
- <ProductName>.NET Framework 2.0 %28x86%29</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.0 %28x86%29</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
- <Visible>False</Visible>
- <ProductName>Windows Installer 3.1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\..\src\Thrift.csproj">
- <Project>{499EB63C-D74C-47E8-AE48-A2FC94538E9D}</Project>
- <Name>Thrift</Name>
- </ProjectReference>
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
- <PropertyGroup>
- <PreBuildEvent>rmdir /s /q "$(ProjectDir)gen-csharp"
-del /f /q "$(ProjectDir)ThriftImpl.dll"
-SET OUTPUT_DIR=$(ProjectDir)
-SET THRIFT_FILE=$(ProjectDir)\..\..\..\..\test\ThriftTest.thrift
-for %25%25I in ("%25OUTPUT_DIR%25") do set SHORT_DIR=%25%25~fsI
-for %25%25I in ("%25THRIFT_FILE%25") do set THRIFT_SHORT=%25%25~fsI
-"$(ProjectDir)\..\..\..\..\compiler\cpp\thrift.exe" --gen csharp -o %25SHORT_DIR%25 %25THRIFT_SHORT%25
-$(MSBuildToolsPath)\Csc.exe /t:library /out:"$(ProjectDir)ThriftImpl.dll" /recurse:"$(ProjectDir)gen-csharp"\* /reference:"$(ProjectDir)..\..\src\bin\Debug\Thrift.dll"</PreBuildEvent>
- </PropertyGroup>
-</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/lib/csharp/test/ThriftTest/maketest.sh
----------------------------------------------------------------------
diff --git a/lib/csharp/test/ThriftTest/maketest.sh b/lib/csharp/test/ThriftTest/maketest.sh
deleted file mode 100755
index 210a523..0000000
--- a/lib/csharp/test/ThriftTest/maketest.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-../../../../compiler/cpp/thrift --gen csharp -o . ../../../../test/ThriftTest.thrift
-gmcs /t:library /out:./ThriftImpl.dll /recurse:./gen-csharp/* /reference:../../Thrift.dll
-gmcs /out:TestClientServer.exe /reference:../../Thrift.dll /reference:ThriftImpl.dll TestClient.cs TestServer.cs Program.cs
-
-export MONO_PATH=../../
-
-timeout 120 ./TestClientServer.exe server &
-sleep 1
-./TestClientServer.exe client
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/test/Makefile.am
----------------------------------------------------------------------
diff --git a/test/Makefile.am b/test/Makefile.am
index 1d52c59..fb39a12 100755
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -25,6 +25,11 @@ SUBDIRS += c_glib
PRECROSS_TARGET += precross-c_glib
endif
+if WITH_MONO
+SUBDIRS += csharp
+PRECROSS_TARGET += precross-csharp
+endif
+
if WITH_CPP
SUBDIRS += cpp
PRECROSS_TARGET += precross-cpp
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/test/csharp/Makefile.am
----------------------------------------------------------------------
diff --git a/test/csharp/Makefile.am b/test/csharp/Makefile.am
new file mode 100644
index 0000000..7aa332c
--- /dev/null
+++ b/test/csharp/Makefile.am
@@ -0,0 +1,87 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+GENERATED = \
+ gen-csharp/Thrift/Test/Bonk.cs \
+ gen-csharp/Thrift/Test/Bools.cs \
+ gen-csharp/Thrift/Test/BoolTest.cs \
+ gen-csharp/Thrift/Test/CrazyNesting.cs \
+ gen-csharp/Thrift/Test/EmptyStruct.cs \
+ gen-csharp/Thrift/Test/GuessProtocolStruct.cs \
+ gen-csharp/Thrift/Test/Insanity.cs \
+ gen-csharp/Thrift/Test/LargeDeltas.cs \
+ gen-csharp/Thrift/Test/ListBonks.cs \
+ gen-csharp/Thrift/Test/ListTypeVersioningV1.cs \
+ gen-csharp/Thrift/Test/ListTypeVersioningV2.cs \
+ gen-csharp/Thrift/Test/NestedListsBonk.cs \
+ gen-csharp/Thrift/Test/NestedListsI32x2.cs \
+ gen-csharp/Thrift/Test/NestedListsI32x3.cs \
+ gen-csharp/Thrift/Test/NestedMixedx2.cs \
+ gen-csharp/Thrift/Test/Numberz.cs \
+ gen-csharp/Thrift/Test/OneField.cs \
+ gen-csharp/Thrift/Test/SecondService.cs \
+ gen-csharp/Thrift/Test/StructA.cs \
+ gen-csharp/Thrift/Test/StructB.cs \
+ gen-csharp/Thrift/Test/ThriftTest.Constants.cs \
+ gen-csharp/Thrift/Test/ThriftTest.cs \
+ gen-csharp/Thrift/Test/VersioningTestV1.cs \
+ gen-csharp/Thrift/Test/VersioningTestV2.cs \
+ gen-csharp/Thrift/Test/Xception.cs \
+ gen-csharp/Thrift/Test/Xception2.cs \
+ gen-csharp/Thrift/Test/Xtruct.cs \
+ gen-csharp/Thrift/Test/Xtruct2.cs \
+ gen-csharp/Thrift/Test/Xtruct3.cs
+
+BUILT_SOURCES = $(GENERATED)
+
+if MONO_MCS
+CSC = mcs
+else
+CSC = gmcs
+endif
+
+if NET_2_0
+CSC_DEFINES = -d:NET_2_0
+endif
+
+LIBDIR = $(top_builddir)/lib/csharp
+
+THRIFT = $(top_builddir)/compiler/cpp/thrift
+
+$(GENERATED): $(top_srcdir)/test/ThriftTest.thrift $(THRIFT)
+ $(THRIFT) --gen csharp -o . $<
+
+precross: TestClientServer.exe
+
+ThriftImpl.dll: $(GENERATED) $(LIBDIR)/Thrift.dll
+ $(CSC) $(CSC_DEFINES) -t:library -out:$@ -reference:$(LIBDIR)/Thrift.dll $(GENERATED)
+
+SRCS = TestClient.cs TestServer.cs Program.cs
+
+TestClientServer.exe: $(SRCS) ThriftImpl.dll
+ $(CSC) $(CSC_DEFINES) -out:$@ -reference:$(LIBDIR)/Thrift.dll -reference:ThriftImpl.dll $(SRCS)
+
+clean-local:
+ $(RM) -rf gen-csharp *.exe *.dll
+
+TESTPORT = 9500
+check-local: TestClientServer.exe
+ MONO_PATH=$(LIBDIR) timeout 10 mono TestClientServer.exe server --port=$(TESTPORT) &
+ sleep 1
+ MONO_PATH=$(LIBDIR) mono TestClientServer.exe client --port=$(TESTPORT)
[07/10] thrift git commit: THRIFT-3909 Fix c_glib static lib CMake
build
Posted by ns...@apache.org.
THRIFT-3909 Fix c_glib static lib CMake build
This closes #1072
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/21b6d929
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/21b6d929
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/21b6d929
Branch: refs/heads/master
Commit: 21b6d9295a7f10852810a93679fdaf4c28fe72dd
Parents: 080041c
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sun Sep 4 18:49:20 2016 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Sep 4 18:49:20 2016 +0900
----------------------------------------------------------------------
lib/c_glib/test/CMakeLists.txt | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/21b6d929/lib/c_glib/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/CMakeLists.txt b/lib/c_glib/test/CMakeLists.txt
index 95876ed..45ef41f 100644
--- a/lib/c_glib/test/CMakeLists.txt
+++ b/lib/c_glib/test/CMakeLists.txt
@@ -54,47 +54,48 @@ set(testgenc_SOURCES
)
add_library(testgenc STATIC ${testgenc_SOURCES})
-target_link_libraries(testgenc thrift_c_glib)
+LINK_AGAINST_THRIFT_LIBRARY(testgenc thrift_c_glib)
add_executable(testserialization testserialization.c)
-target_link_libraries(testserialization testgenc thrift_c_glib)
+target_link_libraries(testserialization testgenc)
+LINK_AGAINST_THRIFT_LIBRARY(testserialization thrift_c_glib)
add_test(NAME testserialization COMMAND testserialization)
add_executable(testapplicationexception testapplicationexception.c)
-target_link_libraries(testapplicationexception thrift_c_glib)
+LINK_AGAINST_THRIFT_LIBRARY(testapplicationexception thrift_c_glib)
add_test(NAME testapplicationexception COMMAND testapplicationexception)
add_executable(testtransportsocket testtransportsocket.c)
-target_link_libraries(testtransportsocket thrift_c_glib)
+LINK_AGAINST_THRIFT_LIBRARY(testtransportsocket thrift_c_glib)
add_test(NAME testtransportsocket COMMAND testtransportsocket)
add_executable(testbinaryprotocol testbinaryprotocol.c)
-target_link_libraries(testbinaryprotocol thrift_c_glib)
+LINK_AGAINST_THRIFT_LIBRARY(testbinaryprotocol thrift_c_glib)
add_test(NAME testbinaryprotocol COMMAND testbinaryprotocol)
add_executable(testcompactprotocol testcompactprotocol.c)
-target_link_libraries(testcompactprotocol thrift_c_glib)
+LINK_AGAINST_THRIFT_LIBRARY(testcompactprotocol thrift_c_glib)
add_test(NAME testcompactprotocol COMMAND testcompactprotocol)
add_executable(testbufferedtransport testbufferedtransport.c)
-target_link_libraries(testbufferedtransport thrift_c_glib)
+LINK_AGAINST_THRIFT_LIBRARY(testbufferedtransport thrift_c_glib)
add_test(NAME testbufferedtransport COMMAND testbufferedtransport)
add_executable(testframedtransport testframedtransport.c)
-target_link_libraries(testframedtransport thrift_c_glib)
+LINK_AGAINST_THRIFT_LIBRARY(testframedtransport thrift_c_glib)
add_test(NAME testframedtransport COMMAND testframedtransport)
add_executable(testfdtransport testfdtransport.c)
-target_link_libraries(testfdtransport thrift_c_glib)
+LINK_AGAINST_THRIFT_LIBRARY(testfdtransport thrift_c_glib)
add_test(NAME testfdtransport COMMAND testfdtransport)
add_executable(testmemorybuffer testmemorybuffer.c)
-target_link_libraries(testmemorybuffer thrift_c_glib)
+LINK_AGAINST_THRIFT_LIBRARY(testmemorybuffer thrift_c_glib)
add_test(NAME testmemorybuffer COMMAND testmemorybuffer)
add_executable(testsimpleserver testsimpleserver.c)
-target_link_libraries(testsimpleserver thrift_c_glib)
+LINK_AGAINST_THRIFT_LIBRARY(testsimpleserver thrift_c_glib)
add_test(NAME testsimpleserver COMMAND testsimpleserver)
add_executable(testdebugproto testdebugproto.c)
@@ -130,7 +131,7 @@ if(BUILD_CPP)
)
add_library(testgenc_cpp STATIC ${testgenc_cpp_SOURCES})
- target_link_libraries(testgenc_cpp thrift)
+ LINK_AGAINST_THRIFT_LIBRARY(testgenc_cpp thrift)
#HACK: testthrifttestclient.cpp includes ThriftTest.h without gen-*/ prefixes
# so we include it here
[04/10] thrift git commit: THRIFT-3906 Run C# tests with make check
Posted by ns...@apache.org.
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/test/csharp/Program.cs
----------------------------------------------------------------------
diff --git a/test/csharp/Program.cs b/test/csharp/Program.cs
new file mode 100644
index 0000000..8ec00e3
--- /dev/null
+++ b/test/csharp/Program.cs
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+using System;
+using Thrift.Transport;
+using Thrift.Protocol;
+using Thrift.Test; //generated code
+
+namespace Test
+{
+ class Program
+ {
+ static int Main(string[] args)
+ {
+ if (args.Length == 0)
+ {
+ Console.WriteLine("must provide 'server' or 'client' arg");
+ return -1;
+ }
+
+ try
+ {
+ Console.SetBufferSize(Console.BufferWidth, 4096);
+ }
+ catch (Exception)
+ {
+ Console.WriteLine("Failed to grow scroll-back buffer");
+ }
+
+ string[] subArgs = new string[args.Length - 1];
+ for(int i = 1; i < args.Length; i++)
+ {
+ subArgs[i-1] = args[i];
+ }
+ if (args[0] == "client")
+ {
+ return TestClient.Execute(subArgs);
+ }
+ else if (args[0] == "server")
+ {
+ return TestServer.Execute(subArgs) ? 0 : 1;
+ }
+ else
+ {
+ Console.WriteLine("first argument must be 'server' or 'client'");
+ }
+ return 0;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/test/csharp/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/test/csharp/Properties/AssemblyInfo.cs b/test/csharp/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..504ca8d
--- /dev/null
+++ b/test/csharp/Properties/AssemblyInfo.cs
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ThriftTest")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ThriftTest")]
+[assembly: AssemblyCopyright("Copyright � 2009 The Apache Software Foundation")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("f41b193b-f1ab-48ee-8843-f88e43084e26")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/test/csharp/TestClient.cs
----------------------------------------------------------------------
diff --git a/test/csharp/TestClient.cs b/test/csharp/TestClient.cs
new file mode 100644
index 0000000..67673ec
--- /dev/null
+++ b/test/csharp/TestClient.cs
@@ -0,0 +1,836 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+using System;
+using System.Linq;
+using System.Diagnostics;
+using System.Collections.Generic;
+using System.Threading;
+using System.Security.Cryptography.X509Certificates;
+using Thrift.Collections;
+using Thrift.Protocol;
+using Thrift.Transport;
+using Thrift.Test;
+using System.Security.Authentication;
+
+namespace Test
+{
+ public class TestClient
+ {
+ private class TestParams
+ {
+ public int numIterations = 1;
+ public string host = "localhost";
+ public int port = 9090;
+ public string url;
+ public string pipe;
+ public bool buffered;
+ public bool framed;
+ public string protocol;
+ public bool encrypted = false;
+ protected bool _isFirstTransport = true;
+
+
+ public TTransport CreateTransport()
+ {
+ if (url == null)
+ {
+ // endpoint transport
+ TTransport trans = null;
+ if (pipe != null)
+ trans = new TNamedPipeClientTransport(pipe);
+ else
+ {
+ if (encrypted)
+ {
+ string certPath = "../keys/client.p12";
+ X509Certificate cert = new X509Certificate2(certPath, "thrift");
+ trans = new TTLSSocket(host, port, 0, cert, (o, c, chain, errors) => true, null, SslProtocols.Tls);
+ }
+ else
+ {
+ trans = new TSocket(host, port);
+ }
+ }
+
+ // layered transport
+ if (buffered)
+ trans = new TBufferedTransport(trans);
+ if (framed)
+ trans = new TFramedTransport(trans);
+
+ if (_isFirstTransport)
+ {
+ //ensure proper open/close of transport
+ trans.Open();
+ trans.Close();
+ _isFirstTransport = false;
+ }
+ return trans;
+ }
+ else
+ {
+ return new THttpClient(new Uri(url));
+ }
+ }
+
+ public TProtocol CreateProtocol(TTransport transport)
+ {
+ if (protocol == "compact")
+ return new TCompactProtocol(transport);
+ else if (protocol == "json")
+ return new TJSONProtocol(transport);
+ else
+ return new TBinaryProtocol(transport);
+ }
+ };
+
+ private const int ErrorBaseTypes = 1;
+ private const int ErrorStructs = 2;
+ private const int ErrorContainers = 4;
+ private const int ErrorExceptions = 8;
+ private const int ErrorUnknown = 64;
+
+ private class ClientTest
+ {
+ private readonly TTransport transport;
+ private readonly ThriftTest.Client client;
+ private readonly int numIterations;
+ private bool done;
+
+ public int ReturnCode { get; set; }
+
+ public ClientTest(TestParams param)
+ {
+ transport = param.CreateTransport();
+ client = new ThriftTest.Client(param.CreateProtocol(transport));
+ numIterations = param.numIterations;
+ }
+ public void Execute()
+ {
+ if (done)
+ {
+ Console.WriteLine("Execute called more than once");
+ throw new InvalidOperationException();
+ }
+
+ for (int i = 0; i < numIterations; i++)
+ {
+ try
+ {
+ if (!transport.IsOpen)
+ transport.Open();
+ }
+ catch (TTransportException ex)
+ {
+ Console.WriteLine("*** FAILED ***");
+ Console.WriteLine("Connect failed: " + ex.Message);
+ ReturnCode |= ErrorUnknown;
+ Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
+ continue;
+ }
+
+ try
+ {
+ ReturnCode |= ExecuteClientTest(client);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("*** FAILED ***");
+ Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
+ ReturnCode |= ErrorUnknown;
+ }
+ }
+ try
+ {
+ transport.Close();
+ }
+ catch(Exception ex)
+ {
+ Console.WriteLine("Error while closing transport");
+ Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
+ }
+ done = true;
+ }
+ }
+
+ public static int Execute(string[] args)
+ {
+ try
+ {
+ TestParams param = new TestParams();
+ int numThreads = 1;
+ try
+ {
+ for (int i = 0; i < args.Length; i++)
+ {
+ if (args[i] == "-u")
+ {
+ param.url = args[++i];
+ }
+ else if (args[i] == "-n")
+ {
+ param.numIterations = Convert.ToInt32(args[++i]);
+ }
+ else if (args[i] == "-pipe") // -pipe <name>
+ {
+ param.pipe = args[++i];
+ Console.WriteLine("Using named pipes transport");
+ }
+ else if (args[i].Contains("--host="))
+ {
+ param.host = args[i].Substring(args[i].IndexOf("=") + 1);
+ }
+ else if (args[i].Contains("--port="))
+ {
+ param.port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1));
+ }
+ else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered")
+ {
+ param.buffered = true;
+ Console.WriteLine("Using buffered sockets");
+ }
+ else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed")
+ {
+ param.framed = true;
+ Console.WriteLine("Using framed transport");
+ }
+ else if (args[i] == "-t")
+ {
+ numThreads = Convert.ToInt32(args[++i]);
+ }
+ else if (args[i] == "--compact" || args[i] == "--protocol=compact")
+ {
+ param.protocol = "compact";
+ Console.WriteLine("Using compact protocol");
+ }
+ else if (args[i] == "--json" || args[i] == "--protocol=json")
+ {
+ param.protocol = "json";
+ Console.WriteLine("Using JSON protocol");
+ }
+ else if (args[i] == "--ssl")
+ {
+ param.encrypted = true;
+ Console.WriteLine("Using encrypted transport");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("*** FAILED ***");
+ Console.WriteLine("Error while parsing arguments");
+ Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
+ return ErrorUnknown;
+ }
+
+ var tests = Enumerable.Range(0, numThreads).Select(_ => new ClientTest(param)).ToArray();
+ //issue tests on separate threads simultaneously
+ var threads = tests.Select(test => new Thread(test.Execute)).ToArray();
+ DateTime start = DateTime.Now;
+ foreach (var t in threads)
+ t.Start();
+ foreach (var t in threads)
+ t.Join();
+ Console.WriteLine("Total time: " + (DateTime.Now - start));
+ Console.WriteLine();
+ return tests.Select(t => t.ReturnCode).Aggregate((r1, r2) => r1 | r2);
+ }
+ catch (Exception outerEx)
+ {
+ Console.WriteLine("*** FAILED ***");
+ Console.WriteLine("Unexpected error");
+ Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace);
+ return ErrorUnknown;
+ }
+ }
+
+ public static string BytesToHex(byte[] data) {
+ return BitConverter.ToString(data).Replace("-", string.Empty);
+ }
+
+ public static byte[] PrepareTestData(bool randomDist)
+ {
+ byte[] retval = new byte[0x100];
+ int initLen = Math.Min(0x100,retval.Length);
+
+ // linear distribution, unless random is requested
+ if (!randomDist) {
+ for (var i = 0; i < initLen; ++i) {
+ retval[i] = (byte)i;
+ }
+ return retval;
+ }
+
+ // random distribution
+ for (var i = 0; i < initLen; ++i) {
+ retval[i] = (byte)0;
+ }
+ var rnd = new Random();
+ for (var i = 1; i < initLen; ++i) {
+ while( true) {
+ int nextPos = rnd.Next() % initLen;
+ if (retval[nextPos] == 0) {
+ retval[nextPos] = (byte)i;
+ break;
+ }
+ }
+ }
+ return retval;
+ }
+
+ public static int ExecuteClientTest(ThriftTest.Client client)
+ {
+ int returnCode = 0;
+
+ Console.Write("testVoid()");
+ client.testVoid();
+ Console.WriteLine(" = void");
+
+ Console.Write("testString(\"Test\")");
+ string s = client.testString("Test");
+ Console.WriteLine(" = \"" + s + "\"");
+ if ("Test" != s)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorBaseTypes;
+ }
+
+ Console.Write("testBool(true)");
+ bool t = client.testBool((bool)true);
+ Console.WriteLine(" = " + t);
+ if (!t)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorBaseTypes;
+ }
+ Console.Write("testBool(false)");
+ bool f = client.testBool((bool)false);
+ Console.WriteLine(" = " + f);
+ if (f)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorBaseTypes;
+ }
+
+ Console.Write("testByte(1)");
+ sbyte i8 = client.testByte((sbyte)1);
+ Console.WriteLine(" = " + i8);
+ if (1 != i8)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorBaseTypes;
+ }
+
+ Console.Write("testI32(-1)");
+ int i32 = client.testI32(-1);
+ Console.WriteLine(" = " + i32);
+ if (-1 != i32)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorBaseTypes;
+ }
+
+ Console.Write("testI64(-34359738368)");
+ long i64 = client.testI64(-34359738368);
+ Console.WriteLine(" = " + i64);
+ if (-34359738368 != i64)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorBaseTypes;
+ }
+
+ // TODO: Validate received message
+ Console.Write("testDouble(5.325098235)");
+ double dub = client.testDouble(5.325098235);
+ Console.WriteLine(" = " + dub);
+ if (5.325098235 != dub)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorBaseTypes;
+ }
+ Console.Write("testDouble(-0.000341012439638598279)");
+ dub = client.testDouble(-0.000341012439638598279);
+ Console.WriteLine(" = " + dub);
+ if (-0.000341012439638598279 != dub)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorBaseTypes;
+ }
+
+ byte[] binOut = PrepareTestData(true);
+ Console.Write("testBinary(" + BytesToHex(binOut) + ")");
+ try
+ {
+ byte[] binIn = client.testBinary(binOut);
+ Console.WriteLine(" = " + BytesToHex(binIn));
+ if (binIn.Length != binOut.Length)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorBaseTypes;
+ }
+ for (int ofs = 0; ofs < Math.Min(binIn.Length, binOut.Length); ++ofs)
+ if (binIn[ofs] != binOut[ofs])
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorBaseTypes;
+ }
+ }
+ catch (Thrift.TApplicationException ex)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorBaseTypes;
+ Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
+ }
+
+ // binary equals? only with hashcode option enabled ...
+ Console.WriteLine("Test CrazyNesting");
+ if( typeof(CrazyNesting).GetMethod("Equals").DeclaringType == typeof(CrazyNesting))
+ {
+ CrazyNesting one = new CrazyNesting();
+ CrazyNesting two = new CrazyNesting();
+ one.String_field = "crazy";
+ two.String_field = "crazy";
+ one.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF };
+ two.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF };
+ if (!one.Equals(two))
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorContainers;
+ throw new Exception("CrazyNesting.Equals failed");
+ }
+ }
+
+ // TODO: Validate received message
+ Console.Write("testStruct({\"Zero\", 1, -3, -5})");
+ Xtruct o = new Xtruct();
+ o.String_thing = "Zero";
+ o.Byte_thing = (sbyte)1;
+ o.I32_thing = -3;
+ o.I64_thing = -5;
+ Xtruct i = client.testStruct(o);
+ Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}");
+
+ // TODO: Validate received message
+ Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})");
+ Xtruct2 o2 = new Xtruct2();
+ o2.Byte_thing = (sbyte)1;
+ o2.Struct_thing = o;
+ o2.I32_thing = 5;
+ Xtruct2 i2 = client.testNest(o2);
+ i = i2.Struct_thing;
+ Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}");
+
+ Dictionary<int, int> mapout = new Dictionary<int, int>();
+ for (int j = 0; j < 5; j++)
+ {
+ mapout[j] = j - 10;
+ }
+ Console.Write("testMap({");
+ bool first = true;
+ foreach (int key in mapout.Keys)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ Console.Write(", ");
+ }
+ Console.Write(key + " => " + mapout[key]);
+ }
+ Console.Write("})");
+
+ Dictionary<int, int> mapin = client.testMap(mapout);
+
+ Console.Write(" = {");
+ first = true;
+ foreach (int key in mapin.Keys)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ Console.Write(", ");
+ }
+ Console.Write(key + " => " + mapin[key]);
+ }
+ Console.WriteLine("}");
+
+ // TODO: Validate received message
+ List<int> listout = new List<int>();
+ for (int j = -2; j < 3; j++)
+ {
+ listout.Add(j);
+ }
+ Console.Write("testList({");
+ first = true;
+ foreach (int j in listout)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ Console.Write(", ");
+ }
+ Console.Write(j);
+ }
+ Console.Write("})");
+
+ List<int> listin = client.testList(listout);
+
+ Console.Write(" = {");
+ first = true;
+ foreach (int j in listin)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ Console.Write(", ");
+ }
+ Console.Write(j);
+ }
+ Console.WriteLine("}");
+
+ //set
+ // TODO: Validate received message
+ THashSet<int> setout = new THashSet<int>();
+ for (int j = -2; j < 3; j++)
+ {
+ setout.Add(j);
+ }
+ Console.Write("testSet({");
+ first = true;
+ foreach (int j in setout)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ Console.Write(", ");
+ }
+ Console.Write(j);
+ }
+ Console.Write("})");
+
+ THashSet<int> setin = client.testSet(setout);
+
+ Console.Write(" = {");
+ first = true;
+ foreach (int j in setin)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ Console.Write(", ");
+ }
+ Console.Write(j);
+ }
+ Console.WriteLine("}");
+
+
+ Console.Write("testEnum(ONE)");
+ Numberz ret = client.testEnum(Numberz.ONE);
+ Console.WriteLine(" = " + ret);
+ if (Numberz.ONE != ret)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorStructs;
+ }
+
+ Console.Write("testEnum(TWO)");
+ ret = client.testEnum(Numberz.TWO);
+ Console.WriteLine(" = " + ret);
+ if (Numberz.TWO != ret)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorStructs;
+ }
+
+ Console.Write("testEnum(THREE)");
+ ret = client.testEnum(Numberz.THREE);
+ Console.WriteLine(" = " + ret);
+ if (Numberz.THREE != ret)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorStructs;
+ }
+
+ Console.Write("testEnum(FIVE)");
+ ret = client.testEnum(Numberz.FIVE);
+ Console.WriteLine(" = " + ret);
+ if (Numberz.FIVE != ret)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorStructs;
+ }
+
+ Console.Write("testEnum(EIGHT)");
+ ret = client.testEnum(Numberz.EIGHT);
+ Console.WriteLine(" = " + ret);
+ if (Numberz.EIGHT != ret)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorStructs;
+ }
+
+ Console.Write("testTypedef(309858235082523)");
+ long uid = client.testTypedef(309858235082523L);
+ Console.WriteLine(" = " + uid);
+ if (309858235082523L != uid)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorStructs;
+ }
+
+ // TODO: Validate received message
+ Console.Write("testMapMap(1)");
+ Dictionary<int, Dictionary<int, int>> mm = client.testMapMap(1);
+ Console.Write(" = {");
+ foreach (int key in mm.Keys)
+ {
+ Console.Write(key + " => {");
+ Dictionary<int, int> m2 = mm[key];
+ foreach (int k2 in m2.Keys)
+ {
+ Console.Write(k2 + " => " + m2[k2] + ", ");
+ }
+ Console.Write("}, ");
+ }
+ Console.WriteLine("}");
+
+ // TODO: Validate received message
+ Insanity insane = new Insanity();
+ insane.UserMap = new Dictionary<Numberz, long>();
+ insane.UserMap[Numberz.FIVE] = 5000L;
+ Xtruct truck = new Xtruct();
+ truck.String_thing = "Truck";
+ truck.Byte_thing = (sbyte)8;
+ truck.I32_thing = 8;
+ truck.I64_thing = 8;
+ insane.Xtructs = new List<Xtruct>();
+ insane.Xtructs.Add(truck);
+ Console.Write("testInsanity()");
+ Dictionary<long, Dictionary<Numberz, Insanity>> whoa = client.testInsanity(insane);
+ Console.Write(" = {");
+ foreach (long key in whoa.Keys)
+ {
+ Dictionary<Numberz, Insanity> val = whoa[key];
+ Console.Write(key + " => {");
+
+ foreach (Numberz k2 in val.Keys)
+ {
+ Insanity v2 = val[k2];
+
+ Console.Write(k2 + " => {");
+ Dictionary<Numberz, long> userMap = v2.UserMap;
+
+ Console.Write("{");
+ if (userMap != null)
+ {
+ foreach (Numberz k3 in userMap.Keys)
+ {
+ Console.Write(k3 + " => " + userMap[k3] + ", ");
+ }
+ }
+ else
+ {
+ Console.Write("null");
+ }
+ Console.Write("}, ");
+
+ List<Xtruct> xtructs = v2.Xtructs;
+
+ Console.Write("{");
+ if (xtructs != null)
+ {
+ foreach (Xtruct x in xtructs)
+ {
+ Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, ");
+ }
+ }
+ else
+ {
+ Console.Write("null");
+ }
+ Console.Write("}");
+
+ Console.Write("}, ");
+ }
+ Console.Write("}, ");
+ }
+ Console.WriteLine("}");
+
+ sbyte arg0 = 1;
+ int arg1 = 2;
+ long arg2 = long.MaxValue;
+ Dictionary<short, string> multiDict = new Dictionary<short, string>();
+ multiDict[1] = "one";
+ Numberz arg4 = Numberz.FIVE;
+ long arg5 = 5000000;
+ Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
+ Xtruct multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);
+ Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing
+ + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n");
+
+ try
+ {
+ Console.WriteLine("testException(\"Xception\")");
+ client.testException("Xception");
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ }
+ catch (Xception ex)
+ {
+ if (ex.ErrorCode != 1001 || ex.Message != "Xception")
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
+ }
+ try
+ {
+ Console.WriteLine("testException(\"TException\")");
+ client.testException("TException");
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ }
+ catch (Thrift.TException)
+ {
+ // OK
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
+ }
+ try
+ {
+ Console.WriteLine("testException(\"ok\")");
+ client.testException("ok");
+ // OK
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
+ }
+
+ try
+ {
+ Console.WriteLine("testMultiException(\"Xception\", ...)");
+ client.testMultiException("Xception", "ignore");
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ }
+ catch (Xception ex)
+ {
+ if (ex.ErrorCode != 1001 || ex.Message != "This is an Xception")
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
+ }
+ try
+ {
+ Console.WriteLine("testMultiException(\"Xception2\", ...)");
+ client.testMultiException("Xception2", "ignore");
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ }
+ catch (Xception2 ex)
+ {
+ if (ex.ErrorCode != 2002 || ex.Struct_thing.String_thing != "This is an Xception2")
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
+ }
+ try
+ {
+ Console.WriteLine("testMultiException(\"success\", \"OK\")");
+ if ("OK" != client.testMultiException("success", "OK").String_thing)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorExceptions;
+ Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
+ }
+
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ Console.WriteLine("Test Oneway(1)");
+ client.testOneway(1);
+ sw.Stop();
+ if (sw.ElapsedMilliseconds > 1000)
+ {
+ Console.WriteLine("*** FAILED ***");
+ returnCode |= ErrorBaseTypes;
+ }
+
+ Console.Write("Test Calltime()");
+ var times = 50;
+ sw.Reset();
+ sw.Start();
+ for (int k = 0; k < times; ++k)
+ client.testVoid();
+ sw.Stop();
+ Console.WriteLine(" = {0} ms a testVoid() call", sw.ElapsedMilliseconds / times);
+ return returnCode;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/test/csharp/TestServer.cs
----------------------------------------------------------------------
diff --git a/test/csharp/TestServer.cs b/test/csharp/TestServer.cs
new file mode 100644
index 0000000..a9af715
--- /dev/null
+++ b/test/csharp/TestServer.cs
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+using System;
+using System.Collections.Generic;
+using System.Security.Cryptography.X509Certificates;
+using Thrift.Collections;
+using Thrift.Test; //generated code
+using Thrift.Transport;
+using Thrift.Protocol;
+using Thrift.Server;
+using Thrift;
+using System.Threading;
+using System.Text;
+using System.Security.Authentication;
+
+namespace Test
+{
+ public class TestServer
+ {
+ public static int _clientID = -1;
+ public delegate void TestLogDelegate(string msg, params object[] values);
+
+ public class TradeServerEventHandler : TServerEventHandler
+ {
+ public int callCount = 0;
+ public void preServe()
+ {
+ callCount++;
+ }
+ public Object createContext(Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output)
+ {
+ callCount++;
+ return null;
+ }
+ public void deleteContext(Object serverContext, Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output)
+ {
+ callCount++;
+ }
+ public void processContext(Object serverContext, Thrift.Transport.TTransport transport)
+ {
+ callCount++;
+ }
+ };
+
+ public class TestHandler : ThriftTest.Iface, Thrift.TControllingHandler
+ {
+ public TServer server { get; set; }
+ private int handlerID;
+ private StringBuilder reusableStringBuilder = new StringBuilder();
+ private TestLogDelegate testLogDelegate;
+
+ public TestHandler()
+ {
+ handlerID = Interlocked.Increment(ref _clientID);
+ testLogDelegate += testConsoleLogger;
+ testLogDelegate.Invoke("New TestHandler instance created");
+ }
+
+ public void testConsoleLogger(string msg, params object[] values)
+ {
+ reusableStringBuilder.Clear();
+ reusableStringBuilder.AppendFormat("handler{0:D3}:",handlerID);
+ reusableStringBuilder.AppendFormat(msg, values);
+ reusableStringBuilder.AppendLine();
+ Console.Write( reusableStringBuilder.ToString() );
+ }
+
+ public void testVoid()
+ {
+ testLogDelegate.Invoke("testVoid()");
+ }
+
+ public string testString(string thing)
+ {
+ testLogDelegate.Invoke("testString({0})", thing);
+ return thing;
+ }
+
+ public bool testBool(bool thing)
+ {
+ testLogDelegate.Invoke("testBool({0})", thing);
+ return thing;
+ }
+
+ public sbyte testByte(sbyte thing)
+ {
+ testLogDelegate.Invoke("testByte({0})", thing);
+ return thing;
+ }
+
+ public int testI32(int thing)
+ {
+ testLogDelegate.Invoke("testI32({0})", thing);
+ return thing;
+ }
+
+ public long testI64(long thing)
+ {
+ testLogDelegate.Invoke("testI64({0})", thing);
+ return thing;
+ }
+
+ public double testDouble(double thing)
+ {
+ testLogDelegate.Invoke("testDouble({0})", thing);
+ return thing;
+ }
+
+ public byte[] testBinary(byte[] thing)
+ {
+ string hex = BitConverter.ToString(thing).Replace("-", string.Empty);
+ testLogDelegate.Invoke("testBinary({0:X})", hex);
+ return thing;
+ }
+
+ public Xtruct testStruct(Xtruct thing)
+ {
+ testLogDelegate.Invoke("testStruct({{\"{0}\", {1}, {2}, {3}}})", thing.String_thing, thing.Byte_thing, thing.I32_thing, thing.I64_thing);
+ return thing;
+ }
+
+ public Xtruct2 testNest(Xtruct2 nest)
+ {
+ Xtruct thing = nest.Struct_thing;
+ testLogDelegate.Invoke("testNest({{{0}, {{\"{1}\", {2}, {3}, {4}, {5}}}}})",
+ nest.Byte_thing,
+ thing.String_thing,
+ thing.Byte_thing,
+ thing.I32_thing,
+ thing.I64_thing,
+ nest.I32_thing);
+ return nest;
+ }
+
+ public Dictionary<int, int> testMap(Dictionary<int, int> thing)
+ {
+ reusableStringBuilder.Clear();
+ reusableStringBuilder.Append("testMap({{");
+ bool first = true;
+ foreach (int key in thing.Keys)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ reusableStringBuilder.Append(", ");
+ }
+ reusableStringBuilder.AppendFormat("{0} => {1}", key, thing[key]);
+ }
+ reusableStringBuilder.Append("}})");
+ testLogDelegate.Invoke(reusableStringBuilder.ToString());
+ return thing;
+ }
+
+ public Dictionary<string, string> testStringMap(Dictionary<string, string> thing)
+ {
+ reusableStringBuilder.Clear();
+ reusableStringBuilder.Append("testStringMap({{");
+ bool first = true;
+ foreach (string key in thing.Keys)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ reusableStringBuilder.Append(", ");
+ }
+ reusableStringBuilder.AppendFormat("{0} => {1}", key, thing[key]);
+ }
+ reusableStringBuilder.Append("}})");
+ testLogDelegate.Invoke(reusableStringBuilder.ToString());
+ return thing;
+ }
+
+ public THashSet<int> testSet(THashSet<int> thing)
+ {
+ reusableStringBuilder.Clear();
+ reusableStringBuilder.Append("testSet({{");
+ bool first = true;
+ foreach (int elem in thing)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ reusableStringBuilder.Append(", ");
+ }
+ reusableStringBuilder.AppendFormat("{0}", elem);
+ }
+ reusableStringBuilder.Append("}})");
+ testLogDelegate.Invoke(reusableStringBuilder.ToString());
+ return thing;
+ }
+
+ public List<int> testList(List<int> thing)
+ {
+ reusableStringBuilder.Clear();
+ reusableStringBuilder.Append("testList({{");
+ bool first = true;
+ foreach (int elem in thing)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ reusableStringBuilder.Append(", ");
+ }
+ reusableStringBuilder.AppendFormat("{0}", elem);
+ }
+ reusableStringBuilder.Append("}})");
+ testLogDelegate.Invoke(reusableStringBuilder.ToString());
+ return thing;
+ }
+
+ public Numberz testEnum(Numberz thing)
+ {
+ testLogDelegate.Invoke("testEnum({0})", thing);
+ return thing;
+ }
+
+ public long testTypedef(long thing)
+ {
+ testLogDelegate.Invoke("testTypedef({0})", thing);
+ return thing;
+ }
+
+ public Dictionary<int, Dictionary<int, int>> testMapMap(int hello)
+ {
+ testLogDelegate.Invoke("testMapMap({0})", hello);
+ Dictionary<int, Dictionary<int, int>> mapmap =
+ new Dictionary<int, Dictionary<int, int>>();
+
+ Dictionary<int, int> pos = new Dictionary<int, int>();
+ Dictionary<int, int> neg = new Dictionary<int, int>();
+ for (int i = 1; i < 5; i++)
+ {
+ pos[i] = i;
+ neg[-i] = -i;
+ }
+
+ mapmap[4] = pos;
+ mapmap[-4] = neg;
+
+ return mapmap;
+ }
+
+ public Dictionary<long, Dictionary<Numberz, Insanity>> testInsanity(Insanity argument)
+ {
+ testLogDelegate.Invoke("testInsanity()");
+
+ Xtruct hello = new Xtruct();
+ hello.String_thing = "Hello2";
+ hello.Byte_thing = 2;
+ hello.I32_thing = 2;
+ hello.I64_thing = 2;
+
+ Xtruct goodbye = new Xtruct();
+ goodbye.String_thing = "Goodbye4";
+ goodbye.Byte_thing = (sbyte)4;
+ goodbye.I32_thing = 4;
+ goodbye.I64_thing = (long)4;
+
+ Insanity crazy = new Insanity();
+ crazy.UserMap = new Dictionary<Numberz, long>();
+ crazy.UserMap[Numberz.EIGHT] = (long)8;
+ crazy.Xtructs = new List<Xtruct>();
+ crazy.Xtructs.Add(goodbye);
+
+ Insanity looney = new Insanity();
+ crazy.UserMap[Numberz.FIVE] = (long)5;
+ crazy.Xtructs.Add(hello);
+
+ Dictionary<Numberz, Insanity> first_map = new Dictionary<Numberz, Insanity>();
+ Dictionary<Numberz, Insanity> second_map = new Dictionary<Numberz, Insanity>(); ;
+
+ first_map[Numberz.TWO] = crazy;
+ first_map[Numberz.THREE] = crazy;
+
+ second_map[Numberz.SIX] = looney;
+
+ Dictionary<long, Dictionary<Numberz, Insanity>> insane =
+ new Dictionary<long, Dictionary<Numberz, Insanity>>();
+ insane[(long)1] = first_map;
+ insane[(long)2] = second_map;
+
+ return insane;
+ }
+
+ public Xtruct testMulti(sbyte arg0, int arg1, long arg2, Dictionary<short, string> arg3, Numberz arg4, long arg5)
+ {
+ testLogDelegate.Invoke("testMulti()");
+
+ Xtruct hello = new Xtruct(); ;
+ hello.String_thing = "Hello2";
+ hello.Byte_thing = arg0;
+ hello.I32_thing = arg1;
+ hello.I64_thing = arg2;
+ return hello;
+ }
+
+ /**
+ * Print 'testException(%s)' with arg as '%s'
+ * @param string arg - a string indication what type of exception to throw
+ * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
+ * elsen if arg == "TException" throw TException
+ * else do not throw anything
+ */
+ public void testException(string arg)
+ {
+ testLogDelegate.Invoke("testException({0})", arg);
+ if (arg == "Xception")
+ {
+ Xception x = new Xception();
+ x.ErrorCode = 1001;
+ x.Message = arg;
+ throw x;
+ }
+ if (arg == "TException")
+ {
+ throw new Thrift.TException();
+ }
+ return;
+ }
+
+ public Xtruct testMultiException(string arg0, string arg1)
+ {
+ testLogDelegate.Invoke("testMultiException({0}, {1})", arg0,arg1);
+ if (arg0 == "Xception")
+ {
+ Xception x = new Xception();
+ x.ErrorCode = 1001;
+ x.Message = "This is an Xception";
+ throw x;
+ }
+ else if (arg0 == "Xception2")
+ {
+ Xception2 x = new Xception2();
+ x.ErrorCode = 2002;
+ x.Struct_thing = new Xtruct();
+ x.Struct_thing.String_thing = "This is an Xception2";
+ throw x;
+ }
+
+ Xtruct result = new Xtruct();
+ result.String_thing = arg1;
+ return result;
+ }
+
+ public void testStop()
+ {
+ if (server != null)
+ {
+ server.Stop();
+ }
+ }
+
+ public void testOneway(int arg)
+ {
+ testLogDelegate.Invoke("testOneway({0}), sleeping...", arg);
+ System.Threading.Thread.Sleep(arg * 1000);
+ testLogDelegate.Invoke("testOneway finished");
+ }
+
+ } // class TestHandler
+
+ private enum ServerType
+ {
+ TSimpleServer,
+ TThreadedServer,
+ TThreadPoolServer,
+ }
+
+ private enum ProcessorFactoryType
+ {
+ TSingletonProcessorFactory,
+ TPrototypeProcessorFactory,
+ }
+
+ public static bool Execute(string[] args)
+ {
+ try
+ {
+ bool useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false;
+ ServerType serverType = ServerType.TSimpleServer;
+ ProcessorFactoryType processorFactoryType = ProcessorFactoryType.TSingletonProcessorFactory;
+ int port = 9090;
+ string pipe = null;
+ for (int i = 0; i < args.Length; i++)
+ {
+ if (args[i] == "-pipe") // -pipe name
+ {
+ pipe = args[++i];
+ }
+ else if (args[i].Contains("--port="))
+ {
+ port = int.Parse(args[i].Substring(args[i].IndexOf("=") + 1));
+ }
+ else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered")
+ {
+ useBufferedSockets = true;
+ }
+ else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed")
+ {
+ useFramed = true;
+ }
+ else if (args[i] == "--compact" || args[i] == "--protocol=compact")
+ {
+ compact = true;
+ }
+ else if (args[i] == "--json" || args[i] == "--protocol=json")
+ {
+ json = true;
+ }
+ else if (args[i] == "--threaded" || args[i] == "--server-type=threaded")
+ {
+ serverType = ServerType.TThreadedServer;
+ }
+ else if (args[i] == "--threadpool" || args[i] == "--server-type=threadpool")
+ {
+ serverType = ServerType.TThreadPoolServer;
+ }
+ else if (args[i] == "--prototype" || args[i] == "--processor=prototype")
+ {
+ processorFactoryType = ProcessorFactoryType.TPrototypeProcessorFactory;
+ }
+ else if (args[i] == "--ssl")
+ {
+ useEncryption = true;
+ }
+ }
+
+ // Transport
+ TServerTransport trans;
+ if (pipe != null)
+ {
+ trans = new TNamedPipeServerTransport(pipe);
+ }
+ else
+ {
+ if (useEncryption)
+ {
+ string certPath = "../keys/server.p12";
+ trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2(certPath, "thrift"), null, null, SslProtocols.Tls);
+ }
+ else
+ {
+ trans = new TServerSocket(port, 0, useBufferedSockets);
+ }
+ }
+
+ TProtocolFactory proto;
+ if (compact)
+ proto = new TCompactProtocol.Factory();
+ else if (json)
+ proto = new TJSONProtocol.Factory();
+ else
+ proto = new TBinaryProtocol.Factory();
+
+ TProcessorFactory processorFactory;
+ if (processorFactoryType == ProcessorFactoryType.TPrototypeProcessorFactory)
+ {
+ processorFactory = new TPrototypeProcessorFactory<ThriftTest.Processor, TestHandler>();
+ }
+ else
+ {
+ // Processor
+ TestHandler testHandler = new TestHandler();
+ ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler);
+ processorFactory = new TSingletonProcessorFactory(testProcessor);
+ }
+
+ TTransportFactory transFactory;
+ if (useFramed)
+ transFactory = new TFramedTransport.Factory();
+ else
+ transFactory = new TTransportFactory();
+
+ TServer serverEngine;
+ switch (serverType)
+ {
+ case ServerType.TThreadPoolServer:
+ serverEngine = new TThreadPoolServer(processorFactory, trans, transFactory, proto);
+ break;
+ case ServerType.TThreadedServer:
+ serverEngine = new TThreadedServer(processorFactory, trans, transFactory, proto);
+ break;
+ default:
+ serverEngine = new TSimpleServer(processorFactory, trans, transFactory, proto);
+ break;
+ }
+
+ //Server event handler
+ TradeServerEventHandler serverEvents = new TradeServerEventHandler();
+ serverEngine.setEventHandler(serverEvents);
+
+ // Run it
+ string where = (pipe != null ? "on pipe " + pipe : "on port " + port);
+ Console.WriteLine("Starting the " + serverType.ToString() + " " + where +
+ (processorFactoryType == ProcessorFactoryType.TPrototypeProcessorFactory ? " with processor prototype factory " : "") +
+ (useBufferedSockets ? " with buffered socket" : "") +
+ (useFramed ? " with framed transport" : "") +
+ (useEncryption ? " with encryption" : "") +
+ (compact ? " with compact protocol" : "") +
+ (json ? " with json protocol" : "") +
+ "...");
+ serverEngine.Serve();
+
+ }
+ catch (Exception x)
+ {
+ Console.Error.Write(x);
+ return false;
+ }
+ Console.WriteLine("done.");
+ return true;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/test/csharp/ThriftTest.csproj
----------------------------------------------------------------------
diff --git a/test/csharp/ThriftTest.csproj b/test/csharp/ThriftTest.csproj
new file mode 100644
index 0000000..65c0daf
--- /dev/null
+++ b/test/csharp/ThriftTest.csproj
@@ -0,0 +1,141 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.21022</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>ThriftTest</RootNamespace>
+ <AssemblyName>ThriftTest</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <UpgradeBackupLocation />
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="ThriftImpl, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>.\ThriftImpl.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="TestClient.cs" />
+ <Compile Include="TestServer.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 2.0 %28x86%29</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.0 %28x86%29</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\lib\csharp\Thrift.csproj">
+ <Project>{499EB63C-D74C-47E8-AE48-A2FC94538E9D}</Project>
+ <Name>Thrift</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+ <PropertyGroup>
+ <PreBuildEvent>rmdir /s /q "$(ProjectDir)gen-csharp"
+del /f /q "$(ProjectDir)ThriftImpl.dll"
+SET OUTPUT_DIR=$(ProjectDir)
+SET THRIFT_FILE=$(ProjectDir)\..\ThriftTest.thrift
+for %25%25I in ("%25OUTPUT_DIR%25") do set SHORT_DIR=%25%25~fsI
+for %25%25I in ("%25THRIFT_FILE%25") do set THRIFT_SHORT=%25%25~fsI
+"$(ProjectDir)\..\..\compiler\cpp\thrift.exe" --gen csharp -o %25SHORT_DIR%25 %25THRIFT_SHORT%25
+$(MSBuildToolsPath)\Csc.exe /t:library /out:"$(ProjectDir)ThriftImpl.dll" /recurse:"$(ProjectDir)gen-csharp"\* /reference:"$(ProjectDir)..\..\lib\csharp\bin\Debug\Thrift.dll"</PreBuildEvent>
+ </PropertyGroup>
+</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/test/csharp/ThriftTest.sln
----------------------------------------------------------------------
diff --git a/test/csharp/ThriftTest.sln b/test/csharp/ThriftTest.sln
new file mode 100644
index 0000000..1765a03
--- /dev/null
+++ b/test/csharp/ThriftTest.sln
@@ -0,0 +1,17 @@
+\ufeff
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThriftTest", "ThriftTest.csproj", "{48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+EndGlobal
http://git-wip-us.apache.org/repos/asf/thrift/blob/88c5ee71/test/tests.json
----------------------------------------------------------------------
diff --git a/test/tests.json b/test/tests.json
index 3938c57..0dbc8bf 100644
--- a/test/tests.json
+++ b/test/tests.json
@@ -331,7 +331,7 @@
{
"name": "csharp",
"env": {
- "MONO_PATH": "../.."
+ "MONO_PATH": "../../lib/csharp/"
},
"transports": [
"buffered",
@@ -361,7 +361,7 @@
"client"
]
},
- "workdir": "../lib/csharp/test/ThriftTest"
+ "workdir": "csharp"
},
{
"name": "perl",
[10/10] thrift git commit: THRIFT-3917 Check
backports.ssl_match_hostname module version
Posted by ns...@apache.org.
THRIFT-3917 Check backports.ssl_match_hostname module version
This closes #1076
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/d2b4f248
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/d2b4f248
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/d2b4f248
Branch: refs/heads/master
Commit: d2b4f248368be36ff24c5a54fa4f8cfb86b7ab36
Parents: d4eecda
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sun Sep 4 18:49:23 2016 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Sep 4 18:49:23 2016 +0900
----------------------------------------------------------------------
lib/py/src/transport/sslcompat.py | 43 ++++++++++++++++++++++++----------
lib/py/test/test_sslsocket.py | 16 ++++++-------
2 files changed, 39 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/d2b4f248/lib/py/src/transport/sslcompat.py
----------------------------------------------------------------------
diff --git a/lib/py/src/transport/sslcompat.py b/lib/py/src/transport/sslcompat.py
index 19cfaca..7bf5e06 100644
--- a/lib/py/src/transport/sslcompat.py
+++ b/lib/py/src/transport/sslcompat.py
@@ -17,10 +17,13 @@
# under the License.
#
+import logging
import sys
from thrift.transport.TTransport import TTransportException
+logger = logging.getLogger(__name__)
+
def legacy_validate_callback(self, cert, hostname):
"""legacy method to validate the peer's SSL certificate, and to check
@@ -61,20 +64,36 @@ def legacy_validate_callback(self, cert, hostname):
% (hostname, cert))
-try:
- import ipaddress # noqa
- _match_has_ipaddress = True
-except ImportError:
- _match_has_ipaddress = False
+def _optional_dependencies():
+ try:
+ import ipaddress # noqa
+ logger.debug('ipaddress module is available')
+ ipaddr = True
+ except ImportError:
+ logger.warn('ipaddress module is unavailable')
+ ipaddr = False
-try:
- from backports.ssl_match_hostname import match_hostname
- _match_hostname = match_hostname
-except ImportError:
if sys.hexversion < 0x030500F0:
- _match_has_ipaddress = False
+ try:
+ from backports.ssl_match_hostname import match_hostname, __version__ as ver
+ ver = list(map(int, ver.split('.')))
+ logger.debug('backports.ssl_match_hostname module is available')
+ match = match_hostname
+ if ver[0] * 10 + ver[1] >= 35:
+ return ipaddr, match
+ else:
+ logger.warn('backports.ssl_match_hostname module is too old')
+ ipaddr = False
+ except ImportError:
+ logger.warn('backports.ssl_match_hostname is unavailable')
+ ipaddr = False
try:
from ssl import match_hostname
- _match_hostname = match_hostname
+ logger.debug('ssl.match_hostname is available')
+ match = match_hostname
except ImportError:
- _match_hostname = legacy_validate_callback
+ logger.warn('using legacy validation callback')
+ match = legacy_validate_callback
+ return ipaddr, match
+
+_match_has_ipaddress, _match_hostname = _optional_dependencies()
http://git-wip-us.apache.org/repos/asf/thrift/blob/d2b4f248/lib/py/test/test_sslsocket.py
----------------------------------------------------------------------
diff --git a/lib/py/test/test_sslsocket.py b/lib/py/test/test_sslsocket.py
index 93d34d0..3e4b266 100644
--- a/lib/py/test/test_sslsocket.py
+++ b/lib/py/test/test_sslsocket.py
@@ -30,8 +30,6 @@ import warnings
from contextlib import contextmanager
import _import_local_thrift # noqa
-from thrift.transport.TSSLSocket import TSSLSocket, TSSLServerSocket
-from thrift.transport.TTransport import TTransportException
SCRIPT_DIR = os.path.realpath(os.path.dirname(__file__))
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(SCRIPT_DIR)))
@@ -133,16 +131,16 @@ class TSSLSocketTest(unittest.TestCase):
def _assert_connection_failure(self, server, path=None, **client_args):
logging.disable(logging.CRITICAL)
- with self._connectable_client(server, True, path=path, **client_args) as (acc, client):
- try:
+ try:
+ with self._connectable_client(server, True, path=path, **client_args) as (acc, client):
# We need to wait for a connection failure, but not too long. 20ms is a tunable
# compromise between test speed and stability
client.setTimeout(20)
with self._assert_raises(TTransportException):
client.open()
self.assertTrue(acc.client is None)
- finally:
- logging.disable(logging.NOTSET)
+ finally:
+ logging.disable(logging.NOTSET)
def _assert_raises(self, exc):
if sys.hexversion >= 0x020700F0:
@@ -334,6 +332,8 @@ class TSSLSocketTest(unittest.TestCase):
self._assert_connection_success(server, ssl_context=client_context)
if __name__ == '__main__':
- # import logging
- # logging.basicConfig(level=logging.DEBUG)
+ logging.basicConfig(level=logging.WARN)
+ from thrift.transport.TSSLSocket import TSSLSocket, TSSLServerSocket
+ from thrift.transport.TTransport import TTransportException
+
unittest.main()
[08/10] thrift git commit: THRIFT-3910 Do not invoke pip as part of
build process
Posted by ns...@apache.org.
THRIFT-3910 Do not invoke pip as part of build process
This closes #1073
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/bf9fa905
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/bf9fa905
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/bf9fa905
Branch: refs/heads/master
Commit: bf9fa905d22d2714670b5d492a319daf26f5a32c
Parents: 21b6d92
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sun Sep 4 18:49:21 2016 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Sep 4 18:49:21 2016 +0900
----------------------------------------------------------------------
appveyor.yml | 1 +
build/cmake/DefineOptions.cmake | 3 +--
build/cmake/FindPip.cmake | 30 ------------------------------
build/docker/centos/Dockerfile | 6 ++++--
build/docker/centos6/Dockerfile | 3 +++
build/docker/debian/Dockerfile | 4 ++++
build/docker/ubuntu/Dockerfile | 4 ++++
configure.ac | 26 ++++++++++++++++++--------
lib/py/CMakeLists.txt | 1 -
lib/py/Makefile.am | 4 ----
lib/py/requirements.txt | 3 ---
lib/py/setup.py | 14 ++++++++++++++
lib/py/src/transport/TSSLSocket.py | 2 +-
test/Makefile.am | 4 +++-
test/py.twisted/Makefile.am | 1 +
15 files changed, 54 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/appveyor.yml
----------------------------------------------------------------------
diff --git a/appveyor.yml b/appveyor.yml
index ffd5334..d68d3e3 100755
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -71,6 +71,7 @@ build_script:
# - set PATH=%PATH%;C:\Program Files (x86)\Haskell Platform\2014.2.0.0\bin
# - set PATH=%PATH%;C:\Program Files (x86)\Haskell Platform\2014.2.0.0\lib\extralibs\bin
- set PATH=C:\Python27-x64\scripts;C:\Python27-x64;%PATH%
+- pip install ipaddress backports.ssl_match_hostname tornado twisted
- mkdir cmake-build
- cd cmake-build
- cmake -G "Visual Studio 14 2015 Win64" -DWITH_SHARED_LIB=OFF -DLIBEVENT_ROOT=C:\libevent-2.0.22-stable -DZLIB_INCLUDE_DIR=C:\zlib-1.2.8 -DZLIB_LIBRARY=C:\zlib-1.2.8\release\zlibstatic.lib -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR%" ..
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/build/cmake/DefineOptions.cmake
----------------------------------------------------------------------
diff --git a/build/cmake/DefineOptions.cmake b/build/cmake/DefineOptions.cmake
index 01dae35..6dd59e0 100644
--- a/build/cmake/DefineOptions.cmake
+++ b/build/cmake/DefineOptions.cmake
@@ -103,9 +103,8 @@ endif()
option(WITH_PYTHON "Build Python Thrift library" ON)
find_package(PythonInterp QUIET) # for Python executable
find_package(PythonLibs QUIET) # for Python.h
-find_package(Pip QUIET)
CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON
- "BUILD_LIBRARIES;WITH_PYTHON;PYTHONLIBS_FOUND;PIP_FOUND" OFF)
+ "BUILD_LIBRARIES;WITH_PYTHON;PYTHONLIBS_FOUND" OFF)
# Haskell
option(WITH_HASKELL "Build Haskell Thrift library" ON)
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/build/cmake/FindPip.cmake
----------------------------------------------------------------------
diff --git a/build/cmake/FindPip.cmake b/build/cmake/FindPip.cmake
deleted file mode 100644
index 45fdb99..0000000
--- a/build/cmake/FindPip.cmake
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-
-# PIP_FOUND - system has pip
-# PIP_EXECUTABLE - the pip executable
-#
-# It will search the PATH environment variable
-
-include(FindPackageHandleStandardArgs)
-
-find_program(PIP_EXECUTABLE NAMES pip)
-find_package_handle_standard_args(PIP DEFAULT_MSG PIP_EXECUTABLE)
-mark_as_advanced(PIP_EXECUTABLE)
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/build/docker/centos/Dockerfile
----------------------------------------------------------------------
diff --git a/build/docker/centos/Dockerfile b/build/docker/centos/Dockerfile
index f544a24..a31492b 100644
--- a/build/docker/centos/Dockerfile
+++ b/build/docker/centos/Dockerfile
@@ -56,9 +56,11 @@ RUN yum install -y \
# Python Dependencies
RUN yum install -y \
python-devel \
+ python-pip \
python-setuptools \
- python-twisted-web \
- python-pip
+ python-six \
+ python-twisted-web && \
+ pip install -U backports.ssl_match_hostname ipaddress tornado
# Ruby Dependencies
RUN yum install -y \
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/build/docker/centos6/Dockerfile
----------------------------------------------------------------------
diff --git a/build/docker/centos6/Dockerfile b/build/docker/centos6/Dockerfile
index d0dc51a..4df75de 100644
--- a/build/docker/centos6/Dockerfile
+++ b/build/docker/centos6/Dockerfile
@@ -40,6 +40,9 @@ RUN yum install -y epel-release && \
python-pip \
&& yum clean all
+# optional dependencies
+RUN pip install ipaddress backports.ssl_match_hostname tornado
+
# CMake
RUN curl -sSL https://cmake.org/files/v3.4/cmake-3.4.1.tar.gz | tar -xz && \
cd cmake-3.4.1 && ./bootstrap && make -j4 && make install && \
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/build/docker/debian/Dockerfile
----------------------------------------------------------------------
diff --git a/build/docker/debian/Dockerfile b/build/docker/debian/Dockerfile
index 22dd3b5..285c85b 100644
--- a/build/docker/debian/Dockerfile
+++ b/build/docker/debian/Dockerfile
@@ -145,6 +145,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# Ruby
RUN gem install bundler --no-ri --no-rdoc
+# Python optional dependencies
+RUN pip2 install -U ipaddress backports.ssl_match_hostname tornado
+RUN pip3 install -U backports.ssl_match_hostname tornado
+
# Go
RUN curl -sSL https://storage.googleapis.com/golang/go1.4.3.linux-amd64.tar.gz | tar -C /usr/local/ -xz
ENV PATH /usr/local/go/bin:$PATH
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/build/docker/ubuntu/Dockerfile
----------------------------------------------------------------------
diff --git a/build/docker/ubuntu/Dockerfile b/build/docker/ubuntu/Dockerfile
index 99f0a8f..2797a1c 100644
--- a/build/docker/ubuntu/Dockerfile
+++ b/build/docker/ubuntu/Dockerfile
@@ -163,6 +163,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# Ruby
RUN gem install bundler --no-ri --no-rdoc
+# Python optional dependencies
+RUN pip2 install -U ipaddress backports.ssl_match_hostname tornado
+RUN pip3 install -U backports.ssl_match_hostname tornado
+
# Go
RUN curl -sSL https://storage.googleapis.com/golang/go1.4.3.linux-amd64.tar.gz | tar -C /usr/local/ -xz
ENV PATH /usr/local/go/bin:$PATH
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index fb22699..b79094c 100755
--- a/configure.ac
+++ b/configure.ac
@@ -280,20 +280,25 @@ AM_CONDITIONAL(WITH_LUA, [test "$have_lua" = "yes"])
AM_PATH_PYTHON(2.6,, :)
AX_THRIFT_LIB(python, [Python], yes)
if test "$with_python" = "yes"; then
- AC_PATH_PROG([PIP], [pip])
- AC_PATH_PROG([TRIAL], [trial])
- if test -n "$TRIAL" && test "x$PYTHON" != "x" && test "x$PYTHON" != "x:" ; then
+ if test -n "$PYTHON"; then
have_python="yes"
fi
+ AC_PATH_PROG([TRIAL], [trial])
+ if test -n "$TRIAL"; then
+ have_trial="yes"
+ fi
fi
AM_CONDITIONAL(WITH_PYTHON, [test "$have_python" = "yes"])
+AM_CONDITIONAL(WITH_TWISTED_TEST, [test "$have_trial" = "yes"])
# Find "python3" executable.
# It's distro specific and far from ideal but needed to cross test py2-3 at once.
-AC_PATH_PROG([PYTHON3], [python3])
-AC_PATH_PROG([PIP3], [pip3])
-if test "x$PYTHON3" != "x" && test "x$PYTHON3" != "x:" && test "x$PIP3" != "x" ; then
- have_py3="yes"
+# TODO: find "python2" if it's 3.x
+if python --version 2>&1 | grep -q "Python 2"; then
+ AC_PATH_PROGS([PYTHON3], [python3 python3.5 python35 python3.4 python34])
+ if test -n "$PYTHON3"; then
+ have_py3="yes"
+ fi
fi
AM_CONDITIONAL(WITH_PY3, [test "$have_py3" = "yes"])
@@ -859,7 +864,12 @@ if test "$have_python" = "yes" ; then
echo
echo "Python Library:"
echo " Using Python .............. : $PYTHON"
- echo " Using Trial ............... : $TRIAL"
+ if test "$have_py3" = "yes" ; then
+ echo " Using Python3 ............. : $PYTHON3"
+ fi
+ if test "$have_trial" = "yes"; then
+ echo " Using trial ............... : $TRIAL"
+ fi
fi
if test "$have_php" = "yes" ; then
echo
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/lib/py/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/lib/py/CMakeLists.txt b/lib/py/CMakeLists.txt
index 2ec8b56..7bb91fe 100644
--- a/lib/py/CMakeLists.txt
+++ b/lib/py/CMakeLists.txt
@@ -20,7 +20,6 @@
include_directories(${PYTHON_INCLUDE_DIRS})
add_custom_target(python_build ALL
- COMMAND ${PIP_EXECUTABLE} install -r requirements.txt || ${PIP_EXECUTABLE} install --user -r requirements.txt
COMMAND ${PYTHON_EXECUTABLE} setup.py build
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building Python library"
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/lib/py/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/py/Makefile.am b/lib/py/Makefile.am
index f324715..fd9ce25 100644
--- a/lib/py/Makefile.am
+++ b/lib/py/Makefile.am
@@ -21,7 +21,6 @@ DESTDIR ?= /
if WITH_PY3
py3-build:
- $(PIP3) install -r requirements.txt || $(PIP3) install --user -r requirements.txt
$(PYTHON3) setup.py build
py3-test: py3-build
$(PYTHON3) test/thrift_json.py
@@ -32,7 +31,6 @@ py3-test:
endif
all-local: py3-build
- $(PIP) install -r requirements.txt || $(PIP) install --user -r requirements.txt
$(PYTHON) setup.py build
# We're ignoring prefix here because site-packages seems to be
@@ -40,7 +38,6 @@ all-local: py3-build
# Old version (can't put inline because it's not portable).
#$(PYTHON) setup.py install --prefix=$(prefix) --root=$(DESTDIR) $(PYTHON_SETUPUTIL_ARGS)
install-exec-hook:
- $(PIP) install -r requirements.txt
$(PYTHON) setup.py install --root=$(DESTDIR) --prefix=$(PY_PREFIX) $(PYTHON_SETUPUTIL_ARGS)
clean-local:
@@ -54,7 +51,6 @@ EXTRA_DIST = \
CMakeLists.txt \
coding_standards.md \
compat \
- requirements.txt \
setup.py \
setup.cfg \
src \
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/lib/py/requirements.txt
----------------------------------------------------------------------
diff --git a/lib/py/requirements.txt b/lib/py/requirements.txt
deleted file mode 100644
index 2254a28..0000000
--- a/lib/py/requirements.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-six
-backports.ssl_match_hostname >= 3.5
-ipaddress
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/lib/py/setup.py
----------------------------------------------------------------------
diff --git a/lib/py/setup.py b/lib/py/setup.py
index ca10096..99b7172 100644
--- a/lib/py/setup.py
+++ b/lib/py/setup.py
@@ -78,6 +78,14 @@ def run_setup(with_binary):
else:
extensions = dict()
+ ssl_deps = []
+ if sys.version_info[0] == 2:
+ ssl_deps.append('ipaddress')
+ if sys.hexversion < 0x03050000:
+ ssl_deps.append('backports.ssl_match_hostname>=3.5')
+ tornado_deps = ['tornado>=4.0']
+ twisted_deps = ['twisted']
+
setup(name='thrift',
version='1.0.0-dev',
description='Python bindings for the Apache Thrift RPC system',
@@ -86,6 +94,12 @@ def run_setup(with_binary):
url='http://thrift.apache.org',
license='Apache License 2.0',
install_requires=['six>=1.7.2'],
+ extras_require={
+ 'ssl': ssl_deps,
+ 'tornado': tornado_deps,
+ 'twisted': twisted_deps,
+ 'all': ssl_deps + tornado_deps + twisted_deps,
+ },
packages=[
'thrift',
'thrift.protocol',
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/lib/py/src/transport/TSSLSocket.py
----------------------------------------------------------------------
diff --git a/lib/py/src/transport/TSSLSocket.py b/lib/py/src/transport/TSSLSocket.py
index 12bc356..0f7d45e 100644
--- a/lib/py/src/transport/TSSLSocket.py
+++ b/lib/py/src/transport/TSSLSocket.py
@@ -346,7 +346,7 @@ class TSSLServerSocket(TSocket.TServerSocket, TSSLBase):
TSSLBase.__init__(self, True, None, kwargs)
TSocket.TServerSocket.__init__(self, host, port, unix_socket)
if self._should_verify and not _match_has_ipaddress:
- raise ValueError('Need ipaddress and backports.ssl_match_hostname'
+ raise ValueError('Need ipaddress and backports.ssl_match_hostname '
'module to verify client certificate')
def setCertfile(self, certfile):
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/test/Makefile.am
----------------------------------------------------------------------
diff --git a/test/Makefile.am b/test/Makefile.am
index fb39a12..1a1bf47 100755
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -53,8 +53,10 @@ endif
if WITH_PYTHON
SUBDIRS += py
PRECROSS_TARGET += precross-py
-SUBDIRS += py.twisted
SUBDIRS += py.tornado
+if WITH_TWISTED_TEST
+SUBDIRS += py.twisted
+endif
endif
if WITH_RUBY
http://git-wip-us.apache.org/repos/asf/thrift/blob/bf9fa905/test/py.twisted/Makefile.am
----------------------------------------------------------------------
diff --git a/test/py.twisted/Makefile.am b/test/py.twisted/Makefile.am
index 5020215..78cde22 100644
--- a/test/py.twisted/Makefile.am
+++ b/test/py.twisted/Makefile.am
@@ -18,6 +18,7 @@
#
THRIFT = $(top_builddir)/compiler/cpp/thrift
+TRIAL ?= trial
stubs: ../ThriftTest.thrift ../SmallTest.thrift
$(THRIFT) --gen py:twisted ../ThriftTest.thrift
[09/10] thrift git commit: THRIFT-3911 Loosen Ruby dev dependency
version requirements
Posted by ns...@apache.org.
THRIFT-3911 Loosen Ruby dev dependency version requirements
This closes #1074
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/d4eecda6
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/d4eecda6
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/d4eecda6
Branch: refs/heads/master
Commit: d4eecda6b2f8b3b27a191605a054aa3bf79a4684
Parents: bf9fa90
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sun Sep 4 18:49:22 2016 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Sep 4 18:49:22 2016 +0900
----------------------------------------------------------------------
lib/rb/thrift.gemspec | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/d4eecda6/lib/rb/thrift.gemspec
----------------------------------------------------------------------
diff --git a/lib/rb/thrift.gemspec b/lib/rb/thrift.gemspec
index 8e8deba..166a93f 100644
--- a/lib/rb/thrift.gemspec
+++ b/lib/rb/thrift.gemspec
@@ -27,11 +27,11 @@ Gem::Specification.new do |s|
s.require_paths = %w[lib ext]
- s.add_development_dependency 'rspec', '~> 2.10.0'
- s.add_development_dependency "rack", "~> 1.5.2"
- s.add_development_dependency "rack-test", "~> 0.6.2"
- s.add_development_dependency "thin", "~> 1.5.0"
- s.add_development_dependency "bundler"
- s.add_development_dependency 'rake', '~> 10.5.0'
+ s.add_development_dependency 'rspec', ['>= 2.10.0', '< 2.14.0']
+ s.add_development_dependency "rack", "~> 1.5"
+ s.add_development_dependency "rack-test", "~> 0.6"
+ s.add_development_dependency "thin", "~> 1.5"
+ s.add_development_dependency "bundler", "~> 1"
+ s.add_development_dependency 'rake', '~> 10.5'
end
[02/10] thrift git commit: THRIFT-3046: Allow PSR4 class loading for
generated classes (PHP)
Posted by ns...@apache.org.
THRIFT-3046: Allow PSR4 class loading for generated classes (PHP)
Allow test to be used with psr4 autoloading
This closes #1010
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/d1ceba44
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/d1ceba44
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/d1ceba44
Branch: refs/heads/master
Commit: d1ceba449d3c6bb431386abc11495f21f9824238
Parents: 7b0cb9a
Author: Andreas Scheja <a....@gmail.com>
Authored: Sun May 15 21:49:04 2016 +0200
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sat Sep 3 15:58:37 2016 +0900
----------------------------------------------------------------------
test/php/Makefile.am | 4 +++-
test/php/TestClient.php | 6 +++++-
test/php/TestPsr4.php | 23 +++++++++++++++++++++++
3 files changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/d1ceba44/test/php/Makefile.am
----------------------------------------------------------------------
diff --git a/test/php/Makefile.am b/test/php/Makefile.am
index 11974da..7c4347f 100755
--- a/test/php/Makefile.am
+++ b/test/php/Makefile.am
@@ -22,13 +22,15 @@ THRIFT = $(top_builddir)/compiler/cpp/thrift
stubs: ../ThriftTest.thrift
$(THRIFT) --gen php ../ThriftTest.thrift
$(THRIFT) --gen php:inlined ../ThriftTest.thrift
+ $(MKDIR_P) gen-php-psr4
+ $(THRIFT) -out gen-php-psr4 --gen php:psr4 ../ThriftTest.thrift
precross: stubs
check: stubs
clean-local:
- $(RM) -r gen-php gen-phpi
+ $(RM) -r gen-php gen-phpi gen-php-psr4
client: stubs
php TestClient.php
http://git-wip-us.apache.org/repos/asf/thrift/blob/d1ceba44/test/php/TestClient.php
----------------------------------------------------------------------
diff --git a/test/php/TestClient.php b/test/php/TestClient.php
index 946334d..2443ee0 100755
--- a/test/php/TestClient.php
+++ b/test/php/TestClient.php
@@ -15,7 +15,11 @@ if (!isset($MODE)) {
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', __DIR__ . '/../../lib/php/lib');
-$loader->registerDefinition('ThriftTest', $GEN_DIR);
+if ($GEN_DIR === 'gen-php-psr4') {
+ $loader->registerNamespace('ThriftTest', $GEN_DIR);
+} else {
+ $loader->registerDefinition('ThriftTest', $GEN_DIR);
+}
$loader->register();
/*
http://git-wip-us.apache.org/repos/asf/thrift/blob/d1ceba44/test/php/TestPsr4.php
----------------------------------------------------------------------
diff --git a/test/php/TestPsr4.php b/test/php/TestPsr4.php
new file mode 100644
index 0000000..d30bf1c
--- /dev/null
+++ b/test/php/TestPsr4.php
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+<?php
+$GEN_DIR = 'gen-php-psr4';
+include_once('TestClient.php');
+?>