| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package conflict_test
- import (
- "fmt"
- "testing"
- "time"
- "git.wecise.com/wecise/mring"
- "git.wecise.com/wecise/mring/matrix"
- "git.wecise.com/wecise/mring/mservice/service"
- "git.wecise.com/wecise/odbserver/odb/test"
- "git.wecise.com/wecise/odbserver/test/unit/mql/conflict"
- "gitee.com/wecisecode/util/logger"
- "github.com/stretchr/testify/require"
- )
- func TestConflict(t *testing.T) {
- st := time.Now()
- conflict.ConflictTest(t)
- logger.Warn("Done", time.Since(st))
- }
- func TestConflictConcur(t *testing.T) {
- logger.DefaultLogger().SetFormat("yyyy-MM-dd HH:mm:ss.SSSSSS [pid] [level] file:line msg", "\n")
- logger.DefaultLogger().SetConsoleLevel(logger.INFO)
- logger.SetLevel(logger.INFO)
- logger.Info(mring.GNode().Name(), "初始化 G ...")
- // 等待所有节点就绪,拓扑关系稳定
- mring.GNode().MeshReady(1 * time.Second)
- conflict.ConflictTest(t)
- if true {
- return
- }
- // 提前初始化G,排除G初始化时间
- g := test.TestG()
- gt := conflict.GT(t, g)
- gt.InitG()
- if matrix.Config().N == 0 || matrix.Config().N == 1 {
- // 测试状态,只有第一节点执行建类操作
- logger.Info(mring.GNode().Name(), "初始化 类 ...")
- gt.Class(``)
- } else {
- logger.Info(mring.GNode().Name(), "等待第一测试节点 初始化 类 ...")
- }
- // 所有测试节点,等待初始化建类完成
- if e := mring.GNode().GlobalSync("conflict.class", 60*time.Second); e != nil {
- logger.Error(mring.GNode().Name(), "节点间状态同步失败,", e)
- require.Nil(t, e, fmt.Sprint("节点间状态同步失败,", e))
- return
- }
- // 开始数据插入
- func() {
- logger.Info(mring.GNode().Name(), "初始化完成,开始计时")
- ts := time.Now()
- // info, e := selfmonitor.CPUMonitorStart(nil, "/tmp/bench", -1)
- // logger.Info(info)
- // if e != nil {
- // logger.Errorf(e.Error())
- // }
- defer func() {
- logger.SetLevel(logger.INFO)
- logger.Info(mring.GNode().Name(), "数据插入完成,计时结束")
- logger.Info(mring.GNode().Name(), "use time", time.Now().Sub(ts).Seconds(), "seconds")
- // if e != nil {
- // logger.Errorf(e.Error())
- // }
- // logger.Info(selfmonitor.CPUMonitorStop())
- }()
- logger.SetLevel(logger.WARN)
- gt.DataConcurrent(1000)
- // gt.Data()
- // gt.Valid()
- // conflict.ConflictTest(t)
- }()
- logger.Info(mring.GNode().Name(), "等待后台数据数据...")
- for service.ProcessingCount() > 0 {
- time.Sleep(100 * time.Millisecond)
- }
- logger.Info(mring.GNode().Name(), "等待所有节点完成测试...")
- if e := mring.GNode().GlobalSync("conflict.end", 60*time.Second); e != nil {
- logger.Error(mring.GNode().Name(), "节点间状态同步失败,", e)
- require.Nil(t, e, fmt.Sprint(mring.GNode().Name(), "节点间状态同步失败,", e))
- return
- }
- service.LogStatisticsInfo()
- time.Sleep(1 * time.Second)
- }
|