Skip to content

Commit

Permalink
update:
Browse files Browse the repository at this point in the history
after notify, offline endpoints will be destroyed asynchronously after 2s delay
  • Loading branch information
liangwei3 committed Jul 6, 2023
1 parent e57f0c5 commit f7a78ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
15 changes: 15 additions & 0 deletions cluster/motanCluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,26 @@ func TestNotify(t *testing.T) {
t.Fatalf("cluster notify-refers size not correct. expect :2, refers size:%d", len(cluster.Refers))
}
urls = append(urls, &motan.URL{Host: "127.0.0.1", Port: 8001, Protocol: "test"})
var destroyEndpoint motan.EndPoint
for _, j := range cluster.Refers {
if j.GetURL().Port == 8002 {
destroyEndpoint = j
}
}
if destroyEndpoint == nil {
t.Fatalf("cluster endpoint is nil")
}
if !destroyEndpoint.IsAvailable() {
t.Fatalf("cluster endpoint should be not available")
}
cluster.Notify(RegistryURL, urls)
time.Sleep(time.Second * 3)
if len(cluster.Refers) != 1 {
t.Fatalf("cluster notify-refers size not correct. expect :2, refers size:%d", len(cluster.Refers))
}
if destroyEndpoint.IsAvailable() {
t.Fatalf("cluster endpoint should not be available")
}
}

func TestCall(t *testing.T) {
Expand Down
16 changes: 14 additions & 2 deletions core/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"errors"
"fmt"
"sync/atomic"
"time"
)

Expand Down Expand Up @@ -116,6 +117,7 @@ func (t *TestProvider) GetPath() string {
type TestEndPoint struct {
URL *URL
ProcessTime int64
available atomic.Value
}

func (t *TestEndPoint) GetURL() *URL {
Expand All @@ -137,10 +139,20 @@ func (t *TestEndPoint) Call(request Request) Response {
}

func (t *TestEndPoint) IsAvailable() bool {
return true
return t.available.Load().(bool)
}

func (t *TestEndPoint) Initialize() {
t.SetAvailable(true)
}

func (t *TestEndPoint) Destroy() {}
func (t *TestEndPoint) Destroy() {
t.SetAvailable(false)
}

func (t *TestEndPoint) SetAvailable(a bool) {
t.available.Store(a)
}

func (t *TestEndPoint) SetProxy(proxy bool) {}

Expand Down
4 changes: 3 additions & 1 deletion ha/backupRequestHA_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ func TestBackupRequestHA_Call3(t *testing.T) {
}

func getEP(processTime int64) motan.EndPoint {
fep := &motan.FilterEndPoint{Caller: &motan.TestEndPoint{ProcessTime: processTime}}
caller := &motan.TestEndPoint{ProcessTime: processTime}
motan.Initialize(caller)
fep := &motan.FilterEndPoint{Caller: caller}
mf := &filter.MetricsFilter{}
mf.SetContext(&motan.Context{Config: config.NewConfig()})
mf.SetNext(motan.GetLastEndPointFilter())
Expand Down

0 comments on commit f7a78ae

Please sign in to comment.