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

Mod:rw problem

parent 82ab22b9
No related branches found
No related tags found
No related merge requests found
......@@ -239,12 +239,12 @@ func GetApplicationConfig() *ApplicationConfig {
// GetProviderConfig find the provider config
// if not found, create new one
func GetProviderConfig() ProviderConfig {
func GetProviderConfig() *ProviderConfig {
if providerConfig == nil {
logger.Warnf("providerConfig is nil!")
return ProviderConfig{}
return &ProviderConfig{}
}
return *providerConfig
return providerConfig
}
// GetConsumerConfig find the consumer config
......
......@@ -18,6 +18,7 @@
package config
import (
"go.uber.org/atomic"
"path/filepath"
"testing"
)
......@@ -90,7 +91,7 @@ func TestLoad(t *testing.T) {
func TestLoadWithSingleReg(t *testing.T) {
doInitConsumerWithSingleRegistry()
MockInitProviderWithSingleRegistry()
mockInitProviderWithSingleRegistry()
ms := &MockService{}
SetConsumerService(ms)
......@@ -233,3 +234,55 @@ func TestConfigLoaderWithConfigCenterSingleRegistry(t *testing.T) {
assert.Equal(t, "mock://127.0.0.1:2182", consumerConfig.Registries[constant.DEFAULT_KEY].Address)
}
// mockInitProviderWithSingleRegistry will init a mocked providerConfig
func mockInitProviderWithSingleRegistry() {
providerConfig = &ProviderConfig{
ApplicationConfig: &ApplicationConfig{
Organization: "dubbo_org",
Name: "dubbo",
Module: "module",
Version: "2.6.0",
Owner: "dubbo",
Environment: "test"},
Registry: &RegistryConfig{
Address: "mock://127.0.0.1:2181",
Username: "user1",
Password: "pwd1",
},
Registries: map[string]*RegistryConfig{},
Services: map[string]*ServiceConfig{
"MockService": {
InterfaceName: "com.MockService",
Protocol: "mock",
Cluster: "failover",
Loadbalance: "random",
Retries: "3",
Group: "huadong_idc",
Version: "1.0.0",
Methods: []*MethodConfig{
{
Name: "GetUser",
Retries: "2",
Loadbalance: "random",
Weight: 200,
},
{
Name: "GetUser1",
Retries: "2",
Loadbalance: "random",
Weight: 200,
},
},
exported: new(atomic.Bool),
},
},
Protocols: map[string]*ProtocolConfig{
"mock": {
Name: "mock",
Ip: "127.0.0.1",
Port: "20000",
},
},
}
}
......@@ -109,6 +109,11 @@ func NewServiceConfig(id string, context context.Context) *ServiceConfig {
}
}
// InitExported will set exported as false atom bool
func (c *ServiceConfig) InitExported() {
c.exported = atomic.NewBool(false)
}
// IsExport will return whether the service config is exported or not
func (c *ServiceConfig) IsExport() bool {
return c.exported.Load()
......@@ -288,55 +293,3 @@ func (c *ServiceConfig) GetExportedUrls() []*common.URL {
}
return nil
}
// MockInitProviderWithSingleRegistry will init a mocked providerConfig
func MockInitProviderWithSingleRegistry() {
providerConfig = &ProviderConfig{
ApplicationConfig: &ApplicationConfig{
Organization: "dubbo_org",
Name: "dubbo",
Module: "module",
Version: "2.6.0",
Owner: "dubbo",
Environment: "test"},
Registry: &RegistryConfig{
Address: "mock://127.0.0.1:2181",
Username: "user1",
Password: "pwd1",
},
Registries: map[string]*RegistryConfig{},
Services: map[string]*ServiceConfig{
"MockService": {
InterfaceName: "com.MockService",
Protocol: "mock",
Cluster: "failover",
Loadbalance: "random",
Retries: "3",
Group: "huadong_idc",
Version: "1.0.0",
Methods: []*MethodConfig{
{
Name: "GetUser",
Retries: "2",
Loadbalance: "random",
Weight: 200,
},
{
Name: "GetUser1",
Retries: "2",
Loadbalance: "random",
Weight: 200,
},
},
exported: new(atomic.Bool),
},
},
Protocols: map[string]*ProtocolConfig{
"mock": {
Name: "mock",
Ip: "127.0.0.1",
Port: "20000",
},
},
}
}
......@@ -52,7 +52,7 @@ func TestConfigurableExporter(t *testing.T) {
MaxMsgLen: 10240000000,
SessionName: "server",
}})
config.MockInitProviderWithSingleRegistry()
mockInitProviderWithSingleRegistry()
metadataService := inmemory.NewMetadataService()
exported := NewMetadataServiceExporter(metadataService)
assert.Equal(t, false, exported.IsExported())
......@@ -62,3 +62,57 @@ func TestConfigurableExporter(t *testing.T) {
exported.Unexport()
assert.Equal(t, false, exported.IsExported())
}
// mockInitProviderWithSingleRegistry will init a mocked providerConfig
func mockInitProviderWithSingleRegistry() {
providerConfig := &config.ProviderConfig{
ApplicationConfig: &config.ApplicationConfig{
Organization: "dubbo_org",
Name: "dubbo",
Module: "module",
Version: "2.6.0",
Owner: "dubbo",
Environment: "test"},
Registry: &config.RegistryConfig{
Address: "mock://127.0.0.1:2181",
Username: "user1",
Password: "pwd1",
},
Registries: map[string]*config.RegistryConfig{},
Services: map[string]*config.ServiceConfig{
"MockService": {
InterfaceName: "com.MockService",
Protocol: "mock",
Cluster: "failover",
Loadbalance: "random",
Retries: "3",
Group: "huadong_idc",
Version: "1.0.0",
Methods: []*config.MethodConfig{
{
Name: "GetUser",
Retries: "2",
Loadbalance: "random",
Weight: 200,
},
{
Name: "GetUser1",
Retries: "2",
Loadbalance: "random",
Weight: 200,
},
},
},
},
Protocols: map[string]*config.ProtocolConfig{
"mock": {
Name: "mock",
Ip: "127.0.0.1",
Port: "20000",
},
},
}
providerConfig.Services["MockService"].InitExported()
config.SetProviderConfig(*providerConfig)
}
......@@ -28,18 +28,27 @@ import (
// Metadataservice is used to define meta data related behaviors
type MetadataService interface {
// ServiceName will get the service's name in meta service , which is application name
ServiceName() (string, error)
// ExportURL will store the exported url in metadata
ExportURL(url common.URL) (bool, error)
// UnexportURL will delete the exported url in metadata
UnexportURL(url common.URL) error
//RefreshMetadata(exportedRevision string, subscribedRevision string) bool
// SubscribeURL will store the subscribed url in metadata
SubscribeURL(url common.URL) (bool, error)
// UnsubscribeURL will delete the subscribed url in metadata
UnsubscribeURL(url common.URL) error
// PublishServiceDefinition will generate the target url's code info
PublishServiceDefinition(url common.URL) error
// GetExportedURLs will get the target exported url in metadata
GetExportedURLs(serviceInterface string, group string, version string, protocol string) (sets.Set, error)
// GetExportedURLs will get the target subscribed url in metadata
GetSubscribedURLs() (sets.Set, error)
// GetServiceDefinition will get the target service info store in metadata
GetServiceDefinition(interfaceName string, group string, version string) (string, error)
// GetServiceDefinition will get the target service info store in metadata by service key
GetServiceDefinitionByServiceKey(serviceKey string) (string, error)
// Version will return the metadata service version
Version() string
common.RPCService
}
......
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