summaryrefslogtreecommitdiff
path: root/test/haxe
diff options
context:
space:
mode:
authorOleksii Prudkyi <Oleksii.Prudkyi@gmail.com>2016-05-19 16:55:11 +0300
committerJens Geyer <jensg@apache.org>2016-05-29 00:43:13 +0200
commit39a09ac5e49481d39dd1bcb6757ffe182e3df20a (patch)
tree05533b021721a19519632ebbff34a78e033938c1 /test/haxe
parent26b36dc61e511f0086a25f4e3f2491cdc286444a (diff)
downloadthrift-39a09ac5e49481d39dd1bcb6757ffe182e3df20a.tar.gz
THRIFT-3833 haxe http server implementation (by embeding into php web server)
Client: Haxe Patch: Oleksii Prudkyi <Oleksii.Prudkyi@gmail.com> + some modifications by Jens Geyer This closes #1013 This closes #1020
Diffstat (limited to 'test/haxe')
-rw-r--r--test/haxe/Makefile.am24
-rw-r--r--test/haxe/php-web-server.hxml43
-rw-r--r--test/haxe/router.php31
-rw-r--r--test/haxe/src/Arguments.hx12
-rw-r--r--test/haxe/src/Main.hx32
-rw-r--r--test/haxe/src/TestClient.hx4
-rw-r--r--test/haxe/src/TestServer.hx19
7 files changed, 155 insertions, 10 deletions
diff --git a/test/haxe/Makefile.am b/test/haxe/Makefile.am
index 6094452f9..1a32185ec 100644
--- a/test/haxe/Makefile.am
+++ b/test/haxe/Makefile.am
@@ -23,11 +23,12 @@ THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift
BIN_CPP = bin/Main-debug
BIN_PHP = bin/php/Main-debug.php
+BIN_PHP_WEB = bin/php-web-server/Main-debug.php
gen-haxe/thrift/test/ThriftTest.hx: $(THRIFTTEST)
$(THRIFTCMD) $(THRIFTTEST)
-all-local: $(BIN_CPP) $(BIN_PHP)
+all-local: $(BIN_CPP) $(BIN_PHP) $(BIN_PHP_WEB)
$(BIN_CPP): \
src/*.hx \
@@ -41,6 +42,11 @@ $(BIN_PHP): \
gen-haxe/thrift/test/ThriftTest.hx
$(HAXE) --cwd . php.hxml
+$(BIN_PHP_WEB): \
+ src/*.hx \
+ ../../lib/haxe/src/org/apache/thrift/**/*.hx \
+ gen-haxe/thrift/test/ThriftTest.hx
+ $(HAXE) --cwd . php-web-server.hxml
@@ -56,20 +62,30 @@ $(BIN_PHP): \
clean-local:
$(RM) -r gen-haxe bin
-check: check_cpp check_php
+.NOTPARALLEL:
+
+check: check_cpp \
+ check_php \
+ check_php_web
check_cpp: $(BIN_CPP)
- timeout 10 $(BIN_CPP) server &
+ timeout 20 $(BIN_CPP) server &
sleep 1
$(BIN_CPP) client
sleep 10
check_php: $(BIN_PHP)
- timeout 10 php -f $(BIN_PHP) server &
+ timeout 20 php -f $(BIN_PHP) server &
sleep 1
php -f $(BIN_PHP) client
sleep 10
+check_php_web: $(BIN_PHP_WEB) $(BIN_CPP)
+ timeout 20 php -S 127.0.0.1:9090 router.php &
+ sleep 1
+ $(BIN_CPP) client --transport http
+ sleep 10
+
EXTRA_DIST = \
src \
diff --git a/test/haxe/php-web-server.hxml b/test/haxe/php-web-server.hxml
new file mode 100644
index 000000000..395a8521e
--- /dev/null
+++ b/test/haxe/php-web-server.hxml
@@ -0,0 +1,43 @@
+#
+# 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 gen-haxe
+-cp ../../lib/haxe/src
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#PHP target
+-php bin/php-web-server/
+--php-front Main-debug.php
+
+#defines
+-D phpwebserver
+
+
+#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
diff --git a/test/haxe/router.php b/test/haxe/router.php
new file mode 100644
index 000000000..e34135cc9
--- /dev/null
+++ b/test/haxe/router.php
@@ -0,0 +1,31 @@
+<?php
+/*
+ * 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 thrift
+ */
+
+
+
+//router file to run testing web server
+
+//set_time_limit(1);
+
+require_once dirname(__FILE__) . '/bin/php-web-server/Main-debug.php';
+
+
diff --git a/test/haxe/src/Arguments.hx b/test/haxe/src/Arguments.hx
index cae91dfda..cc1074987 100644
--- a/test/haxe/src/Arguments.hx
+++ b/test/haxe/src/Arguments.hx
@@ -72,12 +72,18 @@ class Arguments
public function new() {
#if sys
- try {
+ #if !phpwebserver
+ try {
ParseArgs();
- } catch (e : String) {
+ } catch (e : String) {
trace(GetHelp());
throw e;
- }
+ }
+ #else
+ //forcing server
+ server = true;
+ transport = http;
+ #end
#else
trace("WN: Platform does not support program arguments, using defaults.");
#end
diff --git a/test/haxe/src/Main.hx b/test/haxe/src/Main.hx
index 30c04a6e9..9eb828f1f 100644
--- a/test/haxe/src/Main.hx
+++ b/test/haxe/src/Main.hx
@@ -31,6 +31,15 @@ import thrift.test.*; // generated code
class Main
{
static function main() {
+ #if phpwebserver
+ initPhpWebServer();
+ //check method
+ if(php.Web.getMethod() != 'POST') {
+ Sys.println('http endpoint for thrift test server');
+ return;
+ }
+ #end
+
try {
var args = new Arguments();
@@ -48,4 +57,27 @@ class Main
}
}
+ #if phpwebserver
+ private static function initPhpWebServer()
+ {
+ //remap trace to error log
+ haxe.Log.trace = function(v:Dynamic, ?infos:haxe.PosInfos)
+ {
+ // handle trace
+ var newValue : Dynamic;
+ if (infos != null && infos.customParams!=null) {
+ var extra:String = "";
+ for( v in infos.customParams )
+ extra += "," + v;
+ newValue = v + extra;
+ }
+ else {
+ newValue = v;
+ }
+ var msg = infos != null ? infos.fileName + ':' + infos.lineNumber + ': ' : '';
+ Sys.stderr().writeString('${msg}${newValue}\n');
+ }
+ }
+ #end
+
}
diff --git a/test/haxe/src/TestClient.hx b/test/haxe/src/TestClient.hx
index 9436865e1..aa496dc8d 100644
--- a/test/haxe/src/TestClient.hx
+++ b/test/haxe/src/TestClient.hx
@@ -212,7 +212,9 @@ class TestClient {
case socket:
transport = new TSocket(args.host, args.port);
case http:
- transport = new THttpClient(args.host);
+ var uri = 'http://${args.host}:${args.port}';
+ trace('- http client : ${uri}');
+ transport = new THttpClient(uri);
default:
throw "Unhandled transport";
}
diff --git a/test/haxe/src/TestServer.hx b/test/haxe/src/TestServer.hx
index 8f4604a6e..450c8f28c 100644
--- a/test/haxe/src/TestServer.hx
+++ b/test/haxe/src/TestServer.hx
@@ -42,8 +42,18 @@ class TestServer
transport = new TServerSocket( args.port);
case http:
trace("- http");
- throw "HTTP server not implemented yet";
+ #if !phpwebserver
+ throw "HTTP server not implemented yet";
//transport = new THttpServer( targetHost);
+ #else
+ transport = new TWrappingServerTransport(
+ new TStreamTransport(
+ new TFileStream("php://input", Read),
+ new TFileStream("php://output", Append)
+ )
+ );
+
+ #end
default:
throw "Unhandled transport";
}
@@ -84,7 +94,12 @@ class TestServer
switch( args.servertype)
{
case simple:
- server = new TSimpleServer( processor, transport, transfactory, protfactory);
+ var simpleServer = new TSimpleServer( processor, transport, transfactory, protfactory);
+ #if phpwebserver
+ simpleServer.runOnce = true;
+ #end
+ server = simpleServer;
+
default:
throw "Unhandled server type";
}