Skip to content

Commit bf87e92

Browse files
committed
Merge pull request #1534 from dhermes/final-bigtable-system-tests
Adding final non-HappyBase Bigtable system tests.
2 parents 9cb19bd + 1736b59 commit bf87e92

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

system_tests/bigtable.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
2424
from gcloud._helpers import UTC
2525
from gcloud.bigtable.client import Client
2626
from gcloud.bigtable.column_family import MaxVersionsGCRule
27+
from gcloud.bigtable.row import ApplyLabelFilter
28+
from gcloud.bigtable.row import ColumnQualifierRegexFilter
29+
from gcloud.bigtable.row import RowFilterChain
30+
from gcloud.bigtable.row import RowFilterUnion
2731
from gcloud.bigtable.row_data import Cell
32+
from gcloud.bigtable.row_data import PartialRowData
2833
from gcloud.environment_vars import TESTS_PROJECT
2934

3035

@@ -43,6 +48,7 @@
4348
CELL_VAL3 = b'altcol-cell-val'
4449
CELL_VAL4 = b'foo'
4550
ROW_KEY = b'row-key'
51+
ROW_KEY_ALT = b'row-key-alt'
4652
EXISTING_CLUSTERS = []
4753
EXPECTED_ZONES = (
4854
'asia-east1-b',
@@ -384,3 +390,95 @@ def test_read_row(self):
384390
},
385391
}
386392
self.assertEqual(partial_row_data.cells, expected_row_contents)
393+
394+
def test_read_rows(self):
395+
row = self._table.row(ROW_KEY)
396+
row_alt = self._table.row(ROW_KEY_ALT)
397+
self.rows_to_delete.extend([row, row_alt])
398+
399+
cell1, cell2, cell3, cell4 = self._write_to_row(row, row_alt,
400+
row, row_alt)
401+
row.commit()
402+
row_alt.commit()
403+
404+
rows_data = self._table.read_rows()
405+
self.assertEqual(rows_data.rows, {})
406+
rows_data.consume_all()
407+
408+
# NOTE: We should refrain from editing protected data on instances.
409+
# Instead we should make the values public or provide factories
410+
# for constructing objects with them.
411+
row_data = PartialRowData(ROW_KEY)
412+
row_data._chunks_encountered = True
413+
row_data._committed = True
414+
row_data._cells = {
415+
COLUMN_FAMILY_ID1: {
416+
COL_NAME1: [cell1],
417+
COL_NAME2: [cell3],
418+
},
419+
}
420+
421+
row_alt_data = PartialRowData(ROW_KEY_ALT)
422+
row_alt_data._chunks_encountered = True
423+
row_alt_data._committed = True
424+
row_alt_data._cells = {
425+
COLUMN_FAMILY_ID1: {
426+
COL_NAME1: [cell2],
427+
},
428+
COLUMN_FAMILY_ID2: {
429+
COL_NAME3: [cell4],
430+
},
431+
}
432+
433+
expected_rows = {
434+
ROW_KEY: row_data,
435+
ROW_KEY_ALT: row_alt_data,
436+
}
437+
self.assertEqual(rows_data.rows, expected_rows)
438+
439+
def test_read_with_label_applied(self):
440+
row = self._table.row(ROW_KEY)
441+
self.rows_to_delete.append(row)
442+
443+
cell1, _, cell3, _ = self._write_to_row(row, None, row)
444+
row.commit()
445+
446+
# Combine a label with column 1.
447+
label1 = u'label-red'
448+
label1_filter = ApplyLabelFilter(label1)
449+
col1_filter = ColumnQualifierRegexFilter(COL_NAME1)
450+
chain1 = RowFilterChain(filters=[col1_filter, label1_filter])
451+
452+
# Combine a label with column 2.
453+
label2 = u'label-blue'
454+
label2_filter = ApplyLabelFilter(label2)
455+
col2_filter = ColumnQualifierRegexFilter(COL_NAME2)
456+
chain2 = RowFilterChain(filters=[col2_filter, label2_filter])
457+
458+
# Bring our two labeled columns together.
459+
row_filter = RowFilterUnion(filters=[chain1, chain2])
460+
partial_row_data = self._table.read_row(ROW_KEY, filter_=row_filter)
461+
self.assertTrue(partial_row_data.committed)
462+
self.assertEqual(partial_row_data.row_key, ROW_KEY)
463+
464+
cells_returned = partial_row_data.cells
465+
col_fam1 = cells_returned.pop(COLUMN_FAMILY_ID1)
466+
# Make sure COLUMN_FAMILY_ID1 was the only key.
467+
self.assertEqual(len(cells_returned), 0)
468+
469+
cell1_new, = col_fam1.pop(COL_NAME1)
470+
cell3_new, = col_fam1.pop(COL_NAME2)
471+
# Make sure COL_NAME1 and COL_NAME2 were the only keys.
472+
self.assertEqual(len(col_fam1), 0)
473+
474+
# Check that cell1 has matching values and gained a label.
475+
self.assertEqual(cell1_new.value, cell1.value)
476+
self.assertEqual(cell1_new.timestamp, cell1.timestamp)
477+
self.assertEqual(cell1.labels, [])
478+
self.assertEqual(cell1_new.labels, [label1])
479+
480+
# Check that cell3 has matching values and gained a label.
481+
self.assertEqual(cell3_new.value, cell3.value)
482+
self.assertEqual(cell3_new.timestamp, cell3.timestamp)
483+
self.assertEqual(cell3.labels, [])
484+
self.assertEqual(cell3_new.labels, [label2])

0 commit comments

Comments
 (0)