Skip to content

Commit

Permalink
add actual ActivePlacement() impl and test
Browse files Browse the repository at this point in the history
  • Loading branch information
vdarulis committed Dec 1, 2020
1 parent 7cf1806 commit 156b3f1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/aggregator/client/tcp_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ func (c *TCPClient) ActivePlacement() (placement.Placement, int, error) {
return nil, 0, err
}
defer onPlacementDoneFn()
// TODO: expose version once related PR lands
return placement.Clone(), 0, nil

return placement.Clone(), stagedPlacement.Version(), nil
}

//nolint:gocritic
Expand Down
47 changes: 39 additions & 8 deletions src/aggregator/client/tcp_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"time"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/m3db/m3/src/cluster/kv/mem"
Expand Down Expand Up @@ -197,14 +198,6 @@ var (
SetInstances(testPlacementInstances)
)

func mustNewTestTCPClient(t *testing.T, opts Options) *TCPClient {
c, err := NewClient(opts)
require.NoError(t, err)
value, ok := c.(*TCPClient)
require.True(t, ok)
return value
}

func TestTCPClientWriteUntimedMetricClosed(t *testing.T) {
c := mustNewTestTCPClient(t, testOptions())
require.NoError(t, c.Close())
Expand Down Expand Up @@ -794,6 +787,44 @@ func TestTCPClientWriteTimeRangeFor(t *testing.T) {
}
}

func TestTCPClientInitAndClose(t *testing.T) {
c := mustNewTestTCPClient(t, testOptions())
require.NoError(t, c.Init())
require.NoError(t, c.Close())
}

func TestTCPClientActivePlacement(t *testing.T) {
var (
c = mustNewTestTCPClient(t, testOptions())
emptyPl = placement.NewPlacement()
ctrl = gomock.NewController(t)
mockPl = placement.NewMockPlacement(ctrl)
stagedPlacement = placement.NewMockActiveStagedPlacement(ctrl)
watcher = placement.NewMockStagedPlacementWatcher(ctrl)
doneCalls int
)

c.placementWatcher = watcher
watcher.EXPECT().ActiveStagedPlacement().Return(stagedPlacement, func() { doneCalls++ }, nil)
stagedPlacement.EXPECT().Version().Return(42)
stagedPlacement.EXPECT().ActivePlacement().Return(mockPl, func() { doneCalls++ }, nil)
mockPl.EXPECT().Clone().Return(emptyPl)

pl, v, err := c.ActivePlacement()
assert.NoError(t, err)
assert.Equal(t, 42, v)
assert.Equal(t, 2, doneCalls)
assert.Equal(t, emptyPl, pl)
}

func mustNewTestTCPClient(t *testing.T, opts Options) *TCPClient {
c, err := NewClient(opts)
require.NoError(t, err)
value, ok := c.(*TCPClient)
require.True(t, ok)
return value
}

// TODO: clean this up as it's in use by other test files
func testOptions() Options {
return testTCPClientOptions()
Expand Down

0 comments on commit 156b3f1

Please sign in to comment.