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