Skip to content

Commit 88b462b

Browse files
authored
Ensure tests run under Go 1.16 (#782)
Uses of time.UnixMilli() introduced recently, which only work with Go 1.17 or higher, are replaced with equivalent code that works under Go 1.16. If/when this module moves past Go 1.16, these changes may be reverted.
1 parent e1f5945 commit 88b462b

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

builder_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ func (f v1MessageSetBuilder) bytes() []byte {
134134
wb.writeInt64(msg.Offset) // offset
135135
}
136136
wb.writeBytes(newWB().call(func(wb *kafkaWriteBuffer) {
137-
wb.writeInt32(-1) // crc, unused
138-
wb.writeInt8(1) // magic
139-
wb.writeInt8(0) // attributes -- zero, no compression for the inner message
140-
wb.writeInt64(msg.Time.UnixMilli()) // timestamp
137+
wb.writeInt32(-1) // crc, unused
138+
wb.writeInt8(1) // magic
139+
wb.writeInt8(0) // attributes -- zero, no compression for the inner message
140+
wb.writeInt64(1000 * msg.Time.Unix()) // timestamp
141141
wb.writeBytes(msg.Key)
142142
wb.writeBytes(msg.Value)
143143
}))
@@ -147,15 +147,15 @@ func (f v1MessageSetBuilder) bytes() []byte {
147147
})
148148
if f.codec != nil {
149149
bs = newWB().call(func(wb *kafkaWriteBuffer) {
150-
wb.writeInt64(f.msgs[len(f.msgs)-1].Offset) // offset of the wrapper message is the last offset of the inner messages
150+
wb.writeInt64(f.msgs[len(f.msgs)-1].Offset) // offset of the wrapper message is the last offset of the inner messages
151151
wb.writeBytes(newWB().call(func(wb *kafkaWriteBuffer) {
152152
bs := mustCompress(bs, f.codec)
153-
wb.writeInt32(-1) // crc, unused
154-
wb.writeInt8(1) // magic
155-
wb.writeInt8(f.codec.Code()) // attributes
156-
wb.writeInt64(f.msgs[0].Time.UnixMilli()) // timestamp
157-
wb.writeBytes(nil) // key is always nil for compressed
158-
wb.writeBytes(bs) // the value is the compressed message
153+
wb.writeInt32(-1) // crc, unused
154+
wb.writeInt8(1) // magic
155+
wb.writeInt8(f.codec.Code()) // attributes
156+
wb.writeInt64(1000 * f.msgs[0].Time.Unix()) // timestamp
157+
wb.writeBytes(nil) // key is always nil for compressed
158+
wb.writeBytes(bs) // the value is the compressed message
159159
}))
160160
})
161161
}
@@ -179,23 +179,23 @@ func (f v2MessageSetBuilder) bytes() []byte {
179179
return newWB().call(func(wb *kafkaWriteBuffer) {
180180
wb.writeInt64(f.msgs[0].Offset)
181181
wb.writeBytes(newWB().call(func(wb *kafkaWriteBuffer) {
182-
wb.writeInt32(0) // leader epoch
183-
wb.writeInt8(2) // magic = 2
184-
wb.writeInt32(0) // crc, unused
185-
wb.writeInt16(attributes) // record set attributes
186-
wb.writeInt32(0) // record set last offset delta
187-
wb.writeInt64(f.msgs[0].Time.UnixMilli()) // record set first timestamp
188-
wb.writeInt64(f.msgs[0].Time.UnixMilli()) // record set last timestamp
189-
wb.writeInt64(0) // record set producer id
190-
wb.writeInt16(0) // record set producer epoch
191-
wb.writeInt32(0) // record set base sequence
192-
wb.writeInt32(int32(len(f.msgs))) // record set count
182+
wb.writeInt32(0) // leader epoch
183+
wb.writeInt8(2) // magic = 2
184+
wb.writeInt32(0) // crc, unused
185+
wb.writeInt16(attributes) // record set attributes
186+
wb.writeInt32(0) // record set last offset delta
187+
wb.writeInt64(1000 * f.msgs[0].Time.Unix()) // record set first timestamp
188+
wb.writeInt64(1000 * f.msgs[0].Time.Unix()) // record set last timestamp
189+
wb.writeInt64(0) // record set producer id
190+
wb.writeInt16(0) // record set producer epoch
191+
wb.writeInt32(0) // record set base sequence
192+
wb.writeInt32(int32(len(f.msgs))) // record set count
193193
bs := newWB().call(func(wb *kafkaWriteBuffer) {
194194
for i, msg := range f.msgs {
195195
wb.Write(newWB().call(func(wb *kafkaWriteBuffer) {
196196
bs := newWB().call(func(wb *kafkaWriteBuffer) {
197197
wb.writeInt8(0) // record attributes, not used here
198-
wb.writeVarInt(time.Now().UnixMilli() - msg.Time.UnixMilli()) // timestamp
198+
wb.writeVarInt(1000 * (time.Now().Unix() - msg.Time.Unix())) // timestamp
199199
wb.writeVarInt(int64(i)) // offset delta
200200
wb.writeVarInt(int64(len(msg.Key))) // key len
201201
wb.Write(msg.Key) // key bytes

message_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ func (r *readerHelper) readMessageErr() (msg Message, err error) {
742742
return
743743
}
744744
msg.Offset = r.offset
745-
msg.Time = time.UnixMilli(timestamp)
745+
msg.Time = time.Unix(timestamp / 1000, (timestamp % 1000) * 1000000)
746746
msg.Headers = headers
747747
return
748748
}

0 commit comments

Comments
 (0)