diff --git a/endpoint/motanCommonEndpoint.go b/endpoint/motanCommonEndpoint.go index be0bfa91..538967ec 100644 --- a/endpoint/motanCommonEndpoint.go +++ b/endpoint/motanCommonEndpoint.go @@ -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) } diff --git a/endpoint/motanCommonEndpoint_test.go b/endpoint/motanCommonEndpoint_test.go index edb70c98..2957c717 100644 --- a/endpoint/motanCommonEndpoint_test.go +++ b/endpoint/motanCommonEndpoint_test.go @@ -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")