本文整理汇总了Golang中github.com/cockroachdb/cockroach/proto.Transaction.Status方法的典型用法代码示例。如果您正苦于以下问题:Golang Transaction.Status方法的具体用法?Golang Transaction.Status怎么用?Golang Transaction.Status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/proto.Transaction
的用法示例。
在下文中一共展示了Transaction.Status方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestEndTransactionWithErrors
// TestEndTransactionWithErrors verifies various error conditions
// are checked such as transaction already being committed or
// aborted, or timestamp or epoch regression.
func TestEndTransactionWithErrors(t *testing.T) {
rng, mc, clock, _ := createTestRangeWithClock(t)
defer rng.Stop()
regressTS := clock.Now()
*mc = hlc.ManualClock(1)
txn := NewTransaction(engine.Key(""), 1, proto.SERIALIZABLE, clock)
testCases := []struct {
key engine.Key
existStatus proto.TransactionStatus
existEpoch int32
existTS proto.Timestamp
expErrRegexp string
}{
{engine.Key("a"), proto.COMMITTED, txn.Epoch, txn.Timestamp, "txn {.*}: already committed"},
{engine.Key("b"), proto.ABORTED, txn.Epoch, txn.Timestamp, "txn {.*}: already aborted"},
{engine.Key("c"), proto.PENDING, txn.Epoch + 1, txn.Timestamp, "txn {.*}: epoch regression: 0"},
{engine.Key("d"), proto.PENDING, txn.Epoch, regressTS, "txn {.*}: timestamp regression: {WallTime:1 Logical:0 .*}"},
}
for _, test := range testCases {
// Establish existing txn state by writing directly to range engine.
var existTxn proto.Transaction
gogoproto.Merge(&existTxn, txn)
existTxn.ID = test.key
existTxn.Status = test.existStatus
existTxn.Epoch = test.existEpoch
existTxn.Timestamp = test.existTS
txnKey := engine.MakeKey(engine.KeyLocalTransactionPrefix, test.key)
if err := engine.PutProto(rng.engine, txnKey, &existTxn); err != nil {
t.Fatal(err)
}
// End the transaction, verify expected error.
txn.ID = test.key
args, reply := endTxnArgs(txn, true, 0)
args.Timestamp = txn.Timestamp
err := rng.ReadWriteCmd("EndTransaction", args, reply)
if err == nil {
t.Errorf("expected error matching %q", test.expErrRegexp)
} else {
if matched, regexpErr := regexp.MatchString(test.expErrRegexp, err.Error()); !matched || regexpErr != nil {
t.Errorf("expected error to match %q (%v): %v", test.expErrRegexp, regexpErr, err.Error())
}
}
}
}