From d72db5c2f53158aeae750ef44f4e872521b31629 Mon Sep 17 00:00:00 2001 From: siam Date: Mon, 22 Jun 2026 16:48:34 +0800 Subject: [PATCH 01/10] add tests --- tests/ClientTest.php | 10 ++++++++++ tests/TestCase.php | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 9b5505b..1fb2ea4 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -65,6 +65,16 @@ public function testCalculatorServiceByStreamSocketTransporter() $this->assertSame($a + $b, $client->add($a, $b)); } + public function testCalculatorServiceByMultiplexRpcTransporter() + { + $client = ClientFactory::create($this->service, $this->createMultiplexRpcTransporter()); + + $a = rand(1, 99); + $b = rand(1, 99); + + $this->assertSame($a + $b, $client->add($a, $b)); + } + public function testMetadataManager() { MetadataManager::register( diff --git a/tests/TestCase.php b/tests/TestCase.php index 95e1f3a..a8b360e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -13,6 +13,7 @@ use FriendsOfHyperf\Jet\Registry\ConsulRegistry; use FriendsOfHyperf\Jet\Transporter\GuzzleHttpTransporter; +use FriendsOfHyperf\Jet\Transporter\MultiplexRpcTransporter; use FriendsOfHyperf\Jet\Transporter\StreamSocketTransporter; /** @@ -63,6 +64,11 @@ public function createStreamSocketTransporter() return new StreamSocketTransporter($this->jsonrpcHost, $this->jsonrpcPort, $this->jsonrpcTimeout); } + public function createMultiplexRpcTransporter() + { + return new MultiplexRpcTransporter($this->jsonrpcHost, $this->jsonrpcPort, $this->jsonrpcTimeout); + } + protected function createRegistry() { return new ConsulRegistry(['uri' => $this->consulUri, 'timeout' => $this->consulTimeout]); From 39c844f8ad078253b8670617a3c655f5fcd86690 Mon Sep 17 00:00:00 2001 From: siam Date: Mon, 22 Jun 2026 16:53:12 +0800 Subject: [PATCH 02/10] Update TestCase.php --- tests/TestCase.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index a8b360e..2c625e0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -38,6 +38,12 @@ class TestCase extends \PHPUnit\Framework\TestCase private $jsonrpcHttpTimeout; + private $jsonrpcLengthCheckHost; + + private $jsonrpcLengthCheckPort; + + private $jsonrpcLengthCheckTimeout; + public function __construct($name = null, array $data = [], $dataName = '') { parent::__construct($name, $data, $dataName); @@ -52,6 +58,10 @@ public function __construct($name = null, array $data = [], $dataName = '') $this->jsonrpcHttpHost = $_ENV['JSONRPC_HTTP_HOST'] ?? '127.0.0.1'; $this->jsonrpcHttpPort = (int) ($_ENV['JSONRPC_HTTP_PORT'] ?? 9502); $this->jsonrpcHttpTimeout = (int) ($_ENV['JSONRPC_HTTP_TIMEOUT'] ?? 2); + + $this->jsonrpcLengthCheckHost = $_ENV['JSONRPC_LENGTH_CHECK_HOST'] ?? '127.0.0.1'; + $this->jsonrpcLengthCheckPort = (int) ($_ENV['JSONRPC_LENGTH_CHECK_PORT'] ?? 9504); + $this->jsonrpcLengthCheckTimeout = (int) ($_ENV['JSONRPC_LENGTH_CHECK_TIMEOUT'] ?? 2); } public function createGuzzleHttpTransporter() @@ -66,7 +76,7 @@ public function createStreamSocketTransporter() public function createMultiplexRpcTransporter() { - return new MultiplexRpcTransporter($this->jsonrpcHost, $this->jsonrpcPort, $this->jsonrpcTimeout); + return new MultiplexRpcTransporter($this->jsonrpcLengthCheckHost, $this->jsonrpcLengthCheckPort, $this->jsonrpcLengthCheckTimeout); } protected function createRegistry() From 414abf8e9c129c55cedae1e8e86074116fc49a84 Mon Sep 17 00:00:00 2001 From: siam Date: Mon, 22 Jun 2026 16:55:27 +0800 Subject: [PATCH 03/10] Update phpunit.xml.dist --- phpunit.xml.dist | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3b21407..a7028ab 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -27,5 +27,8 @@ + + + From 1447d0cb86c3008d34c794c0484481da01d1c0eb Mon Sep 17 00:00:00 2001 From: siam Date: Mon, 22 Jun 2026 17:24:39 +0800 Subject: [PATCH 04/10] Update MultiplexRpcTransporter.php --- src/Transporter/MultiplexRpcTransporter.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Transporter/MultiplexRpcTransporter.php b/src/Transporter/MultiplexRpcTransporter.php index cfd220e..bfb6d17 100644 --- a/src/Transporter/MultiplexRpcTransporter.php +++ b/src/Transporter/MultiplexRpcTransporter.php @@ -11,10 +11,8 @@ namespace FriendsOfHyperf\Jet\Transporter; -use Exception; use FriendsOfHyperf\Jet\Exception\ConnectionException; use FriendsOfHyperf\Jet\Exception\RecvFailedException; -use RuntimeException; class MultiplexRpcTransporter extends StreamSocketTransporter { @@ -45,7 +43,7 @@ public function receive() } /** - * @throws Exception + * @throws \Exception */ private function readBytes(int $length): string { @@ -58,7 +56,7 @@ private function readBytes(int $length): string $selected = stream_select($read, $write, $except, $this->timeout); if ($selected === false) { - throw new RuntimeException('Failed to select stream.'); + throw new \RuntimeException('Failed to select stream.'); } if ($selected === 0) { @@ -79,6 +77,7 @@ private function readBytes(int $length): string $buffer .= $chunk; } + var_dump($buffer); } return $buffer; From e946ffbcdbdca83a1df2d6acb4a1a5fb98c941b4 Mon Sep 17 00:00:00 2001 From: siam Date: Mon, 22 Jun 2026 17:37:21 +0800 Subject: [PATCH 05/10] Update ClientTest.php --- tests/ClientTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 1fb2ea4..423a2e4 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -12,8 +12,10 @@ namespace FriendsOfHyperf\Jet\Tests; use FriendsOfHyperf\Jet\ClientFactory; +use FriendsOfHyperf\Jet\DataFormatter\MultiplexDataFormatter; use FriendsOfHyperf\Jet\Metadata; use FriendsOfHyperf\Jet\MetadataManager; +use FriendsOfHyperf\Jet\Packer\JsonMultiplexPacker; use FriendsOfHyperf\Jet\RegistryManager; /** @@ -67,7 +69,12 @@ public function testCalculatorServiceByStreamSocketTransporter() public function testCalculatorServiceByMultiplexRpcTransporter() { - $client = ClientFactory::create($this->service, $this->createMultiplexRpcTransporter()); + $client = ClientFactory::create( + $this->service, + $this->createMultiplexRpcTransporter(), + new JsonMultiplexPacker(), + new MultiplexDataFormatter(), + ); $a = rand(1, 99); $b = rand(1, 99); From e42874980bf44a251c594fc92e9032685b19352d Mon Sep 17 00:00:00 2001 From: siam Date: Mon, 22 Jun 2026 17:42:31 +0800 Subject: [PATCH 06/10] Update MultiplexRpcTransporter.php --- src/Transporter/MultiplexRpcTransporter.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Transporter/MultiplexRpcTransporter.php b/src/Transporter/MultiplexRpcTransporter.php index bfb6d17..5b89b04 100644 --- a/src/Transporter/MultiplexRpcTransporter.php +++ b/src/Transporter/MultiplexRpcTransporter.php @@ -77,7 +77,6 @@ private function readBytes(int $length): string $buffer .= $chunk; } - var_dump($buffer); } return $buffer; From c80c9668385322bc12ed8c50417bff18227f286e Mon Sep 17 00:00:00 2001 From: siam Date: Mon, 22 Jun 2026 18:09:19 +0800 Subject: [PATCH 07/10] Update phpunit.xml.dist --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a7028ab..5b4e2dd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -28,7 +28,7 @@ - + From abaa1b0274e7b2642a166f7da03f9d118ceb2af2 Mon Sep 17 00:00:00 2001 From: siam Date: Mon, 22 Jun 2026 18:10:11 +0800 Subject: [PATCH 08/10] Update tests.yaml --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a362e62..32e85c1 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -30,7 +30,7 @@ jobs: run: docker run -d --name=dev-consul -e CONSUL_BIND_INTERFACE=eth0 --net=host consul:1.15.4 - name: Setup Services run: | - docker run -d --name jsonrpc -p 9501:9501 -p 9502:9502 -p 9503:9503 -p 9504:9504 limingxinleo/hyperf-jsonrpc-demo:latest + docker run -d --name jsonrpc -p 9501:9501 -p 9502:9502 -p 9503:9503 -p 9504:9504 -p 9505:9505 friendsofhyperf/hyperf-rpc-demo:latest sleep 10 php ./tests/register.php - name: Run Test Cases From 795a74a4a7779cafa2af7e9fe521032228e02186 Mon Sep 17 00:00:00 2001 From: siam Date: Mon, 22 Jun 2026 18:35:01 +0800 Subject: [PATCH 09/10] Update tests.yaml --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 32e85c1..05aa6e2 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -30,7 +30,7 @@ jobs: run: docker run -d --name=dev-consul -e CONSUL_BIND_INTERFACE=eth0 --net=host consul:1.15.4 - name: Setup Services run: | - docker run -d --name jsonrpc -p 9501:9501 -p 9502:9502 -p 9503:9503 -p 9504:9504 -p 9505:9505 friendsofhyperf/hyperf-rpc-demo:latest + docker run -d --name jsonrpc -p 9501:9501 -p 9502:9502 -p 9503:9503 -p 9504:9504 -p 9505:9505 iisiam/hyperf-rpc-demo:latest sleep 10 php ./tests/register.php - name: Run Test Cases From 074c186dda7a67775ae7f1d4f7fc5458d13b205b Mon Sep 17 00:00:00 2001 From: siam Date: Mon, 22 Jun 2026 18:38:17 +0800 Subject: [PATCH 10/10] Update ClientTest.php --- tests/ClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 423a2e4..2c1ada5 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -73,7 +73,7 @@ public function testCalculatorServiceByMultiplexRpcTransporter() $this->service, $this->createMultiplexRpcTransporter(), new JsonMultiplexPacker(), - new MultiplexDataFormatter(), + new MultiplexDataFormatter() ); $a = rand(1, 99);