-
Notifications
You must be signed in to change notification settings - Fork 14
/
batcher_test.go
65 lines (48 loc) · 1.29 KB
/
batcher_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
package batchers
import (
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestBatcherTracking(t *testing.T) {
s := newBatcher(1)
s.setSourceCount(5)
assert.Equal(t, 5, s.sourceCount)
s.startFileReading("abc")
assert.Contains(t, s.StatusString(), "0/5")
assert.Equal(t, s.ActiveFileCount(), 1)
s.stopFileReading("abc")
assert.Equal(t, 5, s.sourceCount)
assert.Equal(t, 1, s.readCount)
assert.Equal(t, 0, s.ReadErrors())
assert.Contains(t, s.StatusString(), "1/5")
assert.Equal(t, s.ActiveFileCount(), 0)
}
func TestReaderToBatcher(t *testing.T) {
s := newBatcher(10)
testData := `line1
line2
line3`
s.syncReaderToBatcher("string", strings.NewReader(testData), 2)
b1 := <-s.BatchChan()
b2 := <-s.BatchChan()
assert.Len(t, b1.Batch, 2)
assert.Len(t, b2.Batch, 1)
assert.Equal(t, s.errorCount, 0)
assert.Equal(t, s.ReadBytes(), uint64(17))
assert.Equal(t, s.ActiveFileCount(), 0)
}
func TestBatcherWithAutoFlush(t *testing.T) {
s := newBatcher(10)
testData := `line1
line2
line3`
s.syncReaderToBatcherWithTimeFlush("string", strings.NewReader(testData), 2, 1*time.Second)
b1 := <-s.BatchChan()
b2 := <-s.BatchChan()
assert.Len(t, b1.Batch, 2)
assert.Len(t, b2.Batch, 1)
assert.Equal(t, s.errorCount, 0)
assert.Equal(t, s.ReadBytes(), uint64(17))
}