Skip to content
Snippets Groups Projects
Commit d7d42d36 authored by vito.he's avatar vito.he
Browse files

Add:identifier ut

parent 7b8cecf7
No related branches found
No related tags found
No related merge requests found
Showing
with 245 additions and 44 deletions
......@@ -57,7 +57,7 @@ func Test_refresh(t *testing.T) {
// id: "shanghai_reg1",
// Protocol: "mock",
// TimeoutStr: "2s",
// Group: "shanghai_idc",
// group: "shanghai_idc",
// Address: "127.0.0.1:2181",
// Username: "user1",
// Password: "pwd1",
......@@ -160,7 +160,7 @@ func Test_appExternal_refresh(t *testing.T) {
// id: "shanghai_reg1",
// Protocol: "mock",
// TimeoutStr: "2s",
// Group: "shanghai_idc",
// group: "shanghai_idc",
// Address: "127.0.0.1:2181",
// Username: "user1",
// Password: "pwd1",
......@@ -255,7 +255,7 @@ func Test_appExternalWithoutId_refresh(t *testing.T) {
// id: "shanghai_reg1",
// Protocol: "mock",
// TimeoutStr: "2s",
// Group: "shanghai_idc",
// group: "shanghai_idc",
// Address: "127.0.0.1:2181",
// Username: "user1",
// Password: "pwd1",
......@@ -412,7 +412,7 @@ func Test_refreshProvider(t *testing.T) {
// id: "shanghai_reg1",
// Protocol: "mock",
// TimeoutStr: "2s",
// Group: "shanghai_idc",
// group: "shanghai_idc",
// Address: "127.0.0.1:2181",
// Username: "user1",
// Password: "pwd1",
......
......@@ -202,6 +202,7 @@ func (c *ServiceConfig) Unexport() {
exporter.Unexport()
}
c.exporters = nil
c.exported.Store(false)
c.unexported.Store(true)
}
......
......@@ -159,7 +159,7 @@ func Test_RemoveListener(t *testing.T) {
func TestZookeeperDynamicConfiguration_PublishConfig(t *testing.T) {
value := "Test Data"
customGroup := "Custom Group"
customGroup := "Custom group"
key := "myKey"
ts, zk := initZkData(config_center.DEFAULT_GROUP, t)
defer ts.Stop()
......
......@@ -19,6 +19,9 @@ package definition
import (
"bytes"
)
import (
"github.com/apache/dubbo-go/common"
)
......
......@@ -25,19 +25,21 @@ import (
"github.com/apache/dubbo-go/common/constant"
)
type BaseMetadataIdentifier interface {
getFilePathKey(params ...string) string
getIdentifierKey(params ...string) string
// BaseMetadataIdentifier defined for describe the Metadata base identify
type IMetadataIdentifier interface {
GetFilePathKey() string
GetIdentifierKey() string
}
type BaseServiceMetadataIdentifier struct {
serviceInterface string
version string
group string
side string
// BaseMetadataIdentifier is the base implement of BaseMetadataIdentifier interface
type BaseMetadataIdentifier struct {
ServiceInterface string
Version string
Group string
Side string
}
// joinParams...
// joinParams will join the specified char in slice, and build as string
func joinParams(joinChar string, params []string) string {
var joinedStr string
for _, param := range params {
......@@ -47,24 +49,24 @@ func joinParams(joinChar string, params []string) string {
return joinedStr
}
// getIdentifierKey...
func (mdi *BaseServiceMetadataIdentifier) getIdentifierKey(params ...string) string {
return mdi.serviceInterface +
constant.KEY_SEPARATOR + mdi.version +
constant.KEY_SEPARATOR + mdi.group +
constant.KEY_SEPARATOR + mdi.side +
// getIdentifierKey will return string format as service:Version:Group:Side:param1:param2...
func (mdi *BaseMetadataIdentifier) getIdentifierKey(params ...string) string {
return mdi.ServiceInterface +
constant.KEY_SEPARATOR + mdi.Version +
constant.KEY_SEPARATOR + mdi.Group +
constant.KEY_SEPARATOR + mdi.Side +
joinParams(constant.KEY_SEPARATOR, params)
}
// getFilePathKey...
func (mdi *BaseServiceMetadataIdentifier) getFilePathKey(params ...string) string {
path := serviceToPath(mdi.serviceInterface)
// getFilePathKey will return string format as metadata/path/Version/Group/Side/param1/param2...
func (mdi *BaseMetadataIdentifier) getFilePathKey(params ...string) string {
path := serviceToPath(mdi.ServiceInterface)
return constant.DEFAULT_PATH_TAG +
withPathSeparator(path) +
withPathSeparator(mdi.version) +
withPathSeparator(mdi.group) +
withPathSeparator(mdi.side) +
withPathSeparator(mdi.Version) +
withPathSeparator(mdi.Group) +
withPathSeparator(mdi.Side) +
joinParams("/", params)
}
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package identifier
import (
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
var baseId = &BaseMetadataIdentifier{
ServiceInterface: "org.apache.pkg.mockService",
Version: "1.0.0",
Group: "Group",
Side: "provider",
}
func TestBaseGetFilePathKey(t *testing.T) {
assert.Equal(t, "metadata/1.0.0/Group/provider/a/b/c", baseId.getFilePathKey("a", "b", "c"))
}
func TestBaseGetIdentifierKey(t *testing.T) {
assert.Equal(t, "org.apache.pkg.mockService:1.0.0:Group:provider:a:b:c", baseId.getIdentifierKey("a", "b", "c"))
}
......@@ -17,17 +17,18 @@
package identifier
// MetadataIdentifier is inherit baseMetaIdentifier with Application name
type MetadataIdentifier struct {
application string
Application string
BaseMetadataIdentifier
}
// getIdentifierKey...
func (mdi *MetadataIdentifier) getIdentifierKey(params ...string) string {
return mdi.BaseMetadataIdentifier.getIdentifierKey(mdi.application)
func (mdi *MetadataIdentifier) GetIdentifierKey() string {
return mdi.BaseMetadataIdentifier.getIdentifierKey(mdi.Application)
}
// getIdentifierKey...
func (mdi *MetadataIdentifier) getFilePathKey(params ...string) string {
return mdi.BaseMetadataIdentifier.getFilePathKey(mdi.application)
func (mdi *MetadataIdentifier) GetFilePathKey() string {
return mdi.BaseMetadataIdentifier.getFilePathKey(mdi.Application)
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package identifier
import (
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
var metadataId = &MetadataIdentifier{
Application: "app",
BaseMetadataIdentifier: BaseMetadataIdentifier{
ServiceInterface: "org.apache.pkg.mockService",
Version: "1.0.0",
Group: "Group",
Side: "provider",
},
}
func TestGetFilePathKey(t *testing.T) {
assert.Equal(t, "metadata/1.0.0/Group/provider/app", metadataId.GetFilePathKey())
}
func TestGetIdentifierKey(t *testing.T) {
assert.Equal(t, "org.apache.pkg.mockService:1.0.0:Group:provider:app", metadataId.GetIdentifierKey())
}
......@@ -21,18 +21,19 @@ import (
"github.com/apache/dubbo-go/common/constant"
)
// ServiceMetadataIdentifier is inherit baseMetaIdentifier with service params: Revision and Protocol
type ServiceMetadataIdentifier struct {
revision string
protocol string
Revision string
Protocol string
BaseMetadataIdentifier
}
// getIdentifierKey...
func (mdi *ServiceMetadataIdentifier) getIdentifierKey(params ...string) string {
return mdi.BaseMetadataIdentifier.getIdentifierKey(mdi.protocol + constant.KEY_REVISON_PREFIX + mdi.revision)
func (mdi *ServiceMetadataIdentifier) GetIdentifierKey() string {
return mdi.BaseMetadataIdentifier.getIdentifierKey(mdi.Protocol, constant.KEY_REVISON_PREFIX+mdi.Revision)
}
// getIdentifierKey...
func (mdi *ServiceMetadataIdentifier) getFilePathKey(params ...string) string {
return mdi.BaseMetadataIdentifier.getFilePathKey(mdi.protocol + constant.KEY_REVISON_PREFIX + mdi.revision)
func (mdi *ServiceMetadataIdentifier) GetFilePathKey() string {
return mdi.BaseMetadataIdentifier.getFilePathKey(mdi.Protocol, constant.KEY_REVISON_PREFIX+mdi.Revision)
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package identifier
import (
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
var serviceMetadataId = &ServiceMetadataIdentifier{
Revision: "1.0",
Protocol: "dubbo",
BaseMetadataIdentifier: BaseMetadataIdentifier{
ServiceInterface: "org.apache.pkg.mockService",
Version: "1.0.0",
Group: "Group",
Side: "provider",
},
}
func TestServiceGetFilePathKey(t *testing.T) {
assert.Equal(t, "metadata/1.0.0/Group/provider/dubbo/revision1.0", serviceMetadataId.GetFilePathKey())
}
func TestServiceGetIdentifierKey(t *testing.T) {
assert.Equal(t, "org.apache.pkg.mockService:1.0.0:Group:provider:dubbo:revision1.0", serviceMetadataId.GetIdentifierKey())
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package identifier
// SubscriberMetadataIdentifier is inherit baseMetaIdentifier with service params: Revision
type SubscriberMetadataIdentifier struct {
revision string
Revision string
BaseMetadataIdentifier
}
// getIdentifierKey...
func (mdi *SubscriberMetadataIdentifier) getIdentifierKey(params ...string) string {
return mdi.BaseMetadataIdentifier.getIdentifierKey(mdi.revision)
func (mdi *SubscriberMetadataIdentifier) GetIdentifierKey() string {
return mdi.BaseMetadataIdentifier.getIdentifierKey(mdi.Revision)
}
// getIdentifierKey...
func (mdi *SubscriberMetadataIdentifier) getFilePathKey(params ...string) string {
return mdi.BaseMetadataIdentifier.getFilePathKey(mdi.revision)
func (mdi *SubscriberMetadataIdentifier) GetFilePathKey() string {
return mdi.BaseMetadataIdentifier.getFilePathKey(mdi.Revision)
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package identifier
import (
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
var subscribeMetadataId = &SubscriberMetadataIdentifier{
Revision: "1.0",
BaseMetadataIdentifier: BaseMetadataIdentifier{
ServiceInterface: "org.apache.pkg.mockService",
Version: "1.0.0",
Group: "Group",
Side: "provider",
},
}
func TestSubscribeGetFilePathKey(t *testing.T) {
assert.Equal(t, "metadata/1.0.0/Group/provider/1.0", subscribeMetadataId.GetFilePathKey())
}
func TestSubscribeGetIdentifierKey(t *testing.T) {
assert.Equal(t, "org.apache.pkg.mockService:1.0.0:Group:provider:1.0", subscribeMetadataId.GetIdentifierKey())
}
......@@ -18,7 +18,6 @@
package configurable
import (
"fmt"
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config"
_ "github.com/apache/dubbo-go/filter/filter_impl"
......@@ -53,5 +52,7 @@ func TestConfigurableExporter(t *testing.T) {
assert.Equal(t, false, exported.IsExported())
assert.NoError(t, exported.Export())
assert.Equal(t, true, exported.IsExported())
fmt.Println(exported.GetExportedURLs())
assert.Regexp(t, "dubbo://:20000/MetadataService*", exported.GetExportedURLs()[0].String())
exported.Unexport()
assert.Equal(t, false, exported.IsExported())
}
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