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

[Fix][Producer] Stop block request even if Value and Payload are both set #1052

Merged
merged 9 commits into from
Jul 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions pulsar/producer_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,6 @@ func (p *partitionProducer) internalSend(request *sendRequest) {

var schemaPayload []byte
var err error
if msg.Value != nil && msg.Payload != nil {
p.log.Error("Can not set Value and Payload both")
runCallback(request.callback, nil, request.msg, errors.New("can not set Value and Payload both"))
return
}

// The block chan must be closed when returned with exception
defer request.stopBlock()
Expand Down Expand Up @@ -1117,6 +1112,12 @@ func (p *partitionProducer) internalSendAsync(ctx context.Context, msg *Producer
return
}

if msg.Value != nil && msg.Payload != nil {
p.log.Error("Can not set Value and Payload both")
runCallback(callback, nil, msg, newError(InvalidMessage, "Can not set Value and Payload both"))
return
}

// Register transaction operation to transaction and the transaction coordinator.
var newCallback func(MessageID, *ProducerMessage, error)
var txn *transaction
Expand Down
15 changes: 15 additions & 0 deletions pulsar/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ func TestSimpleProducer(t *testing.T) {

_, err = producer.Send(context.Background(), nil)
assert.NotNil(t, err)

_, err = producer.Send(context.Background(), &ProducerMessage{
Payload: []byte("hello"),
Value: []byte("hello"),
})
assert.NotNil(t, err)
}

func TestProducerAsyncSend(t *testing.T) {
Expand Down Expand Up @@ -163,6 +169,15 @@ func TestProducerAsyncSend(t *testing.T) {
wg.Done()
})
wg.Wait()

wg.Add(1)
producer.SendAsync(context.Background(), &ProducerMessage{Payload: []byte("hello"), Value: []byte("hello")},
func(id MessageID, m *ProducerMessage, e error) {
assert.NotNil(t, e)
assert.Nil(t, id)
wg.Done()
})
wg.Wait()
}

func TestProducerCompression(t *testing.T) {
Expand Down