Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Oct 31, 2024
1 parent 9f9a539 commit 6289263
Showing 1 changed file with 68 additions and 51 deletions.
119 changes: 68 additions & 51 deletions Spanner/tests/Unit/TransactionTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function testDatabaseSnapshotSingleUseReadTimestampAndExactStaleness($chu
$transaction = [
'singleUse' => [
'readOnly' => [
'minReadTimestamp' => $timestamp,
'readTimestamp' => $this->formatTimestampForApi($this->timestamp),
'exactStaleness' => $duration,
]
]
Expand Down Expand Up @@ -384,38 +384,40 @@ public function testDatabaseSnapshotPreAllocateReadTimestampAndExactStaleness($c
$duration = new Duration(['seconds' => $seconds, 'nanos' => $nanos]);
$options = [
'readOnly' => [
'minReadTimestamp' => $this->formatTimestampForApi($this->timestamp),
'exactStaleness' => [
'seconds' => $seconds,
'nanos' => $nanos
]
'readTimestamp' => $this->formatTimestampForApi($this->timestamp),
'exactStaleness' => $duration,
]
];
$transaction = new TransactionProto(['id' => self::TRANSACTION]);
$this->spannerClient->beginTransaction(
Argument::that(function ($request) use ($options) {
Argument::type(BeginTransactionRequest::class);
$this->assertEquals(
$request->getOptions(),
$this->createTransactionOptions($options)
);
return true;
}),
Argument::type(BeginTransactionRequest::class),
Argument::type('array')
)
->shouldBeCalledOnce()
->willReturn(new TransactionProto(['id' => self::TRANSACTION]));
->willReturn($transaction);

$this->spannerClient->executeStreamingSql(
Argument::that(function (ExecuteSqlRequest $request) {
$this->assertEquals($request->getTransaction()->getId(), self::TRANSACTION);
return true;
}),
Argument::type(ExecuteSqlRequest::class),
Argument::type('array')
)
->shouldBeCalledOnce()
->willReturn($this->resultGeneratorStream($chunks));

$serializer = $this->serializerForStreamingSql($chunks, $options);
$this->serializer->decodeMessage(
Argument::type(BeginTransactionRequest::class),
Argument::that(function (array $data) use ($options){
$this->assertEquals($data['options'], $options);
return true;
}),
)
->shouldBeCalledOnce()
->willReturn(new BeginTransactionRequest());

$this->serializer->encodeMessage($transaction)
->shouldBeCalledOnce()
->willReturn([]);

$serializer = $this->serializerForStreamingSql($chunks, ['singleUse' => $options]);
$database = $this->database($this->spannerClient->reveal(), $serializer);

$snapshot = $database->snapshot([
Expand All @@ -432,15 +434,17 @@ public function testDatabaseSnapshotPreAllocateReadTimestampAndExactStaleness($c
public function testDatabaseSingleUseSnapshotStrongConsistency($chunks)
{
$this->spannerClient->beginTransaction(Argument::cetera())->shouldNotBeCalled();

$transaction = [
'singleUse' => [
'readOnly' => [
'strong' => true
]
]
];

$this->spannerClient->executeStreamingSql(
Argument::type(ReadRequest::class),
Argument::type(ExecuteSqlRequest::class),
Argument::type('array')
)
->shouldBeCalledOnce()
Expand All @@ -467,31 +471,37 @@ public function testDatabasePreAllocatedSnapshotStrongConsistency($chunks)
'strong' => true
]
];
$transaction = new TransactionProto(['id' => self::TRANSACTION]);
$this->spannerClient->beginTransaction(
Argument::that(function ($request) use ($options) {
Argument::type(BeginTransactionRequest::class);
$this->assertEquals(
$request->getOptions(),
$this->createTransactionOptions($options)
);
return true;
}),
Argument::type(BeginTransactionRequest::class),
Argument::type('array')
)
->shouldBeCalledOnce()
->willReturn(new TransactionProto(['id' => self::TRANSACTION]));
->willReturn($transaction);

$this->spannerClient->executeStreamingSql(
Argument::that(function (ExecuteSqlRequest $request) {
$this->assertEquals($request->getTransaction()->getId(), self::TRANSACTION);
return true;
}),
Argument::type(ExecuteSqlRequest::class),
Argument::type('array')
)
->shouldBeCalledOnce()
->willReturn($this->resultGeneratorStream($chunks));

$database = $this->database($this->spannerClient->reveal());
$this->serializer->decodeMessage(
Argument::type(BeginTransactionRequest::class),
Argument::that(function (array $data) use ($options){
$this->assertEquals($data['options'], $options);
return true;
}),
)
->shouldBeCalledOnce()
->willReturn(new BeginTransactionRequest());

$this->serializer->encodeMessage($transaction)
->shouldBeCalledOnce()
->willReturn([]);

$serializer = $this->serializerForStreamingSql($chunks, ['singleUse' => $options]);
$database = $this->database($this->spannerClient->reveal(), $serializer);

$snapshot = $database->snapshot([
'strong' => true
Expand All @@ -514,14 +524,14 @@ public function testDatabaseSingleUseSnapshotDefaultsToStrongConsistency($chunks
]
];
$this->spannerClient->executeStreamingSql(
Argument::type(ReadRequest::class),
Argument::type(ExecuteSqlRequest::class),
Argument::type('array')
)
->shouldBeCalledOnce()
->willReturn($this->resultGeneratorStream($chunks));

$serializer = $this->serializerForStreamingSql($chunks, $transaction);
$database = $this->database($this->spannerClient->reveal());
$database = $this->database($this->spannerClient->reveal(), $serializer);

$snapshot = $database->snapshot([
'singleUse' => true,
Expand All @@ -540,31 +550,37 @@ public function testDatabasePreAllocatedSnapshotDefaultsToStrongConsistency($chu
'strong' => true
]
];
$transaction = new TransactionProto(['id' => self::TRANSACTION]);
$this->spannerClient->beginTransaction(
Argument::that(function ($request) use ($options) {
Argument::type(BeginTransactionRequest::class);
$this->assertEquals(
$request->getOptions(),
$this->createTransactionOptions($options)
);
return true;
}),
Argument::type(BeginTransactionRequest::class),
Argument::type('array')
)
->shouldBeCalledOnce()
->willReturn(new TransactionProto(['id' => self::TRANSACTION]));
->willReturn($transaction);

$this->spannerClient->executeStreamingSql(
Argument::that(function (ExecuteSqlRequest $request) {
$this->assertEquals($request->getTransaction()->getId(), self::TRANSACTION);
return true;
}),
Argument::type(ExecuteSqlRequest::class),
Argument::type('array')
)
->shouldBeCalledOnce()
->willReturn($this->resultGeneratorStream($chunks));

$database = $this->database($this->spannerClient->reveal());
$this->serializer->decodeMessage(
Argument::type(BeginTransactionRequest::class),
Argument::that(function (array $data) use ($options){
$this->assertEquals($data['options'], $options);
return true;
}),
)
->shouldBeCalledOnce()
->willReturn(new BeginTransactionRequest());

$this->serializer->encodeMessage($transaction)
->shouldBeCalledOnce()
->willReturn([]);

$serializer = $this->serializerForStreamingSql($chunks, ['singleUse' => $options]);
$database = $this->database($this->spannerClient->reveal(), $serializer);

$snapshot = $database->snapshot();

Expand Down Expand Up @@ -605,6 +621,7 @@ public function testDatabaseSnapshotReturnReadTimestamp($chunks)
)
->shouldBeCalledOnce()
->willReturn(new BeginTransactionRequest());

$this->serializer->encodeMessage($transaction)
->shouldBeCalledOnce()
->willReturn([]);
Expand Down

0 comments on commit 6289263

Please sign in to comment.