-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
128 lines (109 loc) · 2.75 KB
/
config_test.go
File metadata and controls
128 lines (109 loc) · 2.75 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package batchify
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAssertValue(t *testing.T) {
is := assert.New(t)
is.NotPanics(func() {
assertValue(true, "error")
})
is.PanicsWithValue("error", func() {
assertValue(false, "error")
})
}
func TestNewBatchConfig(t *testing.T) {
is := assert.New(t)
opts := NewBatchConfig(42, mockDoOk)
is.Equal(42, opts.bufferSize)
is.NotNil(opts.do)
is.EqualValues(0, opts.ttl)
is.Equal(0, opts.shards)
is.Nil(opts.shardingFn)
is.Panics(func() {
opts = opts.WithTimer(-42 * time.Second)
})
opts = opts.WithTimer(21 * time.Second)
is.Equal(42, opts.bufferSize)
is.NotNil(opts.do)
is.EqualValues(21*time.Second, opts.ttl)
is.Equal(0, opts.shards)
is.Nil(opts.shardingFn)
is.Panics(func() {
opts = opts.WithSharding(1, func(key string) uint64 { return 0 })
})
is.Panics(func() {
opts = opts.WithSharding(2, nil)
})
opts = opts.WithSharding(2, func(key string) uint64 { return 0 })
is.Equal(42, opts.bufferSize)
is.NotNil(opts.do)
is.EqualValues(21*time.Second, opts.ttl)
is.Equal(2, opts.shards)
is.NotNil(opts.shardingFn)
is.NotPanics(func() {
opts.Build()
})
is.Panics(func() {
_ = NewBatchConfig(-42, mockDoOk)
})
}
func TestHelperNewBatch(t *testing.T) {
is := assert.New(t)
batch := NewBatch(42, mockDoOk)
b, ok := batch.(*batchImpl[string, string])
is.True(ok)
is.Nil(b.timer)
// is.NotNil(b.mu)
is.Equal(42, b.bufferSize)
is.EqualValues(0, b.ttl)
is.NotNil(b.do)
is.NotNil(b.buffer)
}
func TestHelperNewBatchWithTimer(t *testing.T) {
is := assert.New(t)
batch := NewBatchWithTimer(42, mockDoOk, 21*time.Second)
b, ok := batch.(*batchImpl[string, string])
is.True(ok)
is.NotNil(b.timer)
// is.NotNil(b.mu)
is.Equal(42, b.bufferSize)
is.Equal(21*time.Second, b.ttl)
is.NotNil(b.do)
is.NotNil(b.buffer)
}
func TestHelperNewShardedBatch(t *testing.T) {
is := assert.New(t)
batch := NewShardedBatch(2, mockHasher, 42, mockDoOk)
b, ok := batch.(*shardedBatchImpl[string, string])
is.True(ok)
is.Len(b.batches, 2)
is.NotNil(b.shardingFn)
for i := range b.batches {
bb := b.batches[i].(*batchImpl[string, string])
is.Nil(bb.timer)
// is.NotNil(bb.mu)
is.Equal(42, bb.bufferSize)
is.EqualValues(0, bb.ttl)
is.NotNil(bb.do)
is.NotNil(bb.buffer)
}
}
func TestHelperNewShardedBatchWithTimer(t *testing.T) {
is := assert.New(t)
batch := NewShardedBatchWithTimer(2, mockHasher, 42, mockDoOk, 21*time.Second)
b, ok := batch.(*shardedBatchImpl[string, string])
is.True(ok)
is.Len(b.batches, 2)
is.NotNil(b.shardingFn)
for i := range b.batches {
bb := b.batches[i].(*batchImpl[string, string])
is.NotNil(bb.timer)
// is.NotNil(bb.mu)
is.Equal(42, bb.bufferSize)
is.Equal(21*time.Second, bb.ttl)
is.NotNil(bb.do)
is.NotNil(bb.buffer)
}
}