Skip to content

Commit

Permalink
Self iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
yash30201 committed Apr 5, 2024
1 parent 170d590 commit 8e43aab
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 45 deletions.
1 change: 0 additions & 1 deletion Core/src/GrpcTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace Google\Cloud\Core;

use Google\Auth\GetUniverseDomainInterface;
use Google\ApiCore\ArrayTrait;
use Google\ApiCore\CredentialsWrapper;
use Google\Cloud\Core\Exception\NotFoundException;
use Google\Cloud\Core\Exception\ServiceException;
Expand Down
62 changes: 26 additions & 36 deletions Core/src/Testing/DatastoreOperationRefreshTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,7 @@ public function refreshOperation($stub, RequestHandler $requestHandler, array $o
$options['returnInt64AsObject']
);

$serializer = new Serializer([], [
'google.protobuf.Value' => function ($v) {
return $this->flattenValue($v);
},
'google.protobuf.Timestamp' => function ($v) {
return $this->formatTimestampFromApi($v);
}
], [], [
'google.protobuf.Timestamp' => function ($v) {
if (is_string($v)) {
$dt = new \DateTime($v);
return ['seconds' => $dt->format('U')];
}
return $v;
}
]);
$serializer = $this->getSerializer();

$stub->___setProperty('operation', new Operation(
$requestHandler,
Expand Down Expand Up @@ -105,26 +90,7 @@ public function refreshOperation($stub, RequestHandler $requestHandler, array $o
*/
private function mockSendRequest($methodName, $params, $returnValue, $shouldBeCalledTimes = null)
{
if (isset($this->serializer)) {
$serializer = $this->serializer;
} else {
$serializer = new Serializer([], [
'google.protobuf.Value' => function ($v) {
return $this->flattenValue($v);
},
'google.protobuf.Timestamp' => function ($v) {
return $this->formatTimestampFromApi($v);
}
], [], [
'google.protobuf.Timestamp' => function ($v) {
if (is_string($v)) {
$dt = new \DateTime($v);
return ['seconds' => $dt->format('U')];
}
return $v;
}
]);
}
$serializer = $this->getSerializer();

$prophecy = $this->requestHandler->sendRequest(
DatastoreClient::class,
Expand Down Expand Up @@ -153,4 +119,28 @@ private function mockSendRequest($methodName, $params, $returnValue, $shouldBeCa

$prophecy->willReturn($returnValue);
}

private function getSerializer()
{
if (isset($this->serializer)) {
return $this->serializer;
}

return new Serializer([], [
'google.protobuf.Value' => function ($v) {
return $this->flattenValue($v);
},
'google.protobuf.Timestamp' => function ($v) {
return $this->formatTimestampFromApi($v);
}
], [], [
'google.protobuf.Timestamp' => function ($v) {
if (is_string($v)) {
$dt = new \DateTime($v);
return ['seconds' => $dt->format('U')];
}
return $v;
}
]);
}
}
6 changes: 0 additions & 6 deletions Datastore/src/DatastoreClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,6 @@ public function __construct(array $config = [])
'projectIdRequired' => true,
'hasEmulator' => (bool) $emulatorHost,
'emulatorHost' => $emulatorHost,
'transportConfig' => [
'grpc' => [
// increase default limit to 4MB to prevent metadata exhausted errors
'stubOpts' => ['grpc.max_metadata_size' => 4 * 1024 * 1024,]
],
],
];
$config = $this->buildClientOptions($config);
$config['credentials'] = $this->createCredentialsWrapper(
Expand Down
3 changes: 1 addition & 2 deletions Datastore/src/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ public function lookup(array $keys, array $options = [])
];

$request = $this->serializer->decodeMessage(new LookupRequest(), $data);
$x = $this->serializer->encodeMessage($request);

$res = $this->requestHandler->sendRequest(
DatastoreClient::class,
Expand Down Expand Up @@ -774,7 +773,7 @@ public function commit(array $mutations, array $options = [])
];

if (is_null($options['transaction'])) {
// Remove 'transaction' if `null` to avoid serialization error
// Remove 'transaction' if set to `null` to avoid serialization error
unset($options['transaction']);
}
list($data, $optionalArgs) = $this->splitOptionalArgs($options, ['allowOverwrite', 'baseVersion']);
Expand Down

0 comments on commit 8e43aab

Please sign in to comment.