本文整理匯總了Golang中github.com/cockroachdb/cockroach/internal/client.Txn.UpdateDeadlineMaybe方法的典型用法代碼示例。如果您正苦於以下問題:Golang Txn.UpdateDeadlineMaybe方法的具體用法?Golang Txn.UpdateDeadlineMaybe怎麽用?Golang Txn.UpdateDeadlineMaybe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/internal/client.Txn
的用法示例。
在下文中一共展示了Txn.UpdateDeadlineMaybe方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestRemoveLeaseIfExpiring
func TestRemoveLeaseIfExpiring(t *testing.T) {
defer leaktest.AfterTest(t)()
p := planner{}
mc := hlc.NewManualClock(0)
p.leaseMgr = &LeaseManager{LeaseStore: LeaseStore{clock: hlc.NewClock(mc.UnixNano)}}
p.leases = make([]*LeaseState, 0)
txn := client.Txn{}
p.setTxn(&txn)
if p.removeLeaseIfExpiring(nil) {
t.Error("expected false with nil input")
}
// Add a lease to the planner.
d := int64(LeaseDuration)
l1 := &LeaseState{expiration: parser.DTimestamp{Time: time.Unix(0, mc.UnixNano()+d+1)}}
p.leases = append(p.leases, l1)
et := hlc.Timestamp{WallTime: l1.Expiration().UnixNano()}
txn.UpdateDeadlineMaybe(et)
if p.removeLeaseIfExpiring(l1) {
t.Error("expected false wih a non-expiring lease")
}
if !p.txn.GetDeadline().Equal(et) {
t.Errorf("expected deadline %s but got %s", et, p.txn.GetDeadline())
}
// Advance the clock so that l1 will be expired.
mc.Increment(d + 1)
// Add another lease.
l2 := &LeaseState{expiration: parser.DTimestamp{Time: time.Unix(0, mc.UnixNano()+d+1)}}
p.leases = append(p.leases, l2)
if !p.removeLeaseIfExpiring(l1) {
t.Error("expected true with an expiring lease")
}
et = hlc.Timestamp{WallTime: l2.Expiration().UnixNano()}
txn.UpdateDeadlineMaybe(et)
if !(len(p.leases) == 1 && p.leases[0] == l2) {
t.Errorf("expected leases to contain %s but has %s", l2, p.leases)
}
if !p.txn.GetDeadline().Equal(et) {
t.Errorf("expected deadline %s, but got %s", et, p.txn.GetDeadline())
}
}
示例2: setTxnTimestamps
// setTxnTimestamps sets the transaction's proto timestamps and deadline
// to ts. This is for use with AS OF queries, and should be called in the
// retry block (except in the case of prepare which doesn't use retry). The
// deadline-checking code checks that the `Timestamp` field of the proto
// hasn't exceeded the deadline. Since we set the Timestamp field each retry,
// it won't ever exceed the deadline, and thus setting the deadline here is
// not strictly needed. However, it doesn't do anything incorrect and it will
// possibly find problems if things change in the future, so it is left in.
func setTxnTimestamps(txn *client.Txn, ts hlc.Timestamp) {
txn.Proto.Timestamp = ts
txn.Proto.OrigTimestamp = ts
txn.Proto.MaxTimestamp = ts
txn.UpdateDeadlineMaybe(ts)
}