mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 03:37:44 +08:00
Added Hyperf\LoadBalancer\LoadBalancerInterface::getNodes()
. (#1331)
This commit is contained in:
parent
11b60b7419
commit
322a3477a4
@ -5,13 +5,13 @@ sudo: required
|
|||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- php: 7.2
|
- php: 7.2
|
||||||
env: SW_VERSION="4.4.14"
|
env: SW_VERSION="4.4.15"
|
||||||
- php: 7.3
|
- php: 7.3
|
||||||
env: SW_VERSION="4.4.14"
|
env: SW_VERSION="4.4.15"
|
||||||
- php: 7.4
|
- php: 7.4
|
||||||
env: SW_VERSION="4.4.14"
|
env: SW_VERSION="4.4.15"
|
||||||
- php: master
|
- php: master
|
||||||
env: SW_VERSION="4.4.14"
|
env: SW_VERSION="4.4.15"
|
||||||
|
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- php: master
|
- php: master
|
||||||
@ -41,5 +41,6 @@ before_script:
|
|||||||
|
|
||||||
script:
|
script:
|
||||||
- composer analyse src/di src/json-rpc src/tracer src/metric src/redis src/nats src/db src/retry src/grpc-client src/nsq
|
- composer analyse src/di src/json-rpc src/tracer src/metric src/redis src/nats src/db src/retry src/grpc-client src/nsq
|
||||||
|
- composer analyse src/load-balancer
|
||||||
- composer test -- --exclude-group NonCoroutine
|
- composer test -- --exclude-group NonCoroutine
|
||||||
- vendor/bin/phpunit --group NonCoroutine
|
- vendor/bin/phpunit --group NonCoroutine
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
# v1.1.18 - TBD
|
# v1.1.18 - TBD
|
||||||
|
|
||||||
|
## Added
|
||||||
|
|
||||||
|
- [#1331](https://github.com/hyperf/hyperf/pull/1331) Added `Hyperf\LoadBalancer\LoadBalancerInterface::getNodes()`.
|
||||||
|
|
||||||
## Changed
|
## Changed
|
||||||
|
|
||||||
- [#1324](https://github.com/hyperf/hyperf/pull/1324) `Hyperf\AsyncQueue\Listener\QueueLengthListener` is no longer as the default listener of [hyperf/async-queue](https://github.com/hyperf/async-queue).
|
- [#1324](https://github.com/hyperf/hyperf/pull/1324) `Hyperf\AsyncQueue\Listener\QueueLengthListener` is no longer as the default listener of [hyperf/async-queue](https://github.com/hyperf/async-queue).
|
||||||
|
@ -10,9 +10,9 @@
|
|||||||
"support": {},
|
"support": {},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2",
|
"php": ">=7.2",
|
||||||
|
"ext-bcmath": "*",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"ext-swoole": ">=4.4",
|
"ext-swoole": ">=4.4",
|
||||||
"ext-bcmath": "*",
|
|
||||||
"bandwidth-throttle/token-bucket": "^2.0",
|
"bandwidth-throttle/token-bucket": "^2.0",
|
||||||
"doctrine/annotations": "^1.6",
|
"doctrine/annotations": "^1.6",
|
||||||
"doctrine/inflector": "^1.3",
|
"doctrine/inflector": "^1.3",
|
||||||
@ -28,6 +28,7 @@
|
|||||||
"jcchavezs/zipkin-opentracing": "^0.1.4",
|
"jcchavezs/zipkin-opentracing": "^0.1.4",
|
||||||
"jean85/pretty-package-versions": "^1.2",
|
"jean85/pretty-package-versions": "^1.2",
|
||||||
"laminas/laminas-mime": "^2.7",
|
"laminas/laminas-mime": "^2.7",
|
||||||
|
"markrogoyski/math-php": "^0.49.0",
|
||||||
"monolog/monolog": "^1.24",
|
"monolog/monolog": "^1.24",
|
||||||
"nesbot/carbon": "^2.0",
|
"nesbot/carbon": "^2.0",
|
||||||
"nikic/fast-route": "^1.3",
|
"nikic/fast-route": "^1.3",
|
||||||
|
@ -60,7 +60,7 @@ class BaseClientTest extends TestCase
|
|||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
if (swoole_version() === '4.4.14') {
|
if (in_array(swoole_version(), ['4.4.14', '4.4.15'])) {
|
||||||
$this->markTestSkipped(
|
$this->markTestSkipped(
|
||||||
'Swoole v4.4.14 has a bug on their side.'
|
'Swoole v4.4.14 has a bug on their side.'
|
||||||
);
|
);
|
||||||
|
@ -39,6 +39,11 @@ abstract class AbstractLoadBalancer implements LoadBalancerInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getNodes(): array
|
||||||
|
{
|
||||||
|
return $this->nodes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a node from the node list.
|
* Remove a node from the node list.
|
||||||
*/
|
*/
|
||||||
|
@ -20,11 +20,16 @@ interface LoadBalancerInterface
|
|||||||
public function select(array ...$parameters): Node;
|
public function select(array ...$parameters): Node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Hyperf\LoadBalancer\Node[] $nodes
|
* @param Node[] $nodes
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setNodes(array $nodes);
|
public function setNodes(array $nodes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Node[] $nodes
|
||||||
|
*/
|
||||||
|
public function getNodes(): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a node from the node list.
|
* Remove a node from the node list.
|
||||||
*/
|
*/
|
||||||
|
@ -50,7 +50,7 @@ class WeightedRoundRobin extends AbstractLoadBalancer
|
|||||||
$this->currentWeight = $this->maxWeight;
|
$this->currentWeight = $this->maxWeight;
|
||||||
if ($this->currentWeight == 0) {
|
if ($this->currentWeight == 0) {
|
||||||
// Degrade to random algorithm.
|
// Degrade to random algorithm.
|
||||||
return array_rand($this->nodes);
|
return $this->nodes[array_rand($this->nodes)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,5 +32,6 @@ class RandomTest extends TestCase
|
|||||||
$random = new Random($nodes);
|
$random = new Random($nodes);
|
||||||
$node = $random->select();
|
$node = $random->select();
|
||||||
$this->assertTrue(in_array($node, $nodes));
|
$this->assertTrue(in_array($node, $nodes));
|
||||||
|
$this->assertSame($nodes, $random->getNodes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user