本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.Impl.UnlockShardForAction方法的典型用法代码示例。如果您正苦于以下问题:Golang Impl.UnlockShardForAction方法的具体用法?Golang Impl.UnlockShardForAction怎么用?Golang Impl.UnlockShardForAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/topo.Impl
的用法示例。
在下文中一共展示了Impl.UnlockShardForAction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkShardLockTimeout
func checkShardLockTimeout(ctx context.Context, t *testing.T, ts topo.Impl) {
lockPath, err := ts.LockShardForAction(ctx, "test_keyspace", "10-20", "fake-content")
if err != nil {
t.Fatalf("LockShardForAction: %v", err)
}
// test we can't take the lock again
fastCtx, cancel := context.WithTimeout(ctx, timeUntilLockIsTaken)
if _, err := ts.LockShardForAction(fastCtx, "test_keyspace", "10-20", "unused-fake-content"); err != topo.ErrTimeout {
t.Fatalf("LockShardForAction(again): %v", err)
}
cancel()
// test we can interrupt taking the lock
interruptCtx, cancel := context.WithCancel(ctx)
go func() {
time.Sleep(timeUntilLockIsTaken)
cancel()
}()
if _, err := ts.LockShardForAction(interruptCtx, "test_keyspace", "10-20", "unused-fake-content"); err != topo.ErrInterrupted {
t.Fatalf("LockShardForAction(interrupted): %v", err)
}
if err := ts.UnlockShardForAction(ctx, "test_keyspace", "10-20", lockPath, "fake-results"); err != nil {
t.Fatalf("UnlockShardForAction(): %v", err)
}
// test we can't unlock again
if err := ts.UnlockShardForAction(ctx, "test_keyspace", "10-20", lockPath, "fake-results"); err == nil {
t.Error("UnlockShardForAction(again) worked")
}
}
示例2: checkShardLockUnblocks
// checkShardLockUnblocks makes sure that a routine waiting on a lock
// is unblocked when another routine frees the lock
func checkShardLockUnblocks(ctx context.Context, t *testing.T, ts topo.Impl) {
unblock := make(chan struct{})
finished := make(chan struct{})
// as soon as we're unblocked, we try to lock the shard
go func() {
<-unblock
lockPath, err := ts.LockShardForAction(ctx, "test_keyspace", "10-20", "fake-content")
if err != nil {
t.Fatalf("LockShardForAction(test_keyspace, 10-20) failed: %v", err)
}
if err = ts.UnlockShardForAction(ctx, "test_keyspace", "10-20", lockPath, "fake-results"); err != nil {
t.Fatalf("UnlockShardForAction(test_keyspace, 10-20): %v", err)
}
close(finished)
}()
// lock the shard
lockPath2, err := ts.LockShardForAction(ctx, "test_keyspace", "10-20", "fake-content")
if err != nil {
t.Fatalf("LockShardForAction(test_keyspace, 10-20) failed: %v", err)
}
// unblock the go routine so it starts waiting
close(unblock)
// sleep for a while so we're sure the go routine is blocking
time.Sleep(timeUntilLockIsTaken)
if err = ts.UnlockShardForAction(ctx, "test_keyspace", "10-20", lockPath2, "fake-results"); err != nil {
t.Fatalf("UnlockShardForAction(test_keyspace, 10-20): %v", err)
}
timeout := time.After(10 * time.Second)
select {
case <-finished:
case <-timeout:
t.Fatalf("unlocking timed out")
}
}