github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/internal/utils/tso/tso_test.go (about)

     1  // Licensed to the LF AI & Data foundation under one
     2  // or more contributor license agreements. See the NOTICE file
     3  // distributed with this work for additional information
     4  // regarding copyright ownership. The ASF licenses this file
     5  // to you under the Apache License, Version 2.0 (the
     6  // "License"); you may not use this file except in compliance
     7  // with the License. You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package tso
    18  
    19  import (
    20  	"testing"
    21  	"time"
    22  
    23  	"github.com/stretchr/testify/assert"
    24  )
    25  
    26  func TestParseHybridTs(t *testing.T) {
    27  	var ts uint64 = 426152581543231492
    28  	physical, logical := ParseHybridTs(ts)
    29  	assert.EqualValues(t, 1625643087552, physical)
    30  	assert.EqualValues(t, 4, logical)
    31  }
    32  
    33  func Test_Tso(t *testing.T) {
    34  	t.Run("test ComposeTSByTime", func(t *testing.T) {
    35  		physical := time.Now()
    36  		logical := int64(1000)
    37  		timestamp := ComposeTSByTime(physical, logical)
    38  		pRes, lRes := ParseTS(timestamp)
    39  		assert.Equal(t, physical.Unix(), pRes.Unix())
    40  		assert.Equal(t, uint64(logical), lRes)
    41  	})
    42  
    43  	t.Run("test GetCurrentTime", func(t *testing.T) {
    44  		curTime := GetCurrentTime()
    45  		p, l := ParseTS(curTime)
    46  		subTime := time.Since(p)
    47  		assert.Less(t, subTime, time.Millisecond)
    48  		assert.Equal(t, uint64(0), l)
    49  	})
    50  }