From 09d95d938833fa0154e758c1485080cc63e58661 Mon Sep 17 00:00:00 2001 From: Kyle Jones Date: Fri, 28 Oct 2016 11:14:07 -0700 Subject: [PATCH] bigtable/bttest: add emulator support for DeleteCellsInFamily Change-Id: I3ebf0f9673f4aa406bffbb4f69e5178311c40cc1 Reviewed-on: https://code-review.googlesource.com/8950 Reviewed-by: Gary Elliott --- bigtable/bigtable_test.go | 50 +++++++++++++++++++++++++++++++++++++++ bigtable/bttest/inmem.go | 7 ++++++ 2 files changed, 57 insertions(+) diff --git a/bigtable/bigtable_test.go b/bigtable/bigtable_test.go index 0169c02894d3..132c4f94a6c8 100644 --- a/bigtable/bigtable_test.go +++ b/bigtable/bigtable_test.go @@ -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 diff --git a/bigtable/bttest/inmem.go b/bigtable/bttest/inmem.go index 2a40b3021af3..618964cb8b11 100644 --- a/bigtable/bttest/inmem.go +++ b/bigtable/bttest/inmem.go @@ -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