當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Storage.RetrieveNode方法代碼示例

本文整理匯總了Golang中github.com/tsuru/docker-cluster/cluster.Storage.RetrieveNode方法的典型用法代碼示例。如果您正苦於以下問題:Golang Storage.RetrieveNode方法的具體用法?Golang Storage.RetrieveNode怎麽用?Golang Storage.RetrieveNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/tsuru/docker-cluster/cluster.Storage的用法示例。


在下文中一共展示了Storage.RetrieveNode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: testStorageStoreRetrieveNode

func testStorageStoreRetrieveNode(storage cluster.Storage, t *testing.T) {
    node1 := cluster.Node{Address: "my-addr-1", Metadata: map[string]string{"abc": "def"}}
    defer storage.RemoveNode("my-addr-1")
    err := storage.StoreNode(node1)
    assertIsNil(err, t)
    nd, err := storage.RetrieveNode("my-addr-1")
    assertIsNil(err, t)
    if !reflect.DeepEqual(nd, node1) {
        t.Errorf("unexpected node, expected: %#v, got: %#v", node1, nd)
    }
    _, err = storage.RetrieveNode("my-addr-xxxx")
    if err != cstorage.ErrNoSuchNode {
        t.Errorf("Expected ErrNoSuchNode got: %#v", err)
    }
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:15,代碼來源:storage.go

示例2: testStorageStoreAlreadyLocked

func testStorageStoreAlreadyLocked(storage cluster.Storage, t *testing.T) {
    node1 := cluster.Node{
        Address:  "my-addr-locked",
        Metadata: map[string]string{},
        Healing:  cluster.HealingData{LockedUntil: time.Now().UTC().Add(5 * time.Second), IsFailure: true},
    }
    defer storage.RemoveNode("my-addr-locked")
    err := storage.StoreNode(node1)
    assertIsNil(err, t)
    nd, err := storage.RetrieveNode("my-addr-locked")
    assertIsNil(err, t)
    duration := nd.Healing.LockedUntil.Sub(node1.Healing.LockedUntil)
    if duration < 0 {
        duration = -duration
    }
    if duration > 1*time.Second {
        t.Errorf("unexpected node, expected: %#v, got: %#v", node1, nd)
    }
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:19,代碼來源:storage.go

示例3: testStorageLockNodeHealing

func testStorageLockNodeHealing(storage cluster.Storage, t *testing.T) {
    defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(100))
    node := cluster.Node{Address: "addr-xyz"}
    defer storage.RemoveNode("addr-xyz")
    err := storage.StoreNode(node)
    assertIsNil(err, t)
    successCount := 0
    wg := sync.WaitGroup{}
    wg.Add(50)
    for i := 0; i < 50; i++ {
        go func() {
            defer wg.Done()
            locked, err := storage.LockNodeForHealing("addr-xyz", true, 5*time.Second)
            assertIsNil(err, t)
            if locked {
                successCount++
            }
        }()
    }
    wg.Wait()
    if successCount != 1 {
        t.Fatalf("Expected success in only one goroutine, got: %d", successCount)
    }
    dbNode, err := storage.RetrieveNode("addr-xyz")
    assertIsNil(err, t)
    if dbNode.Healing.LockedUntil.IsZero() {
        t.Fatal("Expected node Healing.LockedUntil not to be zero")
    }
    if !dbNode.Healing.IsFailure {
        t.Fatal("Expected node healing.isFailure to be true")
    }
    dbNode.Healing = cluster.HealingData{}
    err = storage.UpdateNode(dbNode)
    assertIsNil(err, t)
    dbNode, err = storage.RetrieveNode("addr-xyz")
    assertIsNil(err, t)
    if !dbNode.Healing.LockedUntil.IsZero() {
        t.Fatal("Expected node Healing.LockedUntil to be zero")
    }
    if dbNode.Healing.IsFailure {
        t.Fatal("Expected node Healing.IsFailure to be false")
    }
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:43,代碼來源:storage.go


注:本文中的github.com/tsuru/docker-cluster/cluster.Storage.RetrieveNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。