Skip to content

Commit

Permalink
context parseRefers compatible with motanV1Compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
liangwei3 committed Apr 9, 2024
1 parent 8aff236 commit 1537870
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
57 changes: 57 additions & 0 deletions config/compatible.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#only for unit test!!
motan-agent:
port: 9981
mport: 8002
#log_dir: "/data1/logs/agentlog/"
log_dir: "./logs"
registry: "vintage"
application: "pc-yf-test"

motan-server:
testkey:testv

motan-client:
testkey:testv

#config of registries
motan-registry:
vintage:
protocol: vintage
host: 10.**.**.**
port: 8090
registryRetryPeriod: 30000
registrySessionTimeout: 10000
requestTimeout: 5000
consul:
protocol: consul
host: 10.**.**.**
port: 8090
direct:
protocol: direct
host: 10.**.**.**
port: 8013

#conf of basic refers
motan-basicRefer:
mybasicRefer:
group: basic-group
registry: "vintage"
requestTimeout: 1000
haStrategy: failover
loadbalance: random
filter: "accessLog,metrics"
maxClientConnection: 10
minClientConnection: 1
retries: 0
application: pc

#conf of refers
motan-refer:
status-rpc-json:
path: com.weibo.api.test.service.TestRpc
group: test-group
registry: vintage
serialization: simple
protocol: motanV1Compatible
version: 0.1
basicRefer: mybasicRefer
6 changes: 6 additions & 0 deletions core/globalContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ func (c *Context) parseSubGroupSuffix(urlMap map[string]*URL) {
func (c *Context) parseRefers() {
referUrls := c.basicConfToURLs(refersSection)
c.parseSubGroupSuffix(referUrls)
//TODO: to compatible with removed protocol: motanV1Compatible
for k := range referUrls {
if referUrls[k].Protocol == "motanV1Compatible" {
referUrls[k].Protocol = "motan"
}
}
c.RefersURLs = referUrls
}

Expand Down
9 changes: 9 additions & 0 deletions core/globalContext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ func TestGetContext(t *testing.T) {
assert.Equal(t, "motan-demo-rpc", rs.ServiceURLs["mytest-motan2"].Group, "parse serivce key fail")
}

func TestCompatible(t *testing.T) {
rs := &Context{ConfigFile: "../config/compatible.yaml"}
rs.Initialize()
assert.NotNil(t, rs.RefersURLs)
for _, j := range rs.RefersURLs {
assert.Equal(t, j.Protocol, "motan")
}
}

func TestNewContext(t *testing.T) {
configFile := filepath.Join("testdata", "app.yaml")
pool1Context := NewContext(configFile, "app", "app-idc1")
Expand Down

0 comments on commit 1537870

Please sign in to comment.