当前位置: 首页>>代码示例>>Golang>>正文


Golang Storage.RemoveNode方法代码示例

本文整理汇总了Golang中github.com/tsuru/docker-cluster/cluster.Storage.RemoveNode方法的典型用法代码示例。如果您正苦于以下问题:Golang Storage.RemoveNode方法的具体用法?Golang Storage.RemoveNode怎么用?Golang Storage.RemoveNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/tsuru/docker-cluster/cluster.Storage的用法示例。


在下文中一共展示了Storage.RemoveNode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

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

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

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

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

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

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

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

示例12: testStorageStoreRetrieveNodesForMetadata

func testStorageStoreRetrieveNodesForMetadata(storage cluster.Storage, t *testing.T) {
	node1 := cluster.Node{Address: "my-addr-1", Metadata: map[string]string{
		"region": "reg1",
		"foo":    "bar",
	}}
	err := storage.StoreNode(node1)
	assertIsNil(err, t)
	defer storage.RemoveNode("my-addr-1")
	node2 := cluster.Node{Address: "my-addr-2", Metadata: map[string]string{
		"region": "reg2",
		"foo":    "bar",
	}}
	err = storage.StoreNode(node2)
	assertIsNil(err, t)
	defer storage.RemoveNode("my-addr-2")
	nodes, err := storage.RetrieveNodesByMetadata(map[string]string{"region": "reg2"})
	assertIsNil(err, t)
	if len(nodes) != 1 {
		t.Fatalf("unexpected nodes len: %d", len(nodes))
	}
	if nodes[0].Address != node2.Address {
		t.Errorf("unexpected node: %s", nodes[0].Address)
	}
	if !reflect.DeepEqual(node2.Metadata, nodes[0].Metadata) {
		t.Errorf("unexpected node metadata. expected: %#v got: %#v", node2.Metadata, nodes[0].Metadata)
	}
	nodes, err = storage.RetrieveNodesByMetadata(map[string]string{"foo": "bar"})
	assertIsNil(err, t)
	if len(nodes) != 2 {
		t.Fatalf("unexpected nodes len: %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(node1.Metadata, nodes[0].Metadata) {
		t.Errorf("unexpected node metadata. expected: %#v got: %#v", node1.Metadata, nodes[0].Metadata)
	}
	if !reflect.DeepEqual(node2.Metadata, nodes[1].Metadata) {
		t.Errorf("unexpected node metadata. expected: %#v got: %#v", node2.Metadata, nodes[1].Metadata)
	}
}
开发者ID:wdxxs2z,项目名称:docker-cluster,代码行数:42,代码来源:storage.go


注:本文中的github.com/tsuru/docker-cluster/cluster.Storage.RemoveNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。