2021-11-29 20:13:50 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-04-19 13:47:10 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-29 20:13:50 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:47:10 +08:00
|
|
|
//
|
2021-11-29 20:13:50 +08:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2021-04-19 13:47:10 +08:00
|
|
|
|
2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-10-24 10:45:57 +08:00
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
import (
|
2021-09-07 15:45:59 +08:00
|
|
|
"context"
|
2020-11-12 17:58:05 +08:00
|
|
|
"testing"
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
func TestDataSyncService_DMLFlowGraphs(t *testing.T) {
|
2021-09-07 15:45:59 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
replica, err := genSimpleReplica()
|
2021-10-26 14:46:19 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
fac := genFactory()
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-12-17 14:41:33 +08:00
|
|
|
tSafe := newTSafeReplica()
|
2022-05-31 13:42:03 +08:00
|
|
|
dataSyncService := newDataSyncService(ctx, replica, tSafe, fac)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NotNil(t, dataSyncService)
|
|
|
|
|
2022-05-24 21:11:59 +08:00
|
|
|
t.Run("test DMLFlowGraphs", func(t *testing.T) {
|
|
|
|
_, err = dataSyncService.addFlowGraphsForDMLChannels(defaultCollectionID, []Channel{defaultDMLChannel})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, dataSyncService.dmlChannel2FlowGraph, 1)
|
|
|
|
|
|
|
|
_, err = dataSyncService.addFlowGraphsForDMLChannels(defaultCollectionID, []Channel{defaultDMLChannel})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, dataSyncService.dmlChannel2FlowGraph, 1)
|
|
|
|
|
|
|
|
fg, err := dataSyncService.getFlowGraphByDMLChannel(defaultCollectionID, defaultDMLChannel)
|
|
|
|
assert.NotNil(t, fg)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = dataSyncService.startFlowGraphByDMLChannel(defaultCollectionID, defaultDMLChannel)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
dataSyncService.removeFlowGraphsByDMLChannels([]Channel{defaultDMLChannel})
|
|
|
|
assert.Len(t, dataSyncService.dmlChannel2FlowGraph, 0)
|
|
|
|
|
|
|
|
fg, err = dataSyncService.getFlowGraphByDMLChannel(defaultCollectionID, defaultDMLChannel)
|
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
_, err = dataSyncService.addFlowGraphsForDMLChannels(defaultCollectionID, []Channel{defaultDMLChannel})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, dataSyncService.dmlChannel2FlowGraph, 1)
|
|
|
|
|
|
|
|
dataSyncService.close()
|
|
|
|
assert.Len(t, dataSyncService.dmlChannel2FlowGraph, 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test DMLFlowGraphs invalid channel", func(t *testing.T) {
|
|
|
|
fg, err := dataSyncService.getFlowGraphByDMLChannel(defaultCollectionID, "invalid-vChannel")
|
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
err = dataSyncService.startFlowGraphByDMLChannel(defaultCollectionID, "invalid-vChannel")
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test addFlowGraphsForDMLChannels checkReplica Failed", func(t *testing.T) {
|
2022-05-31 13:42:03 +08:00
|
|
|
err = dataSyncService.metaReplica.removeCollection(defaultCollectionID)
|
2022-05-24 21:11:59 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
_, err = dataSyncService.addFlowGraphsForDMLChannels(defaultCollectionID, []Channel{defaultDMLChannel})
|
|
|
|
assert.Error(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
dataSyncService.metaReplica.addCollection(defaultCollectionID, genTestCollectionSchema())
|
2022-05-24 21:11:59 +08:00
|
|
|
})
|
2021-09-07 15:45:59 +08:00
|
|
|
}
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
func TestDataSyncService_DeltaFlowGraphs(t *testing.T) {
|
2021-09-07 15:45:59 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
replica, err := genSimpleReplica()
|
2021-10-26 14:46:19 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
fac := genFactory()
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-12-17 14:41:33 +08:00
|
|
|
tSafe := newTSafeReplica()
|
2022-05-31 13:42:03 +08:00
|
|
|
dataSyncService := newDataSyncService(ctx, replica, tSafe, fac)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NotNil(t, dataSyncService)
|
|
|
|
|
2022-05-24 21:11:59 +08:00
|
|
|
t.Run("test DeltaFlowGraphs", func(t *testing.T) {
|
|
|
|
_, err = dataSyncService.addFlowGraphsForDeltaChannels(defaultCollectionID, []Channel{defaultDeltaChannel})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, dataSyncService.deltaChannel2FlowGraph, 1)
|
|
|
|
|
|
|
|
_, err = dataSyncService.addFlowGraphsForDeltaChannels(defaultCollectionID, []Channel{defaultDeltaChannel})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, dataSyncService.deltaChannel2FlowGraph, 1)
|
|
|
|
|
|
|
|
fg, err := dataSyncService.getFlowGraphByDeltaChannel(defaultCollectionID, defaultDeltaChannel)
|
|
|
|
assert.NotNil(t, fg)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = dataSyncService.startFlowGraphForDeltaChannel(defaultCollectionID, defaultDeltaChannel)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
dataSyncService.removeFlowGraphsByDeltaChannels([]Channel{defaultDeltaChannel})
|
|
|
|
assert.Len(t, dataSyncService.deltaChannel2FlowGraph, 0)
|
|
|
|
|
|
|
|
fg, err = dataSyncService.getFlowGraphByDeltaChannel(defaultCollectionID, defaultDeltaChannel)
|
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
_, err = dataSyncService.addFlowGraphsForDeltaChannels(defaultCollectionID, []Channel{defaultDMLChannel})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, dataSyncService.deltaChannel2FlowGraph, 1)
|
|
|
|
|
|
|
|
dataSyncService.close()
|
|
|
|
assert.Len(t, dataSyncService.deltaChannel2FlowGraph, 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test DeltaFlowGraphs invalid channel", func(t *testing.T) {
|
|
|
|
fg, err := dataSyncService.getFlowGraphByDeltaChannel(defaultCollectionID, "invalid-vChannel")
|
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
err = dataSyncService.startFlowGraphForDeltaChannel(defaultCollectionID, "invalid-vChannel")
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test addFlowGraphsForDeltaChannels checkReplica Failed", func(t *testing.T) {
|
2022-05-31 13:42:03 +08:00
|
|
|
err = dataSyncService.metaReplica.removeCollection(defaultCollectionID)
|
2022-05-24 21:11:59 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
_, err = dataSyncService.addFlowGraphsForDeltaChannels(defaultCollectionID, []Channel{defaultDMLChannel})
|
|
|
|
assert.Error(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
dataSyncService.metaReplica.addCollection(defaultCollectionID, genTestCollectionSchema())
|
2022-05-24 21:11:59 +08:00
|
|
|
})
|
|
|
|
}
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2022-05-24 21:11:59 +08:00
|
|
|
func TestDataSyncService_checkReplica(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2021-12-17 20:12:42 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
replica, err := genSimpleReplica()
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-05-24 21:11:59 +08:00
|
|
|
fac := genFactory()
|
2022-03-09 15:17:59 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-24 13:57:54 +08:00
|
|
|
|
2022-05-24 21:11:59 +08:00
|
|
|
tSafe := newTSafeReplica()
|
2022-05-31 13:42:03 +08:00
|
|
|
dataSyncService := newDataSyncService(ctx, replica, tSafe, fac)
|
2022-05-24 21:11:59 +08:00
|
|
|
assert.NotNil(t, dataSyncService)
|
|
|
|
defer dataSyncService.close()
|
|
|
|
|
|
|
|
t.Run("test checkReplica", func(t *testing.T) {
|
|
|
|
err = dataSyncService.checkReplica(defaultCollectionID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test collection doesn't exist", func(t *testing.T) {
|
2022-05-31 13:42:03 +08:00
|
|
|
err = dataSyncService.metaReplica.removeCollection(defaultCollectionID)
|
2022-05-24 21:11:59 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
err = dataSyncService.checkReplica(defaultCollectionID)
|
|
|
|
assert.Error(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
coll := dataSyncService.metaReplica.addCollection(defaultCollectionID, genTestCollectionSchema())
|
2022-05-24 21:11:59 +08:00
|
|
|
assert.NotNil(t, coll)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test cannot find tSafe", func(t *testing.T) {
|
2022-05-31 13:42:03 +08:00
|
|
|
coll, err := dataSyncService.metaReplica.getCollectionByID(defaultCollectionID)
|
2022-05-24 21:11:59 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
coll.addVDeltaChannels([]Channel{defaultDeltaChannel})
|
|
|
|
coll.addVChannels([]Channel{defaultDMLChannel})
|
|
|
|
|
|
|
|
dataSyncService.tSafeReplica.addTSafe(defaultDeltaChannel)
|
|
|
|
dataSyncService.tSafeReplica.addTSafe(defaultDMLChannel)
|
|
|
|
|
|
|
|
dataSyncService.tSafeReplica.removeTSafe(defaultDeltaChannel)
|
|
|
|
err = dataSyncService.checkReplica(defaultCollectionID)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
dataSyncService.tSafeReplica.removeTSafe(defaultDMLChannel)
|
|
|
|
err = dataSyncService.checkReplica(defaultCollectionID)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
dataSyncService.tSafeReplica.addTSafe(defaultDeltaChannel)
|
|
|
|
dataSyncService.tSafeReplica.addTSafe(defaultDMLChannel)
|
|
|
|
})
|
2021-09-24 13:57:54 +08:00
|
|
|
}
|