Gleiphir2769 commented on code in PR #805:
URL: https://github.com/apache/pulsar-client-go/pull/805#discussion_r983546515


##########
pulsar/message_chunking_test.go:
##########
@@ -0,0 +1,593 @@
+// Licensed to the Apache Software Foundation (ASF) 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
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+
+package pulsar
+
+import (
+       "context"
+       "errors"
+       "fmt"
+       "math/rand"
+       "strings"
+       "sync"
+       "testing"
+       "time"
+
+       "github.com/stretchr/testify/assert"
+)
+
+var _brokerMaxMessageSize = 1024 * 1024
+
+func TestInvalidChunkingConfig(t *testing.T) {
+       client, err := NewClient(ClientOptions{
+               URL: lookupURL,
+       })
+
+       assert.Nil(t, err)
+       defer client.Close()
+
+       // create producer
+       producer, err := client.CreateProducer(ProducerOptions{
+               Topic:           newTopicName(),
+               DisableBatching: false,
+               EnableChunking:  true,
+       })
+
+       assert.Error(t, err, "producer creation should have fail")
+       assert.Nil(t, producer)
+}
+
+func TestLargeMessage(t *testing.T) {
+       rand.Seed(time.Now().Unix())
+
+       client, err := NewClient(ClientOptions{
+               URL: lookupURL,
+       })
+
+       assert.Nil(t, err)
+       defer client.Close()
+
+       topic := newTopicName()
+
+       // create producer without ChunkMaxMessageSize
+       producer1, err := client.CreateProducer(ProducerOptions{
+               Topic:           topic,
+               DisableBatching: true,
+               EnableChunking:  true,
+       })
+       assert.NoError(t, err)
+       assert.NotNil(t, producer1)
+       defer producer1.Close()
+
+       // create producer with ChunkMaxMessageSize
+       producer2, err := client.CreateProducer(ProducerOptions{
+               Topic:               topic,
+               DisableBatching:     true,
+               EnableChunking:      true,
+               ChunkMaxMessageSize: 5,
+       })
+       assert.NoError(t, err)
+       assert.NotNil(t, producer2)
+       defer producer2.Close()
+
+       consumer, err := client.Subscribe(ConsumerOptions{
+               Topic:            topic,
+               Type:             Exclusive,
+               SubscriptionName: "chunk-subscriber",
+       })
+       assert.NoError(t, err)
+       assert.NotNil(t, consumer)
+       defer consumer.Close()
+
+       expectMsgs := make([][]byte, 0, 10)
+
+       // test send chunk with serverMaxMessageSize limit
+       for i := 0; i < 5; i++ {
+               msg := createTestMessagePayload(_brokerMaxMessageSize + 1)
+               expectMsgs = append(expectMsgs, msg)
+               ID, err := producer1.Send(context.Background(), 
&ProducerMessage{
+                       Payload: msg,
+               })
+               assert.NoError(t, err)
+               assert.NotNil(t, ID)
+       }
+
+       // test receive chunk with serverMaxMessageSize limit
+       for i := 0; i < 5; i++ {
+               ctx, cancel := context.WithTimeout(context.Background(), 
time.Second*5)
+               msg, err := consumer.Receive(ctx)
+               cancel()
+               assert.NoError(t, err)
+
+               expectMsg := expectMsgs[i]
+
+               assert.Equal(t, expectMsg, msg.Payload())
+               // ack message
+               err = consumer.Ack(msg)
+               assert.NoError(t, err)
+       }
+
+       // test send chunk with ChunkMaxMessageSize limit
+       for i := 0; i < 5; i++ {
+               msg := createTestMessagePayload(50)
+               expectMsgs = append(expectMsgs, msg)
+               ID, err := producer2.Send(context.Background(), 
&ProducerMessage{
+                       Payload: msg,
+               })
+               assert.NoError(t, err)
+               assert.NotNil(t, ID)
+       }
+
+       // test receive chunk with ChunkMaxMessageSize limit
+       for i := 5; i < 10; i++ {
+               msg, err := consumer.Receive(context.Background())
+               assert.NoError(t, err)
+
+               expectMsg := expectMsgs[i]
+
+               assert.Equal(t, expectMsg, msg.Payload())
+               // ack message
+               err = consumer.Ack(msg)
+               assert.NoError(t, err)
+       }
+}
+
+func TestPublishChunkWithFailure(t *testing.T) {

Review Comment:
   Yes, the biggest challenge is that it is difficult to `stopBroker` here. So 
`TestExpireIncompleteChunksTestExpireIncompleteChunks` is not the "real" 
`expire`. 
   
   Do you think such a test has enough coverage?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to