Skip to content
Snippets Groups Projects
Commit 29144da9 authored by lizhipeng's avatar lizhipeng
Browse files

fix synthesizer bug

parent 79aa2d24
No related branches found
No related tags found
No related merge requests found
......@@ -276,7 +276,7 @@ func (s *serviceDiscoveryRegistry) findMappedServices(url common.URL) *gxset.Has
}
func (s *serviceDiscoveryRegistry) getExportedUrls(subscribedURL common.URL, serviceInstances []registry.ServiceInstance) []common.URL {
filterInstances := make([]registry.ServiceInstance, len(serviceInstances), len(serviceInstances))
var filterInstances []registry.ServiceInstance
for _, s := range serviceInstances {
if !s.IsEnable() || !s.IsHealthy() {
continue
......
......@@ -22,6 +22,7 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/registry"
"github.com/apache/dubbo-go/registry/service/synthesizer"
"net/url"
"strings"
)
......@@ -41,15 +42,16 @@ func (r RestSubscribedURLsSynthesizer) Support(subscribedURL *common.URL) bool {
func (r RestSubscribedURLsSynthesizer) Synthesize(subscribedURL *common.URL, serviceInstances []registry.ServiceInstance) []common.URL {
urls := make([]common.URL, len(serviceInstances), len(serviceInstances))
for _, s := range serviceInstances {
for i, s := range serviceInstances {
splitHost := strings.Split(s.GetHost(), ":")
url := common.NewURLWithOptions(common.WithProtocol(subscribedURL.Protocol), common.WithIp(splitHost[0]),
u := common.NewURLWithOptions(common.WithProtocol(subscribedURL.Protocol), common.WithIp(splitHost[0]),
common.WithPort(splitHost[1]), common.WithPath(subscribedURL.GetParam(constant.INTERFACE_KEY, subscribedURL.Path)),
common.WithParams(url.Values{}),
common.WithParamsValue(constant.SIDE_KEY, constant.PROVIDER_PROTOCOL),
common.WithParamsValue(constant.APPLICATION_KEY, s.GetServiceName()),
common.WithParamsValue(constant.REGISTRY_KEY, "true"),
)
urls = append(urls, *url)
urls[i] = *u
}
return urls
}
......
......@@ -22,6 +22,7 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/registry"
"github.com/stretchr/testify/assert"
"net/url"
"testing"
)
......@@ -50,13 +51,19 @@ func TestRestSubscribedURLsSynthesizer_Synthesize(t *testing.T) {
}
var expectUrls []common.URL
u1, _ := common.NewURL("rest://127.0.0.1:80/org.apache.dubbo-go.mockService", common.WithParamsValue(constant.SIDE_KEY,
constant.PROVIDER_PROTOCOL), common.WithParamsValue(constant.APPLICATION_KEY, "test1"),
u1 := common.NewURLWithOptions(common.WithProtocol("rest"), common.WithIp("127.0.0.1"),
common.WithPort("80"), common.WithPath("org.apache.dubbo-go.mockService"),
common.WithParams(url.Values{}),
common.WithParamsValue(constant.SIDE_KEY, constant.PROVIDER_PROTOCOL),
common.WithParamsValue(constant.APPLICATION_KEY, "test1"),
common.WithParamsValue(constant.REGISTRY_KEY, "true"))
u2, _ := common.NewURL("rest://127.0.0.2:8081/org.apache.dubbo-go.mockService", common.WithParamsValue(constant.SIDE_KEY,
constant.PROVIDER_PROTOCOL), common.WithParamsValue(constant.APPLICATION_KEY, "test2"),
u2 := common.NewURLWithOptions(common.WithProtocol("rest"), common.WithIp("127.0.0.2"),
common.WithPort("8081"), common.WithPath("org.apache.dubbo-go.mockService"),
common.WithParams(url.Values{}),
common.WithParamsValue(constant.SIDE_KEY, constant.PROVIDER_PROTOCOL),
common.WithParamsValue(constant.APPLICATION_KEY, "test2"),
common.WithParamsValue(constant.REGISTRY_KEY, "true"))
expectUrls = append(expectUrls, u1, u2)
expectUrls = append(expectUrls, *u1, *u2)
result := syn.Synthesize(&subUrl, instances)
assert.Equal(t, expectUrls, result)
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment