THRIFT-5757: finish PHP cross-test integration
diff --git a/test/known_failures_Linux.json b/test/known_failures_Linux.json
index 3f00d7a..1f4c18b 100644
--- a/test/known_failures_Linux.json
+++ b/test/known_failures_Linux.json
@@ -127,14 +127,6 @@
"cpp-nodejs_multij-json_http-ip",
"cpp-nodejs_multij-json_http-ip-ssl",
"cpp-nodejs_multij-json_websocket-domain",
- "cpp-php_binary-accel_buffered-ip",
- "cpp-php_binary-accel_framed-ip",
- "cpp-php_json_buffered-ip",
- "cpp-php_json_framed-ip",
- "cpp-php_multi-accel_buffered-ip",
- "cpp-php_multi-accel_framed-ip",
- "cpp-php_multij-json_buffered-ip",
- "cpp-php_multij-json_framed-ip",
"cpp-py_binary-accel_http-domain",
"cpp-py_binary-accel_http-ip",
"cpp-py_binary-accel_http-ip-ssl",
@@ -425,18 +417,6 @@
"java-netstd_multij-json_fastframed-framed-ip-ssl",
"java-netstd_multij-json_framed-ip",
"java-netstd_multij-json_framed-ip-ssl",
- "java-php_binary-accel_buffered-ip",
- "java-php_binary-accel_fastframed-framed-ip",
- "java-php_binary-accel_framed-ip",
- "java-php_json_buffered-ip",
- "java-php_json_fastframed-framed-ip",
- "java-php_json_framed-ip",
- "java-php_multi-accel_buffered-ip",
- "java-php_multi-accel_fastframed-framed-ip",
- "java-php_multi-accel_framed-ip",
- "java-php_multij-json_buffered-ip",
- "java-php_multij-json_fastframed-framed-ip",
- "java-php_multij-json_framed-ip",
"kotlin-netstd_binary_framed-ip",
"kotlin-netstd_compact_framed-ip",
"kotlin-netstd_json_framed-ip",
@@ -669,10 +649,6 @@
"nodejs-nodejs_compact_websocket-domain",
"nodejs-nodejs_header_websocket-domain",
"nodejs-nodejs_json_websocket-domain",
- "nodejs-php_binary-accel_buffered-ip",
- "nodejs-php_binary-accel_framed-ip",
- "nodejs-php_json_buffered-ip",
- "nodejs-php_json_framed-ip",
"nodejs-py_binary-accel_http-domain",
"nodejs-py_binary-accel_http-ip",
"nodejs-py_binary-accel_http-ip-ssl",
@@ -692,7 +668,6 @@
"nodejs-py_json_http-ip",
"nodejs-py_json_http-ip-ssl",
"nodets-netstd_binary_buffered-ip",
- "nodets-php_binary-accel_buffered-ip",
"perl-netstd_binary_buffered-ip",
"perl-netstd_binary_buffered-ip-ssl",
"perl-netstd_binary_framed-ip",
@@ -993,12 +968,6 @@
"py-nodejs_compact_http-domain",
"py-nodejs_header_http-domain",
"py-nodejs_json_http-domain",
- "py-php_accel_buffered-ip",
- "py-php_accel_framed-ip",
- "py-php_binary-accel_buffered-ip",
- "py-php_binary-accel_framed-ip",
- "py-php_json_buffered-ip",
- "py-php_json_framed-ip",
"py-rb_accel-binary_buffered-domain",
"py-rb_accel-binary_buffered-ip",
"py-rb_accel-binary_buffered-ip-ssl",
@@ -1127,4 +1096,4 @@
"rs-netstd_multi-binary_framed-ip",
"rs-netstd_multic-compact_buffered-ip",
"rs-netstd_multic-compact_framed-ip"
-]
\ No newline at end of file
+]
diff --git a/test/php/Handler.php b/test/php/Handler.php
index 3ea1f58..a03554c 100644
--- a/test/php/Handler.php
+++ b/test/php/Handler.php
@@ -89,31 +89,87 @@
public function testMapMap($hello)
{
- return $hello;
+ return [
+ -4 => [
+ -4 => -4,
+ -3 => -3,
+ -2 => -2,
+ -1 => -1,
+ ],
+ 4 => [
+ 4 => 4,
+ 3 => 3,
+ 2 => 2,
+ 1 => 1,
+ ],
+ ];
}
public function testInsanity(\ThriftTest\Insanity $argument)
{
- return $argument;
+ $looney = new \ThriftTest\Insanity();
+
+ return [
+ 1 => [
+ \ThriftTest\Numberz::TWO => $argument,
+ \ThriftTest\Numberz::THREE => $argument,
+ ],
+ 2 => [
+ \ThriftTest\Numberz::SIX => $looney,
+ ],
+ ];
}
public function testMulti($arg0, $arg1, $arg2, array $arg3, $arg4, $arg5)
{
- // TODO: Implement testMulti() method.
+ $result = new \ThriftTest\Xtruct();
+ $result->string_thing = 'Hello2';
+ $result->byte_thing = $arg0;
+ $result->i32_thing = $arg1;
+ $result->i64_thing = $arg2;
+
+ return $result;
}
public function testException($arg)
{
- throw new \Exception($arg);
+ if ($arg === 'Xception') {
+ $exception = new \ThriftTest\Xception();
+ $exception->errorCode = 1001;
+ $exception->message = $arg;
+ throw $exception;
+ }
+
+ if ($arg === 'TException') {
+ throw new \Thrift\Exception\TException('This is a TException');
+ }
}
public function testMultiException($arg0, $arg1)
{
- throw new \Exception($arg0, $arg1);
+ if ($arg0 === 'Xception') {
+ $exception = new \ThriftTest\Xception();
+ $exception->errorCode = 1001;
+ $exception->message = 'This is an Xception';
+ throw $exception;
+ }
+
+ if ($arg0 === 'Xception2') {
+ $exception = new \ThriftTest\Xception2();
+ $exception->errorCode = 2002;
+ $exception->struct_thing = new \ThriftTest\Xtruct();
+ $exception->struct_thing->string_thing = 'This is an Xception2';
+ throw $exception;
+ }
+
+ $result = new \ThriftTest\Xtruct();
+ $result->string_thing = $arg1;
+
+ return $result;
}
public function testOneway($secondsToSleep)
{
- sleep($secondsToSleep);
+ usleep($secondsToSleep * 300000);
}
}
diff --git a/test/php/Makefile.am b/test/php/Makefile.am
index 60a63cf..9aefa9d 100644
--- a/test/php/Makefile.am
+++ b/test/php/Makefile.am
@@ -21,13 +21,12 @@
$(THRIFT) --gen php ../ThriftTest.thrift
$(THRIFT) --gen php:inlined ../ThriftTest.thrift
$(MKDIR_P) gen-php-classmap
- $(THRIFT) -out gen-php-classmap --gen php:classmap ../ThriftTest.thrift
+ $(THRIFT) -out gen-php-classmap --gen php:classmap,server,rest ../ThriftTest.thrift
php_ext_dir:
mkdir -p php_ext_dir
- ln -s ../../../lib/php/src/ext/thrift_protocol/modules/thrift_protocol.so php_ext_dir/
- ln -s "$$(php-config --extension-dir)/json.so" php_ext_dir/
- ln -s "$$(php-config --extension-dir)/sockets.so" php_ext_dir/
+ ln -sf ../../../lib/php/src/ext/thrift_protocol/modules/thrift_protocol.so php_ext_dir/
+ ln -sf "$$(php-config --extension-dir)/sockets.so" php_ext_dir/
precross: stubs php_ext_dir
diff --git a/test/php/TestServer.php b/test/php/TestServer.php
index 3b01752..4afb5d0 100644
--- a/test/php/TestServer.php
+++ b/test/php/TestServer.php
@@ -4,6 +4,14 @@
require_once __DIR__ . '/../../vendor/autoload.php';
+class TBinaryProtocolAcceleratedFactory implements \Thrift\Factory\TProtocolFactory
+{
+ public function getProtocol($trans)
+ {
+ return new \Thrift\Protocol\TBinaryProtocolAccelerated($trans, false, true);
+ }
+}
+
$opts = getopt(
'h::',
[
@@ -30,7 +38,7 @@
--server-type=arg (simple) type of server, "simple", "thread-pool",
"threaded", or "nonblocking"
--transport=arg (buffered) transport: buffered, framed, http, anonpipe, zlib
- --protocol=arg (binary) protocol: binary, compact, header, json
+ --protocol=arg (binary) protocol: binary, compact, json, accel
--multiplex Add TMultiplexedProtocol service name "ThriftTest"
--abstract-namespace Create the domain socket in the Abstract Namespace
(no connection with filesystem pathnames)
@@ -45,10 +53,11 @@
$port = $opts['port'] ?? 9090;
$transport = $opts['transport'] ?? 'buffered';
+$protocol = $opts['protocol'] ?? 'binary';
$loader = new Thrift\ClassLoader\ThriftClassLoader();
-$loader->registerDefinition('ThriftTest', __DIR__ . '/../../lib/php/test/Resources/packages/phpcm');
+$loader->registerDefinition('ThriftTest', __DIR__ . '/gen-php-classmap');
$loader->register();
$sslOptions = \stream_context_create(
@@ -70,6 +79,28 @@
$serverTransportFactory = new \Thrift\Factory\TTransportFactory();
}
+switch ($protocol) {
+ case 'binary':
+ $protocolFactory = new \Thrift\Factory\TBinaryProtocolFactory(false, true);
+ break;
+ case 'accel':
+ if (!function_exists('thrift_protocol_write_binary')) {
+ fwrite(STDERR, "Acceleration extension is not loaded\n");
+ exit(1);
+ }
+ $protocolFactory = new TBinaryProtocolAcceleratedFactory();
+ break;
+ case 'compact':
+ $protocolFactory = new \Thrift\Factory\TCompactProtocolFactory();
+ break;
+ case 'json':
+ $protocolFactory = new \Thrift\Factory\TJSONProtocolFactory();
+ break;
+ default:
+ fwrite(STDERR, "--protocol must be one of {binary|compact|json|accel}\n");
+ exit(1);
+}
+
$serverTransport = new \Thrift\Server\TServerSocket('localhost', $port);
$handler = new Handler();
$processor = new ThriftTest\ThriftTestProcessor($handler);
@@ -79,8 +110,8 @@
$serverTransport,
$serverTransportFactory,
$serverTransportFactory,
- new \Thrift\Factory\TBinaryProtocolFactory(),
- new \Thrift\Factory\TBinaryProtocolFactory()
+ $protocolFactory,
+ $protocolFactory
);
echo "Starting the Test server...\n";
diff --git a/test/php/test_php.ini b/test/php/test_php.ini
index 5eecb32..b135e74 100644
--- a/test/php/test_php.ini
+++ b/test/php/test_php.ini
@@ -1,3 +1,2 @@
;extension=thrift_protocol.so
-;extension=json.so
;extension=sockets.so
diff --git a/test/py/TestClient.py b/test/py/TestClient.py
index 07b39a0..316ff88 100755
--- a/test/py/TestClient.py
+++ b/test/py/TestClient.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Licensed to the Apache Software Foundation (ASF) under one
diff --git a/test/py/TestServer.py b/test/py/TestServer.py
index 59a06ad..dcc46d7 100755
--- a/test/py/TestServer.py
+++ b/test/py/TestServer.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Licensed to the Apache Software Foundation (ASF) under one
diff --git a/test/tests.json b/test/tests.json
index 3ebbaac..a62658e 100644
--- a/test/tests.json
+++ b/test/tests.json
@@ -286,6 +286,7 @@
"server": {
"extra_args": ["TSimpleServer"],
"command": [
+ "python3",
"TestServer.py",
"--verbose",
"--genpydir=gen-py"
@@ -294,6 +295,7 @@
"client": {
"timeout": 15,
"command": [
+ "python3",
"TestClient.py",
"--verbose",
"--host=localhost",
@@ -563,6 +565,8 @@
"command": [
"php",
"-dextension_dir=php_ext_dir",
+ "-dextension=thrift_protocol.so",
+ "-dextension=sockets.so",
"--php-ini=test_php.ini",
"--no-php-ini",
"-ddisplay_errors=stderr",
@@ -589,6 +593,8 @@
"command": [
"php",
"-dextension_dir=php_ext_dir",
+ "-dextension=thrift_protocol.so",
+ "-dextension=sockets.so",
"--php-ini=test_php.ini",
"--no-php-ini",
"-ddisplay_errors=stderr",