forked from liftbridge-io/go-liftbridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
44 lines (34 loc) · 1.23 KB
/
message_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
package liftbridge
import (
"testing"
"github.com/stretchr/testify/require"
)
// Ensure that if the stream doesn't exist, keyPartitioner's Partition returns
// 0.
func TestKeyPartitionerNoPartitions(t *testing.T) {
partitioner := new(keyPartitioner)
partition := partitioner.Partition("foo", []byte("bar"), []byte("baz"), new(Metadata))
require.Equal(t, int32(0), partition)
}
// Ensure keyPartitioner's Partition always returns the same partition for the
// same key.
func TestKeyPartitioner(t *testing.T) {
partitioner := new(keyPartitioner)
streams := map[string]*StreamInfo{
"foo": {
partitions: map[int32]*PartitionInfo{
0: new(PartitionInfo),
1: new(PartitionInfo),
},
},
}
metadata := &Metadata{streams: streams}
partition := partitioner.Partition("foo", []byte("foobarbazqux"), []byte("1"), metadata)
require.Equal(t, int32(1), partition)
partition = partitioner.Partition("foo", []byte("foobarbazqux"), []byte("2"), metadata)
require.Equal(t, int32(1), partition)
partition = partitioner.Partition("foo", []byte("blah"), []byte("3"), metadata)
require.Equal(t, int32(0), partition)
partition = partitioner.Partition("foo", []byte("blah"), []byte("4"), metadata)
require.Equal(t, int32(0), partition)
}