@@ -273,6 +273,76 @@ func TestSampleRowKeys(t *testing.T) {
273273 }
274274}
275275
276+ func TestTableRowsConcurrent (t * testing.T ) {
277+ s := & server {
278+ tables : make (map [string ]* table ),
279+ }
280+ ctx := context .Background ()
281+ newTbl := btapb.Table {
282+ ColumnFamilies : map [string ]* btapb.ColumnFamily {
283+ "cf" : {GcRule : & btapb.GcRule {Rule : & btapb.GcRule_MaxNumVersions {MaxNumVersions : 1 }}},
284+ },
285+ }
286+ tbl , err := s .CreateTable (ctx , & btapb.CreateTableRequest {Parent : "cluster" , TableId : "t" , Table : & newTbl })
287+ if err != nil {
288+ t .Fatalf ("Creating table: %v" , err )
289+ }
290+
291+ // Populate the table
292+ populate := func () {
293+ rowCount := 100
294+ for i := 0 ; i < rowCount ; i ++ {
295+ req := & btpb.MutateRowRequest {
296+ TableName : tbl .Name ,
297+ RowKey : []byte ("row-" + strconv .Itoa (i )),
298+ Mutations : []* btpb.Mutation {{
299+ Mutation : & btpb.Mutation_SetCell_ {SetCell : & btpb.Mutation_SetCell {
300+ FamilyName : "cf" ,
301+ ColumnQualifier : []byte ("col" ),
302+ TimestampMicros : 1000 ,
303+ Value : []byte ("value" ),
304+ }},
305+ }},
306+ }
307+ if _ , err := s .MutateRow (ctx , req ); err != nil {
308+ t .Fatalf ("Populating table: %v" , err )
309+ }
310+ }
311+ }
312+
313+ attempts := 500
314+ finished := make (chan bool )
315+ go func () {
316+ populate ()
317+ mock := & MockSampleRowKeysServer {}
318+ for i := 0 ; i < attempts ; i ++ {
319+ if err := s .SampleRowKeys (& btpb.SampleRowKeysRequest {TableName : tbl .Name }, mock ); err != nil {
320+ t .Errorf ("SampleRowKeys error: %v" , err )
321+ }
322+ }
323+ finished <- true
324+ }()
325+ go func () {
326+ for i := 0 ; i < attempts ; i ++ {
327+ req := & btapb.DropRowRangeRequest {
328+ Name : tbl .Name ,
329+ Target : & btapb.DropRowRangeRequest_DeleteAllDataFromTable {DeleteAllDataFromTable : true },
330+ }
331+ if _ , err = s .DropRowRange (ctx , req ); err != nil {
332+ t .Fatalf ("Dropping all rows: %v" , err )
333+ }
334+ }
335+ finished <- true
336+ }()
337+ for i := 0 ; i < 2 ; i ++ {
338+ select {
339+ case <- finished :
340+ case <- time .After (2 * time .Second ):
341+ t .Fatalf ("Timeout waiting for task %d\n " , i )
342+ }
343+ }
344+ }
345+
276346func TestDropRowRange (t * testing.T ) {
277347 s := & server {
278348 tables : make (map [string ]* table ),
0 commit comments