Skip to content

Commit

Permalink
Merge pull request #400 from cocowh/fix/endpoint
Browse files Browse the repository at this point in the history
fix motanCommonEndpoint.IsAvailable()
  • Loading branch information
rayzhang0603 authored Jun 19, 2024
2 parents db5aa0a + 30745c1 commit 9a0f42f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions endpoint/motanCommonEndpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ func (m *MotanCommonEndpoint) SetURL(url *motan.URL) {
}

func (m *MotanCommonEndpoint) IsAvailable() bool {
if m.available.Load() == nil {
return false
}
return m.available.Load().(bool)
}

Expand Down
17 changes: 17 additions & 0 deletions endpoint/motanCommonEndpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ import (
"time"
)

func TestNotInitCommonEndpoint(t *testing.T) {
url := &motan.URL{Port: 8989, Protocol: "motan"}
url.PutParam(motan.TimeOutKey, "100")
url.PutParam(motan.AsyncInitConnection, "false")
ep := &MotanCommonEndpoint{}
ep.SetURL(url)

ep.SetProxy(true)
ep.SetSerialization(&serialize.SimpleSerialization{})
assert.Equal(t, false, ep.IsAvailable())
assert.Nil(t, ep.keepaliveRunning.Load())

ep.Initialize()
assert.Equal(t, true, ep.IsAvailable())
assert.Equal(t, false, ep.keepaliveRunning.Load())
}

func TestGetV1Name(t *testing.T) {
url := &motan.URL{Port: 8989, Protocol: "motan"}
url.PutParam(motan.TimeOutKey, "100")
Expand Down

0 comments on commit 9a0f42f

Please sign in to comment.