pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mme...@apache.org
Subject [pulsar] branch master updated: Fixed conversion of unix timestamp to golang time (#3659)
Date Fri, 22 Feb 2019 08:28:47 GMT
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 40b374d  Fixed conversion of unix timestamp to golang time (#3659)
40b374d is described below

commit 40b374d3e3009808aed2060c293d78e051ba5a9d
Author: massakam <massakam@yahoo-corp.jp>
AuthorDate: Fri Feb 22 17:28:42 2019 +0900

    Fixed conversion of unix timestamp to golang time (#3659)
---
 pulsar-client-go/pulsar/c_message.go     | 7 +++----
 pulsar-client-go/pulsar/consumer_test.go | 4 ++++
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/pulsar-client-go/pulsar/c_message.go b/pulsar-client-go/pulsar/c_message.go
index 6a9e5e7..0a45127 100644
--- a/pulsar-client-go/pulsar/c_message.go
+++ b/pulsar-client-go/pulsar/c_message.go
@@ -201,10 +201,9 @@ func latestMessageID() *messageID {
 }
 
 func timeFromUnixTimestampMillis(timestamp C.ulonglong) time.Time {
-	ts := int64(timestamp)
-	seconds := ts / int64(time.Millisecond)
-	millis := ts - seconds
-	nanos := millis * int64(time.Millisecond)
+	ts := int64(timestamp) * int64(time.Millisecond)
+	seconds := ts / int64(time.Second)
+	nanos := ts - (seconds * int64(time.Second))
 	return time.Unix(seconds, nanos)
 }
 
diff --git a/pulsar-client-go/pulsar/consumer_test.go b/pulsar-client-go/pulsar/consumer_test.go
index e82ffe6..97db0bd 100644
--- a/pulsar-client-go/pulsar/consumer_test.go
+++ b/pulsar-client-go/pulsar/consumer_test.go
@@ -85,6 +85,7 @@ func TestConsumer(t *testing.T) {
 	ctx := context.Background()
 
 	for i := 0; i < 10; i++ {
+		sendTime := time.Now()
 		if err := producer.Send(ctx, ProducerMessage{
 			Payload: []byte(fmt.Sprintf("hello-%d", i)),
 		}); err != nil {
@@ -92,11 +93,14 @@ func TestConsumer(t *testing.T) {
 		}
 
 		msg, err := consumer.Receive(ctx)
+		recvTime := time.Now()
 		assert.Nil(t, err)
 		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.True(t, sendTime.Unix() <= msg.PublishTime().Unix())
+		assert.True(t, recvTime.Unix() >= msg.PublishTime().Unix())
 
 		consumer.Ack(msg)
 	}


Mime
View raw message