diff options
author | Valery Piashchynski <[email protected]> | 2021-09-16 12:14:09 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-09-16 12:14:09 +0300 |
commit | b24b4e066e32aa9be5617f409b3a01a358273cbb (patch) | |
tree | d2d57e577f344afe9a0d0b475ca25c1bfe51421c /tests | |
parent | 2aa0b99c588dd9c6a921904966ad435d485e23bb (diff) |
Add test PHP-GRPC server
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/plugins/grpc/php_server/.rr.yaml | 22 | ||||
-rw-r--r-- | tests/plugins/grpc/php_server/composer.json | 23 | ||||
-rw-r--r-- | tests/plugins/grpc/php_server/server.crt (renamed from tests/plugins/grpc/configs/server.crt) | 0 | ||||
-rw-r--r-- | tests/plugins/grpc/php_server/server.key (renamed from tests/plugins/grpc/configs/server.key) | 0 | ||||
-rw-r--r-- | tests/plugins/grpc/php_server/service.proto | 11 | ||||
-rw-r--r-- | tests/plugins/grpc/php_server/src/EchoService.php | 17 | ||||
-rw-r--r-- | tests/plugins/grpc/php_server/src/GPBMetadata/Service.php | 27 | ||||
-rw-r--r-- | tests/plugins/grpc/php_server/src/Service/EchoInterface.php | 22 | ||||
-rw-r--r-- | tests/plugins/grpc/php_server/src/Service/Message.php | 58 | ||||
-rw-r--r-- | tests/plugins/grpc/php_server/worker.php | 26 |
10 files changed, 206 insertions, 0 deletions
diff --git a/tests/plugins/grpc/php_server/.rr.yaml b/tests/plugins/grpc/php_server/.rr.yaml new file mode 100644 index 00000000..cc4a9300 --- /dev/null +++ b/tests/plugins/grpc/php_server/.rr.yaml @@ -0,0 +1,22 @@ +grpc: + listen: "tcp://:9001" + proto: "service.proto" + tls: + key: "server.key" + cert: "server.crt" + workers: + command: "php worker.php" + pool: + numWorkers: 4 + +metrics: + address: localhost:2112 + +limit: + interval: 1 + services: + grpc: + maxMemory: 100 + TTL: 0 + idleTTL: 0 + execTTL: 60
\ No newline at end of file diff --git a/tests/plugins/grpc/php_server/composer.json b/tests/plugins/grpc/php_server/composer.json new file mode 100644 index 00000000..b6303291 --- /dev/null +++ b/tests/plugins/grpc/php_server/composer.json @@ -0,0 +1,23 @@ +{ + "name": "app/example-grpc-server", + "description": "Example GRPC Server", + "repositories": [ + { + "type": "path", + "url": "../.." + } + ], + "require": { + "spiral/php-grpc": "*" + }, + "require-dev": { + "grpc/grpc": "^1.36" + }, + "autoload": { + "psr-4": { + "": "src" + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/tests/plugins/grpc/configs/server.crt b/tests/plugins/grpc/php_server/server.crt index 24d67fd7..24d67fd7 100644 --- a/tests/plugins/grpc/configs/server.crt +++ b/tests/plugins/grpc/php_server/server.crt diff --git a/tests/plugins/grpc/configs/server.key b/tests/plugins/grpc/php_server/server.key index 7501dd46..7501dd46 100644 --- a/tests/plugins/grpc/configs/server.key +++ b/tests/plugins/grpc/php_server/server.key diff --git a/tests/plugins/grpc/php_server/service.proto b/tests/plugins/grpc/php_server/service.proto new file mode 100644 index 00000000..60ff84a9 --- /dev/null +++ b/tests/plugins/grpc/php_server/service.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package service; + +service Echo { + rpc Ping (Message) returns (Message) { + } +} + +message Message { + string msg = 1; +}
\ No newline at end of file diff --git a/tests/plugins/grpc/php_server/src/EchoService.php b/tests/plugins/grpc/php_server/src/EchoService.php new file mode 100644 index 00000000..c2707811 --- /dev/null +++ b/tests/plugins/grpc/php_server/src/EchoService.php @@ -0,0 +1,17 @@ +<?php +/** + * Sample GRPC PHP server. + */ + +use Spiral\GRPC\ContextInterface; +use Service\EchoInterface; +use Service\Message; + +class EchoService implements EchoInterface +{ + public function Ping(ContextInterface $ctx, Message $in): Message + { + $out = new Message(); + return $out->setMsg(strtoupper($in->getMsg())); + } +}
\ No newline at end of file diff --git a/tests/plugins/grpc/php_server/src/GPBMetadata/Service.php b/tests/plugins/grpc/php_server/src/GPBMetadata/Service.php new file mode 100644 index 00000000..c1b65b21 --- /dev/null +++ b/tests/plugins/grpc/php_server/src/GPBMetadata/Service.php @@ -0,0 +1,27 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: service.proto + +namespace GPBMetadata; + +class Service +{ + public static $is_initialized = false; + + public static function initOnce() { + $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool(); + + if (static::$is_initialized == true) { + return; + } + $pool->internalAddGeneratedFile(hex2bin( + "0a6e0a0d736572766963652e70726f746f12077365727669636522160a07" . + "4d657373616765120b0a036d736718012001280932340a044563686f122c" . + "0a0450696e6712102e736572766963652e4d6573736167651a102e736572" . + "766963652e4d6573736167652200620670726f746f33" + )); + + static::$is_initialized = true; + } +} + diff --git a/tests/plugins/grpc/php_server/src/Service/EchoInterface.php b/tests/plugins/grpc/php_server/src/Service/EchoInterface.php new file mode 100644 index 00000000..5f336ace --- /dev/null +++ b/tests/plugins/grpc/php_server/src/Service/EchoInterface.php @@ -0,0 +1,22 @@ +<?php +# Generated by the protocol buffer compiler (spiral/grpc). DO NOT EDIT! +# source: service.proto + +namespace Service; + +use Spiral\GRPC; + +interface EchoInterface extends GRPC\ServiceInterface +{ + // GRPC specific service name. + public const NAME = "service.Echo"; + + /** + * @param GRPC\ContextInterface $ctx + * @param Message $in + * @return Message + * + * @throws GRPC\Exception\InvokeException + */ + public function Ping(GRPC\ContextInterface $ctx, Message $in): Message; +} diff --git a/tests/plugins/grpc/php_server/src/Service/Message.php b/tests/plugins/grpc/php_server/src/Service/Message.php new file mode 100644 index 00000000..6c40c879 --- /dev/null +++ b/tests/plugins/grpc/php_server/src/Service/Message.php @@ -0,0 +1,58 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: service.proto + +namespace Service; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Generated from protobuf message <code>service.Message</code> + */ +class Message extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field <code>string msg = 1;</code> + */ + private $msg = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $msg + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Service::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field <code>string msg = 1;</code> + * @return string + */ + public function getMsg() + { + return $this->msg; + } + + /** + * Generated from protobuf field <code>string msg = 1;</code> + * @param string $var + * @return $this + */ + public function setMsg($var) + { + GPBUtil::checkString($var, True); + $this->msg = $var; + + return $this; + } + +} + diff --git a/tests/plugins/grpc/php_server/worker.php b/tests/plugins/grpc/php_server/worker.php new file mode 100644 index 00000000..683a2341 --- /dev/null +++ b/tests/plugins/grpc/php_server/worker.php @@ -0,0 +1,26 @@ +<?php +/** + * Sample GRPC PHP server. + */ + +use Service\EchoInterface; +use Spiral\Goridge\StreamRelay; +use Spiral\GRPC\Server; +use Spiral\RoadRunner\Worker; + +require __DIR__ . '/vendor/autoload.php'; + +$server = new Server(null, [ + 'debug' => false, // optional (default: false) +]); + +$server->registerService(EchoInterface::class, new EchoService()); + +$worker = \method_exists(Worker::class, 'create') + // RoadRunner >= 2.x + ? Worker::create() + // RoadRunner 1.x + : new Worker(new StreamRelay(STDIN, STDOUT)) +; + +$server->serve($worker); |