Skip to content

Commit

Permalink
增加8098server,用于测试server重启后的RPC交互
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed Nov 15, 2018
1 parent e450c7e commit 8b22559
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/rpc-client/test/Cases/RpcTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Swoft\Rpc\Client\Bean\Collector\ReferenceCollector;
use Swoft\Rpc\Client\Service\ServiceProxy;
use SwoftTest\Rpc\Testing\Clients\Demo8098ServiceClient;
use SwoftTest\Rpc\Testing\Clients\DemoServiceClient;
use SwoftTest\Rpc\Testing\Lib\DemoServiceInterface;
use SwoftTest\Rpc\Testing\Pool\Config\DemoServicePoolConfig;
Expand Down Expand Up @@ -68,10 +69,10 @@ public function testRpcServerRestart()
go(function () {
\co::sleep(2);
$cmd = 'php ' . alias('@root') . '/server_restart.php -d';
\co::exec($cmd);
exec($cmd);
\co::sleep(2);

$client = bean(DemoServiceClient::class);
$client = bean(Demo8098ServiceClient::class);
$res = $client->version();
$this->assertEquals('1.0.0', $res);
});
Expand Down
27 changes: 27 additions & 0 deletions src/rpc-client/test/Testing/Clients/Demo8098ServiceClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace SwoftTest\Rpc\Testing\Clients;

use Swoft\Bean\Annotation\Bean;
use Swoft\Rpc\Client\Bean\Annotation\Reference;
use SwoftTest\Rpc\Testing\Lib\DemoServiceInterface;

/**
* Class DemoServiceClient
* @Bean
* @method version
* @method longMessage($string)
* @method get($id)
*/
class Demo8098ServiceClient
{
/**
* @Reference(name="service.demo.8098", fallback="demoFallback", breaker="breaker")
* @var DemoServiceInterface
*/
protected $demoService;

public function __call($name, $arguments)
{
return $this->demoService->$name(...$arguments);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace SwoftTest\Rpc\Testing\Pool\Config;

use Swoft\Bean\Annotation\Bean;
use Swoft\Bean\Annotation\Value;
use Swoft\Pool\PoolProperties;

/**
* Class DemoServicePoolConfig
* @Bean
* @package SwoftTest\Rpc\Client\Testing\Pool\Config
*/
class Demo8098ServicePoolConfig extends PoolProperties
{
protected $name = 'service.demo.8098';

protected $uri = [
'127.0.0.1:8098'
];

/**
* Connection timeout
*
* @var int
*/
protected $timeout = 1;
}
22 changes: 22 additions & 0 deletions src/rpc-client/test/Testing/Pool/Demo8098ServicePool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace SwoftTest\Rpc\Testing\Pool;

use Swoft\Bean\Annotation\Inject;
use Swoft\Bean\Annotation\Pool;
use Swoft\Rpc\Client\Pool\ServicePool as SwoftServicePool;
use SwoftTest\Rpc\Testing\Pool\Config\Demo8098ServicePoolConfig;
use SwoftTest\Rpc\Testing\Pool\Config\DemoServicePoolConfig;

/**
* Class DemoServicePool
* @Pool(name="service.demo.8098")
* @package SwoftTest\Rpc\Testing\Pool
*/
class Demo8098ServicePool extends SwoftServicePool
{
/**
* @Inject
* @var Demo8098ServicePoolConfig
*/
protected $poolConfig;
}
6 changes: 5 additions & 1 deletion src/rpc-client/test/Testing/RpcCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function start()

// tcp启动参数
$tcpHost = $tcpStatus['host'];
$tcpPort = 8098;
$tcpPort = $tcpStatus['port'];
$tcpType = $tcpStatus['type'];
$tcpMode = $tcpStatus['mode'];

Expand Down Expand Up @@ -149,6 +149,10 @@ private function getRpcServer(): RpcServer
$rpcServer = new RpcServer();
$rpcServer->setScriptFile($script);

$rpcServer->tcpSetting['port'] = 8098;
$rpcServer->tcpSetting['port'] = 8098;
$rpcServer->serverSetting['pfile'] = alias('@runtime/8099.pid');

return $rpcServer;
}

Expand Down

0 comments on commit 8b22559

Please sign in to comment.