Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions test.py
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()
5 changes: 3 additions & 2 deletions tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,12 @@ def test_backup_workflow(self):
operation = database.restore(source=backup)
restored_db = operation.result()
self.assertEqual(
self.database_version_time, restored_db.restore_info.backup_info.create_time
self.database_version_time,
restored_db.restore_info.backup_info.version_time,
)

metadata = operation.metadata
self.assertEqual(self.database_version_time, metadata.backup_info.create_time)
self.assertEqual(self.database_version_time, metadata.backup_info.version_time)

database.drop()
backup.delete()
Expand Down