|
|
@ -44,6 +44,31 @@ class ChannelTest extends \PHPUnit\Framework\TestCase |
|
|
|
$this->assertNotNull($channel); |
|
|
|
$this->assertNotNull($channel); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testCreateXdsWithSsl() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$xdsCreds = \Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
$this->assertNotNull($xdsCreds); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testCreateXdsWithInsecure() { |
|
|
|
|
|
|
|
$xdsCreds = \Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createInsecure() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
$this->assertNotNull($xdsCreds); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testCreateXdsWithNull() { |
|
|
|
|
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
|
|
|
|
|
|
$xdsCreds = \Grpc\ChannelCredentials::createXds(null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testCreateXdsWithInvalidType() { |
|
|
|
|
|
|
|
$this->expectException(\TypeError::class); |
|
|
|
|
|
|
|
$xdsCreds = \Grpc\ChannelCredentials::createXds("invalid-type"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testGetConnectivityState() |
|
|
|
public function testGetConnectivityState() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->channel = new Grpc\Channel('localhost:50001', |
|
|
|
$this->channel = new Grpc\Channel('localhost:50001', |
|
|
@ -275,17 +300,90 @@ class ChannelTest extends \PHPUnit\Framework\TestCase |
|
|
|
$this->channel2->close(); |
|
|
|
$this->channel2->close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testPersistentChannelSameChannelCredentials() |
|
|
|
public function persistentChannelSameChannelCredentialsProvider(): array |
|
|
|
{ |
|
|
|
{ |
|
|
|
$creds1 = Grpc\ChannelCredentials::createSsl(); |
|
|
|
return [ |
|
|
|
$creds2 = Grpc\ChannelCredentials::createSsl(); |
|
|
|
[ |
|
|
|
|
|
|
|
Grpc\ChannelCredentials::createSsl(), |
|
|
|
$this->channel1 = new Grpc\Channel('localhost:50019', |
|
|
|
Grpc\ChannelCredentials::createSsl(), |
|
|
|
["credentials" => $creds1, |
|
|
|
50301, |
|
|
|
"grpc_target_persist_bound" => 3, |
|
|
|
], |
|
|
|
]); |
|
|
|
[ |
|
|
|
$this->channel2 = new Grpc\Channel('localhost:50019', |
|
|
|
Grpc\ChannelCredentials::createSsl( |
|
|
|
["credentials" => $creds2]); |
|
|
|
file_get_contents(dirname(__FILE__) . '/../data/ca.pem') |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
Grpc\ChannelCredentials::createSsl( |
|
|
|
|
|
|
|
file_get_contents(dirname(__FILE__) . '/../data/ca.pem') |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
50302, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
Grpc\ChannelCredentials::createInSecure(), |
|
|
|
|
|
|
|
Grpc\ChannelCredentials::createInSecure(), |
|
|
|
|
|
|
|
50303, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
50304, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
50305, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl( |
|
|
|
|
|
|
|
file_get_contents(dirname(__FILE__) . '/../data/ca.pem') |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl( |
|
|
|
|
|
|
|
file_get_contents(dirname(__FILE__) . '/../data/ca.pem') |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
50306, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createInSecure() |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createInSecure() |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
50307, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @dataProvider persistentChannelSameChannelCredentialsProvider |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function testPersistentChannelSameChannelCredentials( |
|
|
|
|
|
|
|
$creds1, |
|
|
|
|
|
|
|
$creds2, |
|
|
|
|
|
|
|
$port |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
$this->channel1 = new Grpc\Channel( |
|
|
|
|
|
|
|
'localhost:' . $port, |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
"credentials" => $creds1, |
|
|
|
|
|
|
|
"grpc_target_persist_bound" => 3, |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
$this->channel2 = new Grpc\Channel( |
|
|
|
|
|
|
|
'localhost:' . $port, |
|
|
|
|
|
|
|
["credentials" => $creds2] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// try to connect on channel1 |
|
|
|
// try to connect on channel1 |
|
|
|
$state = $this->channel1->getConnectivityState(true); |
|
|
|
$state = $this->channel1->getConnectivityState(true); |
|
|
@ -300,70 +398,78 @@ class ChannelTest extends \PHPUnit\Framework\TestCase |
|
|
|
$this->channel2->close(); |
|
|
|
$this->channel2->close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testPersistentChannelDifferentChannelCredentials() |
|
|
|
public function persistentChannelDifferentChannelCredentialsProvider(): array |
|
|
|
{ |
|
|
|
{ |
|
|
|
$creds1 = Grpc\ChannelCredentials::createSsl(); |
|
|
|
return [ |
|
|
|
$creds2 = Grpc\ChannelCredentials::createSsl( |
|
|
|
[ |
|
|
|
file_get_contents(dirname(__FILE__).'/../data/ca.pem')); |
|
|
|
Grpc\ChannelCredentials::createSsl(), |
|
|
|
|
|
|
|
Grpc\ChannelCredentials::createSsl( |
|
|
|
$this->channel1 = new Grpc\Channel('localhost:50020', |
|
|
|
file_get_contents(dirname(__FILE__) . '/../data/ca.pem') |
|
|
|
["credentials" => $creds1, |
|
|
|
), |
|
|
|
"grpc_target_persist_bound" => 3, |
|
|
|
50351, |
|
|
|
]); |
|
|
|
], |
|
|
|
$this->channel2 = new Grpc\Channel('localhost:50020', |
|
|
|
[ |
|
|
|
["credentials" => $creds2]); |
|
|
|
Grpc\ChannelCredentials::createSsl(), |
|
|
|
|
|
|
|
Grpc\ChannelCredentials::createInsecure(), |
|
|
|
// try to connect on channel1 |
|
|
|
50352, |
|
|
|
$state = $this->channel1->getConnectivityState(true); |
|
|
|
], |
|
|
|
$this->waitUntilNotIdle($this->channel1); |
|
|
|
[ |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
$state = $this->channel1->getConnectivityState(); |
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
$this->assertConnecting($state); |
|
|
|
), |
|
|
|
$state = $this->channel2->getConnectivityState(); |
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
$this->assertEquals(GRPC\CHANNEL_IDLE, $state); |
|
|
|
\Grpc\ChannelCredentials::createSsl( |
|
|
|
|
|
|
|
file_get_contents(dirname(__FILE__) . '/../data/ca.pem') |
|
|
|
$this->channel1->close(); |
|
|
|
) |
|
|
|
$this->channel2->close(); |
|
|
|
), |
|
|
|
} |
|
|
|
50353, |
|
|
|
|
|
|
|
], |
|
|
|
public function testPersistentChannelSameChannelCredentialsRootCerts() |
|
|
|
[ |
|
|
|
{ |
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
$creds1 = Grpc\ChannelCredentials::createSsl( |
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
file_get_contents(dirname(__FILE__).'/../data/ca.pem')); |
|
|
|
), |
|
|
|
$creds2 = Grpc\ChannelCredentials::createSsl( |
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
file_get_contents(dirname(__FILE__).'/../data/ca.pem')); |
|
|
|
\Grpc\ChannelCredentials::createInsecure() |
|
|
|
|
|
|
|
), |
|
|
|
$this->channel1 = new Grpc\Channel('localhost:50021', |
|
|
|
50354, |
|
|
|
["credentials" => $creds1, |
|
|
|
], |
|
|
|
"grpc_target_persist_bound" => 3, |
|
|
|
[ |
|
|
|
]); |
|
|
|
\Grpc\ChannelCredentials::createInsecure(), |
|
|
|
$this->channel2 = new Grpc\Channel('localhost:50021', |
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
["credentials" => $creds2]); |
|
|
|
\Grpc\ChannelCredentials::createInsecure() |
|
|
|
|
|
|
|
), |
|
|
|
// try to connect on channel1 |
|
|
|
50355, |
|
|
|
$state = $this->channel1->getConnectivityState(true); |
|
|
|
], |
|
|
|
$this->waitUntilNotIdle($this->channel1); |
|
|
|
[ |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl(), |
|
|
|
$state = $this->channel1->getConnectivityState(); |
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
$this->assertConnecting($state); |
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
$state = $this->channel2->getConnectivityState(); |
|
|
|
), |
|
|
|
$this->assertConnecting($state); |
|
|
|
50356, |
|
|
|
|
|
|
|
], |
|
|
|
$this->channel1->close(); |
|
|
|
]; |
|
|
|
$this->channel2->close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
public function testPersistentChannelDifferentSecureChannelCredentials() |
|
|
|
* @dataProvider persistentChannelDifferentChannelCredentialsProvider |
|
|
|
{ |
|
|
|
*/ |
|
|
|
$creds1 = Grpc\ChannelCredentials::createSsl(); |
|
|
|
public function testPersistentChannelDifferentChannelCredentials( |
|
|
|
$creds2 = Grpc\ChannelCredentials::createInsecure(); |
|
|
|
$creds1, |
|
|
|
|
|
|
|
$creds2, |
|
|
|
$this->channel1 = new Grpc\Channel('localhost:50022', |
|
|
|
$port |
|
|
|
["credentials" => $creds1, |
|
|
|
) { |
|
|
|
"grpc_target_persist_bound" => 3, |
|
|
|
|
|
|
|
]); |
|
|
|
$this->channel1 = new Grpc\Channel( |
|
|
|
$this->channel2 = new Grpc\Channel('localhost:50022', |
|
|
|
'localhost:' . $port, |
|
|
|
["credentials" => $creds2]); |
|
|
|
[ |
|
|
|
|
|
|
|
"credentials" => $creds1, |
|
|
|
|
|
|
|
"grpc_target_persist_bound" => 3, |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
$this->channel2 = new Grpc\Channel( |
|
|
|
|
|
|
|
'localhost:' . $port, |
|
|
|
|
|
|
|
["credentials" => $creds2] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// try to connect on channel1 |
|
|
|
// try to connect on channel1 |
|
|
|
$state = $this->channel1->getConnectivityState(true); |
|
|
|
$state = $this->channel1->getConnectivityState(true); |
|
|
|