Skip to content

Commit

Permalink
bigtable/bttest: add emulator support for DeleteCellsInFamily
Browse files Browse the repository at this point in the history
Change-Id: I3ebf0f9673f4aa406bffbb4f69e5178311c40cc1
Reviewed-on: https://code-review.googlesource.com/8950
Reviewed-by: Gary Elliott <[email protected]>
  • Loading branch information
kyledj authored and garye committed Oct 31, 2016
1 parent 7ee19e7 commit 09d95d9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
50 changes: 50 additions & 0 deletions bigtable/bigtable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,56 @@ func TestClientIntegration(t *testing.T) {
}
checkpoint("tested multiple versions in a cell")

// Check DeleteColumnFamily
if err := adminClient.CreateColumnFamily(ctx, table, "status"); err != nil {
t.Fatalf("Creating column family: %v", err)
}

mut = NewMutation()
mut.Set("status", "start", 0, []byte("1"))
mut.Set("status", "end", 0, []byte("2"))
mut.Set("ts", "col", 0, []byte("3"))
if err := tbl.Apply(ctx, "row1", mut); err != nil {
t.Errorf("Mutating row: %v", err)
}
if err := tbl.Apply(ctx, "row2", mut); err != nil {
t.Errorf("Mutating row: %v", err)
}

mut = NewMutation()
mut.DeleteCellsInFamily("status")
if err := tbl.Apply(ctx, "row1", mut); err != nil {
t.Errorf("Delete cf: %v", err)
}

// ColumnFamily removed
r, err = tbl.ReadRow(ctx, "row1")
if err != nil {
t.Fatalf("Reading row: %v", err)
}
wantRow = Row{"ts": []ReadItem{
{Row: "row1", Column: "ts:col", Timestamp: 0, Value: []byte("3")},
}}
if !reflect.DeepEqual(r, wantRow) {
t.Errorf("column family was not deleted.\n got %v\n want %v", r, wantRow)
}

// ColumnFamily not removed
r, err = tbl.ReadRow(ctx, "row2")
if err != nil {
t.Fatalf("Reading row: %v", err)
}
wantRow = Row{
"ts": []ReadItem{
{Row: "row2", Column: "ts:col", Timestamp: 0, Value: []byte("3")},
},
"status": []ReadItem{
{Row: "row2", Column: "status:start", Timestamp: 0, Value: []byte("1")},
{Row: "row2", Column: "status:end", Timestamp: 0, Value: []byte("2")},
},
}
checkpoint("tested family delete")

// Do highly concurrent reads/writes.
// TODO(dsymonds): Raise this to 1000 when https://github.com/grpc/grpc-go/issues/205 is resolved.
const maxConcurrency = 100
Expand Down
7 changes: 7 additions & 0 deletions bigtable/bttest/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,13 @@ func applyMutations(tbl *table, r *row, muts []*btpb.Mutation, fs map[string]boo
}
case *btpb.Mutation_DeleteFromRow_:
r.cells = make(map[string][]cell)
case *btpb.Mutation_DeleteFromFamily_:
fampre := mut.DeleteFromFamily.FamilyName + ":"
for col, _ := range r.cells {
if strings.HasPrefix(col, fampre) {
delete(r.cells, col)
}
}
}
}
return nil
Expand Down

0 comments on commit 09d95d9

Please sign in to comment.