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
1 change: 1 addition & 0 deletions bigtable/snippets/writes/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
backoff==1.10.0
pytest==5.3.2
25 changes: 21 additions & 4 deletions bigtable/snippets/writes/writes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import uuid
import pytest

import backoff
from google.api_core.exceptions import DeadlineExceeded
from google.cloud import bigtable

from .write_batch import write_batch
Expand Down Expand Up @@ -55,22 +57,37 @@ def table_id(bigtable_instance):


def test_writes(capsys, table_id):
write_simple(PROJECT, BIGTABLE_INSTANCE, table_id)

# `row.commit()` sometimes ends up with DeadlineExceeded, so now
# we put retries with a hard deadline.
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=60)
def _write_simple():
write_simple(PROJECT, BIGTABLE_INSTANCE, table_id)

_write_simple()
out, _ = capsys.readouterr()
assert 'Successfully wrote row' in out

write_increment(PROJECT, BIGTABLE_INSTANCE, table_id)
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=60)
def _write_increment():
write_increment(PROJECT, BIGTABLE_INSTANCE, table_id)

_write_increment()
out, _ = capsys.readouterr()
assert 'Successfully updated row' in out

write_conditional(PROJECT, BIGTABLE_INSTANCE, table_id)
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=60)
def _write_conditional():
write_conditional(PROJECT, BIGTABLE_INSTANCE, table_id)

_write_conditional()
out, _ = capsys.readouterr()
assert 'Successfully updated row\'s os_name' in out

write_batch(PROJECT, BIGTABLE_INSTANCE, table_id)
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=60)
def _write_batch():
write_batch(PROJECT, BIGTABLE_INSTANCE, table_id)

_write_batch()
out, _ = capsys.readouterr()
assert 'Successfully wrote 2 rows' in out
1 change: 1 addition & 0 deletions testing/test-env.tmpl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export CLOUD_STORAGE_BUCKET=$GCLOUD_PROJECT
export API_KEY=
export BIGTABLE_CLUSTER=bigtable-test
export BIGTABLE_ZONE=us-central1-c
export BIGTABLE_INSTANCE=
export SPANNER_INSTANCE=
export COMPOSER_LOCATION=us-central1
export COMPOSER_ENVIRONMENT=
Expand Down