Ejemplo n.º 1
0
 /**
  * @param array $config
  */
 public function __construct(array $config = [])
 {
     $this->codec = new PhpArray(['publishTime' => function ($v) {
         return $this->formatTimestampFromApi($v);
     }]);
     $config['codec'] = $this->codec;
     $this->setRequestWrapper(new GrpcRequestWrapper($config));
     $grpcConfig = $this->getGaxConfig();
     $emulatorHost = getenv('PUBSUB_EMULATOR_HOST');
     $baseUri = $this->getEmulatorBaseUri(self::BASE_URI, $emulatorHost);
     if ($emulatorHost) {
         $grpcConfig += ['serviceAddress' => parse_url($baseUri, PHP_URL_HOST), 'port' => parse_url($baseUri, PHP_URL_PORT), 'sslCreds' => ChannelCredentials::createInsecure()];
     }
     $this->publisherClient = new PublisherClient($grpcConfig);
     $this->subscriberClient = new SubscriberClient($grpcConfig);
 }
Ejemplo n.º 2
0
 public static function setUpBeforeClass()
 {
     $VTROOT = getenv('VTROOT');
     if (!$VTROOT) {
         throw new Exception('VTROOT env var not set; make sure to source dev.env');
     }
     // Pick an unused port.
     $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     socket_bind($sock, 'localhost');
     if (!socket_getsockname($sock, $addr, $port)) {
         throw new Exception('Failed to find unused port for mock vtgate server.');
     }
     socket_close($sock);
     $cmd = "{$VTROOT}/bin/vtgateclienttest -logtostderr -lameduck-period 0 -grpc_port {$port} -service_map grpc-vtgateservice";
     $proc = proc_open($cmd, array(), $pipes);
     if (!$proc) {
         throw new Exception("Failed to start mock vtgate server with command: {$cmd}");
     }
     self::$proc = $proc;
     // Wait for connection to be accepted.
     $ctx = Context::getDefault()->withDeadlineAfter(5.0);
     $level = error_reporting(error_reporting() & ~E_WARNING);
     while (!$ctx->isCancelled()) {
         try {
             $client = new Grpc\Client("{$addr}:{$port}", ['credentials' => \Grpc\ChannelCredentials::createInsecure()]);
         } catch (Exception $e) {
             usleep(100000);
             continue;
         }
         break;
     }
     error_reporting($level);
     self::$client = $client;
     // Test fixtures that can't be statically initialized.
     self::$BIND_VARS = array('bytes' => 'hello', 'int' => 123, 'uint_from_int' => new UnsignedInt(-123), 'uint_from_string' => new UnsignedInt('456'), 'float' => 1.5);
     self::$CALLER_ID = new Proto\Vtrpc\CallerID();
     self::$CALLER_ID->setPrincipal('test_principal');
     self::$CALLER_ID->setComponent('test_component');
     self::$CALLER_ID->setSubcomponent('test_subcomponent');
     self::$KEYSPACE_IDS = array(ProtoUtils::KeyspaceIdFromHex('8000000000000000'), ProtoUtils::KeyspaceIdFromHex('ff000000000000ef'));
     self::$KEY_RANGES = array(ProtoUtils::KeyRangeFromHex('', '8000000000000000'), ProtoUtils::KeyRangeFromHex('8000000000000000', ''));
     self::$ENTITY_KEYSPACE_IDS = array(ProtoUtils::KeyspaceIdFromHex('1234567800000002') => 'hello', ProtoUtils::KeyspaceIdFromHex('1234567800000000') => 123, ProtoUtils::KeyspaceIdFromHex('1234567800000001') => new UnsignedInt(456), ProtoUtils::KeyspaceIdFromHex('1234567800000002') => 1.5);
 }
Ejemplo n.º 3
0
 /**
  * Vitess constructor.
  *
  * @param string $connectionString
  * @param Attributes $attributes
  * @throws PDOException
  * @SuppressWarnings(PHPMD.StaticAccess)
  */
 public function __construct($connectionString, Attributes $attributes)
 {
     $this->attributes = $attributes;
     try {
         $this->ctx = Context::getDefault();
         $credentials = ChannelCredentials::createInsecure();
         $this->grpcClient = new Client($connectionString, ['credentials' => $credentials]);
         $this->connection = new VTGateConn($this->grpcClient);
         $this->clusterConfig = new ClusterConfig();
     } catch (Exception $e) {
         throw new PDOException("Error while connecting to vitess: " . $e->getMessage(), $e->getCode(), $e);
     }
 }