|
|
@ -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,70 +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') |
|
|
|
|
|
|
|
), |
|
|
|
// try to connect on channel1 |
|
|
|
Grpc\ChannelCredentials::createSsl( |
|
|
|
$state = $this->channel1->getConnectivityState(true); |
|
|
|
file_get_contents(dirname(__FILE__) . '/../data/ca.pem') |
|
|
|
$this->waitUntilNotIdle($this->channel1); |
|
|
|
), |
|
|
|
|
|
|
|
50302, |
|
|
|
$state = $this->channel1->getConnectivityState(); |
|
|
|
], |
|
|
|
$this->assertConnecting($state); |
|
|
|
[ |
|
|
|
$state = $this->channel2->getConnectivityState(); |
|
|
|
Grpc\ChannelCredentials::createInSecure(), |
|
|
|
$this->assertConnecting($state); |
|
|
|
Grpc\ChannelCredentials::createInSecure(), |
|
|
|
|
|
|
|
50303, |
|
|
|
$this->channel1->close(); |
|
|
|
], |
|
|
|
$this->channel2->close(); |
|
|
|
[ |
|
|
|
} |
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
public function testPersistentChannelDifferentChannelCredentials() |
|
|
|
), |
|
|
|
{ |
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
$creds1 = Grpc\ChannelCredentials::createSsl(); |
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
$creds2 = Grpc\ChannelCredentials::createSsl( |
|
|
|
), |
|
|
|
file_get_contents(dirname(__FILE__).'/../data/ca.pem')); |
|
|
|
50304, |
|
|
|
|
|
|
|
], |
|
|
|
$this->channel1 = new Grpc\Channel('localhost:50020', |
|
|
|
[ |
|
|
|
["credentials" => $creds1, |
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
"grpc_target_persist_bound" => 3, |
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
]); |
|
|
|
), |
|
|
|
$this->channel2 = new Grpc\Channel('localhost:50020', |
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
["credentials" => $creds2]); |
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
|
|
|
|
), |
|
|
|
// try to connect on channel1 |
|
|
|
50305, |
|
|
|
$state = $this->channel1->getConnectivityState(true); |
|
|
|
], |
|
|
|
$this->waitUntilNotIdle($this->channel1); |
|
|
|
[ |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
$state = $this->channel1->getConnectivityState(); |
|
|
|
\Grpc\ChannelCredentials::createSsl( |
|
|
|
$this->assertConnecting($state); |
|
|
|
file_get_contents(dirname(__FILE__) . '/../data/ca.pem') |
|
|
|
$state = $this->channel2->getConnectivityState(); |
|
|
|
) |
|
|
|
$this->assertEquals(GRPC\CHANNEL_IDLE, $state); |
|
|
|
), |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
$this->channel1->close(); |
|
|
|
\Grpc\ChannelCredentials::createSsl( |
|
|
|
$this->channel2->close(); |
|
|
|
file_get_contents(dirname(__FILE__) . '/../data/ca.pem') |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
), |
|
|
|
public function testPersistentChannelSameChannelCredentialsRootCerts() |
|
|
|
50306, |
|
|
|
{ |
|
|
|
], |
|
|
|
$creds1 = Grpc\ChannelCredentials::createSsl( |
|
|
|
[ |
|
|
|
file_get_contents(dirname(__FILE__).'/../data/ca.pem')); |
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
$creds2 = Grpc\ChannelCredentials::createSsl( |
|
|
|
\Grpc\ChannelCredentials::createInSecure() |
|
|
|
file_get_contents(dirname(__FILE__).'/../data/ca.pem')); |
|
|
|
), |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
$this->channel1 = new Grpc\Channel('localhost:50021', |
|
|
|
\Grpc\ChannelCredentials::createInSecure() |
|
|
|
["credentials" => $creds1, |
|
|
|
), |
|
|
|
|
|
|
|
50307, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @dataProvider persistentChannelSameChannelCredentialsProvider |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function testPersistentChannelSameChannelCredentials( |
|
|
|
|
|
|
|
$creds1, |
|
|
|
|
|
|
|
$creds2, |
|
|
|
|
|
|
|
$port |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
$this->channel1 = new Grpc\Channel( |
|
|
|
|
|
|
|
'localhost:' . $port, |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
"credentials" => $creds1, |
|
|
|
"grpc_target_persist_bound" => 3, |
|
|
|
"grpc_target_persist_bound" => 3, |
|
|
|
]); |
|
|
|
] |
|
|
|
$this->channel2 = new Grpc\Channel('localhost:50021', |
|
|
|
); |
|
|
|
["credentials" => $creds2]); |
|
|
|
$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); |
|
|
@ -353,17 +398,78 @@ class ChannelTest extends \PHPUnit\Framework\TestCase |
|
|
|
$this->channel2->close(); |
|
|
|
$this->channel2->close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testPersistentChannelDifferentSecureChannelCredentials() |
|
|
|
public function persistentChannelDifferentChannelCredentialsProvider(): array |
|
|
|
{ |
|
|
|
{ |
|
|
|
$creds1 = Grpc\ChannelCredentials::createSsl(); |
|
|
|
return [ |
|
|
|
$creds2 = Grpc\ChannelCredentials::createInsecure(); |
|
|
|
[ |
|
|
|
|
|
|
|
Grpc\ChannelCredentials::createSsl(), |
|
|
|
$this->channel1 = new Grpc\Channel('localhost:50022', |
|
|
|
Grpc\ChannelCredentials::createSsl( |
|
|
|
["credentials" => $creds1, |
|
|
|
file_get_contents(dirname(__FILE__) . '/../data/ca.pem') |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
50351, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
Grpc\ChannelCredentials::createSsl(), |
|
|
|
|
|
|
|
Grpc\ChannelCredentials::createInsecure(), |
|
|
|
|
|
|
|
50352, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl( |
|
|
|
|
|
|
|
file_get_contents(dirname(__FILE__) . '/../data/ca.pem') |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
50353, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createInsecure() |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
50354, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createInsecure(), |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createInsecure() |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
50355, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl(), |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createXds( |
|
|
|
|
|
|
|
\Grpc\ChannelCredentials::createSsl() |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
50356, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @dataProvider persistentChannelDifferentChannelCredentialsProvider |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function testPersistentChannelDifferentChannelCredentials( |
|
|
|
|
|
|
|
$creds1, |
|
|
|
|
|
|
|
$creds2, |
|
|
|
|
|
|
|
$port |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->channel1 = new Grpc\Channel( |
|
|
|
|
|
|
|
'localhost:' . $port, |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
"credentials" => $creds1, |
|
|
|
"grpc_target_persist_bound" => 3, |
|
|
|
"grpc_target_persist_bound" => 3, |
|
|
|
]); |
|
|
|
] |
|
|
|
$this->channel2 = new Grpc\Channel('localhost:50022', |
|
|
|
); |
|
|
|
["credentials" => $creds2]); |
|
|
|
$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); |
|
|
|