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


Golang Data.CreateNode方法代碼示例

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


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

示例1: TestData_CreateShardGroup

// Ensure that a shard group can be created on a database for a given timestamp.
func TestData_CreateShardGroup(t *testing.T) {
	var data meta.Data
	if err := data.CreateNode("node0"); err != nil {
		t.Fatal(err)
	} else if err = data.CreateNode("node1"); err != nil {
		t.Fatal(err)
	} else if err = data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	} else if err = data.CreateRetentionPolicy("db0", &meta.RetentionPolicyInfo{Name: "rp0", ReplicaN: 2, Duration: 1 * time.Hour}); err != nil {
		t.Fatal(err)
	}

	// Create shard group.
	if err := data.CreateShardGroup("db0", "rp0", time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)); err != nil {
		t.Fatal(err)
	}

	// Verify the shard group was created.
	if sgi, _ := data.ShardGroupByTimestamp("db0", "rp0", time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)); !reflect.DeepEqual(sgi, &meta.ShardGroupInfo{
		ID:        1,
		StartTime: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC),
		EndTime:   time.Date(2000, time.January, 1, 1, 0, 0, 0, time.UTC),
		Shards: []meta.ShardInfo{
			{ID: 1, OwnerIDs: []uint64{1, 2}},
		},
	}) {
		t.Fatalf("unexpected shard group: %#v", sgi)
	} else if !sgi.Shards[0].OwnedBy(1) || !sgi.Shards[0].OwnedBy(2) || sgi.Shards[0].OwnedBy(3) {
		// Verify shard is correctly owned-by the node.
		t.Fatalf("new shard is not owned by correct node")
	}
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:33,代碼來源:data_test.go

示例2: TestData_CreateNode

// Ensure a node can be created.
func TestData_CreateNode(t *testing.T) {
	var data meta.Data
	if err := data.CreateNode("host0"); err != nil {
		t.Fatal(err)
	} else if !reflect.DeepEqual(data.Nodes, []meta.NodeInfo{{ID: 1, Host: "host0"}}) {
		t.Fatalf("unexpected node: %#v", data.Nodes[0])
	}
}
開發者ID:rhyolight,項目名稱:influxdb,代碼行數:9,代碼來源:data_test.go

示例3: TestData_DeleteShardGroup

// Ensure a shard group can be removed by ID.
func TestData_DeleteShardGroup(t *testing.T) {
	var data meta.Data
	if err := data.CreateNode("node0"); err != nil {
		t.Fatal(err)
	} else if err := data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	} else if err = data.CreateRetentionPolicy("db0", &meta.RetentionPolicyInfo{Name: "rp0", ReplicaN: 1}); err != nil {
		t.Fatal(err)
	} else if err := data.CreateShardGroup("db0", "rp0", time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)); err != nil {
		t.Fatal(err)
	}

	if err := data.DeleteShardGroup("db0", "rp0", 1); err != nil {
		t.Fatal(err)
	}
	if sg := data.Databases[0].RetentionPolicies[0].ShardGroups[0]; !sg.Deleted() {
		t.Fatalf("shard group not correctly flagged as deleted")
	}
}
開發者ID:rhyolight,項目名稱:influxdb,代碼行數:20,代碼來源:data_test.go

示例4: TestData_ShardGroupExpiredDeleted

// Ensure that a shard group is correctly detected as expired.
func TestData_ShardGroupExpiredDeleted(t *testing.T) {
	var data meta.Data
	if err := data.CreateNode("node0"); err != nil {
		t.Fatal(err)
	} else if err = data.CreateNode("node1"); err != nil {
		t.Fatal(err)
	} else if err = data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	} else if err = data.CreateRetentionPolicy("db0", &meta.RetentionPolicyInfo{Name: "rp0", ReplicaN: 2, Duration: 1 * time.Hour}); err != nil {
		t.Fatal(err)
	}

	// Create shard groups.
	if err := data.CreateShardGroup("db0", "rp0", time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)); err != nil {
		t.Fatal(err)
	}
	if err := data.CreateShardGroup("db0", "rp0", time.Date(2001, time.January, 1, 0, 0, 0, 0, time.UTC)); err != nil {
		t.Fatal(err)
	}

	// Check expiration.
	rp, _ := data.RetentionPolicy("db0", "rp0")
	groups := rp.ExpiredShardGroups(time.Date(2001, time.January, 1, 0, 0, 0, 0, time.UTC))
	if len(groups) != 1 {
		t.Fatalf("wrong number of expired shard groups returned, got %d, exp 1", len(groups))
	}
	if groups[0].StartTime != time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC) {
		t.Fatal("wrong shard group marked as expired")
	}

	// Check deletion.
	if err := data.DeleteShardGroup("db0", "rp0", groups[0].ID); err != nil {
		t.Fatal(err)
	}
	groups = rp.DeletedShardGroups()
	if len(groups) != 1 {
		t.Fatalf("wrong number of deleted shard groups returned, got %d, exp 1", len(groups))
	}
	if groups[0].StartTime != time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC) {
		t.Fatal("wrong shard group marked as expired")
	}

}
開發者ID:rhyolight,項目名稱:influxdb,代碼行數:44,代碼來源:data_test.go

示例5: TestData_DeleteNode_Shards

// 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")
		}
	}
}
開發者ID:rhyolight,項目名稱:influxdb,代碼行數:42,代碼來源:data_test.go

示例6: TestData_DeleteNode_Basic

// 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])
	}
}
開發者ID:rhyolight,項目名稱:influxdb,代碼行數:21,代碼來源:data_test.go


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