You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2019/03/08 04:38:36 UTC

[pulsar] branch master updated: Fixes for Go client unit test (#3759)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 44c8fd5  Fixes for Go client unit test (#3759)
44c8fd5 is described below

commit 44c8fd552e1b005d8d531a2f9fb7200682794c46
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Thu Mar 7 20:38:31 2019 -0800

    Fixes for Go client unit test (#3759)
    
    * Fixes for Go client unit test
    
    * Update pulsar-client-go/pulsar/consumer_test.go
    
    Co-Authored-By: merlimat <mm...@apache.org>
---
 pulsar-client-go/pulsar/c_message.go     |  2 +-
 pulsar-client-go/pulsar/client_test.go   |  2 +-
 pulsar-client-go/pulsar/consumer_test.go | 18 ++++++++++++------
 pulsar-client-go/pulsar/producer_test.go |  1 -
 pulsar-client-go/pulsar/reader_test.go   |  8 +++++---
 5 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/pulsar-client-go/pulsar/c_message.go b/pulsar-client-go/pulsar/c_message.go
index c882039..0dfbfa6 100644
--- a/pulsar-client-go/pulsar/c_message.go
+++ b/pulsar-client-go/pulsar/c_message.go
@@ -88,7 +88,7 @@ func buildMessage(message ProducerMessage) *C.pulsar_message_t {
 				C.setString(array, C.CString(s), C.int(i))
 			}
 
-			C.pulsar_message_set_replication_clusters(cMsg, array, size)
+			C.pulsar_message_set_replication_clusters(cMsg, array, C.size_t(size))
 		}
 	}
 
diff --git a/pulsar-client-go/pulsar/client_test.go b/pulsar-client-go/pulsar/client_test.go
index 57b3185..34d9247 100644
--- a/pulsar-client-go/pulsar/client_test.go
+++ b/pulsar-client-go/pulsar/client_test.go
@@ -58,7 +58,7 @@ func TestGetTopicPartitions(t *testing.T) {
 	assert.Equal(t, partitions[0], topic)
 }
 
-const TestTokenFilePath = "/tmp/pulsar-test-data/certs/token.txt"
+const TestTokenFilePath = "/tmp/pulsar-test-data/tokens/token.txt"
 
 func readToken(t *testing.T) string {
 	data, err := ioutil.ReadFile(TestTokenFilePath)
diff --git a/pulsar-client-go/pulsar/consumer_test.go b/pulsar-client-go/pulsar/consumer_test.go
index 97db0bd..9c034ba 100644
--- a/pulsar-client-go/pulsar/consumer_test.go
+++ b/pulsar-client-go/pulsar/consumer_test.go
@@ -59,15 +59,17 @@ func TestConsumer(t *testing.T) {
 	assert.Nil(t, err)
 	defer client.Close()
 
+	topic := fmt.Sprintf("my-topic-%d", time.Now().Unix())
+
 	producer, err := client.CreateProducer(ProducerOptions{
-		Topic: "my-topic",
+		Topic: topic,
 	})
 
 	assert.Nil(t, err)
 	defer producer.Close()
 
 	consumer, err := client.Subscribe(ConsumerOptions{
-		Topic:             "my-topic",
+		Topic:             topic,
 		SubscriptionName:  "my-sub",
 		AckTimeout:        1 * time.Minute,
 		Name:              "my-consumer-name",
@@ -79,7 +81,7 @@ func TestConsumer(t *testing.T) {
 	assert.Nil(t, err)
 	defer consumer.Close()
 
-	assert.Equal(t, consumer.Topic(), "persistent://public/default/my-topic")
+	assert.Equal(t, consumer.Topic(), "persistent://public/default/" + topic)
 	assert.Equal(t, consumer.Subscription(), "my-sub")
 
 	ctx := context.Background()
@@ -98,7 +100,10 @@ func TestConsumer(t *testing.T) {
 		assert.NotNil(t, msg)
 
 		assert.Equal(t, string(msg.Payload()), fmt.Sprintf("hello-%d", i))
-		assert.Equal(t, string(msg.Topic()), "persistent://public/default/my-topic")
+		assert.Equal(t, msg.Topic(), "persistent://public/default/" + topic)
+		fmt.Println("Send time: ", sendTime)
+		fmt.Println("Publish time: ", msg.PublishTime())
+		fmt.Println("Receive time: ", recvTime)
 		assert.True(t, sendTime.Unix() <= msg.PublishTime().Unix())
 		assert.True(t, recvTime.Unix() >= msg.PublishTime().Unix())
 
@@ -367,7 +372,7 @@ func TestConsumerRegex(t *testing.T) {
 	defer producer2.Close()
 
 	consumer, err := client.Subscribe(ConsumerOptions{
-		TopicsPattern:    "topic-\\d+",
+		TopicsPattern:    "persistent://public/default/topic-.*",
 		SubscriptionName: "my-sub",
 	})
 
@@ -393,6 +398,7 @@ func TestConsumerRegex(t *testing.T) {
 	}
 
 	for i := 0; i < 20; i++ {
+		ctx, _ = context.WithTimeout(context.Background(), 1 * time.Second)
 		msg, err := consumer.Receive(ctx)
 		assert.Nil(t, err)
 		assert.NotNil(t, msg)
@@ -471,7 +477,7 @@ func TestConsumer_SubscriptionInitPos(t *testing.T) {
 	assert.Nil(t, err)
 	defer client.Close()
 
-	topicName := "persistent://public/default/testSeek"
+	topicName := fmt.Sprintf("testSeek-%d", time.Now().Unix())
 	subName := "test-subscription-initial-earliest-position"
 
 	// create producer
diff --git a/pulsar-client-go/pulsar/producer_test.go b/pulsar-client-go/pulsar/producer_test.go
index 0a13024..633714b 100644
--- a/pulsar-client-go/pulsar/producer_test.go
+++ b/pulsar-client-go/pulsar/producer_test.go
@@ -195,7 +195,6 @@ func TestProducerZstd(t *testing.T) {
 	defer producer.Close()
 
 	assert.Equal(t, producer.Topic(), "persistent://public/default/my-topic")
-	assert.Equal(t, producer.Name(), "my-producer-name")
 
 	ctx := context.Background()
 
diff --git a/pulsar-client-go/pulsar/reader_test.go b/pulsar-client-go/pulsar/reader_test.go
index 90821a8..e6cb9f2 100644
--- a/pulsar-client-go/pulsar/reader_test.go
+++ b/pulsar-client-go/pulsar/reader_test.go
@@ -58,22 +58,24 @@ func TestReader(t *testing.T) {
 	assert.Nil(t, err)
 	defer client.Close()
 
+	topic := fmt.Sprintf("my-reader-topic-%d", time.Now().Unix())
+
 	producer, err := client.CreateProducer(ProducerOptions{
-		Topic: "my-reader-topic",
+		Topic: topic,
 	})
 
 	assert.Nil(t, err)
 	defer producer.Close()
 
 	reader, err := client.CreateReader(ReaderOptions{
-		Topic:          "my-reader-topic",
+		Topic:          topic,
 		StartMessageID: LatestMessage,
 	})
 
 	assert.Nil(t, err)
 	defer reader.Close()
 
-	assert.Equal(t, reader.Topic(), "persistent://public/default/my-reader-topic")
+	assert.Equal(t, reader.Topic(), "persistent://public/default/" + topic )
 
 	ctx := context.Background()