Skip to content

Commit

Permalink
fix(bigtable/emulator): Sending empty row in SampleRowKeys response (#…
Browse files Browse the repository at this point in the history
…10611)

* fix(bigtable/emulator): Sending empty row in SampleRowKeys response

* test(bigtable): Fix unit tests
  • Loading branch information
bhshkh authored Aug 1, 2024
1 parent 0e5c5c9 commit 928f1a7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions bigtable/bttest/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,13 @@ func (s *server) SampleRowKeys(req *btpb.SampleRowKeysRequest, stream btpb.Bigta
i++
return true
})
if err == nil {
// The last response should be an empty string, indicating the end of the table
stream.Send(&btpb.SampleRowKeysResponse{
RowKey: []byte{},
OffsetBytes: offset,
})
}
return err
}

Expand Down
20 changes: 17 additions & 3 deletions bigtable/bttest/inmem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,25 @@ func TestSampleRowKeys(t *testing.T) {
if len(mock.responses) == 0 {
t.Fatal("Response count: got 0, want > 0")
}
// Make sure the offset of the final response is the offset of the final row
got := mock.responses[len(mock.responses)-1].OffsetBytes
// Make sure the offset of the penultimate response is the offset of the final row
got := mock.responses[len(mock.responses)-2].OffsetBytes
want := int64((rowCount - 1) * len(val))
if got != want {
t.Errorf("Invalid offset: got %d, want %d", got, want)
t.Errorf("Invalid penultimate offset: got %d, want %d", got, want)
}

// Make sure the offset of the final response is the offset of all the rows
got = mock.responses[len(mock.responses)-1].OffsetBytes
want = int64(rowCount * len(val))
if got != want {
t.Errorf("Invalid final offset: got %d, want %d", got, want)
}

// Make sure the key of the final response is empty
gotLastKey := mock.responses[len(mock.responses)-1].RowKey
wantLastKey := ""
if got != want {
t.Errorf("Invalid final RowKey: got %s, want %s", gotLastKey, wantLastKey)
}
}

Expand Down

0 comments on commit 928f1a7

Please sign in to comment.