change file names

This commit is contained in:
yedf2 2021-08-09 20:59:04 +08:00
parent 66d03f5ccb
commit c19e446455
8 changed files with 26 additions and 21 deletions

View File

@ -105,9 +105,6 @@ func MustRemarshal(from interface{}, to interface{}) {
E2P(err)
}
// LogFunc log function type
type LogFunc func(format string, args ...interface{})
// Logf 输出日志
func Logf(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)

View File

@ -2,6 +2,7 @@ package dtmpb
import (
context "context"
"fmt"
"strings"
"github.com/yedf/dtm/dtmcli"
@ -47,8 +48,12 @@ func GetServerAndMethod(grpcURL string) (string, string) {
func GrpcServerLog(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
dtmcli.Logf("grpc server handling: %s %v", info.FullMethod, req)
m, err := handler(ctx, req)
log := dtmcli.If(err != nil, dtmcli.LogRedf, dtmcli.Logf).(dtmcli.LogFunc)
log("grpc server handled: %s %v result: %v err: %v", info.FullMethod, req, m, err)
res := fmt.Sprintf("grpc server handled: %s %v result: %v err: %v", info.FullMethod, req, m, err)
if err != nil {
dtmcli.LogRedf("%s", res)
} else {
dtmcli.Logf("%s", res)
}
return m, err
}
@ -56,7 +61,11 @@ func GrpcServerLog(ctx context.Context, req interface{}, info *grpc.UnaryServerI
func GrpcClientLog(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
dtmcli.Logf("grpc client calling: %s%s %v", cc.Target(), method, req)
err := invoker(ctx, method, req, reply, cc, opts...)
log := dtmcli.If(err != nil, dtmcli.LogRedf, dtmcli.Logf).(dtmcli.LogFunc)
log("grpc client called: %s%s %v result: %v err: %v", cc.Target(), method, req, reply, err)
res := fmt.Sprintf("grpc client called: %s%s %v result: %v err: %v", cc.Target(), method, req, reply, err)
if err != nil {
dtmcli.LogRedf("%s", res)
} else {
dtmcli.Logf("%s", res)
}
return err
}

View File

@ -18,4 +18,5 @@ func TestExamples(t *testing.T) {
assertSucceed(t, examples.TccFireRequest())
assertSucceed(t, examples.TccFireRequestNested())
assertSucceed(t, examples.XaFireRequest())
assertSucceed(t, examples.MsgPbFireRequest())
}

View File

@ -8,7 +8,7 @@ import (
"github.com/yedf/dtm/examples"
)
func TestSagaBarrier(t *testing.T) {
func TestBarrierSaga(t *testing.T) {
sagaBarrierNormal(t)
sagaBarrierRollback(t)

View File

@ -14,7 +14,7 @@ import (
"github.com/yedf/dtm/examples"
)
func TestTccBarrier(t *testing.T) {
func TestBarrierTcc(t *testing.T) {
tccBarrierDisorder(t)
tccBarrierNormal(t)
tccBarrierRollback(t)

View File

@ -0,0 +1,8 @@
package dtmsvr
import (
"testing"
)
func TestPbMsg(t *testing.T) {
}

View File

@ -8,7 +8,7 @@ import (
"github.com/yedf/dtm/examples"
)
func TestSagaWait(t *testing.T) {
func TestWaitSaga(t *testing.T) {
sagaNormalWait(t)
sagaCommittedPendingWait(t)

View File

@ -13,21 +13,11 @@ func MsgPbSetup(app *gin.Engine) {
// MsgPbFireRequest 1
func MsgPbFireRequest() string {
dtmcli.Logf("MsgPbFireRequest")
// reply, err := DtmClient.Call(context.Background(), &dtmpb.DtmRequest{
// Gid: "pb_test",
// TransType: "msg",
// Method: "submit",
// Extra: dtmcli.MS{
// "BusiFunc": BusiPb + "/examples.Busi/Call",
// },
// })
// dtmcli.Logf("reply and err is: %v, %v", reply, err)
req := dtmcli.MustMarshal(&TransReq{Amount: 30})
msg := dtmpb.NewMsgGrpc(DtmGrpcServer, dtmcli.MustGenGid(DtmServer)).
Add(BusiPb+"/examples.Busi/TransOut", req).
Add(BusiPb+"/examples.Busi/TransIn", req)
err := msg.Submit()
e2p(err)
return ""
return msg.Gid
}