Skip to content

Commit

Permalink
Fix #23
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyx committed Jun 5, 2018
2 parents 7e827bf + 87b8d92 commit f4849f8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions componet_notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func getRemoteConfig() ([]*apolloNotify,error) {
Timeout:nofity_connect_timeout,
},&CallBack{
SuccessCallBack:getRemoteConfigSuccessCallBack,
NotModifyCallBack:touchApolloConfigCache,
})

if notifies==nil{
Expand Down
55 changes: 55 additions & 0 deletions componet_timer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"github.com/zouyx/agollo/test"
"time"
"fmt"
)

//func TestInitRefreshInterval(t *testing.T) {
Expand Down Expand Up @@ -37,6 +38,60 @@ func TestAutoSyncConfigServices(t *testing.T) {
//test.Equal(t,"value2",config.Configurations["key2"])
}

func TestAutoSyncConfigServicesNormal2NotModified(t *testing.T) {
go runMockConfigServer(longNotmodifiedConfigResponse)
defer closeMockConfigServer()

time.Sleep(1*time.Second)

appConfig.NextTryConnTime=0

autoSyncConfigServicesSuccessCallBack([]byte(configResponseStr))

config:=GetCurrentApolloConfig()

fmt.Println("sleeping 10s")

time.Sleep(10*time.Second)

fmt.Println("checking cache time left")
it := apolloConfigCache.NewIterator()
for i := int64(0); i < apolloConfigCache.EntryCount(); i++ {
entry := it.Next()
if entry==nil{
break
}
timeLeft, err := apolloConfigCache.TTL([]byte(entry.Key))
test.Nil(t,err)
fmt.Printf("key:%s,time:%v \n",string(entry.Key),timeLeft)
test.Equal(t,timeLeft>=110,true)
}

test.Equal(t,"100004458",config.AppId)
test.Equal(t,"default",config.Cluster)
test.Equal(t,"application",config.NamespaceName)
test.Equal(t,"20170430092936-dee2d58e74515ff3",config.ReleaseKey)
test.Equal(t,"value1",getValue("key1"))
test.Equal(t,"value2",getValue("key2"))

err:=autoSyncConfigServices()

fmt.Println("checking cache time left")
it1 := apolloConfigCache.NewIterator()
for i := int64(0); i < apolloConfigCache.EntryCount(); i++ {
entry := it1.Next()
if entry==nil{
break
}
timeLeft, err := apolloConfigCache.TTL([]byte(entry.Key))
test.Nil(t,err)
fmt.Printf("key:%s,time:%v \n",string(entry.Key),timeLeft)
test.Equal(t,timeLeft>=120,true)
}

fmt.Println(err)
}

//test if not modify
func TestAutoSyncConfigServicesNotModify(t *testing.T) {
go runMockConfigServer(notModifyConfigResponse)
Expand Down
5 changes: 5 additions & 0 deletions config_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func normalConfigResponse(rw http.ResponseWriter, req *http.Request) {
}
}

func longNotmodifiedConfigResponse(rw http.ResponseWriter, req *http.Request) {
time.Sleep(500 * time.Microsecond)
rw.WriteHeader(http.StatusNotModified)
}

func changeConfigResponse(rw http.ResponseWriter, req *http.Request) {
fmt.Fprintf(rw, configChangeResponseStr)
}
Expand Down

0 comments on commit f4849f8

Please sign in to comment.