-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamomq_test.go
66 lines (57 loc) · 1.97 KB
/
dynamomq_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package dynamomq_test
import (
"time"
"github.com/vvatanabe/dynamomq"
"github.com/vvatanabe/dynamomq/internal/clock"
"github.com/vvatanabe/dynamomq/internal/constant"
"github.com/vvatanabe/dynamomq/internal/test"
)
func MarkAsProcessing[T any](m *dynamomq.Message[T], now time.Time) {
ts := clock.FormatRFC3339Nano(now)
m.UpdatedAt = ts
m.ReceivedAt = ts
m.InvisibleUntilAt = clock.FormatRFC3339Nano(now.Add(constant.DefaultVisibilityTimeout))
}
func MarkAsMovedToDLQ[T any](m *dynamomq.Message[T], now time.Time) {
ts := clock.FormatRFC3339Nano(now)
m.QueueType = dynamomq.QueueTypeDLQ
m.ReceiveCount = 0
m.UpdatedAt = ts
m.SentAt = ts
m.ReceivedAt = ""
m.InvisibleUntilAt = ""
}
func MarkAsRestoredFromDLQ[T any](m *dynamomq.Message[T], now time.Time) {
ts := clock.FormatRFC3339Nano(now)
m.QueueType = dynamomq.QueueTypeStandard
m.ReceiveCount = 0
m.UpdatedAt = ts
m.SentAt = ts
m.ReceivedAt = ""
m.InvisibleUntilAt = ""
}
func NewTestMessageItemAsReady(id string, now time.Time) *dynamomq.Message[test.MessageData] {
return dynamomq.NewMessage[test.MessageData](id, test.NewMessageData(id), now)
}
func NewTestMessageItemAsProcessing(id string, now time.Time) *dynamomq.Message[test.MessageData] {
m := dynamomq.NewMessage[test.MessageData](id, test.NewMessageData(id), now)
MarkAsProcessing(m, now)
return m
}
func NewTestMessageItemAsDLQ(id string, now time.Time) *dynamomq.Message[test.MessageData] {
m := dynamomq.NewMessage[test.MessageData](id, test.NewMessageData(id), now)
MarkAsMovedToDLQ(m, now)
return m
}
func NewMessageFromReadyToProcessing(id string,
readyTime time.Time, processingTime time.Time) *dynamomq.ReceiveMessageOutput[test.MessageData] {
m := NewTestMessageItemAsReady(id, readyTime)
MarkAsProcessing(m, processingTime)
m.Version = 2
m.ReceiveCount = 1
m.InvisibleUntilAt = clock.FormatRFC3339Nano(processingTime.Add(constant.DefaultVisibilityTimeout))
r := &dynamomq.ReceiveMessageOutput[test.MessageData]{
ReceivedMessage: m,
}
return r
}