AlexStocks commented on code in PR #36:
URL: https://github.com/apache/dubbo-net/pull/36#discussion_r4642447374


##########
Registry/ProviderDiscovery.cs:
##########
@@ -0,0 +1,276 @@
+/*
+ * 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.
+ */
+
+using DubboNet.Clients.DataModle;
+using DubboNet.Clients.RegistryClient;

Review Comment:
   [P3] `Registry/` 现在装了三套命名空间,新命名空间要 import 旧命名空间才能拿到同目录的类型
   
   head `c98f0c4f` 实测分布(该目录 14 个文件):
   
   | 命名空间 | 文件数 | 文件 |
   |---|---:|---|
   | `DubboNet.Registry` | 9 | 
ProviderDiscovery、ConsumerRegistration、ConsumerRegistrationConfiguration、ConsumerRegistrationRegistries、MultiMyNacosStorage、MultiMyZookeeperStorage、NacosRegistryDefaults、RegistryCategories、ZooKeeperRegistryPaths
 |
   | `DubboNet.Clients.RegistryClient` | 3 | MyNacos、MyZookeeper、ZNode |
   | `DubboNet.Clients.DataModle` | 2 | 
ConsumerRegistrationOptions、NacosRegistryModels |
   
   **保留旧命名空间这件事我认为是对的**,理由可证:这 5 个类型都是 `public`(`public sealed class 
MyNacos`、`public class MyZookeeper`、`public class ZNode`、`public sealed class 
ConsumerRegistrationOptions`、`public sealed class 
NacosServiceInfo`),改命名空间就是破坏性变更;`RegistryImplementationHasItsOwnNamespace_WithoutMovingPublicClients`
 也把这条约定钉成了契约。所以这不是缺陷,是文档缺口。
   
   剩下的成本是可读性:本行 `using DubboNet.Clients.RegistryClient;` 让 `DubboNet.Registry` 
反过来依赖旧命名空间,才能拿到同目录的 `MyZookeeper`/`MyNacos`,形成 `Registry` ↔ 
`Clients.RegistryClient` 双向引用。下一个人打开 `Registry/MyNacos.cs` 看到 `namespace 
DubboNet.Clients.RegistryClient`,第一反应大概率是「搬迁漏改了」,而唯一能说明「这是故意的」的地方是一个测试方法名。
   
   建议:在这 5 个文件的类型注释上方各加一句「目录按所有者归位;命名空间保留以维持公共 API,见 #36」,成本 5 
行。(`Clients.DataModle` 这个拼写是历史遗留,本 PR 不动它是对的,但同样值得注释一句。)
   



##########
Tests/UnitTestForDubboNet/ZooKeeperRegistryPathContractTest.cs:
##########
@@ -18,11 +18,34 @@
 using DubboNet.Clients;
 using DubboNet.Clients.DataModle;
 using DubboNet.Clients.RegistryClient;
+using DubboNet.DubboService;
+using DubboNet.Registry;
 
 namespace UnitTestForDubboNet
 {
     public class ZooKeeperRegistryPathContractTest
     {
+        [Fact]
+        public void SharedProviderUrlContracts_AreOwnedByProtocol()
+        {
+            Assert.Equal("DubboNet.DubboService", 
typeof(ProviderUrlKeys).Namespace);
+            Assert.Equal("DubboNet.DubboService", 
typeof(ProviderProtocolSchemes).Namespace);
+            Assert.Equal("interface", ProviderUrlKeys.Interface);
+            Assert.Equal("dubbo", ProviderProtocolSchemes.Dubbo);
+            Assert.Equal("tri", ProviderProtocolSchemes.Tri);
+        }
+
+        [Fact]
+        public void 
RegistryImplementationHasItsOwnNamespace_WithoutMovingPublicClients()

Review Comment:
   补充一个与你这条回复直接相关的缺口——不是重复提问:`9809cea` 新增的 3 个用例(缺失/空/非空、watch 
传递、恢复回调)我逐行看过,覆盖是有效的,但它们**全部绕开了生产适配器**。
   
   head `c98f0c4f` 的事实:
   
   - `ZooKeeperRegistryPathContractTest.cs:30` 定义 `FakeProviderZooKeeper : 
IProviderZooKeeper`,三个用例(`:58` / `:74` / `:93`)都走 
`ProviderDiscovery.ForZooKeeper(zooKeeper, ...)`。
   - `ForZooKeeper`(`Registry/ProviderDiscovery.cs:72`)直接接收 
`IProviderZooKeeper`,所以 `ZooKeeperReader`(`:46-53`,`private 
sealed`)在整个测试套件里**一次都没被构造**。
   - `MyNacosTest.cs` 的 5 处构造都传 `new ProviderDiscovery(null!, nacos, ...)`,命中的是 
`:67` `zookeeper is null ? null : new ZooKeeperReader(zookeeper)` 的空分支。
   
   于是这两段零执行:
   
   ```csharp
   // ProviderDiscovery.cs:52-53
   public async Task<IReadOnlyList<string>> GetChildrenAsync(string path, 
Watcher watcher) =>
       (await _client.GetChildrenAsync(path, 
watcher).ConfigureAwait(false))?.Children;
   ```
   
   这里的 `?.Children` 是唯一的「ZK 查询返回 null → 降级为 null 列表」语义;而 `:233` 正好有一条专门吃这个 null 
的分支(`ErrorInfo = $"GetChildrenAsync error [{serviceName}]"`)。也就是说生产路径上「适配器把 
null 传下去」和「发现层把 null 当错误」是连着的一段,现在只验证了后者的「显式传 null」版本,前者从未执行。
   
   另一个零执行点是 `:65-70` 的 `ProviderDiscovery(MyZookeeper, ...)` 构造函数——生产环境唯一的 ZK 
接线点。
   
   结构上还多一层麻烦:`MyZookeeper.GetChildrenAsync` 不是 virtual,`ZooKeeperReader` 
又持有具体类型,所以没法用 stub `MyZookeeper` 替换它。低成本的补法只剩一条——在既有 fake 上补「`GetChildrenAsync` 
返回 null → 断言 `GetChildrenAsync error [...]`」,把 null 语义钉住;要真正覆盖适配器那 3 行,得先把 
`MyZookeeper` 的相关方法抽到接口上(那是另一个 PR 的量级,可以另开 issue)。
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to