From 240ea120915d82c7a1350457b090b3cb1debf0e5 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Wed, 24 Feb 2016 13:06:56 -0800 Subject: [PATCH] Implementing HappyBase Table.batch() factory. --- gcloud/bigtable/happybase/table.py | 8 +++--- gcloud/bigtable/happybase/test_table.py | 34 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/gcloud/bigtable/happybase/table.py b/gcloud/bigtable/happybase/table.py index 569f6161e8f99..0753cee599ade 100644 --- a/gcloud/bigtable/happybase/table.py +++ b/gcloud/bigtable/happybase/table.py @@ -24,6 +24,7 @@ from gcloud.bigtable.column_family import MaxAgeGCRule from gcloud.bigtable.column_family import MaxVersionsGCRule from gcloud.bigtable.happybase.batch import _WAL_SENTINEL +from gcloud.bigtable.happybase.batch import Batch from gcloud.bigtable.table import Table as _LowLevelTable @@ -416,10 +417,11 @@ def batch(self, timestamp=None, batch_size=None, transaction=False, for Cloud Bigtable since it does not have a Write Ahead Log. - :raises: :class:`NotImplementedError ` - always (until the method is implemented). + :rtype: :class:`gcloud.bigtable.happybase.batch.Batch` + :returns: A batch bound to this table. """ - raise NotImplementedError + return Batch(self, timestamp=timestamp, batch_size=batch_size, + transaction=transaction, wal=wal) def counter_get(self, row, column): """Retrieve the current value of a counter column. diff --git a/gcloud/bigtable/happybase/test_table.py b/gcloud/bigtable/happybase/test_table.py index 866aba0855b36..922e65f37f4e3 100644 --- a/gcloud/bigtable/happybase/test_table.py +++ b/gcloud/bigtable/happybase/test_table.py @@ -177,6 +177,33 @@ def test_batch(self): with self.assertRaises(NotImplementedError): table.batch() + def test_batch(self): + from gcloud._testing import _Monkey + from gcloud.bigtable.happybase import table as MUT + + name = 'table-name' + connection = None + table = self._makeOne(name, connection) + + timestamp = object() + batch_size = 42 + transaction = False # Must be False when batch_size is non-null + wal = object() + + with _Monkey(MUT, Batch=_MockBatch): + result = table.batch(timestamp=timestamp, batch_size=batch_size, + transaction=transaction, wal=wal) + + self.assertTrue(isinstance(result, _MockBatch)) + self.assertEqual(result.args, (table,)) + expected_kwargs = { + 'timestamp': timestamp, + 'batch_size': batch_size, + 'transaction': transaction, + 'wal': wal, + } + self.assertEqual(result.kwargs, expected_kwargs) + def test_counter_get(self): klass = self._getTargetClass() counter_value = 1337 @@ -470,3 +497,10 @@ def increment_cell_value(self, column_family_id, column, int_value): def commit_modifications(self): return self.commit_result + + +class _MockBatch(object): + + def __init__(self, *args, **kwargs): + self.args = args + self.kwargs = kwargs