AlexStocks commented on code in PR #1144:
URL: https://github.com/apache/dubbo-go-samples/pull/1144#discussion_r3889041883
##########
generic/go-client/cmd/client.go:
##########
@@ -206,3 +197,111 @@ func runGenericTests(svc *genericService) bool {
return failed
}
+
+func runGenericModeChecks(cli *client.Client) bool {
+ failed := false
+ ctx := context.Background()
+
+ if _, err := cli.NewGenericService(
+ UserProvider,
+ client.WithURL(DirectServerURL),
+ client.WithVersion(ServiceVersion),
+ client.WithGroup(ServiceGroup),
+ client.WithGenericType("bad-type"),
+ client.WithSerialization(constant.Hessian2Serialization),
+ ); err == nil {
+ logger.Error("NewGenericService accepted an unknown generic
mode")
+ failed = true
+ } else {
+ logger.Infof("NewGenericService rejected unknown generic mode:
%v", err)
+ }
+
+ testCases := []struct {
+ name string
+ mode string
+ method string
+ types []string
+ args []hessian.Object
+ typed bool
+ expectedID string
+ }{
+ {
+ name: "true",
+ mode: constant.GenericSerializationDefault,
+ method: "GetUser1",
+ types: []string{"java.lang.String"},
+ args: []hessian.Object{"A003"},
+ typed: true,
+ expectedID: "A003",
+ },
+ {
+ name: "gson",
+ mode: constant.GenericSerializationGson,
+ method: "GetOneUser",
+ types: []string{},
+ args: []hessian.Object{},
+ },
+ {
+ name: "bean",
+ mode: constant.GenericSerializationBean,
+ method: "GetOneUser",
+ types: []string{},
+ args: []hessian.Object{},
+ typed: true,
+ expectedID: "1000",
+ },
+ }
+
+ for _, testCase := range testCases {
+ service, err := cli.NewGenericService(
+ UserProvider,
+ client.WithURL(DirectServerURL),
+ client.WithVersion(ServiceVersion),
+ client.WithGroup(ServiceGroup),
+ client.WithGenericType(testCase.mode),
+
client.WithSerialization(constant.Hessian2Serialization),
+ )
+ if err != nil {
+ logger.Errorf("create generic service (%s) failed: %v",
testCase.name, err)
+ failed = true
+ continue
+ }
+ if !testCase.typed {
+ result, invokeErr := service.Invoke(ctx,
testCase.method, testCase.types, testCase.args)
+ if invokeErr != nil {
+ logger.Errorf("%s generic result (%s) failed:
%v", testCase.method, testCase.name, invokeErr)
+ failed = true
+ continue
+ }
+ if result == nil {
Review Comment:
[P1] gson 检查必须断言 JSON 结果形状,不能只判断非 nil
当前分支只要调用没有报错且 result 非 nil 就算通过,因此即使 generic mode 被忽略并回退到默认 Map,这条检查也会全绿。当前
exact-Head CI 已直接暴露该问题:Go provider 阶段返回 type=string 的 JSON,但切换到 Java provider
后,在 URL 明确 generic=gson 的情况下实际返回 type=map[interface {}]interface
{},这里仍然记录成功。这样无法证明 gson 行为,更掩盖了跨语言结果形状不一致。请要求 result 必须是 string,解析 JSON 后断言
ID/Name/Age/Time;如果 Java provider 本来不支持 gson,应把两个 provider 阶段拆分并显式断言/记录不支持,不能把
Map fallback 当作 gson 成功。
##########
generic/go-client/cmd/client.go:
##########
@@ -206,3 +197,111 @@ func runGenericTests(svc *genericService) bool {
return failed
}
+
+func runGenericModeChecks(cli *client.Client) bool {
+ failed := false
+ ctx := context.Background()
+
+ if _, err := cli.NewGenericService(
+ UserProvider,
+ client.WithURL(DirectServerURL),
+ client.WithVersion(ServiceVersion),
+ client.WithGroup(ServiceGroup),
+ client.WithGenericType("bad-type"),
+ client.WithSerialization(constant.Hessian2Serialization),
+ ); err == nil {
+ logger.Error("NewGenericService accepted an unknown generic
mode")
+ failed = true
+ } else {
+ logger.Infof("NewGenericService rejected unknown generic mode:
%v", err)
+ }
+
+ testCases := []struct {
+ name string
+ mode string
+ method string
+ types []string
+ args []hessian.Object
+ typed bool
+ expectedID string
+ }{
+ {
+ name: "true",
+ mode: constant.GenericSerializationDefault,
+ method: "GetUser1",
+ types: []string{"java.lang.String"},
+ args: []hessian.Object{"A003"},
+ typed: true,
+ expectedID: "A003",
+ },
+ {
+ name: "gson",
+ mode: constant.GenericSerializationGson,
+ method: "GetOneUser",
+ types: []string{},
+ args: []hessian.Object{},
+ },
+ {
+ name: "bean",
+ mode: constant.GenericSerializationBean,
+ method: "GetOneUser",
+ types: []string{},
+ args: []hessian.Object{},
+ typed: true,
+ expectedID: "1000",
+ },
+ }
+
+ for _, testCase := range testCases {
+ service, err := cli.NewGenericService(
+ UserProvider,
+ client.WithURL(DirectServerURL),
+ client.WithVersion(ServiceVersion),
+ client.WithGroup(ServiceGroup),
+ client.WithGenericType(testCase.mode),
+
client.WithSerialization(constant.Hessian2Serialization),
+ )
+ if err != nil {
+ logger.Errorf("create generic service (%s) failed: %v",
testCase.name, err)
+ failed = true
+ continue
+ }
+ if !testCase.typed {
+ result, invokeErr := service.Invoke(ctx,
testCase.method, testCase.types, testCase.args)
+ if invokeErr != nil {
+ logger.Errorf("%s generic result (%s) failed:
%v", testCase.method, testCase.name, invokeErr)
+ failed = true
+ continue
+ }
+ if result == nil {
+ logger.Errorf("%s generic result (%s) returned
nil", testCase.method, testCase.name)
+ failed = true
+ continue
+ }
+ logger.Infof("%s generic result (%s) type=%T res: %+v",
testCase.method, testCase.name, result, result)
+ continue
+ }
+
+ var user pkg.User
+ err = service.InvokeWithType(
+ ctx,
+ testCase.method,
+ testCase.types,
+ testCase.args,
+ &user,
+ )
+ if err != nil {
+ logger.Errorf("%s typed result (%s) failed: %v",
testCase.method, testCase.name, err)
+ failed = true
+ continue
+ }
+ if user.ID != testCase.expectedID || user.Name == "" ||
user.Age == 0 {
Review Comment:
[P1] bean typed result 已丢失 Time 字段,但当前完整性判断仍会放行
GetOneUser 明确返回非零 time.Now(),但当前 exact-Head CI 的 Go provider 阶段输出为
Time:0001-01-01 00:00:00,说明 bean Generalize/Realize 后该字段已经静默丢失;同一检查在 Java
provider 阶段又能得到非零 Time。这里仅检查 ID、Name 和 Age,所以实际数据损坏仍被报告为 All generic call
checks passed。请把 user.Time.IsZero() 纳入断言,并覆盖 User 的全部可观察字段;随后修复 Go bean 路径对
time.Time 的处理,或改用明确受支持的 DTO 并在文档中说明限制,不能通过弱化断言接受字段丢失。
--
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]