本文整理汇总了Golang中github.com/cockroachdb/cockroach/util/randutil.NewPseudoSeed函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPseudoSeed函数的具体用法?Golang NewPseudoSeed怎么用?Golang NewPseudoSeed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPseudoSeed函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestGossipPeerings
func TestGossipPeerings(t *testing.T) {
c := StartCluster(t)
defer c.AssertAndStop(t)
num := c.NumNodes()
checkGossip(t, c, 20*time.Second, hasPeers(num))
// Restart the first node.
log.Infof("restarting node 0")
if err := c.Restart(0); err != nil {
t.Fatal(err)
}
checkGossip(t, c, 20*time.Second, hasPeers(num))
// Restart another node (if there is one).
rand.Seed(randutil.NewPseudoSeed())
var pickedNode int
if num > 1 {
pickedNode = rand.Intn(num-1) + 1
}
log.Infof("restarting node %d", pickedNode)
if err := c.Restart(pickedNode); err != nil {
t.Fatal(err)
}
checkGossip(t, c, 20*time.Second, hasPeers(num))
}
开发者ID:Ralkage,项目名称:cockroach,代码行数:26,代码来源:gossip_peerings_test.go
示例2: main
func main() {
// Seed the math/rand RNG from crypto/rand.
rand.Seed(randutil.NewPseudoSeed())
if len(os.Args) == 1 {
os.Args = append(os.Args, "help")
}
if err := cli.Run(os.Args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "Failed running command %q: %v\n", os.Args[1:], err)
os.Exit(1)
}
}
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:12,代码来源:main.go
示例3: main
func main() {
// Instruct Go to use all CPU cores.
// TODO(spencer): this may be excessive and result in worse
// performance. We should keep an eye on this as we move to
// production workloads.
numCPU := runtime.NumCPU()
runtime.GOMAXPROCS(numCPU)
rand.Seed(randutil.NewPseudoSeed())
if log.V(1) {
log.Infof("running using %d processor cores", numCPU)
}
if len(os.Args) == 1 {
os.Args = append(os.Args, "help")
}
if err := cli.Run(os.Args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "Failed running command %q: %v\n", os.Args[1:], err)
os.Exit(1)
}
}
开发者ID:nkhuyu,项目名称:cockroach,代码行数:20,代码来源:main.go
示例4: TestGossipPeerings
func TestGossipPeerings(t *testing.T) {
l := localcluster.Create(*numNodes, stopper)
l.Start()
defer l.AssertAndStop(t)
checkGossip(t, l, 20*time.Second, hasPeers(len(l.Nodes)))
// Restart the first node.
log.Infof("restarting node 0")
if err := l.Nodes[0].Restart(5); err != nil {
t.Fatal(err)
}
checkGossip(t, l, 20*time.Second, hasPeers(len(l.Nodes)))
// Restart another node.
rand.Seed(randutil.NewPseudoSeed())
pickedNode := rand.Intn(len(l.Nodes)-1) + 1
log.Infof("restarting node %d", pickedNode)
if err := l.Nodes[pickedNode].Restart(5); err != nil {
t.Fatal(err)
}
checkGossip(t, l, 20*time.Second, hasPeers(len(l.Nodes)))
}
开发者ID:nporsche,项目名称:cockroach,代码行数:23,代码来源:gossip_peerings_test.go
示例5: TestFailedReplicaChange
func TestFailedReplicaChange(t *testing.T) {
defer leaktest.AfterTest(t)
defer func() { storage.TestingCommandFilter = nil }()
seed := randutil.NewPseudoSeed()
rand.Seed(seed)
log.Infof("using seed %d", seed)
mtc := startMultiTestContext(t, 2)
defer mtc.Stop()
var runFilter atomic.Value
runFilter.Store(true)
storage.TestingCommandFilter = func(args roachpb.Request, _ roachpb.Header) error {
if runFilter.Load().(bool) {
if et, ok := args.(*roachpb.EndTransactionRequest); ok && et.Commit {
return util.Errorf("boom")
}
return nil
}
return nil
}
rng, err := mtc.stores[0].GetReplica(1)
if err != nil {
t.Fatal(err)
}
err = rng.ChangeReplicas(roachpb.ADD_REPLICA,
roachpb.ReplicaDescriptor{
NodeID: mtc.stores[1].Ident.NodeID,
StoreID: mtc.stores[1].Ident.StoreID,
}, rng.Desc())
if err == nil || !strings.Contains(err.Error(), "boom") {
t.Fatalf("did not get expected error: %s", err)
}
// After the aborted transaction, r.Desc was not updated.
// TODO(bdarnell): expose and inspect raft's internal state.
if len(rng.Desc().Replicas) != 1 {
t.Fatalf("expected 1 replica, found %d", len(rng.Desc().Replicas))
}
// The pending config change flag was cleared, so a subsequent attempt
// can succeed.
runFilter.Store(false)
// The first failed replica change has laid down intents. Make sure those
// are pushable by making the transaction abandoned.
mtc.manualClock.Increment(10 * storage.DefaultHeartbeatInterval.Nanoseconds())
err = rng.ChangeReplicas(roachpb.ADD_REPLICA,
roachpb.ReplicaDescriptor{
NodeID: mtc.stores[1].Ident.NodeID,
StoreID: mtc.stores[1].Ident.StoreID,
}, rng.Desc())
if err != nil {
t.Fatal(err)
}
// Wait for the range to sync to both replicas (mainly so leaktest doesn't
// complain about goroutines involved in the process).
if err := util.IsTrueWithin(func() bool {
for _, store := range mtc.stores {
rang, err := store.GetReplica(1)
if err != nil {
return false
}
if len(rang.Desc().Replicas) == 1 {
return false
}
}
return true
}, 1*time.Second); err != nil {
t.Fatal(err)
}
}
开发者ID:nporsche,项目名称:cockroach,代码行数:77,代码来源:client_raft_test.go
注:本文中的github.com/cockroachdb/cockroach/util/randutil.NewPseudoSeed函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论