forked from Azure/azure-service-bus-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_test.go
55 lines (46 loc) · 1.37 KB
/
batch_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
package servicebus
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewMessageBatch(t *testing.T) {
mb := NewMessageBatch(StandardMaxMessageSizeInBytes, "messageID", &BatchOptions{})
assert.Equal(t, StandardMaxMessageSizeInBytes, mb.MaxSize)
}
func TestMessageBatch_AddOneMessage(t *testing.T) {
mb := NewMessageBatch(StandardMaxMessageSizeInBytes, "messageID", &BatchOptions{})
msg := NewMessageFromString("Foo")
ok, err := mb.Add(msg)
assert.True(t, ok)
assert.NoError(t, err)
}
func TestMessageBatch_AddManyMessages(t *testing.T) {
bOpts := &BatchOptions{
SessionID: ptrString("foobarbazzbuzz"),
}
mb := NewMessageBatch(StandardMaxMessageSizeInBytes, "messageID", bOpts)
wrapperSize := mb.Size()
msg := NewMessageFromString("Foo")
ok, err := mb.Add(msg)
assert.True(t, ok)
assert.NoError(t, err)
msgSize := mb.Size() - wrapperSize
limit := ((int(mb.MaxSize) - 100) / msgSize) - 1
for i := 0; i < limit; i++ {
ok, err := mb.Add(msg)
assert.True(t, ok)
assert.NoError(t, err)
}
ok, err = mb.Add(msg)
assert.False(t, ok)
assert.NoError(t, err)
}
func TestMessageBatch_Clear(t *testing.T) {
mb := NewMessageBatch(StandardMaxMessageSizeInBytes, "messageID", &BatchOptions{})
ok, err := mb.Add(NewMessageFromString("foo"))
assert.True(t, ok)
assert.NoError(t, err)
assert.Equal(t, 175, mb.Size())
mb.Clear()
assert.Equal(t, 100, mb.Size())
}