本文整理匯總了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)
}
}