Skip to content

Commit

Permalink
kvserver: add LookupNextReplica test
Browse files Browse the repository at this point in the history
Release note: none
Epic: none
  • Loading branch information
pav-kv committed Jan 31, 2023
1 parent 23be73b commit 198090b
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions pkg/kv/kvserver/store_replica_btree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestStoreReplicaBTree_VisitKeyRange(t *testing.T) {
})
}

func TestStoreReplicaBTree_LookupPrecedingReplica(t *testing.T) {
func TestStoreReplicaBTree_LookupPrecedingAndNextReplica(t *testing.T) {
defer leaktest.AfterTest(t)()

ctx := context.Background()
Expand Down Expand Up @@ -116,25 +116,29 @@ func TestStoreReplicaBTree_LookupPrecedingReplica(t *testing.T) {
require.Zero(t, b.ReplaceOrInsertReplica(ctx, repl5))

for i, tc := range []struct {
key string
expRepl *Replica
key string
preRepl *Replica
nextRepl *Replica
}{
{"", nil},
{"a", nil},
{"aa", nil},
{"b", repl2},
{"bb", repl2},
{"c", repl3},
{"cc", repl3},
{"d", repl3},
{"dd", repl3},
{"e", repl3},
{"ee", repl3},
{"f", repl5},
{"\xff\xff", repl5},
{"", nil, repl2},
{"a", nil, repl2},
{"aa", nil, repl3},
{"b", repl2, repl3},
{"bb", repl2, repl5},
{"c", repl3, repl5},
{"cc", repl3, repl5},
{"d", repl3, repl5},
{"dd", repl3, repl5},
{"e", repl3, repl5},
{"ee", repl3, nil},
{"f", repl5, nil},
{"\xff\xff", repl5, nil},
} {
if repl := b.LookupPrecedingReplica(ctx, roachpb.RKey(tc.key)); repl != tc.expRepl {
t.Errorf("%d: expected replica %v; got %v", i, tc.expRepl, repl)
if got, want := b.LookupPrecedingReplica(ctx, roachpb.RKey(tc.key)), tc.preRepl; got != want {
t.Errorf("%d: expected preceding replica %v; got %v", i, want, got)
}
if got, want := b.LookupNextReplica(ctx, roachpb.RKey(tc.key)), tc.nextRepl; got != want {
t.Errorf("%d: expected next replica %v; got %v", i, want, got)
}
}
}
Expand Down

0 comments on commit 198090b

Please sign in to comment.