Skip to content

Commit

Permalink
Fix nil point error for the position api
Browse files Browse the repository at this point in the history
Signed-off-by: SimFG <[email protected]>
  • Loading branch information
SimFG committed Oct 26, 2023
1 parent 712f4ad commit 2d91577
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
8 changes: 6 additions & 2 deletions server/store/meta_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ func UpdateTaskCollectionPosition(taskPositionStore api.MetaStore[*meta.TaskColl
if metaPosition.TargetPositions == nil {
metaPosition.TargetPositions = make(map[string]*meta.PositionInfo)
}
metaPosition.Positions[pChannelName] = position
metaPosition.OpPositions[pChannelName] = opPosition
if position != nil {
metaPosition.Positions[pChannelName] = position
}
if opPosition != nil {
metaPosition.OpPositions[pChannelName] = opPosition
}
if targetPosition != nil {
metaPosition.TargetPositions[targetPosition.DataPair.GetKey()] = targetPosition
}
Expand Down
35 changes: 35 additions & 0 deletions server/writer_callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,46 @@ import (
"encoding/json"
"testing"

"github.com/cockroachdb/errors"
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus/pkg/log"
"github.com/stretchr/testify/mock"
"github.com/zilliztech/milvus-cdc/server/mocks"
"github.com/zilliztech/milvus-cdc/server/model/meta"
"go.uber.org/zap"
)

func TestJson(t *testing.T) {
b, err := json.Marshal(make(map[string]string))
log.Info(string(b), zap.Error(err))
}

func TestWriterCallback(t *testing.T) {
factory := mocks.NewMetaStoreFactory(t)
store := mocks.NewMetaStore[*meta.TaskCollectionPosition](t)
callback := NewWriteCallback(factory, "test", "12345")

t.Run("fail", func(t *testing.T) {
factory.EXPECT().GetTaskCollectionPositionMetaStore(mock.Anything).Return(store).Once()
store.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("test")).Once()
callback.UpdateTaskCollectionPosition(1, "test", "test", &meta.PositionInfo{
Time: 1,
DataPair: &commonpb.KeyDataPair{
Key: "test",
Data: []byte("test"),
},
}, nil, nil)
})
t.Run("success", func(t *testing.T) {
factory.EXPECT().GetTaskCollectionPositionMetaStore(mock.Anything).Return(store).Once()
store.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).Return([]*meta.TaskCollectionPosition{}, nil).Once()
store.EXPECT().Put(mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
callback.UpdateTaskCollectionPosition(1, "test", "test", &meta.PositionInfo{
Time: 1,
DataPair: &commonpb.KeyDataPair{
Key: "test",
Data: []byte("test"),
},
}, nil, nil)
})
}

0 comments on commit 2d91577

Please sign in to comment.