Skip to content

Commit

Permalink
test flush log
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesCheung96 committed Jul 20, 2022
1 parent 608e373 commit da9a13f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 11 additions & 0 deletions cdc/redo/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ func TestManagerRtsMap(t *testing.T) {
require.Equal(t, uint64(20), logMgr.GetMinResolvedTs())
}

// TestManagerError tests whether internal error in bgUpdateLog could be managed correctly.
func TestManagerError(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
Expand Down Expand Up @@ -357,5 +358,15 @@ func TestManagerError(t *testing.T) {
t.Fatal("bgUpdateLog should return error before context is done")
case err := <-errCh:
require.Regexp(t, ".*invalid black hole writer.*", err)
require.Regexp(t, ".*WriteLog.*", err)
}

go logMgr.bgUpdateLog(ctx, errCh)
select {
case <-ctx.Done():
t.Fatal("bgUpdateLog should return error before context is done")
case err := <-errCh:
require.Regexp(t, ".*invalid black hole writer.*", err)
require.Regexp(t, ".*FlushLog.*", err)
}
}
15 changes: 11 additions & 4 deletions cdc/redo/writer/blackhole_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,25 @@ func (bs *blackHoleWriter) Close() error {
return nil
}

type InvalidBlackHoleWriter struct {
type invalidBlackHoleWriter struct {
*blackHoleWriter
}

func NewInvalidBlackHoleWriter(rl RedoLogWriter) *InvalidBlackHoleWriter {
return &InvalidBlackHoleWriter{
// NewInvalidBlackHoleWriter creates a invalid blackHole writer
func NewInvalidBlackHoleWriter(rl RedoLogWriter) *invalidBlackHoleWriter {
return &invalidBlackHoleWriter{
blackHoleWriter: rl.(*blackHoleWriter),
}
}

func (ibs *InvalidBlackHoleWriter) WriteLog(
func (ibs *invalidBlackHoleWriter) WriteLog(
_ context.Context, _ model.TableID, _ []*model.RedoRowChangedEvent,
) (err error) {
return errors.New("[WriteLog] invalid black hole writer")
}

func (ibs *invalidBlackHoleWriter) FlushLog(
_ context.Context, _, _ model.Ts,
) error {
return errors.New("[FlushLog] invalid black hole writer")
}

0 comments on commit da9a13f

Please sign in to comment.