Skip to content

Commit

Permalink
apply awareness
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroFruit committed Mar 26, 2019
1 parent 4d1bf4e commit 5ad896d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions swim.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,20 @@ func (s *SWIM) probe(member Member) {
// if successfully probed target member, then just return
case <-end:
iLogger.Infof(nil, "probe member [%s] successfully finished", member.ID)
s.awareness.ApplyDelta(-1)
return

// if probe failed, then suspect member
case <-failed:
iLogger.Infof(nil, "probe member [%s] failed, start suspect", member.ID)
s.awareness.ApplyDelta(1)
s.suspect(&member)
return

// if timed-out, then suspect member
case <-T.C:
iLogger.Infof(nil, "probe member [%s] failed, start suspect", member.ID)
s.awareness.ApplyDelta(1)
s.suspect(&member)
return
}
Expand Down
18 changes: 18 additions & 0 deletions swim_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1581,8 +1581,12 @@ func TestSWIM_probe_When_Target_Respond_To_Ping(t *testing.T) {
Port: 11162,
}

awareness := NewAwareness(8)
awareness.ApplyDelta(2)

swim := &SWIM{}
swim.member = mI
swim.awareness = awareness
swim.config = config
swim.mbrStatsMsgStore = pbkStore
swim.memberMap = mm
Expand All @@ -1607,6 +1611,8 @@ func TestSWIM_probe_When_Target_Respond_To_Ping(t *testing.T) {
defer mIMessageEndpoint.Shutdown()

swim.probe(mJMember)

assert.Equal(t, swim.awareness.score, 1)
}

// This test case is for testing if we failed at ping to M_J, then indirect-probing is execute
Expand Down Expand Up @@ -1678,8 +1684,12 @@ func TestSWIM_probe_When_Target_Respond_To_Indirect_Ping(t *testing.T) {
mm.members[m1Member.ID] = m1Member
mm.members[m2Member.ID] = m2Member

awareness := NewAwareness(8)
awareness.ApplyDelta(2)

swim := &SWIM{}
swim.member = mI
swim.awareness = awareness
swim.config = config
swim.mbrStatsMsgStore = pbkStore
swim.memberMap = mm
Expand Down Expand Up @@ -1758,6 +1768,8 @@ func TestSWIM_probe_When_Target_Respond_To_Indirect_Ping(t *testing.T) {

mJMember := Member{ID: MemberID{ID: "mj"}, Addr: net.ParseIP("127.0.0.1"), Port: 11161, Status: Alive}
swim.probe(mJMember)

assert.Equal(t, swim.awareness.score, 1)
}

// This test case is for testing if we failed at ping to M_J, then indirect-probing is execute
Expand Down Expand Up @@ -1818,8 +1830,12 @@ func TestSWIM_probe_When_Target_Not_Respond_To_Indirect_Ping(t *testing.T) {
mm.members[m1Member.ID] = m1Member
mm.members[m2Member.ID] = m2Member

awareness := NewAwareness(8)
awareness.ApplyDelta(2)

swim := &SWIM{}
swim.member = mI
swim.awareness = awareness
swim.config = config
swim.mbrStatsMsgStore = pbkStore
swim.memberMap = mm
Expand Down Expand Up @@ -1906,6 +1922,8 @@ func TestSWIM_probe_When_Target_Not_Respond_To_Indirect_Ping(t *testing.T) {
mJMember := Member{ID: MemberID{ID: "mj"}, Addr: net.ParseIP("127.0.0.1"), Port: 11161, Status: Alive}

swim.probe(mJMember)

assert.Equal(t, swim.awareness.score, 3)
}

func createMessageEndpoint(t *testing.T, messageHandler MessageHandler, sendTimeout time.Duration, port int) MessageEndpoint {
Expand Down

0 comments on commit 5ad896d

Please sign in to comment.