public function testRequestCall() { $this->server = new Grpc\Server(); $port = $this->server->addHttp2Port('0.0.0.0:8888'); $this->server->start(); $channel = new Grpc\Channel('localhost:8888', ['credentials' => Grpc\ChannelCredentials::createInsecure()]); $deadline = Grpc\Timeval::infFuture(); $call = new Grpc\Call($channel, 'dummy_method', $deadline); $event = $call->startBatch([Grpc\OP_SEND_INITIAL_METADATA => [], Grpc\OP_SEND_CLOSE_FROM_CLIENT => true]); $c = $this->server->requestCall(); $this->assertObjectHasAttribute('call', $c); $this->assertObjectHasAttribute('method', $c); $this->assertSame('dummy_method', $c->method); $this->assertObjectHasAttribute('host', $c); $this->assertTrue(is_string($c->host)); $this->assertObjectHasAttribute('absolute_deadline', $c); $this->assertObjectHasAttribute('metadata', $c); unset($call); unset($channel); }
public function setUp() { self::$client = new math\MathClient(getenv('GRPC_TEST_HOST'), ['credentials' => Grpc\ChannelCredentials::createInsecure(), 'update_metadata' => function ($a_hash, $client = []) { $a_copy = $a_hash; $a_copy['foo'] = ['bar']; return $a_copy; }]); }
function greet($name) { $client = new helloworld\GreeterClient('localhost:50051', ['credentials' => Grpc\ChannelCredentials::createInsecure()]); $request = new helloworld\HelloRequest(); $request->setName($name); list($reply, $status) = $client->SayHello($request)->wait(); $message = $reply->getMessage(); return $message; }
public function setUp() { $credentials = Grpc\ChannelCredentials::createSsl(file_get_contents(dirname(__FILE__) . '/../data/ca.pem')); $server_credentials = Grpc\ServerCredentials::createSsl(null, file_get_contents(dirname(__FILE__) . '/../data/server1.key'), file_get_contents(dirname(__FILE__) . '/../data/server1.pem')); $this->server = new Grpc\Server(); $this->port = $this->server->addSecureHttp2Port('0.0.0.0:0', $server_credentials); $this->server->start(); $this->host_override = 'foo.test.google.fr'; $this->channel = new Grpc\Channel('localhost:' . $this->port, ['grpc.ssl_target_name_override' => $this->host_override, 'grpc.default_authority' => $this->host_override, 'credentials' => $credentials]); }
/** * @expectedException InvalidArgumentException */ public function testInvalidMethodName() { $invalid_client = new DummyInvalidClient('host', ['credentials' => Grpc\ChannelCredentials::createInsecure()]); $div_arg = new math\DivArgs(); $invalid_client->InvalidUnaryCall($div_arg); }
function _makeStub($args) { if (!array_key_exists('server_host', $args)) { throw new Exception('Missing argument: --server_host is required'); } if (!array_key_exists('server_port', $args)) { throw new Exception('Missing argument: --server_port is required'); } if (!array_key_exists('test_case', $args)) { throw new Exception('Missing argument: --test_case is required'); } if ($args['server_port'] == 443) { $server_address = $args['server_host']; } else { $server_address = $args['server_host'] . ':' . $args['server_port']; } $test_case = $args['test_case']; $host_override = 'foo.test.google.fr'; if (array_key_exists('server_host_override', $args)) { $host_override = $args['server_host_override']; } $use_tls = false; if (array_key_exists('use_tls', $args) && $args['use_tls'] != 'false') { $use_tls = true; } $use_test_ca = false; if (array_key_exists('use_test_ca', $args) && $args['use_test_ca'] != 'false') { $use_test_ca = true; } $opts = []; if ($use_tls) { if ($use_test_ca) { $ssl_credentials = Grpc\ChannelCredentials::createSsl(file_get_contents(dirname(__FILE__) . '/../data/ca.pem')); } else { $ssl_credentials = Grpc\ChannelCredentials::createSsl(); } $opts['credentials'] = $ssl_credentials; $opts['grpc.ssl_target_name_override'] = $host_override; } else { $opts['credentials'] = Grpc\ChannelCredentials::createInsecure(); } if (in_array($test_case, ['service_account_creds', 'compute_engine_creds', 'jwt_token_creds'])) { if ($test_case == 'jwt_token_creds') { $auth_credentials = ApplicationDefaultCredentials::getCredentials(); } else { $auth_credentials = ApplicationDefaultCredentials::getCredentials($args['oauth_scope']); } $opts['update_metadata'] = $auth_credentials->getUpdateMetadataFunc(); } if ($test_case == 'oauth2_auth_token') { $auth_credentials = ApplicationDefaultCredentials::getCredentials($args['oauth_scope']); $token = $auth_credentials->fetchAuthToken(); $update_metadata = function ($metadata, $authUri = null, ClientInterface $client = null) use($token) { $metadata_copy = $metadata; $metadata_copy[CredentialsLoader::AUTH_METADATA_KEY] = [sprintf('%s %s', $token['token_type'], $token['access_token'])]; return $metadata_copy; }; $opts['update_metadata'] = $update_metadata; } if ($test_case == 'unimplemented_method') { $stub = new grpc\testing\UnimplementedServiceClient($server_address, $opts); } else { $stub = new grpc\testing\TestServiceClient($server_address, $opts); } return $stub; }
public function testInsecureCredentials() { $this->channel = new Grpc\Channel('localhost:0', ['credentials' => Grpc\ChannelCredentials::createInsecure()]); $this->assertSame('Grpc\\Channel', get_class($this->channel)); }
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ # Fix the following two lines to point to your installation include 'vendor/autoload.php'; include 'tests/generated_code/math.php'; function p($line) { echo "{$line}<br/>\n"; } $host = 'localhost:50051'; p("Connecting to host: {$host}"); $client = new math\MathClient($host, ['credentials' => Grpc\ChannelCredentials::createInsecure()]); p('Client class: ' . get_class($client)); p(''); p('Running unary call test:'); $dividend = 7; $divisor = 4; $div_arg = new math\DivArgs(); $div_arg->setDividend($dividend); $div_arg->setDivisor($divisor); $call = $client->Div($div_arg); p('Call peer: ' . $call->getPeer()); p("Dividing {$dividend} by {$divisor}"); list($response, $status) = $call->wait(); p('quotient = ' . $response->getQuotient()); p('remainder = ' . $response->getRemainder()); p('');
/** * @expectedException InvalidArgumentException */ public function testInvalidCreateComposite() { $channel_credentials = Grpc\ChannelCredentials::createComposite('something', 'something'); }
public function testCreateInsecure() { $channel_credentials = Grpc\ChannelCredentials::createInsecure(); $this->assertNull($channel_credentials); }
/** * @expectedException InvalidArgumentException */ public function testInvalidWatchConnectivityState2() { $this->channel = new Grpc\Channel('localhost:0', ['credentials' => Grpc\ChannelCredentials::createInsecure()]); $this->channel->watchConnectivityState(1, 'hi'); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Google\Auth\ApplicationDefaultCredentials; $auth_credentials = ApplicationDefaultCredentials::getCredentials(['https://www.googleapis.com/auth/pubsub']); $channel_credentials = Grpc\ChannelCredentials::createSsl(file_get_contents(__DIR__ . '/../vendor/grpc/grpc/etc/roots.pem')); $opts = ['credentials' => $channel_credentials, 'grpc.ssl_target_name_override' => 'pubsub.googleapis.com']; $client = new google\pubsub\v1\PublisherClient('pubsub.googleapis.com', $opts); $deadline = Grpc\Timeval::InfFuture(); $req = new google\pubsub\v1\ListTopicsRequest(); $proj = getenv('GAE_LONG_APP_ID'); $req->setProject('projects/' . $proj); $call = $client->ListTopics($req, [], ['call_credentials_callback' => function ($context) use($auth_credentials) { return $auth_credentials->updateMetadata([], $context->service_url); }]); list($response, $status) = $call->wait(); if ($status->code != 0) { echo 'gRPC to PubSub failed, printing RPC status:<br>'; print_r($status); exit(1); } foreach ($response->getTopics() as $topic) { echo $topic->getName() . '<br>'; }
public function setUp() { self::$client = new math\MathClient(getenv('GRPC_TEST_HOST'), ['credentials' => Grpc\ChannelCredentials::createInsecure()]); }
$host_override = $args['server_host_override']; } $use_tls = false; if (array_key_exists('use_tls', $args) && $args['use_tls'] != 'false') { $use_tls = true; } $use_test_ca = false; if (array_key_exists('use_test_ca', $args) && $args['use_test_ca'] != 'false') { $use_test_ca = true; } $opts = []; if ($use_tls) { if ($use_test_ca) { $ssl_credentials = Grpc\ChannelCredentials::createSsl(file_get_contents(dirname(__FILE__) . '/../data/ca.pem')); } else { $ssl_credentials = Grpc\ChannelCredentials::createSsl(); } $opts['credentials'] = $ssl_credentials; $opts['grpc.ssl_target_name_override'] = $host_override; } if (in_array($test_case, ['service_account_creds', 'compute_engine_creds', 'jwt_token_creds'])) { if ($test_case == 'jwt_token_creds') { $auth_credentials = ApplicationDefaultCredentials::getCredentials(); } else { $auth_credentials = ApplicationDefaultCredentials::getCredentials($args['oauth_scope']); } $opts['update_metadata'] = $auth_credentials->getUpdateMetadataFunc(); } if ($test_case == 'oauth2_auth_token') { $auth_credentials = ApplicationDefaultCredentials::getCredentials($args['oauth_scope']); $token = $auth_credentials->fetchAuthToken();
public function testPrimaryUserAgentString() { $invalid_client = new DummyInvalidClient('host', ['credentials' => Grpc\ChannelCredentials::createInsecure(), 'grpc.primary_user_agent' => 'testUserAgent']); }
} $use_test_ca = false; if (array_key_exists('use_test_ca', $args) && $args['use_test_ca'] != 'false') { $use_test_ca = true; } $opts = []; if ($use_tls) { if ($use_test_ca) { $ssl_credentials = Grpc\ChannelCredentials::createSsl(file_get_contents(dirname(__FILE__) . '/../data/ca.pem')); } else { $ssl_credentials = Grpc\ChannelCredentials::createSsl(); } $opts['credentials'] = $ssl_credentials; $opts['grpc.ssl_target_name_override'] = $host_override; } else { $opts['credentials'] = Grpc\ChannelCredentials::createInsecure(); } if (in_array($test_case, ['service_account_creds', 'compute_engine_creds', 'jwt_token_creds'])) { if ($test_case == 'jwt_token_creds') { $auth_credentials = ApplicationDefaultCredentials::getCredentials(); } else { $auth_credentials = ApplicationDefaultCredentials::getCredentials($args['oauth_scope']); } $opts['update_metadata'] = $auth_credentials->getUpdateMetadataFunc(); } if ($test_case == 'oauth2_auth_token') { $auth_credentials = ApplicationDefaultCredentials::getCredentials($args['oauth_scope']); $token = $auth_credentials->fetchAuthToken(); $update_metadata = function ($metadata, $authUri = null, ClientInterface $client = null) use($token) { $metadata_copy = $metadata; $metadata_copy[CredentialsLoader::AUTH_METADATA_KEY] = [sprintf('%s %s', $token['token_type'], $token['access_token'])];
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ require dirname(__FILE__) . '/../vendor/autoload.php'; require dirname(__FILE__) . '/route_guide.php'; define('COORD_FACTOR', 10000000.0); $client = new routeguide\RouteGuideClient('localhost:50051', ['credentials' => Grpc\ChannelCredentials::createInsecure()]); function printFeature($feature) { $name = $feature->getName(); if (!$name) { $name_str = 'no feature'; } else { $name_str = "feature called {$name}"; } echo sprintf("Found %s \n at %f, %f\n", $name_str, $feature->getLocation()->getLatitude() / COORD_FACTOR, $feature->getLocation()->getLongitude() / COORD_FACTOR); } /** * Run the getFeature demo. Calls getFeature with a point known to have a * feature and a point known not to have a feature. */ function runGetFeature()
<?php /* * This is a sample for using the PHP Vitess client with VTGateV3. * * Before running this, start up a local V3 demo cluster by running: * vitess/examples/demo$ ./run.py * * Then in another terminal: * vitess/examples/demo$ php client.php --server=localhost:12346 */ require_once __DIR__ . '/../../php/vendor/autoload.php'; use Vitess\Context; use Vitess\VTGateConn; use Vitess\Proto\Topodata\TabletType; $opts = getopt('', array('server:')); // Create a connection. $ctx = Context::getDefault(); $conn = new VTGateConn(new \Vitess\Grpc\Client($opts['server'], ['credentials' => Grpc\ChannelCredentials::createInsecure()])); // Insert something. $tx = $conn->begin($ctx); $tx->execute($ctx, 'INSERT INTO user (name) VALUES (:name)', array('name' => 'sugu')); $tx->commit($ctx); // Read it back. $cursor = $conn->execute($ctx, 'SELECT * FROM user', array(), TabletType::MASTER); while (($row = $cursor->next()) !== FALSE) { print_r($row); } $conn->close();
* modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ $channel = new Grpc\Channel('localhost:1000', ['credentials' => Grpc\ChannelCredentials::createInsecure()]); $deadline = Grpc\Timeval::infFuture(); $call = new Grpc\Call($channel, 'dummy_method', $deadline); $call->cancel(); $channel->close();