-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfreezer_sink_test.go
72 lines (56 loc) · 1.71 KB
/
freezer_sink_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
67
68
69
70
71
72
package freezer
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/uw-labs/straw"
)
func TestSinkCreatesNewDir(t *testing.T) {
assert := assert.New(t)
ss, _ := straw.Open("mem://")
sink, err := NewMessageAutoFlushSink(ss, MessageSinkAutoFlushConfig{Path: "/foo/bar/baz"})
if err != nil {
t.Fatal(err)
}
assert.NoError(sink.Close())
fi, err := ss.Stat("/foo/bar/baz")
assert.NoError(err)
assert.True(fi.IsDir())
assert.Equal("baz", fi.Name())
}
func TestMaxUnflushedTime(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
ss, _ := straw.Open("mem://")
sink, err := NewMessageAutoFlushSink(ss, MessageSinkAutoFlushConfig{Path: "/foo/", MaxUnflushedTime: 5 * time.Millisecond})
if err != nil {
t.Fatal(err)
}
assert.NoError(sink.PutMessage([]byte{1}))
time.Sleep(7 * time.Millisecond)
assert.NoError(sink.PutMessage([]byte{2}))
assert.NoError(sink.Close())
fis, err := ss.Readdir("/foo/00/00/00/00/00/00/")
require.NoError(err)
assert.Equal(2, len(fis))
assert.Equal("00", fis[0].Name())
assert.Equal("01", fis[1].Name())
}
func TestMaxUnflushedMessages(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
ss, _ := straw.Open("mem://")
sink, err := NewMessageAutoFlushSink(ss, MessageSinkAutoFlushConfig{Path: "/foo/", MaxUnflushedTime: 5 * time.Second, MaxUnflushedMessages: 1})
if err != nil {
t.Fatal(err)
}
assert.NoError(sink.PutMessage([]byte{1}))
assert.NoError(sink.PutMessage([]byte{2}))
assert.NoError(sink.Close())
fis, err := ss.Readdir("/foo/00/00/00/00/00/00/")
require.NoError(err)
assert.Equal(2, len(fis))
assert.Equal("00", fis[0].Name())
assert.Equal("01", fis[1].Name())
}