本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/roachpb.Transaction.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Transaction.String方法的具体用法?Golang Transaction.String怎么用?Golang Transaction.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/pkg/roachpb.Transaction
的用法示例。
在下文中一共展示了Transaction.String方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: tryTxn
func tryTxn(kv engine.MVCCKeyValue) (string, error) {
var txn roachpb.Transaction
if err := maybeUnmarshalInline(kv.Value, &txn); err != nil {
return "", err
}
return txn.String() + "\n", nil
}
示例2: TestTransactionString
func TestTransactionString(t *testing.T) {
txnID, err := uuid.FromBytes([]byte("ת\x0f^\xe4-Fؽ\xf7\x16\xe4\xf9\xbe^\xbe"))
if err != nil {
t.Fatal(err)
}
ts1 := hlc.Timestamp{WallTime: 10, Logical: 11}
txn := roachpb.Transaction{
TxnMeta: enginepb.TxnMeta{
Isolation: enginepb.SERIALIZABLE,
Key: roachpb.Key("foo"),
ID: &txnID,
Epoch: 2,
Timestamp: hlc.Timestamp{WallTime: 20, Logical: 21},
Priority: 957356782,
},
Name: "name",
Status: roachpb.COMMITTED,
LastHeartbeat: &ts1,
OrigTimestamp: hlc.Timestamp{WallTime: 30, Logical: 31},
MaxTimestamp: hlc.Timestamp{WallTime: 40, Logical: 41},
}
expStr := `"name" id=d7aa0f5e key="foo" rw=false pri=44.58039917 iso=SERIALIZABLE stat=COMMITTED ` +
`epo=2 ts=0.000000020,21 orig=0.000000030,31 max=0.000000040,41 wto=false rop=false`
if str := txn.String(); str != expStr {
t.Errorf("expected txn %s; got %s", expStr, str)
}
var txnEmpty roachpb.Transaction
_ = txnEmpty.String() // prevent regression of NPE
cmd := storagebase.RaftCommand{
BatchRequest: &roachpb.BatchRequest{},
}
cmd.BatchRequest.Txn = &txn
if actStr, idStr := fmt.Sprintf("%s", &cmd), txnID.String(); !strings.Contains(actStr, idStr) {
t.Fatalf("expected to find '%s' in '%s'", idStr, actStr)
}
}