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 1fe335e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 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
16 changes: 8 additions & 8 deletions gcloud/bigtable/happybase/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
import unittest2


class _SendMixin(object):

_send_called = False

def send(self):
self._send_called = True


class TestBatch(unittest2.TestCase):

def _getTargetClass(self):
Expand Down Expand Up @@ -166,14 +174,6 @@ class BatchWithSend(_SendMixin, klass):
self.assertTrue(batch._send_called)


class _SendMixin(object):

_send_called = False

def send(self):
self._send_called = True


class _MockRowMap(dict):

clear_count = 0
Expand Down
30 changes: 28 additions & 2 deletions gcloud/bigtable/happybase/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,31 @@ def test_delete(self):
table.delete(None)

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)

with self.assertRaises(NotImplementedError):
table.batch()
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()
Expand Down Expand Up @@ -470,3 +489,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 1fe335e

Please sign in to comment.