本文整理匯總了Golang中github.com/portworx/kvdb.Kvdb.Unlock方法的典型用法代碼示例。如果您正苦於以下問題:Golang Kvdb.Unlock方法的具體用法?Golang Kvdb.Unlock怎麽用?Golang Kvdb.Unlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/portworx/kvdb.Kvdb
的用法示例。
在下文中一共展示了Kvdb.Unlock方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: lockBasic
func lockBasic(kv kvdb.Kvdb, t *testing.T) {
lockMethods := getLockMethods(kv)
for _, lockMethod := range lockMethods {
fmt.Println("lock")
key := "locktest"
kvPair, err := lockMethod(key)
assert.NoError(t, err, "Unexpected error in lock")
if kvPair == nil {
return
}
err = kv.Unlock(kvPair)
assert.NoError(t, err, "Unexpected error from Unlock")
kvPair, err = lockMethod(key)
assert.NoError(t, err, "Failed to lock after unlock")
err = kv.Unlock(kvPair)
assert.NoError(t, err, "Unexpected error from Unlock")
}
}
示例2: lock
func lock(kv kvdb.Kvdb, t *testing.T) {
lockMethods := getLockMethods(kv)
for _, lockMethod := range lockMethods {
fmt.Println("lock")
key := "locktest"
kvPair, err := lockMethod(key)
assert.NoError(t, err, "Unexpected error in lock")
if kvPair == nil {
return
}
// For consul unlock does not deal with the value part of the kvPair
/*
stash := *kvPair
stash.Value = []byte("hoohah")
fmt.Println("bad unlock")
err = kv.Unlock(&stash)
assert.Error(t, err, "Unlock should fail for bad KVPair")
*/
fmt.Println("unlock")
err = kv.Unlock(kvPair)
assert.NoError(t, err, "Unexpected error from Unlock")
fmt.Println("relock")
kvPair, err = lockMethod(key)
assert.NoError(t, err, "Failed to lock after unlock")
fmt.Println("reunlock")
err = kv.Unlock(kvPair)
assert.NoError(t, err, "Unexpected error from Unlock")
fmt.Println("repeat lock once")
kvPair, err = lockMethod(key)
assert.NoError(t, err, "Failed to lock unlock")
done := 0
go func() {
time.Sleep(time.Second * 10)
done = 1
err = kv.Unlock(kvPair)
fmt.Println("repeat lock unlock once")
assert.NoError(t, err, "Unexpected error from Unlock")
}()
fmt.Println("repeat lock lock twice")
kvPair, err = lockMethod(key)
assert.NoError(t, err, "Failed to lock")
assert.Equal(t, done, 1, "Locked before unlock")
fmt.Println("repeat lock unlock twice")
err = kv.Unlock(kvPair)
assert.NoError(t, err, "Unexpected error from Unlock")
for done == 0 {
time.Sleep(time.Second)
}
key = "doubleLock"
kvPair, err = lockMethod(key)
assert.NoError(t, err, "Unexpected error in lock")
go func() {
time.Sleep(30 * time.Second)
err = kv.Unlock(kvPair)
assert.NoError(t, err, "Unexpected error from Unlock")
}()
kvPair2, err := lockMethod(key)
assert.NoError(t, err, "Double lock")
err = kv.Unlock(kvPair2)
assert.NoError(t, err, "Unexpected error from Unlock")
}
}