diff --git a/lib/backend/constants.go b/lib/backend/constants.go index 991e77c2..12db5dfb 100644 --- a/lib/backend/constants.go +++ b/lib/backend/constants.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -14,6 +14,7 @@ package backend import ( + "github.com/uber/kraken/core" "github.com/uber/kraken/utils/memsize" "github.com/c2h5oh/datasize" @@ -25,3 +26,8 @@ const ( DefaultConcurrency int = 10 DefaultListMaxKeys int = 250 ) + +var ( + ReadinessCheckNamespace string = core.NamespaceFixture() + ReadinessCheckName string = core.DigestFixture().Hex() +) diff --git a/lib/backend/manager.go b/lib/backend/manager.go index de8bd533..2606024d 100644 --- a/lib/backend/manager.go +++ b/lib/backend/manager.go @@ -29,12 +29,10 @@ import ( var ( ErrNamespaceNotFound = errors.New("no matches for namespace") ) -const isReadyNamespace = "isReadyNamespace" -const isReadyName = "38a03d499119bc417b8a6a016f2cb4540b9f9cc0c13e4da42a73867120d3e908" type backend struct { - regexp *regexp.Regexp - client Client + regexp *regexp.Regexp + client Client mustReady bool } @@ -44,8 +42,8 @@ func newBackend(namespace string, c Client, mustReady bool) (*backend, error) { return nil, fmt.Errorf("regexp: %s", err) } return &backend{ - regexp: re, - client: c, + regexp: re, + client: c, mustReady: mustReady, }, nil } @@ -147,15 +145,15 @@ func (m *Manager) GetClient(namespace string) (Client, error) { // IsReady returns whether the backends are ready (reachable). // A backend must be explicitly configured as required for readiness to be checked. -func (m *Manager) IsReady() (bool, error) { +func (m *Manager) CheckReadiness() error { for _, b := range m.backends { if !b.mustReady { continue } - _, err := b.client.Stat(isReadyNamespace, isReadyName) + _, err := b.client.Stat(ReadinessCheckNamespace, ReadinessCheckName) if err != nil && err != backenderrors.ErrBlobNotFound { - return false, fmt.Errorf("backend for namespace %s not ready: %s", b.regexp.String(), err) + return fmt.Errorf("backend for namespace '%s' not ready: %s", b.regexp.String(), err) } } - return true, nil + return nil } diff --git a/lib/backend/manager_test.go b/lib/backend/manager_test.go index 6a4ea89a..c27e303c 100644 --- a/lib/backend/manager_test.go +++ b/lib/backend/manager_test.go @@ -19,6 +19,7 @@ import ( "github.com/uber-go/tally" "github.com/uber/kraken/core" + "github.com/uber/kraken/lib/backend" . "github.com/uber/kraken/lib/backend" "github.com/uber/kraken/lib/backend/backenderrors" "github.com/uber/kraken/lib/backend/namepath" @@ -159,10 +160,7 @@ func TestManagerBandwidth(t *testing.T) { checkBandwidth(5, 25) } -func TestManagerIsReady(t *testing.T) { - const isReadyNamespace = "isReadyNamespace" - const isReadyName = "38a03d499119bc417b8a6a016f2cb4540b9f9cc0c13e4da42a73867120d3e908" - +func TestManagerCheckReadiness(t *testing.T) { n1 := "foo/*" n2 := "bar/*" @@ -191,7 +189,7 @@ func TestManagerIsReady(t *testing.T) { mockStat1Err: nil, mockStat2Err: errors.New("network error"), expectedRes: false, - expectedErr: errors.New("backend for namespace bar/* not ready: network error"), + expectedErr: errors.New("backend for namespace 'bar/*' not ready: network error"), }, { name: "second required, only first fails", @@ -224,14 +222,13 @@ func TestManagerIsReady(t *testing.T) { mockStat2 = nil } - c1.EXPECT().Stat(isReadyNamespace, isReadyName).Return(mockStat1, tc.mockStat1Err).AnyTimes() - c2.EXPECT().Stat(isReadyNamespace, isReadyName).Return(mockStat2, tc.mockStat2Err).AnyTimes() + c1.EXPECT().Stat(backend.ReadinessCheckNamespace, backend.ReadinessCheckName).Return(mockStat1, tc.mockStat1Err).AnyTimes() + c2.EXPECT().Stat(backend.ReadinessCheckNamespace, backend.ReadinessCheckName).Return(mockStat2, tc.mockStat2Err).AnyTimes() require.NoError(m.Register(n1, c1, tc.mustReady1)) require.NoError(m.Register(n2, c2, tc.mustReady2)) - res, err := m.IsReady() - require.Equal(tc.expectedRes, res) + err := m.CheckReadiness() if tc.expectedErr == nil { require.NoError(err) } else {