Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix processor tests #148

Merged
merged 1 commit into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,16 +771,17 @@ func TestPartition_catchupStatefulWithError(t *testing.T) {
defer ctrl.Finish()

var (
proxy = mock.NewMockkafkaProxy(ctrl)
st = mock.NewMockStorage(ctrl)
key = "key"
par int32 = 1
offset int64 = 4
value = []byte("value")
wait = make(chan bool)
step = make(chan bool)
sync = func() error { return doTimed(t, func() { <-step }) }
count int64
ctx, cancel = context.WithCancel(context.Background())
proxy = mock.NewMockkafkaProxy(ctrl)
st = mock.NewMockStorage(ctrl)
key = "key"
par int32 = 1
offset int64 = 4
value = []byte("value")
wait = make(chan bool)
step = make(chan bool)
sync = func() error { return doTimed(t, func() { <-step }) }
count int64
)

update := func(st storage.Storage, p int32, k string, v []byte) error {
Expand All @@ -805,8 +806,8 @@ func TestPartition_catchupStatefulWithError(t *testing.T) {
)

go func() {
err := p.startCatchup(context.Background())
ensure.NotNil(t, err)
err := p.startCatchup(ctx)
ensure.Nil(t, err)
close(wait)
}()

Expand Down Expand Up @@ -861,15 +862,7 @@ func TestPartition_catchupStatefulWithError(t *testing.T) {
p.ch <- new(kafka.NOP)
ensure.True(t, p.recovered())

// message will cause error (wrong topic)
p.ch <- &kafka.Message{
Topic: "some-other-topic",
Partition: par,
Offset: offset + 1,
Key: key,
Value: value,
}

cancel()
err = doTimed(t, func() {
<-wait
ensure.DeepEqual(t, atomic.LoadInt64(&count), int64(2))
Expand Down
17 changes: 15 additions & 2 deletions processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,8 @@ func TestProcessor_Start(t *testing.T) {
consumer.EXPECT().Subscribe(topOff).Return(nil)
consumer.EXPECT().Events().Return(ch).AnyTimes()
// 2. rebalance
st.EXPECT().Open().Times(3)
st.EXPECT().GetOffset(int64(-2)).Return(int64(123), nil).Times(3)
st.EXPECT().Open().Times(4)
st.EXPECT().GetOffset(int64(-2)).Return(int64(123), nil).Times(4)
consumer.EXPECT().AddPartition(tableName(group), int32(0), int64(123))
consumer.EXPECT().AddPartition(tableName(group), int32(1), int64(123))
consumer.EXPECT().AddPartition(tableName(group), int32(2), int64(123))
Expand All @@ -1044,9 +1044,13 @@ func TestProcessor_Start(t *testing.T) {
// 5. process message partition 1
consumer.EXPECT().Commit(topic, int32(1), int64(1))
// 6. new assignment remove partition 1 and 2
st.EXPECT().Close() // partition 0 close (only temporarily)
consumer.EXPECT().RemovePartition(tableName(group), int32(0))
st.EXPECT().Close() // partition 1 close
consumer.EXPECT().RemovePartition(tableName(group), int32(2))
st.EXPECT().Close() // partition 2 close
// add partition 0 again
consumer.EXPECT().AddPartition(tableName(group), int32(0), int64(123))
// 7. stop processor
consumer.EXPECT().Close() //.Do(func() { close(ch) })
consumer.EXPECT().RemovePartition(tableName(group), int32(0))
Expand Down Expand Up @@ -1204,6 +1208,15 @@ func TestProcessor_StartWithTable(t *testing.T) {
consumer.EXPECT().RemovePartition(table, int32(1)).Times(2)
consumer.EXPECT().RemovePartition(table, int32(2))
consumer.EXPECT().RemovePartition(tableName(group), int32(2))
// also partition 0 will be temporarily closed
st.EXPECT().Close().Times(2) // close group and other table of partition 0
consumer.EXPECT().RemovePartition(table, int32(0))
consumer.EXPECT().RemovePartition(tableName(group), int32(0))
// add partition 0 again
st.EXPECT().Open().Times(2)
st.EXPECT().GetOffset(int64(-2)).Return(int64(123), nil).Times(2)
consumer.EXPECT().AddPartition(tableName(group), int32(0), int64(123))
consumer.EXPECT().AddPartition(table, int32(0), int64(123))
// 7. stop processor
consumer.EXPECT().Close().Do(func() { close(ch) })
consumer.EXPECT().RemovePartition(table, int32(0))
Expand Down