Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bigtable/bttest): Emulator too lenient for empty RowMutation #4359

Merged
merged 19 commits into from Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
88f1a1c
fix(bigtable/bttest): Emulator too lenient for empty RowMutation
jimfulton Jun 30, 2021
5aaa6ce
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jun 30, 2021
e896a56
gofmt
jimfulton Jul 1, 2021
f1b95b2
Merge branch 'error-on-empty-mutations-4309' of github.com:jimfulton/…
jimfulton Jul 1, 2021
2ef25b7
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jul 1, 2021
fa6c370
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jul 7, 2021
b60c91e
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jul 8, 2021
4b59d3f
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jul 8, 2021
1c5c2dc
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jul 9, 2021
007e0f2
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jul 9, 2021
b732f94
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jul 12, 2021
a27c81e
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jul 12, 2021
7f3fab2
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jul 13, 2021
64e6ebb
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jul 15, 2021
ed4a55c
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jul 22, 2021
1ffff6a
Merge branch 'master' into error-on-empty-mutations-4309
crwilcox Jul 27, 2021
b5f885f
Merge branch 'master' into error-on-empty-mutations-4309
jimfulton Jul 27, 2021
b4465c7
merge upstream
jimfulton Jul 27, 2021
a4c7e8b
Merge branch 'error-on-empty-mutations-4309' of github.com:jimfulton/…
jimfulton Jul 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions bigtable/bttest/inmem.go
Expand Up @@ -806,6 +806,12 @@ func newRegexp(pat []byte) (*binaryregexp.Regexp, error) {
}

func (s *server) MutateRow(ctx context.Context, req *btpb.MutateRowRequest) (*btpb.MutateRowResponse, error) {
if len(req.Mutations) == 0 {
return nil, status.Errorf(
codes.InvalidArgument,
"No mutations provided",
)
}
s.mu.Lock()
tbl, ok := s.tables[req.TableName]
s.mu.Unlock()
Expand All @@ -823,6 +829,16 @@ func (s *server) MutateRow(ctx context.Context, req *btpb.MutateRowRequest) (*bt
}

func (s *server) MutateRows(req *btpb.MutateRowsRequest, stream btpb.Bigtable_MutateRowsServer) error {
nMutations := 0
for _, entry := range req.Entries {
nMutations += len(entry.Mutations)
}
if nMutations == 0 {
return status.Errorf(
codes.InvalidArgument,
"No mutations provided",
)
}
s.mu.Lock()
tbl, ok := s.tables[req.TableName]
s.mu.Unlock()
Expand Down
44 changes: 44 additions & 0 deletions bigtable/bttest/inmem_test.go
Expand Up @@ -1979,3 +1979,47 @@ func TestValueFilterRowWithAlternationInRegex(t *testing.T) {
t.Fatalf("Response chunks mismatch: got: + want -\n%s", diff)
}
}

func TestMutateRowEmptyMutationErrors(t *testing.T) {
srv := &server{tables: make(map[string]*table)}
ctx := context.Background()
req := &btpb.MutateRowRequest{
TableName: "mytable",
RowKey: []byte("r"),
Mutations: []*btpb.Mutation{},
}

resp, err := srv.MutateRow(ctx, req)
if resp != nil ||
fmt.Sprint(err) !=
"rpc error: code = InvalidArgument"+
" desc = No mutations provided" {
t.Fatalf("Failed to error %s", err)
}
}

type bigtableTestingMutateRowsServer struct {
grpc.ServerStream
}

func (x *bigtableTestingMutateRowsServer) Send(m *btpb.MutateRowsResponse) error {
return nil
}

func TestMutateRowsEmptyMutationErrors(t *testing.T) {
srv := &server{tables: make(map[string]*table)}
req := &btpb.MutateRowsRequest{
TableName: "mytable",
Entries: []*btpb.MutateRowsRequest_Entry{
{Mutations: []*btpb.Mutation{}},
{Mutations: []*btpb.Mutation{}},
},
}

err := srv.MutateRows(req, &bigtableTestingMutateRowsServer{})
if fmt.Sprint(err) !=
"rpc error: code = InvalidArgument "+
"desc = No mutations provided" {
t.Fatalf("Failed to error %s", err)
}
}