dubbo.apache.org/dubbo-go/v3@v3.1.1/registry/servicediscovery/service_discovery_registry_test.go (about) 1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package servicediscovery 19 20 //import ( 21 // "testing" 22 //) 23 // 24 //import ( 25 // gxset "github.com/dubbogo/gost/container/set" 26 // "github.com/dubbogo/gost/hash/page" 27 // "github.com/stretchr/testify/assert" 28 //) 29 // 30 //import ( 31 // "dubbo.apache.org/dubbo-go/v3/common" 32 // "dubbo.apache.org/dubbo-go/v3/common/extension" 33 // "dubbo.apache.org/dubbo-go/v3/config" 34 // "dubbo.apache.org/dubbo-go/v3/metadata/mapping" 35 // "dubbo.apache.org/dubbo-go/v3/metadata/service" 36 // "dubbo.apache.org/dubbo-go/v3/registry" 37 //) 38 // 39 //var ( 40 // serviceInterface = "org.apache.dubbo.metadata.MetadataService" 41 // group = "dubbo-provider" 42 // version = "1.0.0" 43 //) 44 // 45 //func TestServiceDiscoveryRegistry_Register(t *testing.T) { 46 // config.GetApplicationConfig().MetadataType = "mock" 47 // extension.SetLocalMetadataService("mock", func() (service service.MetadataService, err error) { 48 // service = &mockMetadataService{} 49 // return 50 // }) 51 // 52 // extension.SetServiceDiscovery("mock", func(name string) (discovery registry.ServiceDiscovery, err error) { 53 // return &mockServiceDiscovery{}, nil 54 // }) 55 // 56 // extension.SetGlobalServiceNameMapping(func() mapping.ServiceNameMapping { 57 // return mapping.NewMockServiceNameMapping() 58 // }) 59 // 60 // config.GetBaseConfig().ServiceDiscoveries["mock"] = &config.ServiceDiscoveryConfig{ 61 // Protocol: "mock", 62 // } 63 // registryURL, _ := common.NewURL("service-discovery://localhost:12345", 64 // common.WithParamsValue("service_discovery", "mock"), 65 // common.WithParamsValue("subscribed-services", "a, b , c,d,e ,")) 66 // url, _ := common.NewURL("dubbo://192.168.0.102:20880/" + serviceInterface + 67 // "?&application=" + group + 68 // "&interface=" + serviceInterface + 69 // "&group=" + group + 70 // "&version=" + version + 71 // "&service_discovery=mock" + 72 // "&methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs" + 73 // "&side=provider") 74 // registry, err := newServiceDiscoveryRegistry(registryURL) 75 // assert.Nil(t, err) 76 // assert.NotNil(t, registry) 77 // err = registry.Register(url) 78 // assert.NoError(t, err) 79 //} 80 // 81 //type mockServiceDiscovery struct{} 82 // 83 //func (m *mockServiceDiscovery) String() string { 84 // panic("implement me") 85 //} 86 // 87 //func (m *mockServiceDiscovery) Destroy() error { 88 // panic("implement me") 89 //} 90 // 91 //func (m *mockServiceDiscovery) Register(registry.ServiceInstance) error { 92 // return nil 93 //} 94 // 95 //func (m *mockServiceDiscovery) Update(registry.ServiceInstance) error { 96 // panic("implement me") 97 //} 98 // 99 //func (m *mockServiceDiscovery) Unregister(registry.ServiceInstance) error { 100 // panic("implement me") 101 //} 102 // 103 //func (m *mockServiceDiscovery) GetDefaultPageSize() int { 104 // panic("implement me") 105 //} 106 // 107 //func (m *mockServiceDiscovery) GetServices() *gxset.HashSet { 108 // panic("implement me") 109 //} 110 // 111 //func (m *mockServiceDiscovery) GetInstances(string) []registry.ServiceInstance { 112 // panic("implement me") 113 //} 114 // 115 //func (m *mockServiceDiscovery) GetInstancesByPage(string, int, int) gxpage.Pager { 116 // panic("implement me") 117 //} 118 // 119 //func (m *mockServiceDiscovery) GetHealthyInstancesByPage(string, int, int, bool) gxpage.Pager { 120 // panic("implement me") 121 //} 122 // 123 //func (m *mockServiceDiscovery) GetRequestInstances([]string, int, int) map[string]gxpage.Pager { 124 // panic("implement me") 125 //} 126 // 127 //func (m *mockServiceDiscovery) AddListener(registry.ServiceInstancesChangedListener) error { 128 // panic("implement me") 129 //} 130 // 131 //func (m *mockServiceDiscovery) DispatchEventByServiceName(string) error { 132 // panic("implement me") 133 //} 134 // 135 //func (m *mockServiceDiscovery) DispatchEventForInstances(string, []registry.ServiceInstance) error { 136 // panic("implement me") 137 //} 138 // 139 //func (m *mockServiceDiscovery) DispatchEvent(*registry.ServiceInstancesChangedEvent) error { 140 // panic("implement me") 141 //} 142 // 143 //type mockMetadataService struct{} 144 // 145 //func (m *mockMetadataService) GetExportedURLs(string, string, string, string) ([]*common.URL, error) { 146 // panic("implement me") 147 //} 148 // 149 //func (m *mockMetadataService) GetMetadataInfo(revision string) (*common.MetadataInfo, error) { 150 // panic("implement me") 151 //} 152 // 153 //func (m *mockMetadataService) GetExportedServiceURLs() []*common.URL { 154 // panic("implement me") 155 //} 156 // 157 //func (m *mockMetadataService) GetMetadataServiceURL() *common.URL { 158 // panic("implement me") 159 //} 160 // 161 //func (m *mockMetadataService) SetMetadataServiceURL(url *common.URL) { 162 // panic("implement me") 163 //} 164 // 165 //func (m *mockMetadataService) Reference() string { 166 // panic("implement me") 167 //} 168 // 169 //func (m *mockMetadataService) ServiceName() (string, error) { 170 // panic("implement me") 171 //} 172 // 173 //func (m *mockMetadataService) ExportURL(*common.URL) (bool, error) { 174 // return true, nil 175 //} 176 // 177 //func (m *mockMetadataService) UnexportURL(*common.URL) error { 178 // panic("implement me") 179 //} 180 // 181 //func (m *mockMetadataService) SubscribeURL(*common.URL) (bool, error) { 182 // panic("implement me") 183 //} 184 // 185 //func (m *mockMetadataService) UnsubscribeURL(*common.URL) error { 186 // panic("implement me") 187 //} 188 // 189 //func (m *mockMetadataService) PublishServiceDefinition(*common.URL) error { 190 // return nil 191 //} 192 // 193 //func (m *mockMetadataService) MethodMapper() map[string]string { 194 // panic("implement me") 195 //} 196 // 197 //func (m *mockMetadataService) GetSubscribedURLs() ([]*common.URL, error) { 198 // panic("implement me") 199 //} 200 // 201 //func (m *mockMetadataService) GetServiceDefinition(string, string, string) (string, error) { 202 // panic("implement me") 203 //} 204 // 205 //func (m *mockMetadataService) GetServiceDefinitionByServiceKey(string) (string, error) { 206 // panic("implement me") 207 //} 208 // 209 //func (m *mockMetadataService) RefreshMetadata(string, string) (bool, error) { 210 // panic("implement me") 211 //} 212 // 213 //func (m *mockMetadataService) Version() (string, error) { 214 // panic("implement me") 215 //}