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


Golang Storage.RetrieveNodes方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: testStorageStoreRemoveNode

func testStorageStoreRemoveNode(storage cluster.Storage, t *testing.T) {
	node1 := cluster.Node{Address: "my-addr-1"}
	err := storage.StoreNode(node1)
	assertIsNil(err, t)
	err = storage.RemoveNode("my-addr-1")
	assertIsNil(err, t)
	err = storage.RemoveNode("my-addr-1")
	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:wdxxs2z,項目名稱:docker-cluster,代碼行數:16,代碼來源:storage.go

示例4: 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


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