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


Golang Data.CreateDatabase方法代码示例

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


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

// Ensure that renaming a database returns an error if there is a possibly conflicting CQ
func TestData_RenameDatabase_ErrDatabaseCQConflict(t *testing.T) {
	var data meta.Data
	if err := data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	} else if err := data.CreateDatabase("db1"); err != nil {
		t.Fatal(err)
	} else if err := data.CreateContinuousQuery("db0", "cq0", `CREATE CONTINUOUS QUERY cq0 ON db0 BEGIN SELECT count() INTO "foo"."default"."bar" FROM "foo"."foobar" END`); err != nil {
		t.Fatal(err)
	} else if err := data.CreateContinuousQuery("db1", "cq1", `CREATE CONTINUOUS QUERY cq1 ON db1 BEGIN SELECT count() INTO "db1"."default"."bar" FROM "db0"."foobar" END`); err != nil {
		t.Fatal(err)
	} else if err := data.CreateContinuousQuery("db1", "cq2", `CREATE CONTINUOUS QUERY cq2 ON db1 BEGIN SELECT count() INTO "db0"."default"."bar" FROM "db1"."foobar" END`); err != nil {
		t.Fatal(err)
	} else if err := data.CreateContinuousQuery("db1", "noconflict", `CREATE CONTINUOUS QUERY noconflict ON db1 BEGIN SELECT count() INTO "db1"."default"."bar" FROM "db1"."foobar" END`); err != nil {
		t.Fatal(err)
	} else if err := data.RenameDatabase("db0", "db2"); err == nil {
		t.Fatalf("unexpected rename database success despite cq conflict")
	} else if err := data.DropContinuousQuery("db0", "cq0"); err != nil {
		t.Fatal(err)
	} else if err := data.RenameDatabase("db0", "db2"); err == nil {
		t.Fatalf("unexpected rename database success despite cq conflict")
	} else if err := data.DropContinuousQuery("db1", "cq1"); err != nil {
		t.Fatal(err)
	} else if err := data.RenameDatabase("db0", "db2"); err == nil {
		t.Fatalf("unexpected rename database success despite cq conflict")
	} else if err := data.DropContinuousQuery("db1", "cq2"); err != nil {
		t.Fatal(err)
	} else if err := data.RenameDatabase("db0", "db2"); err != nil {
		t.Fatal(err)
	}
}
开发者ID:realgo,项目名称:influxdb,代码行数:31,代码来源:data_test.go

示例3: TestData_CreateRetentionPolicy

