You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

tcc_service_test.go 3.1 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. package test
  18. import (
  19. "context"
  20. "testing"
  21. "github.com/seata/seata-go/pkg/tm"
  22. "github.com/seata/seata-go/pkg/common/log"
  23. _ "github.com/seata/seata-go/pkg/imports"
  24. "github.com/seata/seata-go/pkg/rm/tcc"
  25. )
  26. type TestTCCServiceBusiness struct {
  27. }
  28. func (T TestTCCServiceBusiness) Prepare(ctx context.Context, params interface{}) error {
  29. log.Infof("TestTCCServiceBusiness Prepare, param %v", params)
  30. return nil
  31. }
  32. func (T TestTCCServiceBusiness) Commit(ctx context.Context, businessActionContext tm.BusinessActionContext) error {
  33. log.Infof("TestTCCServiceBusiness Commit, param %v", businessActionContext)
  34. return nil
  35. }
  36. func (T TestTCCServiceBusiness) Rollback(ctx context.Context, businessActionContext tm.BusinessActionContext) error {
  37. log.Infof("TestTCCServiceBusiness Rollback, param %v", businessActionContext)
  38. return nil
  39. }
  40. func (T TestTCCServiceBusiness) GetActionName() string {
  41. return "TestTCCServiceBusiness"
  42. }
  43. type TestTCCServiceBusiness2 struct {
  44. }
  45. func (T TestTCCServiceBusiness2) Prepare(ctx context.Context, params interface{}) error {
  46. log.Infof("TestTCCServiceBusiness2 Prepare, param %v", params)
  47. return nil
  48. }
  49. func (T TestTCCServiceBusiness2) Commit(ctx context.Context, businessActionContext tm.BusinessActionContext) error {
  50. log.Infof("TestTCCServiceBusiness2 Commit, param %v", businessActionContext)
  51. return nil
  52. }
  53. func (T TestTCCServiceBusiness2) Rollback(ctx context.Context, businessActionContext tm.BusinessActionContext) error {
  54. log.Infof("TestTCCServiceBusiness2 Rollback, param %v", businessActionContext)
  55. return nil
  56. }
  57. func (T TestTCCServiceBusiness2) GetActionName() string {
  58. return "TestTCCServiceBusiness2"
  59. }
  60. func TestNew(test *testing.T) {
  61. var err error
  62. ctx := tm.Begin(context.Background(), "TestTCCServiceBusiness")
  63. defer func() {
  64. resp := tm.CommitOrRollback(ctx, err)
  65. log.Infof("tx result %v", resp)
  66. <-make(chan bool)
  67. }()
  68. tccService := tcc.NewTCCServiceProxy(TestTCCServiceBusiness{})
  69. err = tccService.Prepare(ctx, 1)
  70. if err != nil {
  71. log.Errorf("execute TestTCCServiceBusiness prepare error %s", err.Error())
  72. return
  73. }
  74. tccService2 := tcc.NewTCCServiceProxy(TestTCCServiceBusiness2{})
  75. err = tccService2.Prepare(ctx, 3)
  76. if err != nil {
  77. log.Errorf("execute TestTCCServiceBusiness2 prepare error %s", err.Error())
  78. return
  79. }
  80. }