Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[close #381] Add integration tests for Kafka sink #382

Merged
merged 25 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions cdc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ LDFLAGS += -X "$(CDC_PKG)/pkg/version.GoVersion=$(GOVERSION)"

SCVERSION := stable

TEST_ON_BRANCH ?= release-6.5

include tools/Makefile

default: build buildsucc
Expand Down Expand Up @@ -208,7 +210,7 @@ rawkv_data:
cdc_state_checker:
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/cdc_state_checker ./tests/utils/cdc_state_checker/

integration_test_build: check_failpoint_ctl rawkv_data cdc_state_checker
integration_test_build: check_failpoint_ctl rawkv_data cdc_state_checker kafka_consumer
$(FAILPOINT_ENABLE)
$(GOTEST) -ldflags '$(LDFLAGS)' -c -cover -covermode=atomic \
-coverpkg=github.com/tikv/migration/... \
Expand All @@ -219,8 +221,12 @@ integration_test_build: check_failpoint_ctl rawkv_data cdc_state_checker
$(FAILPOINT_DISABLE)

integration_test: prepare_test_binaries check_third_party_binary integration_test_build
tests/integration_tests/run.sh "$(CASE)"
@bash <(curl -s https://codecov.io/bash) -F cdc -s /tmp/tikv_cdc_test -f *.out -t $(TIKV_MIGRATION_CODECOV_TOKEN)
tests/integration_tests/run.sh tikv "$(CASE)"
@bash <(curl -s https://codecov.io/bash) -F cdc -s /tmp/tikv_cdc_test -f *.out -t "$(TIKV_MIGRATION_CODECOV_TOKEN)"

integration_test_kafka: prepare_test_binaries check_third_party_binary integration_test_build
tests/integration_tests/run.sh kafka "$(CASE)"
@bash <(curl -s https://codecov.io/bash) -F cdc -s /tmp/tikv_cdc_test -f *.out -t "$(TIKV_MIGRATION_CODECOV_TOKEN)"

# To make try on integration tests easier.
# Comment out the succeed cases and retry from the failed one.
Expand All @@ -242,7 +248,7 @@ integration_test_by_group: prepare_test_binaries check_third_party_binary integr
tests/integration_tests/run_group.sh others

prepare_test_binaries:
cd scripts && ./download-integration-test-binaries.sh master && cd ..
cd scripts && ./download-integration-test-binaries.sh "$(TEST_ON_BRANCH)" && cd ..
touch prepare_test_binaries

check_third_party_binary:
Expand Down
6 changes: 3 additions & 3 deletions cdc/cdc/sink/codec/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,11 @@ func (b *JSONEventBatchDecoder) NextChangedEvent() (*model.RawKVEntry, error) {
valueLen := binary.BigEndian.Uint64(b.valueBytes[:8])
value := b.valueBytes[8 : valueLen+8]
b.valueBytes = b.valueBytes[valueLen+8:]
mvMsg := new(mqMessageValue)
if err := mvMsg.Decode(value); err != nil {
kvMsg := new(mqMessageValue)
if err := kvMsg.Decode(value); err != nil {
return nil, errors.Trace(err)
}
kvEvent := mqMessageToKvEvent(b.nextKey, mvMsg)
kvEvent := mqMessageToKvEvent(b.nextKey, kvMsg)
b.nextKey = nil
return kvEvent, nil
}
Expand Down
6 changes: 6 additions & 0 deletions cdc/cdc/sink/mq.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/log"
"github.com/tikv/migration/cdc/cdc/model"
"github.com/tikv/migration/cdc/cdc/sink/codec"
Expand Down Expand Up @@ -243,6 +244,11 @@ func (k *mqSink) runWorker(ctx context.Context, partition int32) error {
return 0, nil
}

failpoint.Inject("SinkFlushEventPanic", func() {
time.Sleep(time.Second)
log.Fatal("kafka sink injected error")
})

for _, msg := range messages {
err := k.writeToProducer(ctx, msg, codec.EncoderNeedAsyncWrite, partition)
if err != nil {
Expand Down
Loading
Loading