@@ -1053,6 +1053,84 @@ func TestReadRowsWithlabelTransformer(t *testing.T) {
10531053 }
10541054}
10551055
1056+ func TestReadRowsReversed (t * testing.T ) {
1057+ ctx := context .Background ()
1058+ srv := & server {
1059+ tables : make (map [string ]* table ),
1060+ }
1061+ newTbl := btapb.Table {
1062+ ColumnFamilies : map [string ]* btapb.ColumnFamily {
1063+ "cf" : {GcRule : & btapb.GcRule {Rule : & btapb.GcRule_MaxNumVersions {MaxNumVersions : 1 }}},
1064+ },
1065+ }
1066+ tbl , err := srv .CreateTable (ctx , & btapb.CreateTableRequest {Parent : "cluster" , TableId : "t" , Table : & newTbl })
1067+ if err != nil {
1068+ t .Fatalf ("Creating table: %v" , err )
1069+ }
1070+ entries := []struct {
1071+ row string
1072+ value []byte
1073+ }{
1074+ {"row1" , []byte ("a" )},
1075+ {"row2" , []byte ("b" )},
1076+ }
1077+
1078+ for _ , entry := range entries {
1079+ req := & btpb.MutateRowRequest {
1080+ TableName : tbl .Name ,
1081+ RowKey : []byte (entry .row ),
1082+ Mutations : []* btpb.Mutation {{
1083+ Mutation : & btpb.Mutation_SetCell_ {SetCell : & btpb.Mutation_SetCell {
1084+ FamilyName : "cf" ,
1085+ ColumnQualifier : []byte ("cq" ),
1086+ TimestampMicros : 1000 ,
1087+ Value : entry .value ,
1088+ }},
1089+ }},
1090+ }
1091+ if _ , err := srv .MutateRow (ctx , req ); err != nil {
1092+ t .Fatalf ("Failed to insert entry %v into server: %v" , entry , err )
1093+ }
1094+ }
1095+
1096+ rrss := new (MockReadRowsServer )
1097+ rreq := & btpb.ReadRowsRequest {TableName : tbl .Name , Reversed : true }
1098+ if err := srv .ReadRows (rreq , rrss ); err != nil {
1099+ t .Fatalf ("Failed to read rows: %v" , err )
1100+ }
1101+
1102+ var gotChunks []* btpb.ReadRowsResponse_CellChunk
1103+ for _ , res := range rrss .responses {
1104+ gotChunks = append (gotChunks , res .Chunks ... )
1105+ }
1106+
1107+ wantChunks := []* btpb.ReadRowsResponse_CellChunk {
1108+ {
1109+ RowKey : []byte ("row2" ),
1110+ FamilyName : & wrappers.StringValue {Value : "cf" },
1111+ Qualifier : & wrappers.BytesValue {Value : []byte ("cq" )},
1112+ TimestampMicros : 1000 ,
1113+ Value : []byte ("b" ),
1114+ RowStatus : & btpb.ReadRowsResponse_CellChunk_CommitRow {
1115+ CommitRow : true ,
1116+ },
1117+ },
1118+ {
1119+ RowKey : []byte ("row1" ),
1120+ FamilyName : & wrappers.StringValue {Value : "cf" },
1121+ Qualifier : & wrappers.BytesValue {Value : []byte ("cq" )},
1122+ TimestampMicros : 1000 ,
1123+ Value : []byte ("a" ),
1124+ RowStatus : & btpb.ReadRowsResponse_CellChunk_CommitRow {
1125+ CommitRow : true ,
1126+ },
1127+ },
1128+ }
1129+ if diff := cmp .Diff (gotChunks , wantChunks , cmp .Comparer (proto .Equal )); diff != "" {
1130+ t .Fatalf ("Response chunks mismatch: got: + want -\n %s" , diff )
1131+ }
1132+ }
1133+
10561134func TestCheckAndMutateRowWithoutPredicate (t * testing.T ) {
10571135 s := & server {
10581136 tables : make (map [string ]* table ),
0 commit comments