2021-01-19 11:37:16 +08:00
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-04-19 10:34:56 +08:00
|
|
|
const (
|
|
|
|
collectionID0 = UniqueID(0)
|
|
|
|
collectionID1 = UniqueID(1)
|
|
|
|
collectionName0 = "collection_0"
|
|
|
|
collectionName1 = "collection_1"
|
|
|
|
)
|
|
|
|
|
2021-01-25 18:33:10 +08:00
|
|
|
func TestMetaService_All(t *testing.T) {
|
2021-01-19 11:37:16 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
replica := newReplica()
|
2021-01-25 18:33:10 +08:00
|
|
|
mFactory := &MasterServiceFactory{}
|
2021-04-19 10:34:56 +08:00
|
|
|
mFactory.setCollectionID(collectionID0)
|
|
|
|
mFactory.setCollectionName(collectionName0)
|
|
|
|
ms := newMetaService(ctx, replica, mFactory)
|
2021-01-25 18:33:10 +08:00
|
|
|
|
|
|
|
t.Run("Test getCollectionNames", func(t *testing.T) {
|
2021-04-19 10:34:56 +08:00
|
|
|
names, err := ms.getCollectionNames(ctx)
|
2021-01-25 18:33:10 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(names))
|
2021-04-19 10:34:56 +08:00
|
|
|
assert.Equal(t, collectionName0, names[0])
|
2021-01-25 18:33:10 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test createCollection", func(t *testing.T) {
|
2021-04-19 10:34:56 +08:00
|
|
|
hasColletion := ms.replica.hasCollection(collectionID0)
|
2021-01-25 18:33:10 +08:00
|
|
|
assert.False(t, hasColletion)
|
|
|
|
|
2021-04-19 10:34:56 +08:00
|
|
|
err := ms.createCollection(ctx, collectionName0)
|
2021-01-25 18:33:10 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-19 10:34:56 +08:00
|
|
|
hasColletion = ms.replica.hasCollection(collectionID0)
|
2021-01-25 18:33:10 +08:00
|
|
|
assert.True(t, hasColletion)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test loadCollections", func(t *testing.T) {
|
2021-04-19 10:34:56 +08:00
|
|
|
hasColletion := ms.replica.hasCollection(collectionID1)
|
2021-01-25 18:33:10 +08:00
|
|
|
assert.False(t, hasColletion)
|
|
|
|
|
|
|
|
mFactory.setCollectionID(1)
|
2021-04-19 10:34:56 +08:00
|
|
|
mFactory.setCollectionName(collectionName1)
|
|
|
|
err := ms.loadCollections(ctx)
|
2021-01-25 18:33:10 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-04-19 10:34:56 +08:00
|
|
|
hasColletion = ms.replica.hasCollection(collectionID0)
|
2021-01-25 18:33:10 +08:00
|
|
|
assert.True(t, hasColletion)
|
2021-04-19 10:34:56 +08:00
|
|
|
hasColletion = ms.replica.hasCollection(collectionID1)
|
2021-01-25 18:33:10 +08:00
|
|
|
assert.True(t, hasColletion)
|
|
|
|
})
|
2021-01-19 11:37:16 +08:00
|
|
|
|
2021-04-19 10:34:56 +08:00
|
|
|
t.Run("Test Init", func(t *testing.T) {
|
|
|
|
ms1 := newMetaService(ctx, replica, mFactory)
|
|
|
|
ms1.init()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test printCollectionStruct", func(t *testing.T) {
|
|
|
|
mf := &MetaFactory{}
|
|
|
|
collectionMeta := mf.CollectionMetaFactory(collectionID0, collectionName0)
|
|
|
|
printCollectionStruct(collectionMeta)
|
|
|
|
})
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|