Skip to content

Commit 240ea12

Browse files
committed
Implementing HappyBase Table.batch() factory.
1 parent e19f2b7 commit 240ea12

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

gcloud/bigtable/happybase/table.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from gcloud.bigtable.column_family import MaxAgeGCRule
2525
from gcloud.bigtable.column_family import MaxVersionsGCRule
2626
from gcloud.bigtable.happybase.batch import _WAL_SENTINEL
27+
from gcloud.bigtable.happybase.batch import Batch
2728
from gcloud.bigtable.table import Table as _LowLevelTable
2829

2930

@@ -416,10 +417,11 @@ def batch(self, timestamp=None, batch_size=None, transaction=False,
416417
for Cloud Bigtable since it does not have a Write Ahead
417418
Log.
418419
419-
:raises: :class:`NotImplementedError <exceptions.NotImplementedError>`
420-
always (until the method is implemented).
420+
:rtype: :class:`gcloud.bigtable.happybase.batch.Batch`
421+
:returns: A batch bound to this table.
421422
"""
422-
raise NotImplementedError
423+
return Batch(self, timestamp=timestamp, batch_size=batch_size,
424+
transaction=transaction, wal=wal)
423425

424426
def counter_get(self, row, column):
425427
"""Retrieve the current value of a counter column.

gcloud/bigtable/happybase/test_table.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,33 @@ def test_batch(self):
177177
with self.assertRaises(NotImplementedError):
178178
table.batch()
179179

180+
def test_batch(self):
181+
from gcloud._testing import _Monkey
182+
from gcloud.bigtable.happybase import table as MUT
183+
184+
name = 'table-name'
185+
connection = None
186+
table = self._makeOne(name, connection)
187+
188+
timestamp = object()
189+
batch_size = 42
190+
transaction = False # Must be False when batch_size is non-null
191+
wal = object()
192+
193+
with _Monkey(MUT, Batch=_MockBatch):
194+
result = table.batch(timestamp=timestamp, batch_size=batch_size,
195+
transaction=transaction, wal=wal)
196+
197+
self.assertTrue(isinstance(result, _MockBatch))
198+
self.assertEqual(result.args, (table,))
199+
expected_kwargs = {
200+
'timestamp': timestamp,
201+
'batch_size': batch_size,
202+
'transaction': transaction,
203+
'wal': wal,
204+
}
205+
self.assertEqual(result.kwargs, expected_kwargs)
206+
180207
def test_counter_get(self):
181208
klass = self._getTargetClass()
182209
counter_value = 1337
@@ -470,3 +497,10 @@ def increment_cell_value(self, column_family_id, column, int_value):
470497

471498
def commit_modifications(self):
472499
return self.commit_result
500+
501+
502+
class _MockBatch(object):
503+
504+
def __init__(self, *args, **kwargs):
505+
self.args = args
506+
self.kwargs = kwargs

0 commit comments

Comments
 (0)