未验证 提交 bd3056fc 编写于 作者: C Cai Yudong 提交者: GitHub

Improve tso codecov (#7407)

Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>
上级 3721cbfe
......@@ -12,6 +12,7 @@
package tso
import (
"math"
"os"
"strings"
"testing"
......@@ -87,8 +88,58 @@ func TestGlobalTSOAllocator_All(t *testing.T) {
assert.Nil(t, err)
})
t.Run("Alloc", func(t *testing.T) {
_, err := gTestTsoAllocator.Alloc(100)
assert.Nil(t, err)
})
t.Run("AllocOne", func(t *testing.T) {
_, err := gTestTsoAllocator.AllocOne()
assert.Nil(t, err)
})
t.Run("Reset", func(t *testing.T) {
gTestTsoAllocator.Reset()
})
}
func TestGlobalTSOAllocator_Fail(t *testing.T) {
endpoints := os.Getenv("ETCD_ENDPOINTS")
if endpoints == "" {
endpoints = "localhost:2379"
}
etcdEndpoints := strings.Split(endpoints, ",")
etcdKV, err := tsoutil.NewTSOKVBase(etcdEndpoints, "/test/root/kv", "tsoTest")
assert.NoError(t, err)
gTestTsoAllocator = NewGlobalTSOAllocator("timestamp", etcdKV)
t.Run("Initialize", func(t *testing.T) {
err := gTestTsoAllocator.Initialize()
assert.Nil(t, err)
})
t.Run("GenerateTSO_invalid", func(t *testing.T) {
_, err := gTestTsoAllocator.GenerateTSO(0)
assert.NotNil(t, err)
})
gTestTsoAllocator.SetLimitMaxLogic(true)
t.Run("SetTSO_invalid", func(t *testing.T) {
err := gTestTsoAllocator.SetTSO(0)
assert.NotNil(t, err)
err = gTestTsoAllocator.SetTSO(math.MaxUint64)
assert.NotNil(t, err)
})
t.Run("Alloc_invalid", func(t *testing.T) {
_, err := gTestTsoAllocator.Alloc(0)
assert.NotNil(t, err)
_, err = gTestTsoAllocator.Alloc(math.MaxUint32)
assert.NotNil(t, err)
})
t.Run("Reset", func(t *testing.T) {
gTestTsoAllocator.Reset()
})
}
......@@ -68,19 +68,19 @@ type timestampOracle struct {
lastSavedTime atomic.Value
}
func (t *timestampOracle) loadTimestamp() (time.Time, error) {
strData, err := t.txnKV.Load(t.key)
var binData []byte = []byte(strData)
if err != nil {
return typeutil.ZeroTime, err
}
if len(binData) == 0 {
return typeutil.ZeroTime, nil
}
return typeutil.ParseTimestamp(binData)
}
//func (t *timestampOracle) loadTimestamp() (time.Time, error) {
// strData, err := t.txnKV.Load(t.key)
//
// var binData []byte = []byte(strData)
//
// if err != nil {
// return typeutil.ZeroTime, err
// }
// if len(binData) == 0 {
// return typeutil.ZeroTime, nil
// }
// return typeutil.ParseTimestamp(binData)
//}
// save timestamp, if lastTs is 0, we think the timestamp doesn't exist, so create it,
// otherwise, update it.
......@@ -95,12 +95,10 @@ func (t *timestampOracle) saveTimestamp(ts time.Time) error {
}
func (t *timestampOracle) InitTimestamp() error {
//last, err := t.loadTimestamp()
//if err != nil {
// return err
//}
next := time.Now()
// If the current system time minus the saved etcd timestamp is less than `updateTimestampGuard`,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册