Snow-kal commented on code in PR #1144:
URL: https://github.com/apache/dubbo-go-samples/pull/1144#discussion_r3889589477
##########
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:
感谢建议,已修复
true 和 gson 现在都会校验完整 User,包括非零 Time。由于 Bean generalizer 无法 round-trip Go
time.Time 的未导出内部状态,bean 模式改用明确支持的 beanUserDTO,仅包含 ID、Name 和 Age
<img width="1073" height="1009" alt="image"
src="https://github.com/user-attachments/assets/f96cbeb1-7451-47ef-88ed-a84622a2fc6a"
/>
--
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]