Skip to content

Commit

Permalink
Rename dc.NopClient to dc.NoopClient (#1396)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshtin committed Mar 23, 2021
1 parent e2e2600 commit 7a6539c
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 48 deletions.
File renamed without changes.
Expand Up @@ -22,7 +22,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:generate mockgen -copyright_file ../../LICENSE -package $GOPACKAGE -source $GOFILE -destination clientInterface_mock.go
//go:generate mockgen -copyright_file ../../LICENSE -package $GOPACKAGE -source $GOFILE -destination interface_mock.go

package dynamicconfig

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -31,60 +31,56 @@ import (
"go.temporal.io/server/common/log"
)

// nopClient is a dummy implements of dynamicconfig Client interface, all operations will always return default values.
type nopClient struct{}
type (
// noopClient is a dummy implements of dynamicconfig Client interface, all operations will always return default values.
noopClient struct{}
)

// NewNoopClient creates a nop client
func NewNoopClient() *noopClient {
return &noopClient{}
}

// NewNoopCollection creates a new nop collection
func NewNoopCollection() *Collection {
return NewCollection(&noopClient{}, log.NewNoopLogger())
}

func (mc *nopClient) GetValue(name Key, defaultValue interface{}) (interface{}, error) {
func (mc *noopClient) GetValue(name Key, defaultValue interface{}) (interface{}, error) {
return nil, errors.New("unable to find key")
}

func (mc *nopClient) GetValueWithFilters(
name Key, filters map[Filter]interface{}, defaultValue interface{},
) (interface{}, error) {
func (mc *noopClient) GetValueWithFilters(name Key, filters map[Filter]interface{}, defaultValue interface{}) (interface{}, error) {
return nil, errors.New("unable to find key")
}

func (mc *nopClient) GetIntValue(name Key, filters map[Filter]interface{}, defaultValue int) (int, error) {
func (mc *noopClient) GetIntValue(name Key, filters map[Filter]interface{}, defaultValue int) (int, error) {
return defaultValue, errors.New("unable to find key")
}

func (mc *nopClient) GetFloatValue(name Key, filters map[Filter]interface{}, defaultValue float64) (float64, error) {
func (mc *noopClient) GetFloatValue(name Key, filters map[Filter]interface{}, defaultValue float64) (float64, error) {
return defaultValue, errors.New("unable to find key")
}

func (mc *nopClient) GetBoolValue(name Key, filters map[Filter]interface{}, defaultValue bool) (bool, error) {
func (mc *noopClient) GetBoolValue(name Key, filters map[Filter]interface{}, defaultValue bool) (bool, error) {
if filters[Namespace] == "TestRawHistoryNamespace" {
return true, errors.New("unable to find key")
}
return defaultValue, errors.New("unable to find key")
}

func (mc *nopClient) GetStringValue(name Key, filters map[Filter]interface{}, defaultValue string) (string, error) {
func (mc *noopClient) GetStringValue(name Key, filters map[Filter]interface{}, defaultValue string) (string, error) {
return defaultValue, errors.New("unable to find key")
}

func (mc *nopClient) GetMapValue(
name Key, filters map[Filter]interface{}, defaultValue map[string]interface{},
) (map[string]interface{}, error) {
func (mc *noopClient) GetMapValue(name Key, filters map[Filter]interface{}, defaultValue map[string]interface{}) (map[string]interface{}, error) {
return defaultValue, errors.New("unable to find key")
}

func (mc *nopClient) GetDurationValue(
name Key, filters map[Filter]interface{}, defaultValue time.Duration,
) (time.Duration, error) {
func (mc *noopClient) GetDurationValue(name Key, filters map[Filter]interface{}, defaultValue time.Duration) (time.Duration, error) {
return defaultValue, errors.New("unable to find key")
}

func (mc *nopClient) UpdateValue(name Key, value interface{}) error {
func (mc *noopClient) UpdateValue(name Key, value interface{}) error {
return errors.New("unable to update key")
}

// NewNopClient creates a nop client
func NewNopClient() Client {
return &nopClient{}
}

// NewNopCollection creates a new nop collection
func NewNopCollection() *Collection {
return NewCollection(&nopClient{}, log.NewNoopLogger())
}
2 changes: 1 addition & 1 deletion common/namespace/handler_GlobalNamespaceDisabled_test.go
Expand Up @@ -88,7 +88,7 @@ func (s *namespaceHandlerGlobalNamespaceDisabledSuite) TearDownSuite() {

func (s *namespaceHandlerGlobalNamespaceDisabledSuite) SetupTest() {
logger := log.NewNoopLogger()
dcCollection := dc.NewCollection(dc.NewNopClient(), logger)
dcCollection := dc.NewCollection(dc.NewNoopClient(), logger)
s.minRetentionDays = 1
s.maxBadBinaryCount = 10
s.metadataMgr = s.TestBase.MetadataManager
Expand Down
Expand Up @@ -88,7 +88,7 @@ func (s *namespaceHandlerGlobalNamespaceEnabledMasterClusterSuite) TearDownSuite

func (s *namespaceHandlerGlobalNamespaceEnabledMasterClusterSuite) SetupTest() {
logger := log.NewNoopLogger()
dcCollection := dc.NewCollection(dc.NewNopClient(), logger)
dcCollection := dc.NewCollection(dc.NewNoopClient(), logger)
s.minRetentionDays = 1
s.maxBadBinaryCount = 10
s.metadataMgr = s.TestBase.MetadataManager
Expand Down
Expand Up @@ -89,7 +89,7 @@ func (s *namespaceHandlerGlobalNamespaceEnabledNotMasterClusterSuite) TearDownSu

func (s *namespaceHandlerGlobalNamespaceEnabledNotMasterClusterSuite) SetupTest() {
logger := log.NewNoopLogger()
dcCollection := dc.NewCollection(dc.NewNopClient(), logger)
dcCollection := dc.NewCollection(dc.NewNoopClient(), logger)
s.minRetentionDays = 1
s.maxBadBinaryCount = 10
s.metadataMgr = s.TestBase.MetadataManager
Expand Down
2 changes: 1 addition & 1 deletion common/namespace/handler_test.go
Expand Up @@ -91,7 +91,7 @@ func (s *namespaceHandlerCommonSuite) TearDownSuite() {

func (s *namespaceHandlerCommonSuite) SetupTest() {
logger := log.NewNoopLogger()
dcCollection := dc.NewCollection(dc.NewNopClient(), logger)
dcCollection := dc.NewCollection(dc.NewNoopClient(), logger)
s.minRetentionDays = 1
s.maxBadBinaryCount = 10
s.metadataMgr = s.TestBase.MetadataManager
Expand Down
8 changes: 4 additions & 4 deletions host/onebox.go
Expand Up @@ -377,7 +377,7 @@ func (c *temporalImpl) startFrontend(hosts map[string][]string, startWG *sync.Wa
}
params.ClusterMetadata = c.clusterMetadata
params.MetricsClient = metrics.NewClient(params.MetricsScope, metrics.GetMetricsServiceIdx(params.Name, c.logger))
params.DynamicConfig = newIntegrationConfigClient(dynamicconfig.NewNopClient())
params.DynamicConfig = newIntegrationConfigClient(dynamicconfig.NewNoopClient())
params.ArchivalMetadata = c.archiverMetadata
params.ArchiverProvider = c.archiverProvider
params.ESConfig = c.esConfig
Expand Down Expand Up @@ -441,7 +441,7 @@ func (c *temporalImpl) startHistory(
}
params.ClusterMetadata = c.clusterMetadata
params.MetricsClient = metrics.NewClient(params.MetricsScope, metrics.GetMetricsServiceIdx(params.Name, c.logger))
integrationClient := newIntegrationConfigClient(dynamicconfig.NewNopClient())
integrationClient := newIntegrationConfigClient(dynamicconfig.NewNoopClient())
c.overrideHistoryDynamicConfig(integrationClient)
params.DynamicConfig = integrationClient

Expand Down Expand Up @@ -524,7 +524,7 @@ func (c *temporalImpl) startMatching(hosts map[string][]string, startWG *sync.Wa
}
params.ClusterMetadata = c.clusterMetadata
params.MetricsClient = metrics.NewClient(params.MetricsScope, metrics.GetMetricsServiceIdx(params.Name, c.logger))
params.DynamicConfig = newIntegrationConfigClient(dynamicconfig.NewNopClient())
params.DynamicConfig = newIntegrationConfigClient(dynamicconfig.NewNoopClient())
params.ArchivalMetadata = c.archiverMetadata
params.ArchiverProvider = c.archiverProvider

Expand Down Expand Up @@ -567,7 +567,7 @@ func (c *temporalImpl) startWorker(hosts map[string][]string, startWG *sync.Wait
}
params.ClusterMetadata = c.clusterMetadata
params.MetricsClient = metrics.NewClient(params.MetricsScope, metrics.GetMetricsServiceIdx(params.Name, c.logger))
params.DynamicConfig = newIntegrationConfigClient(dynamicconfig.NewNopClient())
params.DynamicConfig = newIntegrationConfigClient(dynamicconfig.NewNoopClient())
params.ArchivalMetadata = c.archiverMetadata
params.ArchiverProvider = c.archiverProvider

Expand Down
2 changes: 1 addition & 1 deletion host/testcluster.go
Expand Up @@ -239,7 +239,7 @@ func setupShards(testBase persistencetests.TestBase, numHistoryShards int32, log
}

func newArchiverBase(enabled bool, logger log.Logger) *ArchiverBase {
dcCollection := dynamicconfig.NewNopCollection()
dcCollection := dynamicconfig.NewNoopCollection()
if !enabled {
return &ArchiverBase{
metadata: archiver.NewArchivalMetadata(dcCollection, "", false, "", false, &config.ArchivalNamespaceDefaults{}),
Expand Down
2 changes: 1 addition & 1 deletion service/frontend/dcRedirectionHandler_test.go
Expand Up @@ -105,7 +105,7 @@ func (s *dcRedirectionHandlerSuite) SetupTest() {
s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.currentClusterName).AnyTimes()
s.mockClusterMetadata.EXPECT().IsGlobalNamespaceEnabled().Return(true).AnyTimes()

s.config = NewConfig(dynamicconfig.NewCollection(dynamicconfig.NewNopClient(), s.mockResource.GetLogger()), 0, false)
s.config = NewConfig(dynamicconfig.NewCollection(dynamicconfig.NewNoopClient(), s.mockResource.GetLogger()), 0, false)

frontendHandlerGRPC := NewWorkflowHandler(s.mockResource, s.config, nil)

Expand Down
2 changes: 1 addition & 1 deletion service/frontend/dcRedirectionPolicy_test.go
Expand Up @@ -138,7 +138,7 @@ func (s *selectedAPIsForwardingRedirectionPolicySuite) SetupTest() {

logger := log.NewDefaultLogger()

s.mockConfig = NewConfig(dynamicconfig.NewCollection(dynamicconfig.NewNopClient(), logger), 0, false)
s.mockConfig = NewConfig(dynamicconfig.NewCollection(dynamicconfig.NewNoopClient(), logger), 0, false)
s.mockClusterMetadata.EXPECT().IsGlobalNamespaceEnabled().Return(true).AnyTimes()
s.policy = NewSelectedAPIsForwardingPolicy(
s.currentClusterName,
Expand Down
2 changes: 1 addition & 1 deletion service/frontend/workflowHandler_test.go
Expand Up @@ -1385,7 +1385,7 @@ func (s *workflowHandlerSuite) checkResponse(err error, response interface{},
}

func (s *workflowHandlerSuite) newConfig() *Config {
return NewConfig(dc.NewCollection(dc.NewNopClient(), s.mockResource.GetLogger()), numHistoryShards, false)
return NewConfig(dc.NewCollection(dc.NewNoopClient(), s.mockResource.GetLogger()), numHistoryShards, false)
}

func (s *workflowHandlerSuite) newRespondActivityTaskCompletedRequest(tokenNamespaceId string) *workflowservice.RespondActivityTaskCompletedRequest {
Expand Down
2 changes: 1 addition & 1 deletion service/history/configs/config.go
Expand Up @@ -453,7 +453,7 @@ func (config *Config) GetShardID(namespaceID, workflowID string) int32 {
}

func NewDynamicConfigForTest() *Config {
dc := dynamicconfig.NewNopCollection()
dc := dynamicconfig.NewNoopCollection()
config := NewConfig(dc, 1, false)
// reduce the duration of long poll to increase test speed
config.LongPollExpirationInterval = dc.GetDurationPropertyFilteredByNamespace(dynamicconfig.HistoryLongPollExpirationInterval, 10*time.Second)
Expand Down
2 changes: 1 addition & 1 deletion service/history/historyEngine_test.go
Expand Up @@ -185,7 +185,7 @@ var testGlobalChildNamespaceEntry = cache.NewGlobalNamespaceCacheEntryForTest(
)

func NewDynamicConfigForTest() *configs.Config {
dc := dynamicconfig.NewNopCollection()
dc := dynamicconfig.NewNoopCollection()
config := configs.NewConfig(dc, 1, false)
// reduce the duration of long poll to increase test speed
config.LongPollExpirationInterval = dc.GetDurationPropertyFilteredByNamespace(dynamicconfig.HistoryLongPollExpirationInterval, 10*time.Second)
Expand Down
2 changes: 1 addition & 1 deletion service/history/taskPriorityAssigner_test.go
Expand Up @@ -67,7 +67,7 @@ func (s *taskPriorityAssignerSuite) SetupTest() {
s.mockNamespaceCache = cache.NewMockNamespaceCache(s.controller)

s.testTaskProcessRPS = 10
dc := dynamicconfig.NewNopCollection()
dc := dynamicconfig.NewNoopCollection()
config := NewDynamicConfigForTest()
config.TaskProcessRPS = dc.GetIntPropertyFilteredByNamespace(dynamicconfig.TaskProcessRPS, s.testTaskProcessRPS)

Expand Down
2 changes: 1 addition & 1 deletion service/matching/matcher_test.go
Expand Up @@ -66,7 +66,7 @@ func TestMatcherSuite(t *testing.T) {
func (t *MatcherTestSuite) SetupTest() {
t.controller = gomock.NewController(t.T())
t.client = matchingservicemock.NewMockMatchingServiceClient(t.controller)
cfg := NewConfig(dynamicconfig.NewNopCollection())
cfg := NewConfig(dynamicconfig.NewNoopCollection())
t.taskQueue = newTestTaskQueueID(uuid.New(), taskQueuePartitionPrefix+"tl0/1", enumspb.TASK_QUEUE_TYPE_WORKFLOW)
tlCfg, err := newTaskQueueConfig(t.taskQueue, cfg, t.newNamespaceCache())
t.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion service/matching/matchingEngine_test.go
Expand Up @@ -1994,7 +1994,7 @@ func validateTimeRange(t time.Time, expectedDuration time.Duration) bool {
}

func defaultTestConfig() *Config {
config := NewConfig(dynamicconfig.NewNopCollection())
config := NewConfig(dynamicconfig.NewNoopCollection())
config.LongPollExpirationInterval = dynamicconfig.GetDurationPropertyFnFilteredByTaskQueueInfo(100 * time.Millisecond)
config.MaxTaskDeleteBatchSize = dynamicconfig.GetIntPropertyFilteredByTaskQueueInfo(1)
return config
Expand Down
2 changes: 1 addition & 1 deletion service/matching/taskQueueManager_test.go
Expand Up @@ -248,7 +248,7 @@ func TestCheckIdleTaskQueue(t *testing.T) {
controller := gomock.NewController(t)
defer controller.Finish()

cfg := NewConfig(dynamicconfig.NewNopCollection())
cfg := NewConfig(dynamicconfig.NewNoopCollection())
cfg.IdleTaskqueueCheckInterval = dynamicconfig.GetDurationPropertyFnFilteredByTaskQueueInfo(10 * time.Millisecond)

// Idle
Expand Down
2 changes: 1 addition & 1 deletion temporal/server.go
Expand Up @@ -122,7 +122,7 @@ func (s *Server) Start() error {
dynamicConfig, err = dynamicconfig.NewFileBasedClient(&s.so.config.DynamicConfigClient, s.logger, s.stoppedCh)
if err != nil {
s.logger.Info("Error creating file based dynamic config client, use no-op config client instead.", tag.Error(err))
dynamicConfig = dynamicconfig.NewNopClient()
dynamicConfig = dynamicconfig.NewNoopClient()
}
}
dc := dynamicconfig.NewCollection(dynamicConfig, s.logger)
Expand Down

0 comments on commit 7a6539c

Please sign in to comment.