mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
lease: remove redundant get method
This commit is contained in:
parent
c349e089b1
commit
4871a4a5f3
@ -274,10 +274,7 @@ func (le *lessor) Renew(id LeaseID) (int64, error) {
|
||||
func (le *lessor) Lookup(id LeaseID) *Lease {
|
||||
le.mu.Lock()
|
||||
defer le.mu.Unlock()
|
||||
if l, ok := le.leaseMap[id]; ok {
|
||||
return l
|
||||
}
|
||||
return nil
|
||||
return le.leaseMap[id]
|
||||
}
|
||||
|
||||
func (le *lessor) Promote(extend time.Duration) {
|
||||
@ -408,15 +405,6 @@ func (le *lessor) findExpiredLeases() []*Lease {
|
||||
return leases
|
||||
}
|
||||
|
||||
// get gets the lease with given id.
|
||||
// get is a helper function for testing, at least for now.
|
||||
func (le *lessor) get(id LeaseID) *Lease {
|
||||
le.mu.Lock()
|
||||
defer le.mu.Unlock()
|
||||
|
||||
return le.leaseMap[id]
|
||||
}
|
||||
|
||||
func (le *lessor) initAndRecover() {
|
||||
tx := le.b.BatchTx()
|
||||
tx.Lock()
|
||||
|
@ -43,7 +43,7 @@ func TestLessorGrant(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("could not grant lease 1 (%v)", err)
|
||||
}
|
||||
gl := le.get(l.ID)
|
||||
gl := le.Lookup(l.ID)
|
||||
|
||||
if !reflect.DeepEqual(gl, l) {
|
||||
t.Errorf("lease = %v, want %v", gl, l)
|
||||
@ -107,7 +107,7 @@ func TestLessorRevoke(t *testing.T) {
|
||||
t.Fatal("failed to revoke lease:", err)
|
||||
}
|
||||
|
||||
if le.get(l.ID) != nil {
|
||||
if le.Lookup(l.ID) != nil {
|
||||
t.Errorf("got revoked lease %x", l.ID)
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ func TestLessorRenew(t *testing.T) {
|
||||
t.Errorf("ttl = %d, want %d", ttl, l.TTL)
|
||||
}
|
||||
|
||||
l = le.get(l.ID)
|
||||
l = le.Lookup(l.ID)
|
||||
if l.expiry.Sub(time.Now()) < 9*time.Second {
|
||||
t.Errorf("failed to renew the lease")
|
||||
}
|
||||
@ -210,12 +210,12 @@ func TestLessorRecover(t *testing.T) {
|
||||
|
||||
// Create a new lessor with the same backend
|
||||
nle := newLessor(be, minLeaseTTL)
|
||||
nl1 := nle.get(l1.ID)
|
||||
nl1 := nle.Lookup(l1.ID)
|
||||
if nl1 == nil || nl1.TTL != l1.TTL {
|
||||
t.Errorf("nl1 = %v, want nl1.TTL= %d", nl1.TTL, l1.TTL)
|
||||
}
|
||||
|
||||
nl2 := nle.get(l2.ID)
|
||||
nl2 := nle.Lookup(l2.ID)
|
||||
if nl2 == nil || nl2.TTL != l2.TTL {
|
||||
t.Errorf("nl2 = %v, want nl2.TTL= %d", nl2.TTL, l2.TTL)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user