test(keeper): add test cases
This commit is contained in:
parent
f1902dd69c
commit
c81bb880f0
|
@ -2,6 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
|
@ -96,3 +97,38 @@ func TestAdapter2(t *testing.T) {
|
|||
|
||||
conn.Exec(context.Background(), "drop database "+c.Metrics.Database.Name, util.GetQidOwn())
|
||||
}
|
||||
|
||||
func Test_adapterTableSql(t *testing.T) {
|
||||
conn, _ := db.NewConnector("root", "taosdata", "127.0.0.1", 6041, false)
|
||||
defer conn.Close()
|
||||
|
||||
dbName := "db_202412031446"
|
||||
conn.Exec(context.Background(), "create database "+dbName, util.GetQidOwn())
|
||||
defer conn.Exec(context.Background(), "drop database "+dbName, util.GetQidOwn())
|
||||
|
||||
conn, _ = db.NewConnectorWithDb("root", "taosdata", "127.0.0.1", 6041, dbName, false)
|
||||
defer conn.Close()
|
||||
|
||||
conn.Exec(context.Background(), adapterTableSql, util.GetQidOwn())
|
||||
|
||||
testCases := []struct {
|
||||
ep string
|
||||
wantErr bool
|
||||
}{
|
||||
{"", false},
|
||||
{"hello", false},
|
||||
{strings.Repeat("a", 128), false},
|
||||
{strings.Repeat("a", 255), false},
|
||||
{strings.Repeat("a", 256), true},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
sql := fmt.Sprintf("create table d%d using adapter_requests tags ('%s', 0)", i, tc.ep)
|
||||
_, err := conn.Exec(context.Background(), sql, util.GetQidOwn())
|
||||
if tc.wantErr {
|
||||
assert.Error(t, err) // [0x2653] Value too long for column/tag: endpoint
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -748,13 +748,14 @@ func (gm *GeneralMetric) initColumnSeqMap() error {
|
|||
}
|
||||
|
||||
func (gm *GeneralMetric) createSTables() error {
|
||||
var createTableSql = "create stable if not exists taosd_cluster_basic " +
|
||||
"(ts timestamp, first_ep varchar(255), first_ep_dnode_id INT, cluster_version varchar(20)) " +
|
||||
"tags (cluster_id varchar(50))"
|
||||
|
||||
if gm.conn == nil {
|
||||
return errNoConnection
|
||||
}
|
||||
|
||||
createTableSql := "create stable if not exists taosd_cluster_basic " +
|
||||
"(ts timestamp, first_ep varchar(255), first_ep_dnode_id INT, cluster_version varchar(20)) " +
|
||||
"tags (cluster_id varchar(50))"
|
||||
|
||||
_, err := gm.conn.Exec(context.Background(), createTableSql, util.GetQidOwn())
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/taosdata/taoskeeper/db"
|
||||
|
@ -255,6 +256,7 @@ func TestGenMetric(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetSubTableName(t *testing.T) {
|
||||
tests := []struct {
|
||||
stbName string
|
||||
|
@ -356,3 +358,42 @@ func TestGetSubTableName(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_createSTables(t *testing.T) {
|
||||
conn, _ := db.NewConnector("root", "taosdata", "127.0.0.1", 6041, false)
|
||||
defer conn.Close()
|
||||
|
||||
dbName := "db_202412031527"
|
||||
conn.Exec(context.Background(), "create database "+dbName, util.GetQidOwn())
|
||||
defer conn.Exec(context.Background(), "drop database "+dbName, util.GetQidOwn())
|
||||
|
||||
conn, _ = db.NewConnectorWithDb("root", "taosdata", "127.0.0.1", 6041, dbName, false)
|
||||
defer conn.Close()
|
||||
|
||||
gm := GeneralMetric{conn: conn}
|
||||
gm.createSTables()
|
||||
|
||||
testCases := []struct {
|
||||
ep string
|
||||
wantErr bool
|
||||
}{
|
||||
{"", false},
|
||||
{"hello", false},
|
||||
{strings.Repeat("a", 128), false},
|
||||
{strings.Repeat("a", 255), false},
|
||||
{strings.Repeat("a", 256), true},
|
||||
}
|
||||
|
||||
conn.Exec(context.Background(),
|
||||
"create table d0 using taosd_cluster_basic tags('cluster_id')", util.GetQidOwn())
|
||||
|
||||
for _, tc := range testCases {
|
||||
sql := fmt.Sprintf("insert into d0 (ts, first_ep) values(%d, '%s')", time.Now().UnixMilli(), tc.ep)
|
||||
_, err := conn.Exec(context.Background(), sql, util.GetQidOwn())
|
||||
if tc.wantErr {
|
||||
assert.Error(t, err) // [0x2653] Value too long for column/tag: endpoint
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/taosdata/taoskeeper/db"
|
||||
"github.com/taosdata/taoskeeper/util"
|
||||
)
|
||||
|
||||
func TestCreateClusterInfoSql(t *testing.T) {
|
||||
conn, _ := db.NewConnector("root", "taosdata", "127.0.0.1", 6041, false)
|
||||
defer conn.Close()
|
||||
|
||||
dbName := "db_202412031539"
|
||||
conn.Exec(context.Background(), "create database "+dbName, util.GetQidOwn())
|
||||
defer conn.Exec(context.Background(), "drop database "+dbName, util.GetQidOwn())
|
||||
|
||||
conn, _ = db.NewConnectorWithDb("root", "taosdata", "127.0.0.1", 6041, dbName, false)
|
||||
defer conn.Close()
|
||||
|
||||
conn.Exec(context.Background(), CreateClusterInfoSql, util.GetQidOwn())
|
||||
|
||||
testCases := []struct {
|
||||
ep string
|
||||
wantErr bool
|
||||
}{
|
||||
{"", false},
|
||||
{"hello", false},
|
||||
{strings.Repeat("a", 128), false},
|
||||
{strings.Repeat("a", 255), false},
|
||||
{strings.Repeat("a", 256), true},
|
||||
}
|
||||
|
||||
conn.Exec(context.Background(),
|
||||
"create table d0 using cluster_info tags('cluster_id')", util.GetQidOwn())
|
||||
|
||||
for _, tc := range testCases {
|
||||
sql := fmt.Sprintf("insert into d0 (ts, first_ep) values(%d, '%s')", time.Now().UnixMilli(), tc.ep)
|
||||
_, err := conn.Exec(context.Background(), sql, util.GetQidOwn())
|
||||
if tc.wantErr {
|
||||
assert.Error(t, err) // [0x2653] Value too long for column/tag: endpoint
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -315,7 +315,6 @@ func (cmd *Command) TransferDataToDest(data *db.Data, dstTable string, tagNum in
|
|||
|
||||
// cluster_info
|
||||
func (cmd *Command) TransferTaosdClusterBasicInfo() error {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
endTime := time.Now()
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/taosdata/taoskeeper/db"
|
||||
"github.com/taosdata/taoskeeper/infrastructure/config"
|
||||
"github.com/taosdata/taoskeeper/util"
|
||||
)
|
||||
|
||||
func TestTransferTaosdClusterBasicInfo(t *testing.T) {
|
||||
config.InitConfig()
|
||||
|
||||
conn, _ := db.NewConnector("root", "taosdata", "127.0.0.1", 6041, false)
|
||||
defer conn.Close()
|
||||
|
||||
dbName := "db_202412031539"
|
||||
conn.Exec(context.Background(), "create database "+dbName, util.GetQidOwn())
|
||||
defer conn.Exec(context.Background(), "drop database "+dbName, util.GetQidOwn())
|
||||
|
||||
conn, _ = db.NewConnectorWithDb("root", "taosdata", "127.0.0.1", 6041, dbName, false)
|
||||
defer conn.Close()
|
||||
|
||||
cmd := Command{conn: conn, fromTime: time.Now().Add(time.Duration(1 * time.Hour))}
|
||||
cmd.TransferTaosdClusterBasicInfo()
|
||||
|
||||
testCases := []struct {
|
||||
ep string
|
||||
wantErr bool
|
||||
}{
|
||||
{"", false},
|
||||
{"hello", false},
|
||||
{strings.Repeat("a", 128), false},
|
||||
{strings.Repeat("a", 255), false},
|
||||
{strings.Repeat("a", 256), true},
|
||||
}
|
||||
|
||||
conn.Exec(context.Background(),
|
||||
"create table d0 using taosd_cluster_basic tags('cluster_id')", util.GetQidOwn())
|
||||
|
||||
for _, tc := range testCases {
|
||||
sql := fmt.Sprintf("insert into d0 (ts, first_ep) values(%d, '%s')", time.Now().UnixMilli(), tc.ep)
|
||||
_, err := conn.Exec(context.Background(), sql, util.GetQidOwn())
|
||||
if tc.wantErr {
|
||||
assert.Error(t, err) // [0x2653] Value too long for column/tag: endpoint
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEmpty(t *testing.T) {
|
||||
}
|
|
@ -118,9 +118,7 @@ func GetQid(qidStr string) uint64 {
|
|||
}
|
||||
|
||||
func GetQidOwn() uint64 {
|
||||
|
||||
id := atomic.AddUint64(&globalCounter64, 1)
|
||||
|
||||
if id > 0x00ffffffffffffff {
|
||||
atomic.StoreUint64(&globalCounter64, 1)
|
||||
id = 1
|
||||
|
|
Loading…
Reference in New Issue