Files
EdgeAPI/internal/db/models/node_dao_test.go

119 lines
2.7 KiB
Go
Raw Normal View History

2022-04-04 12:08:08 +08:00
//go:build plus
// +build plus
package models_test
2020-07-22 22:17:53 +08:00
import (
"encoding/json"
2022-04-04 12:08:08 +08:00
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
2021-11-11 14:16:42 +08:00
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
2020-07-22 22:17:53 +08:00
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/dbs"
2022-04-04 12:08:08 +08:00
"github.com/iwind/TeaGo/logs"
2020-08-21 12:32:33 +08:00
"testing"
2021-08-22 11:35:33 +08:00
"time"
2020-07-22 22:17:53 +08:00
)
2020-08-21 12:32:33 +08:00
func TestNodeDAO_FindAllNodeIdsMatch(t *testing.T) {
2021-01-10 17:34:35 +08:00
var tx *dbs.Tx
2022-04-04 12:08:08 +08:00
dbs.NotifyReady()
nodeIds, err := models.SharedNodeDAO.FindAllNodeIdsMatch(tx, 1, true, 0)
2020-08-21 12:32:33 +08:00
if err != nil {
t.Fatal(err)
}
t.Log(nodeIds)
}
func TestNodeDAO_UpdateNodeUp(t *testing.T) {
dbs.NotifyReady()
2021-01-10 17:34:35 +08:00
var tx *dbs.Tx
2022-04-04 12:08:08 +08:00
err := models.SharedNodeDAO.UpdateNodeUp(tx, 57, false)
if err != nil {
t.Fatal(err)
}
2021-04-12 19:19:15 +08:00
t.Log("ok")
}
2021-07-31 22:23:11 +08:00
func TestNodeDAO_FindEnabledNodeClusterIds(t *testing.T) {
dbs.NotifyReady()
var tx *dbs.Tx
2022-04-04 12:08:08 +08:00
clusterIds, err := models.NewNodeDAO().FindEnabledAndOnNodeClusterIds(tx, 48)
2021-07-31 22:23:11 +08:00
if err != nil {
t.Fatal(err)
}
t.Log(clusterIds)
}
2021-08-22 11:35:33 +08:00
func TestNodeDAO_ComposeNodeConfig(t *testing.T) {
dbs.NotifyReady()
var before = time.Now()
2021-08-22 11:35:33 +08:00
var tx *dbs.Tx
2021-11-11 14:16:42 +08:00
var cacheMap = utils.NewCacheMap()
var dataMap = shared.NewDataMap()
//var dataMap *nodeconfigs.DataMap
nodeConfig, err := models.SharedNodeDAO.ComposeNodeConfig(tx, 48, dataMap, cacheMap)
2021-08-22 11:35:33 +08:00
if err != nil {
t.Fatal(err)
}
nodeConfig.DataMap = dataMap
2021-08-22 11:35:33 +08:00
t.Log(len(nodeConfig.Servers), "servers")
2021-11-11 14:16:42 +08:00
t.Log(cacheMap.Len(), "items")
2021-08-22 11:35:33 +08:00
t.Log(time.Since(before).Seconds()*1000, "ms")
data, err := json.Marshal(nodeConfig)
if err != nil {
t.Fatal(err)
}
t.Log(len(data), "bytes")
2021-08-22 11:35:33 +08:00
}
2022-04-04 12:08:08 +08:00
func TestNodeDAO_ComposeNodeConfig_ParentNodes(t *testing.T) {
dbs.NotifyReady()
teaconst.IsPlus = true
var tx *dbs.Tx
var cacheMap = utils.NewCacheMap()
nodeConfig, err := models.SharedNodeDAO.ComposeNodeConfig(tx, 48, nil, cacheMap)
2022-04-04 12:08:08 +08:00
if err != nil {
t.Fatal(err)
}
logs.PrintAsJSON(nodeConfig.ParentNodes, t)
}
func TestNodeDAO_FindEnabledNodeIdWithUniqueId(t *testing.T) {
dbs.NotifyReady()
var tx *dbs.Tx
// init
{
_, err := models.SharedNodeDAO.FindEnabledNodeIdWithUniqueId(tx, "a186380dbd26ccd49e75d178ec59df1b")
if err != nil {
t.Fatal(err)
}
}
var before = time.Now()
nodeId, err := models.SharedNodeDAO.FindEnabledNodeIdWithUniqueId(tx, "a186380dbd26ccd49e75d178ec59df1b")
if err != nil {
t.Fatal(err)
}
t.Log("cost:", time.Since(before).Seconds()*1000, "ms")
t.Log("nodeId:", nodeId)
{
before = time.Now()
nodeId, err := models.SharedNodeDAO.FindEnabledNodeIdWithUniqueId(tx, "a186380dbd26ccd49e75d178ec59df1b")
if err != nil {
t.Fatal(err)
}
t.Log("cost:", time.Since(before).Seconds()*1000, "ms")
t.Log("nodeId:", nodeId)
}
}