// Ensure a retention policy can be created.
func TestData_CreateRetentionPolicy(t *testing.T) {
	data := meta.Data{Nodes: []meta.NodeInfo{{ID: 1}, {ID: 2}}}
	if err := data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	}

	// Create policy.
	if err := data.CreateRetentionPolicy("db0", &meta.RetentionPolicyInfo{
		Name:     "rp0",
		ReplicaN: 2,
		Duration: 4 * time.Hour,
	}); err != nil {
		t.Fatal(err)
	}

	// Verify policy exists.
	if !reflect.DeepEqual(data.Databases[0].RetentionPolicies, []meta.RetentionPolicyInfo{
		{
			Name:               "rp0",
			ReplicaN:           2,
			Duration:           4 * time.Hour,
			ShardGroupDuration: 1 * time.Hour,
		},
	}) {
		t.Fatalf("unexpected policies: %#v", data.Databases[0].RetentionPolicies)
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:28,代码来源:data_test.go

示例4: TestData_RenameDatabaseUpdatesPrivileges

// Ensure that user privileges are updated correctly when database is renamed.
func TestData_RenameDatabaseUpdatesPrivileges(t *testing.T) {
	var data meta.Data
	for i := 0; i < 2; i++ {
		if err := data.CreateDatabase(fmt.Sprintf("db%d", i)); err != nil {
			t.Fatal(err)
		}
	}

	data.Users = []meta.UserInfo{{
		Name:  "susy",
		Hash:  "ABC123",
		Admin: true,
		Privileges: map[string]influxql.Privilege{
			"db1": influxql.AllPrivileges, "db0": influxql.ReadPrivilege}}}

	if err := data.RenameDatabase("db1", "db2"); err != nil {
		t.Fatal(err)
	} else if !reflect.DeepEqual(data.Users,
		[]meta.UserInfo{{
			Name:  "susy",
			Hash:  "ABC123",
			Admin: true,
			Privileges: map[string]influxql.Privilege{
				"db2": influxql.AllPrivileges, "db0": influxql.ReadPrivilege}}}) {
		t.Fatalf("unexpected user privileges: %#v", data.Users)
	}
}
开发者ID:realgo,项目名称:influxdb,代码行数:28,代码来源:data_test.go

示例5: TestData_UpdateRetentionPolicy

// Ensure that a retention policy can be updated.
func TestData_UpdateRetentionPolicy(t *testing.T) {
	var data meta.Data
	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)
	}

	// Update the policy.
	var rpu meta.RetentionPolicyUpdate
	rpu.SetName("rp1")
	rpu.SetDuration(10 * time.Hour)
	rpu.SetReplicaN(3)
	if err := data.UpdateRetentionPolicy("db0", "rp0", &rpu); err != nil {
		t.Fatal(err)
	}

	// Verify the policy was changed.
	if rpi, _ := data.RetentionPolicy("db0", "rp1"); !reflect.DeepEqual(rpi, &meta.RetentionPolicyInfo{
		Name:               "rp1",
		Duration:           10 * time.Hour,
		ShardGroupDuration: 3600000000000,
		ReplicaN:           3,
	}) {
		t.Fatalf("unexpected policy: %#v", rpi)
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:28,代码来源:data_test.go

示例6: TestData_CreateDatabase

// Ensure a database can be created.
func TestData_CreateDatabase(t *testing.T) {
	var data meta.Data
	if err := data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	} else if !reflect.DeepEqual(data.Databases, []meta.DatabaseInfo{{Name: "db0"}}) {
		t.Fatalf("unexpected databases: %#v", data.Databases)
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:9,代码来源:data_test.go

示例7: TestData_DropRetentionPolicy_ErrRetentionPolicyNotFound

// Ensure an error is returned when deleting a non-existent policy.
func TestData_DropRetentionPolicy_ErrRetentionPolicyNotFound(t *testing.T) {
	var data meta.Data
	if err := data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	}
	if err := data.DropRetentionPolicy("db0", "rp0"); err != meta.ErrRetentionPolicyNotFound {
		t.Fatal(err)
	}
}
开发者ID:realgo,项目名称:influxdb,代码行数:10,代码来源:data_test.go

示例8: TestData_CreateDatabase_ErrDatabaseExists

// Ensure that creating an already existing database returns an error.
func TestData_CreateDatabase_ErrDatabaseExists(t *testing.T) {
	var data meta.Data
	if err := data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	}
	if err := data.CreateDatabase("db0"); err != meta.ErrDatabaseExists {
		t.Fatalf("unexpected error: %s", err)
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:10,代码来源:data_test.go

示例9: TestData_DropRetentionPolicy_ErrRetentionPolicyNotFound

// Ensure an error is returned when deleting a non-existent policy.
func TestData_DropRetentionPolicy_ErrRetentionPolicyNotFound(t *testing.T) {
	var data meta.Data
	if err := data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	}
	expErr := influxdb.ErrRetentionPolicyNotFound("rp0")
	if err := data.DropRetentionPolicy("db0", "rp0"); err.Error() != expErr.Error() {
		t.Fatal(err)
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:11,代码来源:data_test.go

示例10: TestData_CreateRetentionPolicy_ErrRetentionPolicyExists

// Ensure that creating an already existing policy returns an error.
func TestData_CreateRetentionPolicy_ErrRetentionPolicyExists(t *testing.T) {
	var data meta.Data
	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)
	}
	if err := data.CreateRetentionPolicy("db0", &meta.RetentionPolicyInfo{Name: "rp0", ReplicaN: 1}); err != meta.ErrRetentionPolicyExists {
		t.Fatalf("unexpected error: %s", err)
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:12,代码来源:data_test.go

示例11: TestData_CreateContinuousQuery

// Ensure a continuous query can be created.
func TestData_CreateContinuousQuery(t *testing.T) {
	var data meta.Data
	if err := data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	} else if err := data.CreateContinuousQuery("db0", "cq0", "SELECT count() FROM foo"); err != nil {
		t.Fatal(err)
	} else if !reflect.DeepEqual(data.Databases[0].ContinuousQueries, []meta.ContinuousQueryInfo{
		{Name: "cq0", Query: "SELECT count() FROM foo"},
	}) {
		t.Fatalf("unexpected queries: %#v", data.Databases[0].ContinuousQueries)
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:13,代码来源:data_test.go

示例12: TestData_DropRetentionPolicy

// Ensure a retention policy can be removed.
func TestData_DropRetentionPolicy(t *testing.T) {
	var data meta.Data
	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)
	}

	if err := data.DropRetentionPolicy("db0", "rp0"); err != nil {
		t.Fatal(err)
	} else if len(data.Databases[0].RetentionPolicies) != 0 {
		t.Fatalf("unexpected policies: %#v", data.Databases[0].RetentionPolicies)
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:15,代码来源:data_test.go

示例13: TestData_DropDatabase

// Ensure a database can be removed.
func TestData_DropDatabase(t *testing.T) {
	var data meta.Data
	for i := 0; i < 3; i++ {
		if err := data.CreateDatabase(fmt.Sprintf("db%d", i)); err != nil {
			t.Fatal(err)
		}
	}

	if err := data.DropDatabase("db1"); err != nil {
		t.Fatal(err)
	} else if !reflect.DeepEqual(data.Databases, []meta.DatabaseInfo{{Name: "db0"}, {Name: "db2"}}) {
		t.Fatalf("unexpected databases: %#v", data.Databases)
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:15,代码来源:data_test.go

示例14: TestData_CreateSubscription

// Ensure a subscription can be created.
func TestData_CreateSubscription(t *testing.T) {
	var data meta.Data
	rpi := &meta.RetentionPolicyInfo{
		Name:     "rp0",
		ReplicaN: 3,
	}
	if err := data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	} else if err := data.CreateRetentionPolicy("db0", rpi); err != nil {
		t.Fatal(err)
	} else if err := data.CreateSubscription("db0", "rp0", "s0", "ANY", []string{"udp://h0:1234", "udp://h1:1234"}); err != nil {
		t.Fatal(err)
	} else if !reflect.DeepEqual(data.Databases[0].RetentionPolicies[0].Subscriptions, []meta.SubscriptionInfo{
		{Name: "s0", Mode: "ANY", Destinations: []string{"udp://h0:1234", "udp://h1:1234"}},
	}) {
		t.Fatalf("unexpected subscriptions: %#v", data.Databases[0].RetentionPolicies[0].Subscriptions)
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:19,代码来源:data_test.go

示例15: TestData_RetentionPolicy

// Ensure that a retention policy can be retrieved.
func TestData_RetentionPolicy(t *testing.T) {
	var data meta.Data
	if err := data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	} else if err = data.CreateRetentionPolicy("db0", &meta.RetentionPolicyInfo{Name: "rp0"}); err != nil {
		t.Fatal(err)
	} else if err = data.CreateRetentionPolicy("db0", &meta.RetentionPolicyInfo{Name: "rp1"}); err != nil {
		t.Fatal(err)
	}

	if rpi, err := data.RetentionPolicy("db0", "rp0"); err != nil {
		t.Fatal(err)
	} else if !reflect.DeepEqual(rpi, &meta.RetentionPolicyInfo{
		Name:               "rp0",
		ShardGroupDuration: 604800000000000,
	}) {
		t.Fatalf("unexpected value: %#v", rpi)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:20,代码来源:data_test.go


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