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()
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
streamingReplica, err := genSimpleReplica()
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-10-26 14:46:19 +08:00
|
|
|
historicalReplica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-09-07 15:45:59 +08:00
|
|
|
fac, err := genFactory()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-12-17 14:41:33 +08:00
|
|
|
tSafe := newTSafeReplica()
|
2021-12-17 20:12:42 +08:00
|
|
|
dataSyncService := newDataSyncService(ctx, streamingReplica, historicalReplica, tSafe, fac)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NotNil(t, dataSyncService)
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
dataSyncService.addFlowGraphsForDMLChannels(defaultCollectionID, []Channel{defaultDMLChannel})
|
|
|
|
assert.Len(t, dataSyncService.dmlChannel2FlowGraph, 1)
|
|
|
|
|
|
|
|
dataSyncService.addFlowGraphsForDMLChannels(defaultCollectionID, []Channel{defaultDMLChannel})
|
|
|
|
assert.Len(t, dataSyncService.dmlChannel2FlowGraph, 1)
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
fg, err := dataSyncService.getFlowGraphByDMLChannel(defaultCollectionID, defaultDMLChannel)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NotNil(t, fg)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
fg, err = dataSyncService.getFlowGraphByDMLChannel(defaultCollectionID, "invalid-vChannel")
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
err = dataSyncService.startFlowGraphByDMLChannel(defaultCollectionID, defaultDMLChannel)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
err = dataSyncService.startFlowGraphByDMLChannel(defaultCollectionID, "invalid-vChannel")
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
dataSyncService.removeFlowGraphsByDMLChannels([]Channel{defaultDMLChannel})
|
|
|
|
assert.Len(t, dataSyncService.dmlChannel2FlowGraph, 0)
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
fg, err = dataSyncService.getFlowGraphByDMLChannel(defaultCollectionID, defaultDMLChannel)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
2021-12-17 20:12:42 +08:00
|
|
|
|
|
|
|
dataSyncService.addFlowGraphsForDMLChannels(defaultCollectionID, []Channel{defaultDMLChannel})
|
|
|
|
assert.Len(t, dataSyncService.dmlChannel2FlowGraph, 1)
|
|
|
|
|
|
|
|
dataSyncService.close()
|
|
|
|
assert.Len(t, dataSyncService.dmlChannel2FlowGraph, 0)
|
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()
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
streamingReplica, err := genSimpleReplica()
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-10-26 14:46:19 +08:00
|
|
|
historicalReplica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-09-07 15:45:59 +08:00
|
|
|
fac, err := genFactory()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-12-17 14:41:33 +08:00
|
|
|
tSafe := newTSafeReplica()
|
2021-12-17 20:12:42 +08:00
|
|
|
dataSyncService := newDataSyncService(ctx, streamingReplica, historicalReplica, tSafe, fac)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NotNil(t, dataSyncService)
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
dataSyncService.addFlowGraphsForDeltaChannels(defaultCollectionID, []Channel{defaultDeltaChannel})
|
|
|
|
assert.Len(t, dataSyncService.deltaChannel2FlowGraph, 1)
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
dataSyncService.addFlowGraphsForDeltaChannels(defaultCollectionID, []Channel{defaultDeltaChannel})
|
|
|
|
assert.Len(t, dataSyncService.deltaChannel2FlowGraph, 1)
|
|
|
|
|
|
|
|
fg, err := dataSyncService.getFlowGraphByDeltaChannel(defaultCollectionID, defaultDeltaChannel)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NotNil(t, fg)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
fg, err = dataSyncService.getFlowGraphByDeltaChannel(defaultCollectionID, "invalid-vChannel")
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
err = dataSyncService.startFlowGraphForDeltaChannel(defaultCollectionID, defaultDeltaChannel)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
err = dataSyncService.startFlowGraphForDeltaChannel(defaultCollectionID, "invalid-vChannel")
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
dataSyncService.removeFlowGraphsByDeltaChannels([]Channel{defaultDeltaChannel})
|
|
|
|
assert.Len(t, dataSyncService.deltaChannel2FlowGraph, 0)
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
fg, err = dataSyncService.getFlowGraphByDeltaChannel(defaultCollectionID, defaultDeltaChannel)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
2021-09-24 13:57:54 +08:00
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
dataSyncService.addFlowGraphsForDeltaChannels(defaultCollectionID, []Channel{defaultDMLChannel})
|
|
|
|
assert.Len(t, dataSyncService.deltaChannel2FlowGraph, 1)
|
2021-09-24 13:57:54 +08:00
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
dataSyncService.close()
|
|
|
|
assert.Len(t, dataSyncService.deltaChannel2FlowGraph, 0)
|
2021-09-24 13:57:54 +08:00
|
|
|
}
|