Exemplo n.º 1
0
// Ensure a node can be removed.
func TestData_DeleteNode_Basic(t *testing.T) {
	var data meta.Data
	if err := data.CreateNode("host0"); err != nil {
		t.Fatal(err)
	} else if err = data.CreateNode("host1"); err != nil {
		t.Fatal(err)
	} else if err := data.CreateNode("host2"); err != nil {
		t.Fatal(err)
	}

	if err := data.DeleteNode(1, false); err != nil {
		t.Fatal(err)
	} else if len(data.Nodes) != 2 {
		t.Fatalf("unexpected node count: %d", len(data.Nodes))
	} else if data.Nodes[0] != (meta.NodeInfo{ID: 2, Host: "host1"}) {
		t.Fatalf("unexpected node: %#v", data.Nodes[0])
	} else if data.Nodes[1] != (meta.NodeInfo{ID: 3, Host: "host2"}) {
		t.Fatalf("unexpected node: %#v", data.Nodes[1])
	}
}
Exemplo n.º 2
0
// Ensure a node can be removed with shard info in play
func TestData_DeleteNode_Shards(t *testing.T) {
	var data meta.Data
	if err := data.CreateNode("host0"); err != nil {
		t.Fatal(err)
	} else if err = data.CreateNode("host1"); err != nil {
		t.Fatal(err)
	} else if err := data.CreateNode("host2"); err != nil {
		t.Fatal(err)
	} else if err := data.CreateNode("host3"); err != nil {
		t.Fatal(err)
	}

	if err := data.CreateDatabase("mydb"); err != nil {
		t.Fatal(err)
	}

	rpi := &meta.RetentionPolicyInfo{
		Name:     "myrp",
		ReplicaN: 3,
	}
	if err := data.CreateRetentionPolicy("mydb", rpi); err != nil {
		t.Fatal(err)
	}
	if err := data.CreateShardGroup("mydb", "myrp", time.Now()); err != nil {
		t.Fatal(err)
	}
	if len(data.Databases[0].RetentionPolicies[0].ShardGroups[0].Shards[0].Owners) != 3 {
		t.Fatal("wrong number of shard owners")
	}
	if err := data.DeleteNode(2, false); err != nil {
		t.Fatal(err)
	}
	if got, exp := len(data.Databases[0].RetentionPolicies[0].ShardGroups[0].Shards[0].Owners), 2; exp != got {
		t.Fatalf("wrong number of shard owners, got %d, exp %d", got, exp)
	}
	for _, s := range data.Databases[0].RetentionPolicies[0].ShardGroups[0].Shards {
		if s.OwnedBy(2) {
			t.Fatal("shard still owned by delted node")
		}
	}
}