MCPcopy
hub / github.com/dgraph-io/dgraph / TestIdBump

Function TestIdBump

dgraph/cmd/zero/zero_test.go:57–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

55}
56
57func TestIdBump(t *testing.T) {
58 dialOpts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
59 con, err := grpc.NewClient(testutil.GetSockAddrZero(), dialOpts...)
60 require.NoError(t, err)
61 zc := pb.NewZeroClient(con)
62
63 ctx := context.Background()
64 res, err := zc.AssignIds(ctx, &pb.Num{Val: 10, Type: pb.Num_UID})
65 require.NoError(t, err)
66 require.Equal(t, uint64(10), res.GetEndId()-res.GetStartId()+1)
67
68 // Next assignment's startId should be greater than 10.
69 res, err = zc.AssignIds(ctx, &pb.Num{Val: 50, Type: pb.Num_UID})
70 require.NoError(t, err)
71 require.Greater(t, res.GetStartId(), uint64(10))
72 require.Equal(t, uint64(50), res.GetEndId()-res.GetStartId()+1)
73
74 bumpTo := res.GetEndId() + 100000
75
76 // Bump the lease to (last result + 100000).
77 _, err = zc.AssignIds(ctx, &pb.Num{Val: bumpTo, Type: pb.Num_UID, Bump: true})
78 require.NoError(t, err)
79
80 // Next assignment's startId should be greater than bumpTo.
81 res, err = zc.AssignIds(ctx, &pb.Num{Val: 10, Type: pb.Num_UID})
82 require.NoError(t, err)
83 require.Greater(t, res.GetStartId(), bumpTo)
84 require.Equal(t, uint64(10), res.GetEndId()-res.GetStartId()+1)
85
86 // If bump request is less than maxLease, then it should result in no-op.
87 _, err = zc.AssignIds(ctx, &pb.Num{Val: 10, Type: pb.Num_UID, Bump: true})
88 require.Contains(t, err.Error(), "Nothing to be leased")
89}
90
91func TestProposalKey(t *testing.T) {
92 id := uint64(2)

Callers

nothing calls this directly

Calls 6

AssignIdsMethod · 0.95
GetSockAddrZeroFunction · 0.92
NewZeroClientFunction · 0.92
GetEndIdMethod · 0.80
GetStartIdMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected