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


Golang cluster.Storage類代碼示例

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


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

示例1: testStorageLockNodeHealingAfterTimeout

func testStorageLockNodeHealingAfterTimeout(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)
	locked, err := storage.LockNodeForHealing("addr-xyz", true, 200*time.Millisecond)
	assertIsNil(err, t)
	locked, err = storage.LockNodeForHealing("addr-xyz", true, 200*time.Millisecond)
	assertIsNil(err, t)
	if locked {
		t.Fatal("Expected LockNodeForHealing to return false before timeout")
	}
	time.Sleep(300 * time.Millisecond)
	successCount := int32(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 {
				atomic.AddInt32(&successCount, 1)
			}
		}()
	}
	wg.Wait()
	if successCount != 1 {
		t.Fatalf("Expected LockNodeForHealing after timeout to lock only once, got: %d", successCount)
	}
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:32,代碼來源:storage.go

示例2: testStorageStoreRetrieveNodes

func testStorageStoreRetrieveNodes(storage cluster.Storage, t *testing.T) {
	node1 := cluster.Node{Address: "my-addr-1"}
	defer storage.RemoveNode("my-addr-1")
	err := storage.StoreNode(node1)
	assertIsNil(err, t)
	node2 := cluster.Node{Address: "my-addr-2", Metadata: map[string]string{"foo": "bar"}}
	defer storage.RemoveNode("my-addr-2")
	err = storage.StoreNode(node2)
	assertIsNil(err, t)
	nodes, err := storage.RetrieveNodes()
	assertIsNil(err, t)
	if len(nodes) != 2 {
		t.Fatalf("unexpected number of nodes, expected 2, got: %d", len(nodes))
	}
	sort.Sort(cluster.NodeList(nodes))
	if nodes[0].Address != node1.Address || nodes[1].Address != node2.Address {
		t.Errorf("unexpected nodes: %#v", nodes)
	}
	if !reflect.DeepEqual(node2.Metadata, nodes[1].Metadata) {
		t.Errorf("unexpected node metadata. expected: %#v got: %#v", node2.Metadata, nodes[1].Metadata)
	}
	if !reflect.DeepEqual(nodes[0].Metadata, map[string]string{}) {
		t.Errorf("unexpected node metadata. expected empty map got: %#v", nodes[0].Metadata)
	}
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:25,代碼來源:storage.go

示例3: testRetrieveImages

func testRetrieveImages(storage cluster.Storage, t *testing.T) {
	defer storage.RemoveImage("img-1", "id1", "host-1.something")
	defer storage.RemoveImage("img-1", "id1", "host-2")
	defer storage.RemoveImage("img-1", "id2", "host-2")
	err := storage.StoreImage("img-1", "id1", "host-1.something")
	assertIsNil(err, t)
	err = storage.StoreImage("img-1", "id1", "host-2")
	assertIsNil(err, t)
	imgs, err := storage.RetrieveImages()
	assertIsNil(err, t)
	if len(imgs) != 2 {
		t.Errorf("Unexpected len %d - expected %d", len(imgs), 2)
	}
}
開發者ID:roberto,項目名稱:docker-cluster,代碼行數:14,代碼來源:storage.go

示例4: testStorageUnlockNode

func testStorageUnlockNode(storage cluster.Storage, t *testing.T) {
	node := cluster.Node{Address: "addr-xyz"}
	defer storage.RemoveNode("addr-xyz")
	err := storage.StoreNode(node)
	assertIsNil(err, t)
	locked, err := storage.LockNodeForHealing("addr-xyz", true, 200*time.Millisecond)
	assertIsNil(err, t)
	err = storage.UnlockNode("addr-xyz")
	assertIsNil(err, t)
	locked, err = storage.LockNodeForHealing("addr-xyz", true, 200*time.Millisecond)
	assertIsNil(err, t)
	if !locked {
		t.Fatal("Expected LockNodeForHealing to return true after unlocking")
	}
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:15,代碼來源:storage.go

示例5: testStorageExtendNodeLock

func testStorageExtendNodeLock(storage cluster.Storage, t *testing.T) {
	node := cluster.Node{Address: "addr-xyz"}
	defer storage.RemoveNode("addr-xyz")
	err := storage.StoreNode(node)
	assertIsNil(err, t)
	locked, err := storage.LockNodeForHealing("addr-xyz", true, 200*time.Millisecond)
	assertIsNil(err, t)
	time.Sleep(300 * time.Millisecond)
	err = storage.ExtendNodeLock("addr-xyz", 200*time.Millisecond)
	assertIsNil(err, t)
	locked, err = storage.LockNodeForHealing("addr-xyz", true, 200*time.Millisecond)
	assertIsNil(err, t)
	if locked {
		t.Fatal("Expected LockNodeForHealing to return false after extending timeout")
	}
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:16,代碼來源:storage.go

示例6: testStorageStoreRetrieveImage

func testStorageStoreRetrieveImage(storage cluster.Storage, t *testing.T) {
	defer storage.RemoveImage("img-1")
	defer storage.RemoveImage("img-2")
	err := storage.StoreImage("img-1", "host-1")
	assertIsNil(err, t)
	err = storage.StoreImage("img-1", "host-2")
	assertIsNil(err, t)
	err = storage.StoreImage("img-2", "host-2")
	assertIsNil(err, t)
	hosts, err := storage.RetrieveImage("img-1")
	assertIsNil(err, t)
	sort.Strings(hosts)
	if !reflect.DeepEqual(hosts, []string{"host-1", "host-2"}) {
		t.Errorf("unexpected array %#v", hosts)
	}
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:16,代碼來源:storage.go

示例7: testStorageStoreClearMetadata

func testStorageStoreClearMetadata(storage cluster.Storage, t *testing.T) {
	defer storage.RemoveNode("my-addr-1")
	err := storage.StoreNode(cluster.Node{Address: "my-addr-1", Metadata: map[string]string{"pool": "p1"}})
	assertIsNil(err, t)
	err = storage.RemoveNode("my-addr-1")
	assertIsNil(err, t)
	err = storage.StoreNode(cluster.Node{Address: "my-addr-1"})
	assertIsNil(err, t)
	nodes, err := storage.RetrieveNodes()
	assertIsNil(err, t)
	if len(nodes) != 1 || nodes[0].Address != "my-addr-1" {
		t.Errorf("unexpected nodes: %#v", nodes)
	}
	if !reflect.DeepEqual(nodes[0].Metadata, map[string]string{}) {
		t.Errorf("unexpected node metadata. expected empty map, got: %#v", nodes[0].Metadata)
	}
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:17,代碼來源:storage.go

示例8: testStorageStoreUpdateNode

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

示例9: testStorageStoreRemoveNodes

func testStorageStoreRemoveNodes(storage cluster.Storage, t *testing.T) {
	node1 := cluster.Node{Address: "my-addr-1"}
	err := storage.StoreNode(node1)
	assertIsNil(err, t)
	node2 := cluster.Node{Address: "my-addr-2"}
	err = storage.StoreNode(node2)
	assertIsNil(err, t)
	err = storage.RemoveNodes([]string{"my-addr-1", "my-addr-2", "my-addr-3"})
	assertIsNil(err, t)
	err = storage.RemoveNodes([]string{"my-addr-1", "my-addr-2"})
	if err != cstorage.ErrNoSuchNode {
		t.Errorf("cstorage.ErrNoSuchNode was expected, got: %s", err)
	}
	nodes, err := storage.RetrieveNodes()
	assertIsNil(err, t)
	if len(nodes) > 0 {
		t.Errorf("nodes should be empty, found: %#v", nodes)
	}
}
開發者ID:roberto,項目名稱:docker-cluster,代碼行數:19,代碼來源:storage.go

示例10: testStorageStoreRemoveImage

func testStorageStoreRemoveImage(storage cluster.Storage, t *testing.T) {
	err := storage.StoreImage("img-1", "host-1")
	assertIsNil(err, t)
	err = storage.StoreImage("img-1", "host-2")
	assertIsNil(err, t)
	err = storage.RemoveImage("img-1")
	assertIsNil(err, t)
	_, err = storage.RetrieveImage("img-1")
	if err != cstorage.ErrNoSuchImage {
		t.Errorf("Error should be cstorage.ErrNoSuchImage, received: %s", err)
	}
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:12,代碼來源:storage.go

示例11: testStorageStoreImageIgnoreDups

func testStorageStoreImageIgnoreDups(storage cluster.Storage, t *testing.T) {
	defer storage.RemoveImage("img-x", "id1", "host-1")
	err := storage.StoreImage("img-x", "id1", "host-1")
	assertIsNil(err, t)
	err = storage.StoreImage("img-x", "id1", "host-1")
	assertIsNil(err, t)
	img, err := storage.RetrieveImage("img-x")
	assertIsNil(err, t)
	expected := cluster.Image{Repository: "img-x", LastId: "id1", LastNode: "host-1", History: []cluster.ImageHistory{{
		Node:    "host-1",
		ImageId: "id1",
	}}}
	compareImage(img, expected, t)
}
開發者ID:roberto,項目名稱:docker-cluster,代碼行數:14,代碼來源:storage.go

示例12: testStorageStoreImageIgnoreDups

func testStorageStoreImageIgnoreDups(storage cluster.Storage, t *testing.T) {
	defer storage.RemoveImage("img-x")
	err := storage.StoreImage("img-x", "host-1")
	assertIsNil(err, t)
	err = storage.StoreImage("img-x", "host-1")
	assertIsNil(err, t)
	hosts, err := storage.RetrieveImage("img-x")
	assertIsNil(err, t)
	if len(hosts) != 1 {
		t.Fatalf("Expected host list to have len 1, got: %d", len(hosts))
	}
	if hosts[0] != "host-1" {
		t.Fatalf("Expected host list to have value host-1, got: %s", hosts[0])
	}
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:15,代碼來源:storage.go

示例13: testStorageStoreRepeatedNodes

func testStorageStoreRepeatedNodes(storage cluster.Storage, t *testing.T) {
	defer storage.RemoveNode("my-addr-1")
	err := storage.StoreNode(cluster.Node{Address: "my-addr-1"})
	assertIsNil(err, t)
	err = storage.StoreNode(cluster.Node{Address: "my-addr-1"})
	if err != cstorage.ErrDuplicatedNodeAddress {
		t.Fatalf("Expected error cstorage.ErrDuplicatedNodeAddress, got: %#v", err)
	}
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:9,代碼來源:storage.go

示例14: testStorageStoreRemoveContainer

func testStorageStoreRemoveContainer(storage cluster.Storage, t *testing.T) {
	err := storage.StoreContainer("container-1", "host-9")
	assertIsNil(err, t)
	err = storage.RemoveContainer("container-1")
	assertIsNil(err, t)
	_, err = storage.RetrieveContainer("container-1")
	if err != cstorage.ErrNoSuchContainer {
		t.Errorf("Error should be cstorage.ErrNoSuchContainer, received: %s", err)
	}
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:10,代碼來源:storage.go

示例15: testStorageStoreEmptyMetadata

func testStorageStoreEmptyMetadata(storage cluster.Storage, t *testing.T) {
	defer storage.RemoveNode("my-addr-1")
	node1 := cluster.Node{Address: "my-addr-1", Metadata: map[string]string{}}
	err := storage.StoreNode(node1)
	assertIsNil(err, t)
	nodes, err := storage.RetrieveNodes()
	assertIsNil(err, t)
	if len(nodes) != 1 || nodes[0].Address != node1.Address {
		t.Errorf("unexpected nodes: %#v", nodes)
	}
}
開發者ID:wdxxs2z,項目名稱:docker-cluster,代碼行數:11,代碼來源:storage.go


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