/* * 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. */ package test import ( "context" "testing" "time" ) import ( "github.com/seata/seata-go/pkg/common/log" _ "github.com/seata/seata-go/pkg/imports" txapi "github.com/seata/seata-go/pkg/protocol/transaction/api" "github.com/seata/seata-go/pkg/rm/tcc" "github.com/seata/seata-go/pkg/rm/tcc/api" ) type TestTCCServiceBusiness struct { } func (T TestTCCServiceBusiness) Prepare(ctx context.Context, params interface{}) error { log.Infof("TestTCCServiceBusiness Prepare, param %v", params) return nil } func (T TestTCCServiceBusiness) Commit(ctx context.Context, businessActionContext api.BusinessActionContext) error { log.Infof("TestTCCServiceBusiness Commit, param %v", businessActionContext) return nil } func (T TestTCCServiceBusiness) Rollback(ctx context.Context, businessActionContext api.BusinessActionContext) error { log.Infof("TestTCCServiceBusiness Rollback, param %v", businessActionContext) return nil } func (T TestTCCServiceBusiness) GetActionName() string { return "TestTCCServiceBusiness" } type TestTCCServiceBusiness2 struct { } func (T TestTCCServiceBusiness2) Prepare(ctx context.Context, params interface{}) error { log.Infof("TestTCCServiceBusiness2 Prepare, param %v", params) return nil } func (T TestTCCServiceBusiness2) Commit(ctx context.Context, businessActionContext api.BusinessActionContext) error { log.Infof("TestTCCServiceBusiness2 Commit, param %v", businessActionContext) return nil } func (T TestTCCServiceBusiness2) Rollback(ctx context.Context, businessActionContext api.BusinessActionContext) error { log.Infof("TestTCCServiceBusiness2 Rollback, param %v", businessActionContext) return nil } func (T TestTCCServiceBusiness2) GetActionName() string { return "TestTCCServiceBusiness2" } func TestNew(test *testing.T) { var err error ctx := txapi.Begin(context.Background(), "TestTCCServiceBusiness") defer func() { resp := txapi.CommitOrRollback(ctx, err) log.Infof("tx result %v", resp) }() tccService := tcc.NewTCCServiceProxy(TestTCCServiceBusiness{}) err = tccService.Prepare(ctx, 1) tccService2 := tcc.NewTCCServiceProxy(TestTCCServiceBusiness2{}) err = tccService2.Prepare(ctx, 3) time.Sleep(time.Second * 1000) }