github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/client/meta_cache_test.go (about) 1 package client 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestMetaCache(t *testing.T) { 10 meta := &metaCache{ 11 sessionTsMap: make(map[string]uint64), 12 collInfoMap: make(map[string]collInfo), 13 } 14 15 t.Run("session-ts-get", func(t *testing.T) { 16 ts, ok := meta.getSessionTs("") 17 assert.False(t, ok) 18 assert.Equal(t, uint64(0), ts) 19 }) 20 21 t.Run("session-ts-set-then-get", func(t *testing.T) { 22 meta.setSessionTs("0", 1) 23 ts, ok := meta.getSessionTs("0") 24 assert.True(t, ok) 25 assert.Equal(t, uint64(1), ts) 26 }) 27 28 t.Run("session-ts-monotonic-set", func(t *testing.T) { 29 meta.setSessionTs("0", 2) 30 meta.setSessionTs("0", 1) 31 ts, ok := meta.getSessionTs("0") 32 assert.True(t, ok) 33 assert.Equal(t, uint64(2), ts) 34 }) 35 36 t.Run("info-get", func(t *testing.T) { 37 info, ok := meta.getCollectionInfo("") 38 assert.False(t, ok) 39 assert.Nil(t, info) 40 }) 41 42 t.Run("info-set-get", func(t *testing.T) { 43 info1 := &collInfo{ 44 Name: "aaa", 45 } 46 meta.setCollectionInfo(info1.Name, info1) 47 info2, ok := meta.getCollectionInfo(info1.Name) 48 assert.Equal(t, info1, info2) 49 assert.True(t, ok) 50 meta.setCollectionInfo(info1.Name, nil) 51 info2, ok = meta.getCollectionInfo(info1.Name) 52 assert.Nil(t, info2) 53 assert.False(t, ok) 54 }) 55 }