Skip to content

Commit

Permalink
Implementing HappyBase Table.batch() factory.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Feb 24, 2016
1 parent e19f2b7 commit 240ea12
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
8 changes: 5 additions & 3 deletions gcloud/bigtable/happybase/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 <exceptions.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.
Expand Down
34 changes: 34 additions & 0 deletions gcloud/bigtable/happybase/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 240ea12

Please sign in to comment.