Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fix PITR restored database version time assertion (#238)
This PR fixes the assertion to use `metadata.backup_info.version_time` instead of `metadata.backup_info.create_time`. It looks it was passing before the backend correctly supported it and I forgot to re-run the tests before merging #148 (whoops!) and so it is currently failing and preventing #205 from being merged: https://source.cloud.google.com/results/invocations/8f0f5dab-1b35-4ce3-bb72-0ce9e79ab89d/targets/cloud-devrel%2Fclient-libraries%2Fpython%2Fgoogleapis%2Fpython-spanner%2Fpresubmit%2Fpresubmit/log
- Loading branch information
Showing
2 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import base64 | ||
import time | ||
from google.cloud import spanner | ||
from google.auth.credentials import AnonymousCredentials | ||
|
||
instance_id = 'test-instance' | ||
database_id = 'test-db' | ||
|
||
spanner_client = spanner.Client( | ||
project='test-project', | ||
client_options={"api_endpoint": 'localhost:9010'}, | ||
credentials=AnonymousCredentials() | ||
) | ||
|
||
instance = spanner_client.instance(instance_id) | ||
op = instance.create() | ||
op.result() | ||
|
||
database = instance.database(database_id, ddl_statements=[ | ||
"CREATE TABLE Test (id STRING(36) NOT NULL, megafield BYTES(MAX)) PRIMARY KEY (id)" | ||
]) | ||
op = database.create() | ||
op.result() | ||
|
||
# This must be large enough that the SDK will split the megafield payload across two query chunks | ||
# and try to recombine them, causing the error: | ||
data = base64.standard_b64encode(("a" * 1000000).encode("utf8")) | ||
|
||
try: | ||
with database.batch() as batch: | ||
batch.insert( | ||
table="Test", | ||
columns=("id", "megafield"), | ||
values=[ | ||
(1, data), | ||
], | ||
) | ||
|
||
with database.snapshot() as snapshot: | ||
toc = time.time() | ||
results = snapshot.execute_sql( | ||
"SELECT * FROM Test" | ||
) | ||
tic = time.time() | ||
|
||
print("TIME: ", tic - toc) | ||
|
||
for row in results: | ||
print("Id: ", row[0]) | ||
print("Megafield: ", row[1][:100]) | ||
finally: | ||
database.drop() | ||
instance.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters