-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expose replicator, rewrite replicator test w/ mocks
- Loading branch information
1 parent
55bd7bb
commit 0ceb188
Showing
7 changed files
with
174 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/bmizerany/assert" | ||
"github.com/hashicorp/nomad/testutil" | ||
"github.com/travisjeffery/jocko" | ||
"github.com/travisjeffery/jocko/broker" | ||
"github.com/travisjeffery/jocko/testutil/mocks" | ||
) | ||
|
||
func TestBroker_Replicate(t *testing.T) { | ||
mockCommitLog := mocks.NewCommitLog() | ||
mockProxy := mocks.NewProxyForFetchMessages(4) | ||
|
||
p := &jocko.Partition{ | ||
Topic: "test", | ||
ID: 0, | ||
Leader: 0, | ||
PreferredLeader: 0, | ||
Replicas: []int32{0}, | ||
CommitLog: mockCommitLog, | ||
} | ||
|
||
replicator := broker.NewReplicator(p, 0, | ||
broker.ReplicatorMinBytes(5), | ||
broker.ReplicatorMaxWaitTime(int32(250*time.Millisecond)), | ||
broker.ReplicatorProxy(mockProxy)) | ||
|
||
defer replicator.Close() | ||
|
||
testutil.WaitForResult(func() (bool, error) { | ||
commitLog := mockCommitLog.Log() | ||
if len(commitLog) < 4 { | ||
return false, nil | ||
} | ||
assert.Equal(t, commitLog, mockProxy.MockedMessages(), "unmatched replicated messages") | ||
return true, nil | ||
}, func(err error) { | ||
t.Fatalf("err: %v", err) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package mocks | ||
|
||
import ( | ||
"io" | ||
"sync" | ||
) | ||
|
||
type MockCommitLog struct { | ||
mu sync.RWMutex | ||
log [][]byte | ||
} | ||
|
||
func NewCommitLog() *MockCommitLog { | ||
return &MockCommitLog{} | ||
} | ||
|
||
func (c *MockCommitLog) Log() [][]byte { | ||
log := [][]byte{} | ||
c.mu.RLock() | ||
log = append(log, c.log...) | ||
c.mu.RUnlock() | ||
return log | ||
} | ||
|
||
func (c *MockCommitLog) Append(b []byte) (int64, error) { | ||
c.mu.Lock() | ||
c.log = append(c.log, b) | ||
c.mu.Unlock() | ||
return 0, nil | ||
} | ||
|
||
func (c *MockCommitLog) DeleteAll() error { | ||
return nil | ||
} | ||
|
||
func (c *MockCommitLog) NewReader(offset int64, maxBytes int32) (io.Reader, error) { | ||
return nil, nil | ||
} | ||
|
||
func (c *MockCommitLog) TruncateTo(int64) error { | ||
return nil | ||
} | ||
|
||
func (c *MockCommitLog) NewestOffset() int64 { | ||
return 0 | ||
} | ||
|
||
func (c *MockCommitLog) OldestOffset() int64 { | ||
return 0 | ||
} |
Oops, something went wrong.