THRIFT-2753 Haxe support: Misc. improvements
Client: Haxe
Patch: Jens Geyer
This closes #229
diff --git a/.gitignore b/.gitignore
index e9d5d9a..e931f1a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -164,6 +164,7 @@
/lib/erl/.eunit
/lib/erl/ebin
/lib/erl/deps/
+/lib/haxe/test/bin
/lib/hs/dist
/lib/java/build
/lib/js/test/build
diff --git a/compiler/cpp/src/generate/t_haxe_generator.cc b/compiler/cpp/src/generate/t_haxe_generator.cc
index 24457e5..3c2207f 100644
--- a/compiler/cpp/src/generate/t_haxe_generator.cc
+++ b/compiler/cpp/src/generate/t_haxe_generator.cc
@@ -719,6 +719,7 @@
bool is_exception,
bool in_class,
bool is_result) {
+ (void) in_class;
generate_haxe_doc(out, tstruct);
string clsname = get_cap_name( tstruct->get_name());
@@ -759,7 +760,7 @@
out << endl;
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- indent(out) << "inline static var " << upcase_string((*m_iter)->get_name()) << " : Int = " << (*m_iter)->get_key() << ";" << endl;
+ indent(out) << "inline static var " << upcase_string((*m_iter)->get_name()) << "_FIELD_ID : Int = " << (*m_iter)->get_key() << ";" << endl;
}
out << endl;
@@ -869,7 +870,7 @@
// Generate deserialization code for known cases
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
indent(out) <<
- "case " << upcase_string((*f_iter)->get_name()) << ":" << endl;
+ "case " << upcase_string((*f_iter)->get_name()) << "_FIELD_ID:" << endl;
indent_up();
indent(out) <<
"if (field.type == " << type_to_enum((*f_iter)->get_type()) << ") {" << endl;
@@ -1079,7 +1080,7 @@
void t_haxe_generator::generate_reflection_getters(ostringstream& out, t_type* type, string field_name, string cap_name) {
(void) type;
(void) cap_name;
- indent(out) << "case " << upcase_string(field_name) << ":" << endl;
+ indent(out) << "case " << upcase_string(field_name) << "_FIELD_ID:" << endl;
indent_up();
indent(out) << "return this." << field_name << ";" << endl;
indent_down();
@@ -1088,7 +1089,7 @@
void t_haxe_generator::generate_reflection_setters(ostringstream& out, t_type* type, string field_name, string cap_name) {
(void) type;
(void) cap_name;
- indent(out) << "case " << upcase_string(field_name) << ":" << endl;
+ indent(out) << "case " << upcase_string(field_name) << "_FIELD_ID:" << endl;
indent_up();
indent(out) << "if (value == null) {" << endl;
indent(out) << " unset" << get_cap_name(field_name) << "();" << endl;
@@ -1170,7 +1171,7 @@
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
t_field* field = *f_iter;
- indent(out) << "case " << upcase_string(field->get_name()) << ":" << endl;
+ indent(out) << "case " << upcase_string(field->get_name()) << "_FIELD_ID:" << endl;
indent_up();
indent(out) << "return " << generate_isset_check(field) << ";" << endl;
indent_down();
@@ -1347,7 +1348,7 @@
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
t_field* field = *f_iter;
std::string field_name = field->get_name();
- indent(out) << "metaDataMap[" << upcase_string(field_name) << "] = new FieldMetaData(\"" << field_name << "\", ";
+ indent(out) << "metaDataMap[" << upcase_string(field_name) << "_FIELD_ID] = new FieldMetaData(\"" << field_name << "\", ";
// Set field requirement type (required, optional, etc.)
if (field->get_req() == t_field::T_REQUIRED) {
@@ -2937,7 +2938,7 @@
std::string t_haxe_generator::get_enum_class_name(t_type* type) {
string package = "";
t_program* program = type->get_program();
- if (program != NULL && program != program_) {
+ if (program != NULL /*&& program != program_*/) {
package = program->get_namespace("haxe") + ".";
}
return package + type->get_name();
diff --git a/configure.ac b/configure.ac
index 9f104fa..04107be 100755
--- a/configure.ac
+++ b/configure.ac
@@ -652,6 +652,7 @@
lib/erl/Makefile
lib/go/Makefile
lib/go/test/Makefile
+ lib/haxe/test/Makefile
lib/hs/Makefile
lib/java/Makefile
lib/js/test/Makefile
diff --git a/lib/haxe/README.md b/lib/haxe/README.md
index 3335b43..82525d4 100644
--- a/lib/haxe/README.md
+++ b/lib/haxe/README.md
@@ -32,17 +32,17 @@
Current status
========================
- tested with Haxe C++ target
-- transports: socket
-- protocols: binary, JSON
+- transports: Socket, HTTP (client only), Stream
+- protocols: Binary, JSON
- tutorial client and server available
- cross-test client and server available
Further developments
========================
-- add HTTP transport, update tutorial and tests accordingly
- improve to work with C#, Java and JavaScript Haxe/OpenFL targets
- improve to work with more (ideally all) Haxe/OpenFL targets
+- add HTTP server, update tutorial and tests accordingly
Dependencies
@@ -53,9 +53,9 @@
after installing Haxe itself. For example, if you plan to target C#, Java and C++,
enter the following commands after installing Haxe:
- haxelib install hxcpp
- haxelib install hxjava
- haxelib install hxcs
+ haxelib install hxcpp
+ haxelib install hxjava
+ haxelib install hxcs
For other targets, please consult the Haxe documentation whether or not any additional
target libraries need to be installed and how to achieve this.
diff --git a/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx b/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx
index edd5e12..1a93332 100644
--- a/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx
+++ b/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -58,6 +58,9 @@
// Reader that manages a 1-byte buffer
private var reader : LookaheadReader;
+ // whether the underlying system holds Strings as UTF-8
+ // http://old.haxe.org/manual/encoding
+ private static var utf8Strings = haxe.Utf8.validate("Ç-ß-Æ-Ю-Ш");
// TJSONProtocol Constructor
public function new( trans : TTransport)
@@ -74,7 +77,7 @@
public function writeMessageBegin(message:TMessage) : Void {
WriteJSONArrayStart();
WriteJSONInteger( JSONConstants.VERSION);
- WriteJSONString( Utf8Encode(message.name));
+ WriteJSONString( BytesFromString(message.name));
WriteJSONInteger( message.type);
WriteJSONInteger( message.seqid);
}
@@ -94,7 +97,7 @@
public function writeFieldBegin(field:TField) : Void {
WriteJSONInteger( field.id );
WriteJSONObjectStart();
- WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( field.type)));
+ WriteJSONString( BytesFromString( JSONConstants.GetTypeNameForTypeID( field.type)));
}
public function writeFieldEnd() : Void {
@@ -105,8 +108,8 @@
public function writeMapBegin(map:TMap) : Void {
WriteJSONArrayStart();
- WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( map.keyType)));
- WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( map.valueType)));
+ WriteJSONString( BytesFromString( JSONConstants.GetTypeNameForTypeID( map.keyType)));
+ WriteJSONString( BytesFromString( JSONConstants.GetTypeNameForTypeID( map.valueType)));
WriteJSONInteger( map.size);
WriteJSONObjectStart();
}
@@ -118,7 +121,7 @@
public function writeListBegin(list:TList) : Void {
WriteJSONArrayStart();
- WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( list.elemType )));
+ WriteJSONString( BytesFromString( JSONConstants.GetTypeNameForTypeID( list.elemType )));
WriteJSONInteger( list.size);
}
@@ -128,7 +131,7 @@
public function writeSetBegin(set:TSet) : Void {
WriteJSONArrayStart();
- WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( set.elemType)));
+ WriteJSONString( BytesFromString( JSONConstants.GetTypeNameForTypeID( set.elemType)));
WriteJSONInteger( set.size);
}
@@ -164,7 +167,7 @@
}
public function writeString(str : String) : Void {
- WriteJSONString( Utf8Encode(str));
+ WriteJSONString( BytesFromString(str));
}
public function writeBinary(bin:Bytes) : Void {
@@ -180,8 +183,7 @@
"Message contained bad version.");
}
- var buf = ReadJSONString(false);
- message.name = Utf8Decode(buf);
+ message.name = ReadJSONString(false);
message.type = ReadJSONInteger();
message.seqid = ReadJSONInteger();
return message;
@@ -211,7 +213,7 @@
{
field.id = ReadJSONInteger();
ReadJSONObjectStart();
- field.type = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+ field.type = JSONConstants.GetTypeIDForTypeName( ReadJSONString(false));
}
return field;
}
@@ -222,8 +224,8 @@
public function readMapBegin() : TMap {
ReadJSONArrayStart();
- var KeyType = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
- var ValueType = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+ var KeyType = JSONConstants.GetTypeIDForTypeName( ReadJSONString(false));
+ var ValueType = JSONConstants.GetTypeIDForTypeName( ReadJSONString(false));
var Count : Int = ReadJSONInteger();
ReadJSONObjectStart();
@@ -238,7 +240,7 @@
public function readListBegin():TList {
ReadJSONArrayStart();
- var ElementType = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+ var ElementType = JSONConstants.GetTypeIDForTypeName( ReadJSONString(false));
var Count : Int = ReadJSONInteger();
var list = new TList( ElementType, Count);
@@ -251,7 +253,7 @@
public function readSetBegin() : TSet {
ReadJSONArrayStart();
- var ElementType = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+ var ElementType = JSONConstants.GetTypeIDForTypeName( ReadJSONString(false));
var Count : Int = ReadJSONInteger();
var set = new TSet( ElementType, Count);
@@ -263,7 +265,7 @@
}
public function readBool() : Bool {
- return (ReadJSONInteger() == 0 ? false : true);
+ return (ReadJSONInteger() != 0);
}
public function readByte() : Int {
@@ -287,8 +289,7 @@
}
public function readString() : String {
- var buf = ReadJSONString(false);
- return Utf8Decode(buf);
+ return ReadJSONString(false);
}
public function readBinary() : Bytes {
@@ -402,7 +403,6 @@
str += JSONConstants.QUOTE;
}
-trace('WriteJSONInt64($str)');
var tmp = BytesFromString( str);
trans.write( tmp, 0, tmp.length);
}
@@ -502,7 +502,7 @@
// Read in a JSON string, unescaping as appropriate.
// Skip Reading from the context if skipContext is true.
- private function ReadJSONString(skipContext : Bool) : Bytes
+ private function ReadJSONString(skipContext : Bool) : String
{
if (!skipContext)
{
@@ -560,7 +560,7 @@
buffer.addString( String.fromCharCode(charcode));
}
- return buffer.getBytes();
+ return StringFromBytes( buffer.getBytes());
}
// Return true if the given byte could be a valid part of a JSON number.
@@ -642,8 +642,6 @@
ReadJSONSyntaxChar( JSONConstants.QUOTE);
}
-trace('ReadJSONInt64() = $str');
-
// process sign
var bMinus = false;
var startAt = 0;
@@ -689,7 +687,7 @@
var str : String = "";
if (StringFromBytes(reader.Peek()) == JSONConstants.QUOTE) {
- str = StringFromBytes( ReadJSONString(true));
+ str = ReadJSONString(true);
// special cases
if( str == JSONConstants.FLOAT_IS_NAN) {
@@ -729,7 +727,7 @@
// Read in a JSON string containing base-64 encoded data and decode it.
private function ReadJSONBase64() : Bytes
{
- var str = StringFromBytes( ReadJSONString(false));
+ var str = ReadJSONString(false);
return Base64.decode( str);
}
@@ -758,21 +756,22 @@
public static function BytesFromString( str : String) : Bytes {
var buf = new BytesBuffer();
- buf.addString( str);
+ if( utf8Strings)
+ buf.addString( str); // no need to encode on UTF8 targets, the string is just fine
+ else
+ buf.addString( Utf8.encode( str));
return buf.getBytes();
}
public static function StringFromBytes( buf : Bytes) : String {
var inp = new BytesInput( buf);
- return inp.readString( buf.length);
- }
-
- public static function Utf8Encode(str : String) : Bytes {
- return BytesFromString( Utf8.encode( str));
- }
-
- public static function Utf8Decode( buf : Bytes) : String {
- return Utf8.decode( StringFromBytes( buf));
+ if( buf.length == 0)
+ return ""; // readString() would return null in that case, which is wrong
+ var str = inp.readString( buf.length);
+ if( utf8Strings)
+ return str; // no need to decode on UTF8 targets, the string is just fine
+ else
+ return Utf8.decode( str);
}
// Convert a byte containing a hex char ('0'-'9' or 'a'-'f') into its corresponding hex value
diff --git a/lib/haxe/src/org/apache/thrift/server/TServer.hx b/lib/haxe/src/org/apache/thrift/server/TServer.hx
index 9b235f69..37105bd 100644
--- a/lib/haxe/src/org/apache/thrift/server/TServer.hx
+++ b/lib/haxe/src/org/apache/thrift/server/TServer.hx
@@ -1,4 +1,4 @@
-/**
+/*
* 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
diff --git a/lib/haxe/src/org/apache/thrift/server/TServerEventHandler.hx b/lib/haxe/src/org/apache/thrift/server/TServerEventHandler.hx
index 08f48b2..83bff95 100644
--- a/lib/haxe/src/org/apache/thrift/server/TServerEventHandler.hx
+++ b/lib/haxe/src/org/apache/thrift/server/TServerEventHandler.hx
@@ -1,4 +1,4 @@
-/**
+/*
* 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
diff --git a/lib/haxe/src/org/apache/thrift/server/TSimpleServer.hx b/lib/haxe/src/org/apache/thrift/server/TSimpleServer.hx
index 20a7195..c516b78 100644
--- a/lib/haxe/src/org/apache/thrift/server/TSimpleServer.hx
+++ b/lib/haxe/src/org/apache/thrift/server/TSimpleServer.hx
@@ -1,4 +1,4 @@
-/**
+/*
* 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
diff --git a/lib/haxe/src/org/apache/thrift/transport/TFileStream.hx b/lib/haxe/src/org/apache/thrift/transport/TFileStream.hx
new file mode 100644
index 0000000..03e031f
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/transport/TFileStream.hx
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+
+package org.apache.thrift.transport;
+
+import haxe.io.Bytes;
+import haxe.io.BytesBuffer;
+import haxe.io.Input;
+import haxe.io.Output;
+
+
+enum TFileMode {
+ CreateNew;
+ Append;
+ Read;
+}
+
+
+class TFileStream implements TStream {
+
+ public var FileName(default,null) : String;
+
+ private var Input : sys.io.FileInput;
+ private var Output : sys.io.FileOutput;
+
+
+ public function new( fname : String, mode : TFileMode) {
+ FileName = fname;
+ switch ( mode)
+ {
+ case TFileMode.CreateNew:
+ Output = sys.io.File.write( fname, true);
+
+ case TFileMode.Append:
+ Output = sys.io.File.append( fname, true);
+
+ case TFileMode.Read:
+ Input = sys.io.File.read( fname, true);
+
+ default:
+ throw new TTransportException( TTransportException.UNKNOWN,
+ "Unsupported mode");
+ }
+
+ }
+
+ public function Close() : Void {
+ if( Input != null) {
+ Input.close();
+ Input = null;
+ }
+ if( Output != null) {
+ Output.close();
+ Output = null;
+ }
+ }
+
+ public function Peek() : Bool {
+ if( Input == null)
+ throw new TTransportException( TTransportException.NOT_OPEN, "File not open for input");
+
+ return (! Input.eof());
+ }
+
+ public function Read( buf : Bytes, offset : Int, count : Int) : Int {
+ if( Input == null)
+ throw new TTransportException( TTransportException.NOT_OPEN, "File not open for input");
+
+ return Input.readBytes( buf, offset, count);
+ }
+
+ public function Write( buf : Bytes, offset : Int, count : Int) : Void {
+ if( Output == null)
+ throw new TTransportException( TTransportException.NOT_OPEN, "File not open for output");
+
+ Output.writeBytes( buf, offset, count);
+ }
+
+ public function Flush() : Void {
+ if( Output != null)
+ Output.flush();
+ }
+
+}
diff --git a/lib/haxe/src/org/apache/thrift/transport/TFramedTransport.hx b/lib/haxe/src/org/apache/thrift/transport/TFramedTransport.hx
index 5d77140..77335e7 100644
--- a/lib/haxe/src/org/apache/thrift/transport/TFramedTransport.hx
+++ b/lib/haxe/src/org/apache/thrift/transport/TFramedTransport.hx
@@ -7,7 +7,7 @@
* "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
+ * 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
diff --git a/lib/haxe/src/org/apache/thrift/transport/TFramedTransportFactory.hx b/lib/haxe/src/org/apache/thrift/transport/TFramedTransportFactory.hx
index 00127bf..3cca1f8 100644
--- a/lib/haxe/src/org/apache/thrift/transport/TFramedTransportFactory.hx
+++ b/lib/haxe/src/org/apache/thrift/transport/TFramedTransportFactory.hx
@@ -7,7 +7,7 @@
* "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
+ * 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
diff --git a/lib/haxe/src/org/apache/thrift/transport/THttpClient.hx b/lib/haxe/src/org/apache/thrift/transport/THttpClient.hx
index d2fda79..52a9d26 100644
--- a/lib/haxe/src/org/apache/thrift/transport/THttpClient.hx
+++ b/lib/haxe/src/org/apache/thrift/transport/THttpClient.hx
@@ -25,30 +25,7 @@
import haxe.io.BytesOutput;
import haxe.io.BytesInput;
-#if openfl
-// OpenFL all targets
-import openfl.errors.EOFError;
-import openfl.events.Event;
-import openfl.events.IOErrorEvent;
-import openfl.events.SecurityErrorEvent;
-import openfl.net.URLLoader;
-import openfl.net.URLLoaderDataFormat;
-import openfl.net.URLRequest;
-import openfl.net.URLRequestMethod;
-#elseif flash
-// Haxe flash, no OpenFL
-import flash.errors.EOFError;
-import flash.events.Event;
-import flash.events.IOErrorEvent;
-import flash.events.SecurityErrorEvent;
-import flash.net.URLLoader;
-import flash.net.URLLoaderDataFormat;
-import flash.net.URLRequest;
-import flash.net.URLRequestMethod;
-#else
-// bare Haxe
import haxe.Http;
-#end
@@ -62,29 +39,15 @@
private var requestBuffer_ : BytesOutput = new BytesOutput();
private var responseBuffer_ : BytesInput = null;
- #if (flash || openfl)
- private var request_ : URLRequest = null;
- #else
private var request_ : Http = null;
- #end
- #if (flash || openfl)
-
- public function new( request : URLRequest) : Void {
- request.contentType = "application/x-thrift";
- request_ = request;
- }
-
- #else
-
public function new( requestUrl : String) : Void {
request_ = new Http(requestUrl);
request_.addHeader( "contentType", "application/x-thrift");
}
- #end
-
+
public override function open() : Void {
}
@@ -100,24 +63,10 @@
throw new TTransportException(TTransportException.UNKNOWN, "Response buffer is empty, no request.");
}
- #if flash
- try {
- var data = Bytes.alloc(len);
- responseBuffer_.readBytes(data, off, len);
- buf.addBytes(data,0,len);
- return len;
- } catch (e : EOFError) {
- throw new TTransportException(TTransportException.UNKNOWN, "No more data available.");
- }
-
- #else
-
var data =Bytes.alloc(len);
len = responseBuffer_.readBytes(data, off, len);
buf.addBytes(data,0,len);
return len;
-
- #end
}
public override function write(buf:Bytes, off : Int, len : Int) : Void {
@@ -125,59 +74,30 @@
}
- #if (flash || openfl)
-
- public override function flush(callback:Error->Void = null) : Void {
- var loader : URLLoader = new URLLoader();
-
- if (callback != null) {
- loader.addEventListener(Event.COMPLETE, function(event:Event) : Void {
- responseBuffer_ = new URLLoader(event.target).data;
- callback(null);
- });
- loader.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent) : Void {
- callback(new TTransportException(TTransportException.UNKNOWN, "IOError: " + event.text));
- responseBuffer_ = null;
- });
- loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(event:SecurityErrorEvent) : Void {
- callback(new TTransportException(TTransportException.UNKNOWN, "SecurityError: " + event.text));
- responseBuffer_ = null;
- });
- }
-
- request_.method = URLRequestMethod.POST;
- loader.dataFormat = URLLoaderDataFormat.BINARY;
- //requestBuffer_.position = 0;
- request_.data = requestBuffer_;
- loader.load(request_);
- }
-
- #else
-
public override function flush(callback:Dynamic->Void = null) : Void {
-
var buffer = requestBuffer_;
requestBuffer_ = new BytesOutput();
responseBuffer_ = null;
request_.onData = function(data : String) {
- responseBuffer_ = new BytesInput(buffer.getBytes());
- callback(null);
- };
- request_.onError = function(msg : String) {
- callback(new TTransportException(TTransportException.UNKNOWN, "IOError: " + msg));
+ var tmp = new BytesBuffer();
+ tmp.addString(data);
+ responseBuffer_ = new BytesInput(tmp.getBytes());
+ if( callback != null) {
+ callback(null);
+ }
};
- #if js
+ request_.onError = function(msg : String) {
+ if( callback != null) {
+ callback(new TTransportException(TTransportException.UNKNOWN, "IOError: " + msg));
+ }
+ };
+
request_.setPostData(buffer.getBytes().toString());
request_.request(true/*POST*/);
- #else
- request_.customRequest( true/*POST*/, buffer);
- #end
}
- #end
-
}
\ No newline at end of file
diff --git a/lib/haxe/src/org/apache/thrift/transport/TServerSocket.hx b/lib/haxe/src/org/apache/thrift/transport/TServerSocket.hx
index 1953244..0eae931 100644
--- a/lib/haxe/src/org/apache/thrift/transport/TServerSocket.hx
+++ b/lib/haxe/src/org/apache/thrift/transport/TServerSocket.hx
@@ -1,4 +1,4 @@
-/**
+/*
* 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
diff --git a/lib/haxe/src/org/apache/thrift/transport/TServerTransport.hx b/lib/haxe/src/org/apache/thrift/transport/TServerTransport.hx
index e0ce697..5819803 100644
--- a/lib/haxe/src/org/apache/thrift/transport/TServerTransport.hx
+++ b/lib/haxe/src/org/apache/thrift/transport/TServerTransport.hx
@@ -1,4 +1,4 @@
-/**
+/*
* 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
diff --git a/lib/haxe/src/org/apache/thrift/transport/TStream.hx b/lib/haxe/src/org/apache/thrift/transport/TStream.hx
new file mode 100644
index 0000000..0e1b52d
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/transport/TStream.hx
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+package org.apache.thrift.transport;
+
+import haxe.io.Bytes;
+import haxe.io.BytesBuffer;
+
+
+interface TStream {
+ function Close() : Void;
+ function Peek() : Bool;
+ function Read( buf : Bytes, offset : Int, count : Int) : Int;
+ function Write( buf : Bytes, offset : Int, count : Int) : Void;
+ function Flush() : Void;
+}
diff --git a/lib/haxe/src/org/apache/thrift/transport/TStreamTransport.hx b/lib/haxe/src/org/apache/thrift/transport/TStreamTransport.hx
new file mode 100644
index 0000000..99203b4
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/transport/TStreamTransport.hx
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ */
+
+package org.apache.thrift.transport;
+
+import org.apache.thrift.transport.*;
+import org.apache.thrift.helper.*;
+
+import haxe.io.Bytes;
+import haxe.io.BytesBuffer;
+import haxe.io.BytesOutput;
+import haxe.io.BytesInput;
+
+
+class TStreamTransport extends TTransport {
+
+ public var InputStream(default,null) : TStream;
+ public var OutputStream(default,null) : TStream;
+
+
+ public function new( input : TStream, output : TStream) {
+ this.InputStream = input;
+ this.OutputStream = output;
+ }
+
+ public override function isOpen() : Bool {
+ return true;
+ }
+
+ public override function peek() : Bool {
+ return (InputStream != null);
+ }
+
+ public override function open() : Void {
+ }
+
+ public override function close() : Void {
+ if (InputStream != null)
+ {
+ InputStream.Close();
+ InputStream = null;
+ }
+ if (OutputStream != null)
+ {
+ OutputStream.Close();
+ OutputStream = null;
+ }
+ }
+
+ public override function read( buf : BytesBuffer, off : Int, len : Int) : Int {
+ if (InputStream == null)
+ {
+ throw new TTransportException( TTransportException.NOT_OPEN,
+ "Cannot read from null InputStream");
+ }
+
+ var data : Bytes = Bytes.alloc(len);
+ var size = InputStream.Read( data, off, len);
+ buf.addBytes( data, 0, size);
+ return size;
+ }
+
+ public override function write(buf:Bytes, off : Int, len : Int) : Void {
+ if (OutputStream == null)
+ {
+ throw new TTransportException( TTransportException.NOT_OPEN,
+ "Cannot write to null OutputStream");
+ }
+
+ OutputStream.Write(buf, off, len);
+ }
+
+ public override function flush(callback:Dynamic->Void =null) : Void {
+ if (OutputStream == null)
+ {
+ var err = new TTransportException( TTransportException.NOT_OPEN,
+ "Cannot flush null OutputStream");
+ if(callback != null)
+ callback(err);
+ else
+ throw err;
+ }
+
+ OutputStream.Flush();
+ }
+
+}
diff --git a/lib/haxe/test/Makefile.am b/lib/haxe/test/Makefile.am
new file mode 100644
index 0000000..5e92f98
--- /dev/null
+++ b/lib/haxe/test/Makefile.am
@@ -0,0 +1,50 @@
+#
+# 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_srcdir)/compiler/cpp/thrift
+THRIFTCMD = $(THRIFT) --gen haxe -r
+THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift
+
+BIN_CPP = bin/Main-debug
+
+gen-haxe/thrift/test/ThriftTest.hx: $(THRIFTTEST)
+ $(THRIFTCMD) $(THRIFTTEST)
+
+all-local: $(BIN_CPP)
+
+$(BIN_CPP): gen-haxe/thrift/test/ThriftTest.hx
+ $(HAXE) --cwd . cpp.hxml
+
+
+#TODO: other haxe targets
+# $(HAXE) --cwd . csharp
+# $(HAXE) --cwd . flash
+# $(HAXE) --cwd . java
+# $(HAXE) --cwd . javascript
+# $(HAXE) --cwd . neko
+# $(HAXE) --cwd . php
+# $(HAXE) --cwd . python # needs Haxe 3.1.4
+
+
+clean-local:
+ $(RM) -r gen-haxe bin
+
+check: $(BIN_CPP)
+ $(BIN_CPP)
+
diff --git a/lib/haxe/test/cpp.hxml b/lib/haxe/test/cpp.hxml
new file mode 100644
index 0000000..73848a8
--- /dev/null
+++ b/lib/haxe/test/cpp.hxml
@@ -0,0 +1,41 @@
+#
+# 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.
+#
+
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#CPP target
+-cpp bin
+
+#To produce 64 bit binaries the file should define the HXCPP_M64 compile variable:
+#-D HXCPP_M64
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/csharp.hxml b/lib/haxe/test/csharp.hxml
new file mode 100644
index 0000000..4c34b0d
--- /dev/null
+++ b/lib/haxe/test/csharp.hxml
@@ -0,0 +1,38 @@
+#
+# 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.
+#
+
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#CSHARP target
+-cs bin/Test.exe
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/flash.hxml b/lib/haxe/test/flash.hxml
new file mode 100644
index 0000000..8b17631
--- /dev/null
+++ b/lib/haxe/test/flash.hxml
@@ -0,0 +1,38 @@
+#
+# 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.
+#
+
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#Flash target
+-swf bin/Test.swf
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/java.hxml b/lib/haxe/test/java.hxml
new file mode 100644
index 0000000..c947159
--- /dev/null
+++ b/lib/haxe/test/java.hxml
@@ -0,0 +1,38 @@
+#
+# 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.
+#
+
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#Java target
+-java bin/Test.jar
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/javascript.hxml b/lib/haxe/test/javascript.hxml
new file mode 100644
index 0000000..18d9964
--- /dev/null
+++ b/lib/haxe/test/javascript.hxml
@@ -0,0 +1,44 @@
+#
+# 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.
+#
+
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#JavaScript target
+-js bin/Test.js
+
+#You can use -D source-map-content (requires Haxe 3.1+) to have the .hx
+#files directly embedded into the map file, this way you only have to
+#upload it, and it will be always in sync with the compiled .js even if
+#you modify your .hx files.
+-D source-map-content
+
+#Generate source map and add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/make_all.bat b/lib/haxe/test/make_all.bat
new file mode 100644
index 0000000..ee18f10
--- /dev/null
+++ b/lib/haxe/test/make_all.bat
@@ -0,0 +1,68 @@
+@echo off
+rem /*
+rem * Licensed to the Apache Software Foundation (ASF) under one
+rem * or more contributor license agreements. See the NOTICE file
+rem * distributed with this work for additional information
+rem * regarding copyright ownership. The ASF licenses this file
+rem * to you under the Apache License, Version 2.0 (the
+rem * "License"); you may not use this file except in compliance
+rem * with the License. You may obtain a copy of the License at
+rem *
+rem * http://www.apache.org/licenses/LICENSE-2.0
+rem *
+rem * Unless required by applicable law or agreed to in writing,
+rem * software distributed under the License is distributed on an
+rem * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+rem * KIND, either express or implied. See the License for the
+rem * specific language governing permissions and limitations
+rem * under the License.
+rem */
+
+setlocal
+if "%HOMEDRIVE%"=="" goto MISSINGVARS
+if "%HOMEPATH%"=="" goto MISSINGVARS
+if "%HAXEPATH%"=="" goto NOTINSTALLED
+
+set path=%HAXEPATH%;%HAXEPATH%\..\neko;%path%
+
+rem # invoke Thrift comnpiler
+thrift -r -gen haxe ..\..\..\test\ThriftTest.thrift
+if errorlevel 1 goto STOP
+
+rem # invoke Haxe compiler for all targets
+for %%a in (*.hxml) do (
+ rem * filter Python, as it is not supported by Haxe 3.1.3 (but will be in 3.1.4)
+ if not "%%a"=="python.hxml" (
+ echo --------------------------
+ echo Building %%a ...
+ echo --------------------------
+ haxe --cwd . %%a
+ )
+)
+
+
+echo.
+echo done.
+pause
+goto eof
+
+:NOTINSTALLED
+echo FATAL: Either Haxe is not installed, or the HAXEPATH variable is not set.
+pause
+goto eof
+
+:MISSINGVARS
+echo FATAL: Unable to locate home folder.
+echo.
+echo Both HOMEDRIVE and HOMEPATH need to be set to point to your Home folder.
+echo The current values are:
+echo HOMEDRIVE=%HOMEDRIVE%
+echo HOMEPATH=%HOMEPATH%
+pause
+goto eof
+
+:STOP
+pause
+goto eof
+
+:eof
diff --git a/lib/haxe/test/make_all.sh b/lib/haxe/test/make_all.sh
new file mode 100644
index 0000000..13b5754
--- /dev/null
+++ b/lib/haxe/test/make_all.sh
@@ -0,0 +1,41 @@
+#!/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.
+#
+
+# invoke Thrift comnpiler
+thrift -r -gen haxe ../../../test/ThriftTest.thrift
+
+# output folder
+if [ ! -d bin ]; then
+ mkdir bin
+fi
+
+# invoke Haxe compiler
+for target in *.hxml; do
+ echo --------------------------
+ echo Building ${target} ...
+ echo --------------------------
+ if [ ! -d bin/${target} ]; then
+ mkdir bin/${target}
+ fi
+ haxe --cwd . ${target}
+done
+
+
+#eof
diff --git a/lib/haxe/test/neko.hxml b/lib/haxe/test/neko.hxml
new file mode 100644
index 0000000..2db70c8
--- /dev/null
+++ b/lib/haxe/test/neko.hxml
@@ -0,0 +1,38 @@
+#
+# 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.
+#
+
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#neko target
+-neko bin/Test.n
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/php.hxml b/lib/haxe/test/php.hxml
new file mode 100644
index 0000000..b86e64c
--- /dev/null
+++ b/lib/haxe/test/php.hxml
@@ -0,0 +1,38 @@
+#
+# 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.
+#
+
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#PHP target
+-php bin/Test.php
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/project.hide b/lib/haxe/test/project.hide
new file mode 100644
index 0000000..16ef98e
--- /dev/null
+++ b/lib/haxe/test/project.hide
@@ -0,0 +1,67 @@
+{
+ "type" : 0
+ ,"target" : 4
+ ,"name" : "Test"
+ ,"main" : null
+ ,"projectPackage" : ""
+ ,"company" : ""
+ ,"license" : ""
+ ,"url" : ""
+ ,"targetData" : [
+ {
+ "pathToHxml" : "flash.hxml"
+ ,"runActionType" : 1
+ ,"runActionText" : "bin/Test.swf"
+ }
+ ,{
+ "pathToHxml" : "javascript.hxml"
+ ,"runActionType" : 1
+ ,"runActionText" : "bin\\index.html"
+ }
+ ,{
+ "pathToHxml" : "neko.hxml"
+ ,"runActionType" : 2
+ ,"runActionText" : "neko bin/Test.n"
+ }
+ ,{
+ "pathToHxml" : "php.hxml"
+ }
+ ,{
+ "pathToHxml" : "cpp.hxml"
+ ,"runActionType" : 2
+ ,"runActionText" : "bin/Main-debug.exe"
+ }
+ ,{
+ "pathToHxml" : "java.hxml"
+ }
+ ,{
+ "pathToHxml" : "csharp.hxml"
+ }
+ ,{
+ "pathToHxml" : "python.hxml"
+ ,"runActionType" : 2
+ ,"runActionText" : "python bin/Test.py"
+ }
+ ]
+ ,"files" : [
+ {
+ "path" : "src\\Main.hx"
+ ,"useTabs" : true
+ ,"indentSize" : 4
+ ,"foldedRegions" : [
+
+ ]
+ ,"activeLine" : 13
+ }
+ ]
+ ,"activeFile" : "src\\Main.hx"
+ ,"openFLTarget" : null
+ ,"openFLBuildMode" : "Debug"
+ ,"runActionType" : null
+ ,"runActionText" : null
+ ,"buildActionCommand" : null
+ ,"hiddenItems" : [
+
+ ]
+ ,"showHiddenItems" : false
+}
\ No newline at end of file
diff --git a/lib/haxe/test/python.hxml b/lib/haxe/test/python.hxml
new file mode 100644
index 0000000..4d6a133
--- /dev/null
+++ b/lib/haxe/test/python.hxml
@@ -0,0 +1,38 @@
+#
+# 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.
+#
+
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#Python target
+-python bin/Test.py
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/src/Main.hx b/lib/haxe/test/src/Main.hx
new file mode 100644
index 0000000..fff8be5
--- /dev/null
+++ b/lib/haxe/test/src/Main.hx
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+
+package;
+
+import org.apache.thrift.*;
+import org.apache.thrift.protocol.*;
+import org.apache.thrift.transport.*;
+import org.apache.thrift.server.*;
+import org.apache.thrift.meta_data.*;
+
+import thrift.test.*; // generated code
+
+class Main
+{
+ static public function main()
+ {
+ try
+ {
+ StreamTest.Run();
+
+ trace("All tests completed.");
+ }
+ catch( e: Dynamic)
+ {
+ trace('$e');
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib/haxe/test/src/StreamTest.hx b/lib/haxe/test/src/StreamTest.hx
new file mode 100644
index 0000000..b28c8e9
--- /dev/null
+++ b/lib/haxe/test/src/StreamTest.hx
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+package;
+
+import haxe.Int64;
+
+import org.apache.thrift.*;
+import org.apache.thrift.protocol.*;
+import org.apache.thrift.transport.*;
+import org.apache.thrift.server.*;
+import org.apache.thrift.meta_data.*;
+
+import thrift.test.*; // generated code
+
+
+class StreamTest extends TestBase {
+
+
+ private inline static var tmpfile : String = "bin/data.tmp";
+
+
+ private static function Expect( expr : Bool, info : String, ?pos : haxe.PosInfos) : Void {
+ if( ! expr) {
+ throw ('Test "$info" failed at '+pos.methodName+' in '+pos.fileName+':'+pos.lineNumber);
+ }
+ }
+
+ private static function MakeTestData() : Xtruct {
+ var data : Xtruct = new Xtruct();
+ data.string_thing = "Streamtest";
+ data.byte_thing = -128;
+ data.i32_thing = 4711;
+ data.i64_thing = Int64.make(0x12345678,0x9ABCDEF0);
+ return data;
+ }
+
+ public static function WriteData() : Xtruct
+ {
+ var stream : TStream = new TFileStream( tmpfile, CreateNew);
+ var trans : TTransport = new TStreamTransport( null, stream);
+ var prot = new TJSONProtocol( trans);
+
+ var data = MakeTestData();
+ data.write(prot);
+ trans.close();
+
+ return data;
+ }
+
+ public static function ReadData() : Xtruct
+ {
+ var stream : TStream = new TFileStream( tmpfile, Read);
+ var trans : TTransport = new TStreamTransport( stream, null);
+ var prot = new TJSONProtocol( trans);
+
+ var data : Xtruct = new Xtruct();
+ data.read(prot);
+ trans.close();
+
+ return data;
+ }
+
+ public static override function Run() : Void
+ {
+ var written = WriteData();
+ var read = ReadData();
+
+ Expect( read.string_thing == written.string_thing, "string data");
+ Expect( read.byte_thing == written.byte_thing, "byte data");
+ Expect( read.i32_thing == written.i32_thing, "i32 data");
+ Expect( Int64.compare( read.i64_thing, written.i64_thing) == 0, "i64 data");
+ }
+
+}
+
+
diff --git a/lib/haxe/test/src/TestBase.hx b/lib/haxe/test/src/TestBase.hx
new file mode 100644
index 0000000..03b66dd
--- /dev/null
+++ b/lib/haxe/test/src/TestBase.hx
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+package;
+
+import org.apache.thrift.*;
+import org.apache.thrift.protocol.*;
+import org.apache.thrift.transport.*;
+import org.apache.thrift.server.*;
+import org.apache.thrift.meta_data.*;
+
+import thrift.test.*; // generated code
+
+class TestBase {
+
+ private function new() {
+ // override, if necessary
+ }
+
+ public static function Run() : Void {
+ throw new AbstractMethodError();
+ }
+}
diff --git a/test/haxe/Makefile.am b/test/haxe/Makefile.am
index 08c0369..127c45d 100644
--- a/test/haxe/Makefile.am
+++ b/test/haxe/Makefile.am
@@ -23,23 +23,23 @@
BIN_CPP = bin/Main-debug
-gen-haxe/ThriftTest/ThriftTest.hx: $(THRIFTTEST)
+gen-haxe/thrift/test/ThriftTest.hx: $(THRIFTTEST)
$(THRIFTCMD) $(THRIFTTEST)
-
+
all-local: $(BIN_CPP)
-
-$(BIN_CPP): gen-haxe/ThriftTest/ThriftTest.hx
+
+$(BIN_CPP): gen-haxe/thrift/test/ThriftTest.hx
$(HAXE) --cwd . cpp.hxml
-
+
#TODO: other haxe targets
-# $(HAXE) --cwd . csharp
-# $(HAXE) --cwd . flash
-# $(HAXE) --cwd . java
-# $(HAXE) --cwd . javascript
-# $(HAXE) --cwd . neko
-# $(HAXE) --cwd . php
-# $(HAXE) --cwd . python # needs Haxe 3.1.4
+# $(HAXE) --cwd . csharp
+# $(HAXE) --cwd . flash
+# $(HAXE) --cwd . java
+# $(HAXE) --cwd . javascript
+# $(HAXE) --cwd . neko
+# $(HAXE) --cwd . php
+# $(HAXE) --cwd . python # needs Haxe 3.1.4
clean-local:
diff --git a/test/haxe/project.hide b/test/haxe/project.hide
index f09030b..a1c09ba 100644
--- a/test/haxe/project.hide
+++ b/test/haxe/project.hide
@@ -29,7 +29,7 @@
,{
"pathToHxml" : "cpp.hxml"
,"runActionType" : 2
- ,"runActionText" : "bin/Main-debug.exe client --json"
+ ,"runActionText" : "bin/Main-debug.exe client --protocol json"
}
,{
"pathToHxml" : "java.hxml"
@@ -45,34 +45,25 @@
]
,"files" : [
{
- "path" : "src\\Arguments.hx"
- ,"useTabs" : true
- ,"indentSize" : 4
- ,"foldedRegions" : [
-
- ]
- ,"activeLine" : 159
- }
- ,{
- "path" : "..\\..\\lib\\haxe\\src\\org\\apache\\thrift\\protocol\\TJSONProtocol.hx"
- ,"useTabs" : true
- ,"indentSize" : 4
- ,"foldedRegions" : [
-
- ]
- ,"activeLine" : 665
- }
- ,{
"path" : "src\\TestClient.hx"
,"useTabs" : true
,"indentSize" : 4
,"foldedRegions" : [
]
- ,"activeLine" : 325
+ ,"activeLine" : 188
+ }
+ ,{
+ "path" : "src\\TestServer.hx"
+ ,"useTabs" : true
+ ,"indentSize" : 4
+ ,"foldedRegions" : [
+
+ ]
+ ,"activeLine" : 88
}
]
- ,"activeFile" : "..\\..\\lib\\haxe\\src\\org\\apache\\thrift\\protocol\\TJSONProtocol.hx"
+ ,"activeFile" : "src\\TestClient.hx"
,"openFLTarget" : null
,"openFLBuildMode" : "Debug"
,"runActionType" : null
diff --git a/test/haxe/src/Arguments.hx b/test/haxe/src/Arguments.hx
index bcf3793..ae23fa1 100644
--- a/test/haxe/src/Arguments.hx
+++ b/test/haxe/src/Arguments.hx
@@ -24,34 +24,49 @@
import org.apache.thrift.transport.*;
import org.apache.thrift.server.*;
import org.apache.thrift.meta_data.*;
+import haxe.io.Path;
using StringTools;
-enum Prot {
+enum ProtocolType {
binary;
json;
}
-enum Trns {
+enum EndpointTransport {
socket;
- http;
+ http;
+}
+
+enum ServerType {
+ simple;
+ /*
+ threadpool;
+ threaded;
+ nonblocking;
+ */
}
class Arguments
{
+ public var printHelpOnly(default,null) : Bool = false;
+
public var server(default,null) : Bool = false;
- public var framed(default,null) : Bool = false;
- public var buffered(default,null) : Bool = false;
- public var protocol(default,null) : Prot = binary;
- public var transport(default,null) : Trns = socket;
-
+ public var servertype(default,null) : ServerType = simple;
+
public var host(default,null) : String = "localhost";
public var port(default,null) : Int = 9090;
+
+ public var protocol(default,null) : ProtocolType = binary;
+ public var transport(default,null) : EndpointTransport = socket;
+ public var framed(default,null) : Bool = false;
+ public var buffered(default,null) : Bool = false;
public var numIterations(default,null) : Int = 1;
public var numThreads(default,null) : Int = 1;
+ public var skipSpeedTest(default,null) : Bool = false;
public function new() {
@@ -70,112 +85,244 @@
#if sys
private static function GetHelp() : String {
+ var sProg = Path.withoutDirectory( Sys.executablePath());
return "\n"
- +Sys.executablePath()+" [client|server] [options]\n"
+ +sProg+" [client|server] [options]\n"
+ +"\n"
+"Modus: Either client or server, the default is client.\n"
+"\n"
- +"Options:\n"
- +" -f, --framed framed transport (supersedes buffered)\n"
- +" -b, --buffered buffered transport\n"
- +" --json JSON protocol\n"
- +" --protocol=<prot> Choose protocol: json, binary (default binary).\n"
- +" --port=<port> Port number for socket transport, default 9090\n"
+ +"Common options:\n"
+ +" -h [ --help ] produce help message\n"
+ +" --port arg (=9090) Port number to listen / connect to\n"
+ /* not supported yet
+ +" --domain-socket arg Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)\n"
+ +" --named-pipe arg Windows Named Pipe (e.g. MyThriftPipe)\n"
+ */
+ +" --protocol arg (=binary) protocol: binary, compact, json\n"
+ /* not supported yet
+ +" --ssl Encrypted Transport using SSL\n"
+ */
+ +"\n"
+ +"Server only options:\n"
+ +" --transport arg (=sockets) Transport: buffered, framed, http, anonpipe\n"
+ /* not supported yet
+ +" --processor-events processor-events\n"
+ +" --server-type arg (=simple) type of server, \"simple\", \"thread-pool\", \n"
+ +" \"threaded\", or \"nonblocking\"\n"
+ +" -n [ --workers ] arg (=4) Number of thread pools workers. Only valid for \n"
+ +" thread-pool server type\n"
+ */
+"\n"
+"Client only options:\n"
- +" --host=<host> Host name, IP or URL, default localhost\n"
- +" -n=<iterations> Number of test iterations\n"
- +" -t=<threads> Number of test threads\n"
- +" -u=<url> Target Host/URL (same as --host)\n"
+ +" --host arg (=localhost) Host to connect\n"
+ +" --transport arg (=sockets) Transport: buffered, framed, http, evhttp\n"
+ /* not supported yet
+ +" --anon-pipes hRead hWrite Windows Anonymous Pipes pair (handles)\n"
+ */
+ +" -n [ --testloops ] arg (=1) Number of Tests\n"
+ +" -t [ --threads ] arg (=1) Number of Test threads\n"
+ +" --skip-speed-test Skip the speed test\n"
+"\n"
- +"All arguments are optional.\n";
+ +"All arguments are optional.\n"
+ ;
}
private function ParseArgs() : Void {
- var step = 0;
- for (arg in Sys.args()) {
+
+ var args = Sys.args().copy();
+ if( (args == null) || (args.length <= 0)) {
+ server = false;
+ numThreads = 1;
+ return;
+ }
+
+ var arg = args.shift();
+ if ( arg == "client") {
+ server = false;
+ numThreads = 1;
+ }
+ else if ( arg == "server") {
+ server = true;
+ numThreads = 4;
+ }
+ else if ( (arg == "-h") || (arg == "--help")) {
+ // -h [ --help ] produce help message
+ Sys.println( GetHelp());
+ printHelpOnly = true;
+ return;
+ }
+ else {
+ throw "First argument must be 'server' or 'client'";
+ }
+
- // server|client
- switch(step) {
- case 0:
- ++step;
- if ( arg == "client")
- server = false;
- else if ( arg == "server")
- server = true;
- else
- throw "First argument must be 'server' or 'client'";
-
- case 1:
- if ( (arg == "-f") || (arg == "--framed")) {
- framed = true;
- } else if (( arg == "-b") || ( arg == "--buffered")) {
- buffered = true;
- } else if (( arg == "--json") || (arg == "--protocol=json")){
- protocol = json;
- } else if (( arg == "--protocol=binary")){
- protocol = binary;
- } else if (arg.startsWith("--host=")) {
- ClientOnlyOption(arg);
- host = arg.substr(arg.indexOf("=") + 1);
- } else if (arg.startsWith("--port=")) {
- var tmp = Std.parseInt(arg.substr(arg.indexOf("=")+1));
- if( tmp != null)
- port = tmp;
- else
- throw "Invalid port number "+arg;
- } else if (arg == "-n") {
- ClientOnlyOption(arg);
- step = 2;
- } else if (arg == "-t") {
- ClientOnlyOption(arg);
- step = 3;
- } else if (arg == "-u") {
- ClientOnlyOption(arg);
- step = 4;
+ while( args.length > 0) {
+ arg = args.shift();
+
+ if ( (arg == "-h") || (arg == "--help")) {
+ // -h [ --help ] produce help message
+ Sys.println( GetHelp());
+ printHelpOnly = true;
+ return;
+ }
+ else if (arg == "--port") {
+ // --port arg (=9090) Port number to listen
+ arg = args.shift();
+ var tmp = Std.parseInt(arg);
+ if( tmp != null) {
+ port = tmp;
} else {
- throw "Unexpected argument "+arg;
- }
-
- case 2: // num iterations
- step = 1;
- var tmp = Std.parseInt(arg);
- if( tmp != null)
- numIterations = tmp;
- else
- throw "Invalid numeric value "+arg;
-
- case 3: // num threads
- step = 1;
- var tmp = Std.parseInt(arg);
- if( tmp != null)
- numThreads = tmp;
- else
- throw "Invalid numeric value "+arg;
-
- case 4: // url
- step = 1;
- host = arg;
-
- default:
- throw "Unexpected state";
+ throw "Invalid port number "+arg;
+ }
+ }
+ else if (arg == "--domain-socket") {
+ // --domain-socket arg Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)
+ throw "domain sockets not supported yet";
+ }
+ else if (arg == "--named-pipe") {
+ // --named-pipe arg Windows Named Pipe (e.g. MyThriftPipe)
+ throw "named pipes not supported yet";
+ }
+ else if (arg == "--protocol") {
+ // --protocol arg (=binary) protocol: binary, compact, json
+ arg = args.shift();
+ if( arg == "binary") {
+ protocol = binary;
+ } else if( arg == "compact") {
+ throw "Compact protocol not supported yet";
+ } else if( arg == "json") {
+ protocol = json;
+ } else {
+ InvalidArg(arg);
+ }
+ }
+ else if (arg == "--ssl") {
+ // --ssl Encrypted Transport using SSL
+ throw "SSL not supported yet";
+ }
+ else {
+ //Server only options:
+ if( server) {
+ ParseServerArgument( arg, args);
+ } else {
+ ParseClientArgument( arg, args);
+ }
}
+ }
+ }
+
-
- if ( framed && buffered)
- {
- trace("WN: framed supersedes buffered transport");
- }
+ private function ParseServerArgument( arg : String, args : Array<String>) : Void {
+ if (arg == "--transport") {
+ // --transport arg (=sockets) Transport: buffered, framed, http, anonpipe
+ arg = args.shift();
+ if( arg == "buffered") {
+ buffered = true;
+ } else if( arg == "framed") {
+ framed = true;
+ } else if( arg == "http") {
+ transport = http;
+ } else if( arg == "anonpipe") {
+ throw "Anon pipes transport not supported yet";
+ } else {
+ InvalidArg(arg);
+ }
+ }
+ else if (arg == "--processor-events") {
+ throw "Processor events not supported yet";
+ }
+ else if (arg == "--server-type") {
+ // --server-type arg (=simple) type of server,
+ // one of "simple", "thread-pool", "threaded", "nonblocking"
+ arg = args.shift();
+ if( arg == "simple") {
+ servertype = simple;
+ } else if( arg == "thread-pool") {
+ throw arg+" server not supported yet";
+ } else if( arg == "threaded") {
+ throw arg+" server not supported yet";
+ } else if( arg == "nonblocking") {
+ throw arg+" server not supported yet";
+ } else {
+ InvalidArg(arg);
+ }
+ }
+ else if ((arg == "-n") || (arg == "--workers")) {
+ // -n [ --workers ] arg (=4) Number of thread pools workers. Only valid for
+ // thread-pool server type
+ arg = args.shift();
+ var tmp = Std.parseInt(arg);
+ if( tmp != null) {
+ numThreads = tmp;
+ } else{
+ throw "Invalid number "+arg;
+ }
+ }
+ else {
+ InvalidArg(arg);
+ }
+ }
+
+ private function ParseClientArgument( arg : String, args : Array<String>) : Void {
+ if (arg == "--host") {
+ // --host arg (=localhost) Host to connect
+ host = args.shift();
+ }
+ else if (arg == "--transport") {
+ // --transport arg (=sockets) Transport: buffered, framed, http, evhttp
+ arg = args.shift();
+ if( arg == "buffered") {
+ buffered = true;
+ } else if( arg == "framed") {
+ framed = true;
+ } else if( arg == "http") {
+ transport = http;
+ } else if( arg == "evhttp") {
+ throw "evhttp transport not supported yet";
+ } else {
+ InvalidArg(arg);
+ }
+ }
+ else if (arg == "--anon-pipes") {
+ // --anon-pipes hRead hWrite Windows Anonymous Pipes pair (handles)
+ throw "Anon pipes transport not supported yet";
+ }
+ else if ((arg == "-n") || (arg == "--testloops")) {
+ // -n [ --testloops ] arg (=1) Number of Tests
+ arg = args.shift();
+ var tmp = Std.parseInt(arg);
+ if( tmp != null) {
+ numIterations = tmp;
+ } else {
+ throw "Invalid number "+arg;
+ }
+ }
+ else if ((arg == "-t") || (arg == "--threads")) {
+ // -t [ --threads ] arg (=1) Number of Test threads
+ arg = args.shift();
+ var tmp = Std.parseInt(arg);
+ if( tmp != null) {
+ numThreads = tmp;
+ } else {
+ throw "Invalid number "+arg;
+ }
+ }
+ else if (arg == "--skip-speed-test") {
+ // --skip-speed-test Skip the speed test
+ skipSpeedTest = true;
+ }
+ else {
+ InvalidArg(arg);
}
}
+
#end
- private function ClientOnlyOption( arg : String) {
- if( server) {
- throw "Unexpected argument in client mode: "+arg;
- }
+ private function InvalidArg( arg : String) : Void {
+ throw 'Invalid argument $arg';
}
}
diff --git a/test/haxe/src/Main.hx b/test/haxe/src/Main.hx
index a8ad147..6d80c21 100644
--- a/test/haxe/src/Main.hx
+++ b/test/haxe/src/Main.hx
@@ -34,6 +34,9 @@
try {
var args = new Arguments();
+ if( args.printHelpOnly)
+ return;
+
if (args.server)
TestServer.Execute(args);
else
diff --git a/test/haxe/src/TestClient.hx b/test/haxe/src/TestClient.hx
index 8698220..3c98e6a 100644
--- a/test/haxe/src/TestClient.hx
+++ b/test/haxe/src/TestClient.hx
@@ -47,16 +47,36 @@
private var errorCnt : Int = 0;
private var failedTests : String = "";
private var print_direct : Bool = false;
+
+ public static var EXITCODE_SUCCESS = 0x00; // no errors bits set
+ //
+ public static var EXITCODE_FAILBIT_BASETYPES = 0x01;
+ public static var EXITCODE_FAILBIT_STRUCTS = 0x02;
+ public static var EXITCODE_FAILBIT_CONTAINERS = 0x04;
+ public static var EXITCODE_FAILBIT_EXCEPTIONS = 0x08;
+ //
+ public static var EXITCODE_ALL_FAILBITS = 0x0F;
+ //
+ private var testsExecuted : Int = 0;
+ private var testsFailed : Int = 0;
+ private var currentTest : Int = 0;
+
public function new(direct : Bool) {
print_direct = direct;
}
+ public function StartTestGroup( groupBit : Int) : Void {
+ currentTest = groupBit;
+ testsExecuted |= groupBit;
+ }
+
public function Expect( expr : Bool, msg : String) : Void {
if ( expr) {
++successCnt;
} else {
++errorCnt;
+ testsFailed |= currentTest;
failedTests += "\n " + msg;
if( print_direct) {
trace('FAIL: $msg');
@@ -64,6 +84,10 @@
}
}
+ public function CalculateExitCode() : Int {
+ var notExecuted : Int = EXITCODE_ALL_FAILBITS & (~testsExecuted);
+ return testsFailed | notExecuted;
+ }
public function PrintSummary() : Void {
var total = successCnt + errorCnt;
@@ -88,57 +112,67 @@
public static function Execute(args : Arguments) : Void
{
+ var exitCode = 0xFF;
try
{
var difft = Timer.stamp();
-
+
if( args.numThreads > 1) {
var threads = new List<Thread>();
for( test in 0 ... args.numThreads) {
threads.add( StartThread( args));
}
+ exitCode = 0;
for( thread in threads) {
- Thread.readMessage(true);
+ exitCode |= Thread.readMessage(true);
}
} else {
var rslt = new TestResults(true);
RunClient(args,rslt);
rslt.PrintSummary();
+ exitCode = rslt.CalculateExitCode();
}
- difft = Timer.stamp() - difft;
+ difft = Timer.stamp() - difft;
trace('total test time: $difft seconds');
}
catch (e : TException)
{
trace('$e');
+ exitCode = 0xFF;
}
catch (e : Dynamic)
{
trace('$e');
+ exitCode = 0xFF;
}
+
+ #if sys
+ Sys.exit( exitCode);
+ #end
}
private static function StartThread(args : Arguments) : Thread {
var thread = Thread.create(
function() : Void {
+ var rslt = new TestResults(false);
var main : Thread = Thread.readMessage(true);
try
{
- var rslt = new TestResults(false);
RunClient(args,rslt);
- // TODO: promote rslt values to main thread
}
catch (e : TException)
{
+ rslt.Expect( false, '$e');
trace('$e');
}
catch (e : Dynamic)
{
+ rslt.Expect( false, '$e');
trace('$e');
}
- main.sendMessage("done");
+ main.sendMessage( rslt.CalculateExitCode());
});
thread.sendMessage(Thread.current());
@@ -154,8 +188,7 @@
case socket:
transport = new TSocket(args.host, args.port);
case http:
- throw "http transport not supported yet";
- //transport = new THttpClient(args.host);
+ transport = new THttpClient(args.host);
default:
throw "Unhandled transport";
}
@@ -164,7 +197,8 @@
if ( args.framed) {
trace("- framed transport");
transport = new TFramedTransport(transport);
- } else if ( args.buffered) {
+ }
+ if ( args.buffered) {
trace("- buffered transport");
throw "TBufferedTransport not implemented yet";
//transport = new TBufferedTransport(transport);
@@ -186,16 +220,18 @@
// run the test code
- HaxeBasicsTest( rslt);
- ClientTest( transport, protocol, rslt);
-
+ HaxeBasicsTest( args, rslt);
+ for( i in 0 ... args.numIterations) {
+ ClientTest( transport, protocol, args, rslt);
+ }
}
- public static function HaxeBasicsTest( rslt : TestResults) : Void
+ public static function HaxeBasicsTest( args : Arguments, rslt : TestResults) : Void
{
// We need to test a few basic things used in the ClientTest
// Anything else beyond this scope should go into /lib/haxe/ instead
+ rslt.StartTestGroup( 0);
var map32 = new IntMap<Int32>();
var map64 = new Int64Map<Int32>();
@@ -272,7 +308,8 @@
}
- public static function ClientTest( transport : TTransport, protocol : TProtocol, rslt : TestResults) : Void
+ public static function ClientTest( transport : TTransport, protocol : TProtocol,
+ args : Arguments, rslt : TestResults) : Void
{
var client = new ThriftTestImpl(protocol,protocol);
try
@@ -295,6 +332,54 @@
var start = Date.now();
+ rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_EXCEPTIONS);
+
+ // if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
+ trace('testException("Xception")');
+ try {
+ client.testException("Xception");
+ rslt.Expect( false, 'testException("Xception") should throw');
+ }
+ catch (e : Xception)
+ {
+ rslt.Expect( e.message == "Xception", 'testException("Xception") - e.message == "Xception"');
+ rslt.Expect( e.errorCode == 1001, 'testException("Xception") - e.errorCode == 1001');
+ }
+ catch (e : Dynamic)
+ {
+ rslt.Expect( false, 'testException("Xception") - $e');
+ }
+
+ // if arg == "TException" throw TException
+ trace('testException("TException")');
+ try {
+ client.testException("TException");
+ rslt.Expect( false, 'testException("TException") should throw');
+ }
+ catch (e : TException)
+ {
+ rslt.Expect( true, 'testException("TException") - $e');
+ }
+ catch (e : Dynamic)
+ {
+ rslt.Expect( false, 'testException("TException") - $e');
+ }
+
+ // else do not throw anything
+ trace('testException("bla")');
+ try {
+ client.testException("bla");
+ rslt.Expect( true, 'testException("bla") should not throw');
+ }
+ catch (e : Dynamic)
+ {
+ rslt.Expect( false, 'testException("bla") - $e');
+ }
+
+
+
+ rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
+
trace('testVoid()');
client.testVoid();
trace(' = void');
@@ -333,6 +418,9 @@
trace(' = $dub');
rslt.Expect(dub == 5.325098235, '$dub == 5.325098235');
+
+ rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
+
trace('testStruct({"Zero", 1, -3, -5})');
var o = new Xtruct();
o.string_thing = "Zero";
@@ -341,7 +429,7 @@
o.i64_thing = Int64.make(0,-5);
var i = client.testStruct(o);
trace(' = {"' + i.string_thing + '", ' + i.byte_thing +', '
- + i.i32_thing +', '+ Int64.toStr(i.i64_thing) + '}');
+ + i.i32_thing +', '+ Int64.toStr(i.i64_thing) + '}');
rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
@@ -364,6 +452,9 @@
rslt.Expect( i.i32_thing == o.i32_thing, "i.i32_thing == o.i32_thing");
rslt.Expect( Int64.compare( i.i64_thing, o.i64_thing) == 0, "i.i64_thing == o.i64_thing");
+
+ rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
+
var mapout = new IntMap< haxe.Int32>();
for ( j in 0 ... 5)
{
@@ -497,6 +588,8 @@
rslt.Expect(setin.size == setout.size, "setin.length == setout.length");
+ rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
+
trace("testEnum(ONE)");
var ret = client.testEnum(Numberz.ONE);
trace(" = " + ret);
@@ -528,6 +621,9 @@
rslt.Expect( Int64.compare( uid, Int64.make( 0x119D0, 0x7E08671B)) == 0,
Int64.toStr(uid)+" == "+Int64.toStr(Int64.make( 0x119D0, 0x7E08671B)));
+
+ rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
+
trace("testMapMap(1)");
var mm = client.testMapMap(1);
trace(" = {");
@@ -551,6 +647,9 @@
rslt.Expect( neg.get(-i) == -i, 'neg.get(-$i) == -$i');
}
+
+ rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
+
var insane = new Insanity();
insane.userMap = new IntMap< Int64>();
insane.userMap.set( Numberz.FIVE, Int64.make(0,5000));
@@ -614,6 +713,7 @@
}
trace("}");
+
var first_map = whoa.get(Int64.make(0,1));
var second_map = whoa.get(Int64.make(0,2));
rslt.Expect( (first_map != null) && (second_map != null), "(first_map != null) && (second_map != null)");
@@ -682,15 +782,19 @@
rslt.Expect( Int64.compare( multiResponse.i64_thing, arg2) == 0, 'multiResponse.I64_thing == arg2');
+ rslt.StartTestGroup( 0);
+
trace("Test Oneway(1)");
client.testOneway(1);
- trace("Test Calltime()");
- var difft = Timer.stamp();
- for ( k in 0 ... 1000) {
- client.testVoid();
+ if( ! args.skipSpeedTest) {
+ trace("Test Calltime()");
+ var difft = Timer.stamp();
+ for ( k in 0 ... 1000) {
+ client.testVoid();
+ }
+ difft = Timer.stamp() - difft;
+ trace('$difft ms per testVoid() call');
}
- difft = Timer.stamp() - difft;
- trace('$difft ms per testVoid() call');
}
}
diff --git a/test/haxe/src/TestServer.hx b/test/haxe/src/TestServer.hx
index 66b06e0..92fab01 100644
--- a/test/haxe/src/TestServer.hx
+++ b/test/haxe/src/TestServer.hx
@@ -53,7 +53,8 @@
if ( args.framed) {
trace("- framed transport");
transfactory = new TFramedTransportFactory();
- } else if ( args.buffered) {
+ }
+ if ( args.buffered) {
trace("- buffered transport");
throw "TBufferedTransport not implemented yet";
//transfactory = new TBufferedTransportFactory();
@@ -79,14 +80,23 @@
var processor = new ThriftTestProcessor(handler);
// Simple Server
- var server = new TSimpleServer( processor, transport, transfactory, protfactory);
+ var server : TServer = null;
+ switch( args.servertype)
+ {
+ case simple:
+ server = new TSimpleServer( processor, transport, transfactory, protfactory);
+ default:
+ throw "Unhandled server type";
+ }
/*
// Server event handler
- var events = new TestServerEventHandler();
- server.setEventHandler(serverEvents);
- handler.server = serverEngine;
+ if( args.serverEvents) {
+ var events = new TestServerEventHandler();
+ server.setEventHandler(serverEvents);
+ handler.server = serverEngine;
+ }
*/
// Run it
diff --git a/tutorial/haxe/Makefile.am b/tutorial/haxe/Makefile.am
index d98be0a..8212648 100644
--- a/tutorial/haxe/Makefile.am
+++ b/tutorial/haxe/Makefile.am
@@ -26,14 +26,14 @@
check: gen-haxe/tutorial/calculator.hx
-bin/Main-debug: gen-haxe/tutorial/calculator.hx
+bin/Main-debug: gen-haxe/tutorial/calculator.hx
$(HAXE) --cwd . cpp.hxml
-
+
tutorialserver: all
bin/Main-debug server
tutorialclient: all
- bin/Main-debug
+ bin/Main-debug
tutorialsecureserver: all
bin/Main-debug server secure
@@ -46,5 +46,5 @@
EXTRA_DIST = \
src/Main.hx \
- src/CalculatorHandler.hx
+ src/CalculatorHandler.hx
diff --git a/tutorial/haxe/project.hide b/tutorial/haxe/project.hide
index 46c0a50..8d5d4ec 100644
--- a/tutorial/haxe/project.hide
+++ b/tutorial/haxe/project.hide
@@ -89,7 +89,7 @@
,"foldedRegions" : [
]
- ,"activeLine" : 276
+ ,"activeLine" : 0
}
]
,"activeFile" : "src\\Main.hx"
diff --git a/tutorial/haxe/src/Main.hx b/tutorial/haxe/src/Main.hx
index 5c9345e..41d8945 100644
--- a/tutorial/haxe/src/Main.hx
+++ b/tutorial/haxe/src/Main.hx
@@ -154,12 +154,8 @@
trace('- socket transport $targetHost:$targetPort');
transport = new TSocket( targetHost, targetPort);
case http:
- trace("- http transport $targetHost");
- #if flash
- transport = new THttpClient( new flash.net.URLRequest(targetHost));
- #else
+ trace('- HTTP transport $targetHost');
transport = new THttpClient( targetHost);
- #end
default:
throw "Unhandled transport";
}