jiazhai commented on a change in pull request #16: Impl consumer logic for go client URL: https://github.com/apache/pulsar-client-go/pull/16#discussion_r308530496
########## File path: pulsar/consumer_test.go ########## @@ -0,0 +1,414 @@ +// +// 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" + "fmt" + "github.com/stretchr/testify/assert" + "log" + "net/http" + "strings" + "testing" + "time" +) + +var ( + adminURL = "http://localhost:8080" + lookupURL = "pulsar://localhost:6650" +) + +func TestProducerConsumer(t *testing.T) { + client, err := NewClient(ClientOptions{ + URL: lookupURL, + }) + + assert.Nil(t, err) + defer client.Close() + + topic := "my-topic" + ctx := context.Background() + + // create consumer + consumer, err := client.Subscribe(ConsumerOptions{ + Topic: topic, + SubscriptionName: "my-sub", + Type: Shared, + }) + assert.Nil(t, err) + defer consumer.Close() + + // create producer + producer, err := client.CreateProducer(ProducerOptions{ + Topic: topic, + DisableBatching: false, + }) + assert.Nil(t, err) + defer producer.Close() + + // send 10 messages + for i := 0; i < 10; i++ { + if err := producer.Send(ctx, &ProducerMessage{ Review comment: ProducerMessage contains these fields: ``` // ProducerMessage abstraction used in Pulsar producer type ProducerMessage struct { // Payload for the message Payload []byte // Key sets the key of the message for routing policy Key string // Properties attach application defined properties on the message Properties map[string]string // EventTime set the event time for a given message EventTime *time.Time // ReplicationClusters override the replication clusters for this message. ReplicationClusters []string // SequenceID set the sequence id to assign to the current message SequenceID *int64 } ``` I would suggest test all these fields as much as possible, not only the Payload part. And open issues to track the fields that could not work. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
