Пример #1
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 -port {$port} -service_map bsonrpc-vt-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 = VTContext::getDefault()->withDeadlineAfter(5.0);
     $client = new BsonRpcClient();
     $level = error_reporting(error_reporting() & ~E_WARNING);
     while (!$ctx->isCancelled()) {
         try {
             $client->dial($ctx, "{$addr}:{$port}");
         } catch (GoRpcException $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 VTUnsignedInt(345), 'uint_from_string' => new VTUnsignedInt('678'), 'float' => 1.5);
     self::$CALLER_ID = new VTCallerId('test_principal', 'test_component', 'test_subcomponent');
     self::$KEYSPACE_IDS = array(VTKeyspaceID::fromHex('8000000000000000'), VTKeyspaceID::fromHex('ff000000000000ef'));
     self::$KEY_RANGES = array(array('', VTKeyspaceID::fromHex('8000000000000000')), array(VTKeyspaceID::fromHex('8000000000000000'), ''));
     self::$ENTITY_KEYSPACE_IDS = array(VTKeyspaceID::fromHex('1234567800000002') => 'hello', VTKeyspaceID::fromHex('1234567800000000') => 123, VTKeyspaceID::fromHex('1234567800000001') => new VTUnsignedInt('456'), VTKeyspaceID::fromHex('1234567800000002') => 1.5);
 }
Пример #2
0
 public function testGetSrvKeyspace()
 {
     $ctx = $this->ctx;
     $conn = $this->conn;
     $expected = new VTSrvKeyspace();
     $expected->partitions[] = new VTSrvKeyspacePartition(VTTabletType::REPLICA, array(new VTShardReference("shard0", array(VTKeyspaceID::fromHex('4000000000000000'), VTKeyspaceID::fromHex('8000000000000000')))));
     $expected->shardingColumnName = 'sharding_column_name';
     $expected->shardingColumnType = VTKeyspaceIDType::UINT64;
     $expected->servedFrom[] = new VTSrvKeyspaceServedFrom(VTTabletType::MASTER, 'other_keyspace');
     $expected->splitShardCount = 128;
     $actual = $conn->getSrvKeyspace($ctx, "big");
     $this->assertEquals($expected, $actual);
 }