From c8eb8b07b3dc84a586caca78915f53d650ea1e45 Mon Sep 17 00:00:00 2001 From: vytautas Date: Thu, 26 May 2022 13:10:46 +0000 Subject: [PATCH] Make cluster.Metadata a struct and stop using mocks for it --- common/cluster/metadata.go | 66 +++----- common/cluster/metadataTest.go | 16 ++ common/cluster/metadata_mock.go | 156 ------------------ common/domain/attrValidator_test.go | 27 +-- common/mocks/ClusterMetadata.go | 146 ---------------- .../persistence-tests/persistenceTestBase.go | 4 +- common/resource/resourceTest.go | 8 +- .../clusterRedirectionHandler_test.go | 4 - service/frontend/workflowHandler_test.go | 34 +--- service/history/constants/test_constants.go | 2 +- .../history/execution/history_builder_test.go | 2 - .../history/execution/state_builder_test.go | 17 +- .../history/failover/marker_notifier_test.go | 20 +-- service/history/historyEngine2_test.go | 20 +-- .../history/historyEngine3_eventsv2_test.go | 19 +-- service/history/historyEngine_test.go | 7 +- .../history/ndc/activity_replicator_test.go | 20 +-- service/history/ndc/branch_manager_test.go | 15 +- .../history/ndc/transaction_manager_test.go | 22 +-- .../queue/timer_queue_processor_base_test.go | 33 ---- .../history/replication/dlq_handler_test.go | 4 - .../replication/task_ack_manager_test.go | 12 +- .../history/replication/task_executor_test.go | 5 - .../replication/task_processor_test.go | 5 - service/history/shard/context_test.go | 2 - service/history/shard/controller_test.go | 20 --- ...cross_cluster_source_task_executor_test.go | 29 +--- ...cross_cluster_target_task_executor_test.go | 4 - .../task/cross_cluster_task_processor_test.go | 1 - .../history/task/cross_cluster_task_test.go | 20 +-- .../task/timer_active_task_executor_test.go | 16 +- .../task/timer_standby_task_executor_test.go | 5 - .../transfer_active_task_executor_test.go | 20 +-- .../transfer_standby_task_executor_test.go | 5 - 34 files changed, 124 insertions(+), 662 deletions(-) delete mode 100644 common/cluster/metadata_mock.go delete mode 100644 common/mocks/ClusterMetadata.go diff --git a/common/cluster/metadata.go b/common/cluster/metadata.go index e9151c0c58c..bf1c458a6ec 100644 --- a/common/cluster/metadata.go +++ b/common/cluster/metadata.go @@ -18,8 +18,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination metadata_mock.go - package cluster import ( @@ -31,24 +29,7 @@ import ( type ( // Metadata provides information about clusters - Metadata interface { - // IsPrimaryCluster whether current cluster is the primary cluster - IsPrimaryCluster() bool - // GetNextFailoverVersion return the next failover version for domain failover - GetNextFailoverVersion(string, int64) int64 - // IsVersionFromSameCluster return true if 2 version are used for the same cluster - IsVersionFromSameCluster(version1 int64, version2 int64) bool - // GetPrimaryClusterName return the primary cluster name - GetPrimaryClusterName() string - // GetCurrentClusterName return the current cluster name - GetCurrentClusterName() string - // GetAllClusterInfo return the all cluster name -> corresponding info - GetAllClusterInfo() map[string]config.ClusterInformation - // ClusterNameForFailoverVersion return the corresponding cluster name for a given failover version - ClusterNameForFailoverVersion(failoverVersion int64) string - } - - metadataImpl struct { + Metadata struct { // failoverVersionIncrement is the increment of each cluster's version when failover happen failoverVersionIncrement int64 // primaryClusterName is the name of the primary cluster, only the primary cluster can register / update domain @@ -75,7 +56,7 @@ func NewMetadata( versionToClusterName[info.InitialFailoverVersion] = clusterName } - return &metadataImpl{ + return Metadata{ failoverVersionIncrement: failoverVersionIncrement, primaryClusterName: primaryClusterName, currentClusterName: currentClusterName, @@ -85,60 +66,55 @@ func NewMetadata( } // GetNextFailoverVersion return the next failover version based on input -func (metadata *metadataImpl) GetNextFailoverVersion(cluster string, currentFailoverVersion int64) int64 { - info, ok := metadata.clusterGroup[cluster] +func (m Metadata) GetNextFailoverVersion(cluster string, currentFailoverVersion int64) int64 { + info, ok := m.clusterGroup[cluster] if !ok { panic(fmt.Sprintf( "Unknown cluster name: %v with given cluster initial failover version map: %v.", cluster, - metadata.clusterGroup, + m.clusterGroup, )) } - failoverVersion := currentFailoverVersion/metadata.failoverVersionIncrement*metadata.failoverVersionIncrement + info.InitialFailoverVersion + failoverVersion := currentFailoverVersion/m.failoverVersionIncrement*m.failoverVersionIncrement + info.InitialFailoverVersion if failoverVersion < currentFailoverVersion { - return failoverVersion + metadata.failoverVersionIncrement + return failoverVersion + m.failoverVersionIncrement } return failoverVersion } // IsVersionFromSameCluster return true if 2 version are used for the same cluster -func (metadata *metadataImpl) IsVersionFromSameCluster(version1 int64, version2 int64) bool { - return (version1-version2)%metadata.failoverVersionIncrement == 0 -} - -func (metadata *metadataImpl) IsPrimaryCluster() bool { - return metadata.primaryClusterName == metadata.currentClusterName +func (m Metadata) IsVersionFromSameCluster(version1 int64, version2 int64) bool { + return (version1-version2)%m.failoverVersionIncrement == 0 } -// GetPrimaryClusterName return the primary cluster name -func (metadata *metadataImpl) GetPrimaryClusterName() string { - return metadata.primaryClusterName +func (m Metadata) IsPrimaryCluster() bool { + return m.primaryClusterName == m.currentClusterName } // GetCurrentClusterName return the current cluster name -func (metadata *metadataImpl) GetCurrentClusterName() string { - return metadata.currentClusterName +func (m Metadata) GetCurrentClusterName() string { + return m.currentClusterName } // GetAllClusterInfo return the all cluster name -> corresponding information -func (metadata *metadataImpl) GetAllClusterInfo() map[string]config.ClusterInformation { - return metadata.clusterGroup +func (m Metadata) GetAllClusterInfo() map[string]config.ClusterInformation { + return m.clusterGroup } // ClusterNameForFailoverVersion return the corresponding cluster name for a given failover version -func (metadata *metadataImpl) ClusterNameForFailoverVersion(failoverVersion int64) string { +func (m Metadata) ClusterNameForFailoverVersion(failoverVersion int64) string { if failoverVersion == common.EmptyVersion { - return metadata.currentClusterName + return m.currentClusterName } - initialFailoverVersion := failoverVersion % metadata.failoverVersionIncrement - clusterName, ok := metadata.versionToClusterName[initialFailoverVersion] + initialFailoverVersion := failoverVersion % m.failoverVersionIncrement + clusterName, ok := m.versionToClusterName[initialFailoverVersion] if !ok { panic(fmt.Sprintf( "Unknown initial failover version %v with given cluster initial failover version map: %v and failover version increment %v.", initialFailoverVersion, - metadata.clusterGroup, - metadata.failoverVersionIncrement, + m.clusterGroup, + m.failoverVersionIncrement, )) } return clusterName diff --git a/common/cluster/metadataTest.go b/common/cluster/metadataTest.go index b6c3370c211..fe5115f3f44 100644 --- a/common/cluster/metadataTest.go +++ b/common/cluster/metadataTest.go @@ -85,6 +85,22 @@ var ( RPCTransport: TestClusterXDCTransport, }, } + + // TestActiveClusterMetadata is metadata for an active cluster + TestActiveClusterMetadata = NewMetadata( + TestFailoverVersionIncrement, + TestCurrentClusterName, + TestCurrentClusterName, + TestAllClusterInfo, + ) + + // TestPassiveClusterMetadata is metadata for a passive cluster + TestPassiveClusterMetadata = NewMetadata( + TestFailoverVersionIncrement, + TestCurrentClusterName, + TestAlternativeClusterName, + TestAllClusterInfo, + ) ) // GetTestClusterMetadata return an cluster metadata instance, which is initialized diff --git a/common/cluster/metadata_mock.go b/common/cluster/metadata_mock.go deleted file mode 100644 index 26e7be5cc13..00000000000 --- a/common/cluster/metadata_mock.go +++ /dev/null @@ -1,156 +0,0 @@ -// The MIT License (MIT) - -// Copyright (c) 2017-2020 Uber Technologies Inc. - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -// Code generated by MockGen. DO NOT EDIT. -// Source: metadata.go - -// Package cluster is a generated GoMock package. -package cluster - -import ( - reflect "reflect" - - gomock "github.com/golang/mock/gomock" - - config "github.com/uber/cadence/common/config" -) - -// MockMetadata is a mock of Metadata interface -type MockMetadata struct { - ctrl *gomock.Controller - recorder *MockMetadataMockRecorder -} - -// MockMetadataMockRecorder is the mock recorder for MockMetadata -type MockMetadataMockRecorder struct { - mock *MockMetadata -} - -// NewMockMetadata creates a new mock instance -func NewMockMetadata(ctrl *gomock.Controller) *MockMetadata { - mock := &MockMetadata{ctrl: ctrl} - mock.recorder = &MockMetadataMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockMetadata) EXPECT() *MockMetadataMockRecorder { - return m.recorder -} - -// IsPrimaryCluster mocks base method -func (m *MockMetadata) IsPrimaryCluster() bool { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsPrimaryCluster") - ret0, _ := ret[0].(bool) - return ret0 -} - -// IsPrimaryCluster indicates an expected call of IsPrimaryCluster -func (mr *MockMetadataMockRecorder) IsPrimaryCluster() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsPrimaryCluster", reflect.TypeOf((*MockMetadata)(nil).IsPrimaryCluster)) -} - -// GetNextFailoverVersion mocks base method -func (m *MockMetadata) GetNextFailoverVersion(arg0 string, arg1 int64) int64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetNextFailoverVersion", arg0, arg1) - ret0, _ := ret[0].(int64) - return ret0 -} - -// GetNextFailoverVersion indicates an expected call of GetNextFailoverVersion -func (mr *MockMetadataMockRecorder) GetNextFailoverVersion(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNextFailoverVersion", reflect.TypeOf((*MockMetadata)(nil).GetNextFailoverVersion), arg0, arg1) -} - -// IsVersionFromSameCluster mocks base method -func (m *MockMetadata) IsVersionFromSameCluster(version1, version2 int64) bool { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsVersionFromSameCluster", version1, version2) - ret0, _ := ret[0].(bool) - return ret0 -} - -// IsVersionFromSameCluster indicates an expected call of IsVersionFromSameCluster -func (mr *MockMetadataMockRecorder) IsVersionFromSameCluster(version1, version2 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsVersionFromSameCluster", reflect.TypeOf((*MockMetadata)(nil).IsVersionFromSameCluster), version1, version2) -} - -// GetPrimaryClusterName mocks base method -func (m *MockMetadata) GetPrimaryClusterName() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetPrimaryClusterName") - ret0, _ := ret[0].(string) - return ret0 -} - -// GetPrimaryClusterName indicates an expected call of GetPrimaryClusterName -func (mr *MockMetadataMockRecorder) GetPrimaryClusterName() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPrimaryClusterName", reflect.TypeOf((*MockMetadata)(nil).GetPrimaryClusterName)) -} - -// GetCurrentClusterName mocks base method -func (m *MockMetadata) GetCurrentClusterName() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetCurrentClusterName") - ret0, _ := ret[0].(string) - return ret0 -} - -// GetCurrentClusterName indicates an expected call of GetCurrentClusterName -func (mr *MockMetadataMockRecorder) GetCurrentClusterName() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentClusterName", reflect.TypeOf((*MockMetadata)(nil).GetCurrentClusterName)) -} - -// GetAllClusterInfo mocks base method -func (m *MockMetadata) GetAllClusterInfo() map[string]config.ClusterInformation { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAllClusterInfo") - ret0, _ := ret[0].(map[string]config.ClusterInformation) - return ret0 -} - -// GetAllClusterInfo indicates an expected call of GetAllClusterInfo -func (mr *MockMetadataMockRecorder) GetAllClusterInfo() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllClusterInfo", reflect.TypeOf((*MockMetadata)(nil).GetAllClusterInfo)) -} - -// ClusterNameForFailoverVersion mocks base method -func (m *MockMetadata) ClusterNameForFailoverVersion(failoverVersion int64) string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ClusterNameForFailoverVersion", failoverVersion) - ret0, _ := ret[0].(string) - return ret0 -} - -// ClusterNameForFailoverVersion indicates an expected call of ClusterNameForFailoverVersion -func (mr *MockMetadataMockRecorder) ClusterNameForFailoverVersion(failoverVersion interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClusterNameForFailoverVersion", reflect.TypeOf((*MockMetadata)(nil).ClusterNameForFailoverVersion), failoverVersion) -} diff --git a/common/domain/attrValidator_test.go b/common/domain/attrValidator_test.go index 3c8e8bd9bec..9b9dd2b0fb8 100644 --- a/common/domain/attrValidator_test.go +++ b/common/domain/attrValidator_test.go @@ -26,7 +26,6 @@ import ( "github.com/stretchr/testify/suite" "github.com/uber/cadence/common/cluster" - "github.com/uber/cadence/common/mocks" "github.com/uber/cadence/common/persistence" "github.com/uber/cadence/common/types" ) @@ -35,9 +34,8 @@ type ( attrValidatorSuite struct { suite.Suite - minRetentionDays int - mockClusterMetadata *mocks.ClusterMetadata - validator *AttrValidatorImpl + minRetentionDays int + validator *AttrValidatorImpl } ) @@ -54,8 +52,7 @@ func (s *attrValidatorSuite) TearDownSuite() { func (s *attrValidatorSuite) SetupTest() { s.minRetentionDays = 1 - s.mockClusterMetadata = &mocks.ClusterMetadata{} - s.validator = newAttrValidator(s.mockClusterMetadata, int32(s.minRetentionDays)) + s.validator = newAttrValidator(cluster.TestActiveClusterMetadata, int32(s.minRetentionDays)) } func (s *attrValidatorSuite) TearDownTest() { @@ -88,10 +85,6 @@ func (s *attrValidatorSuite) TestValidateConfigRetentionPeriod() { } func (s *attrValidatorSuite) TestClusterName() { - s.mockClusterMetadata.On("GetAllClusterInfo").Return( - cluster.TestAllClusterInfo, - ) - err := s.validator.validateClusterName("some random foo bar") s.IsType(&types.BadRequestError{}, err) @@ -103,13 +96,6 @@ func (s *attrValidatorSuite) TestClusterName() { } func (s *attrValidatorSuite) TestValidateDomainReplicationConfigForLocalDomain() { - s.mockClusterMetadata.On("GetCurrentClusterName").Return( - cluster.TestCurrentClusterName, - ) - s.mockClusterMetadata.On("GetAllClusterInfo").Return( - cluster.TestAllClusterInfo, - ) - err := s.validator.validateDomainReplicationConfigForLocalDomain( &persistence.DomainReplicationConfig{ ActiveClusterName: cluster.TestAlternativeClusterName, @@ -154,13 +140,6 @@ func (s *attrValidatorSuite) TestValidateDomainReplicationConfigForLocalDomain() } func (s *attrValidatorSuite) TestValidateDomainReplicationConfigForGlobalDomain() { - s.mockClusterMetadata.On("GetCurrentClusterName").Return( - cluster.TestCurrentClusterName, - ) - s.mockClusterMetadata.On("GetAllClusterInfo").Return( - cluster.TestAllClusterInfo, - ) - err := s.validator.validateDomainReplicationConfigForGlobalDomain( &persistence.DomainReplicationConfig{ ActiveClusterName: cluster.TestCurrentClusterName, diff --git a/common/mocks/ClusterMetadata.go b/common/mocks/ClusterMetadata.go deleted file mode 100644 index 866366690b1..00000000000 --- a/common/mocks/ClusterMetadata.go +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright (c) 2017 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package mocks - -import ( - "github.com/stretchr/testify/mock" - - "github.com/uber/cadence/common/config" -) - -// ClusterMetadata is an autogenerated mock type for the Metadata type -type ClusterMetadata struct { - mock.Mock -} - -// ClusterNameForFailoverVersion provides a mock function with given fields: -func (_m *ClusterMetadata) ClusterNameForFailoverVersion(failoverVersion int64) string { - ret := _m.Called(failoverVersion) - - var r0 string - if rf, ok := ret.Get(0).(func(int64) string); ok { - r0 = rf(failoverVersion) - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// GetAllClusterInfo provides a mock function with given fields: -func (_m *ClusterMetadata) GetAllClusterInfo() map[string]config.ClusterInformation { - ret := _m.Called() - - var r0 map[string]config.ClusterInformation - if rf, ok := ret.Get(0).(func() map[string]config.ClusterInformation); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(map[string]config.ClusterInformation) - } - } - - return r0 -} - -// GetCurrentClusterName provides a mock function with given fields: -func (_m *ClusterMetadata) GetCurrentClusterName() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// GetPrimaryClusterName provides a mock function with given fields: -func (_m *ClusterMetadata) GetPrimaryClusterName() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// GetDeploymentGroup provides a mock function with given fields: -func (_m *ClusterMetadata) GetDeploymentGroup() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// GetNextFailoverVersion provides a mock function with given fields: _a0, _a1 -func (_m *ClusterMetadata) GetNextFailoverVersion(_a0 string, _a1 int64) int64 { - ret := _m.Called(_a0, _a1) - - var r0 int64 - if rf, ok := ret.Get(0).(func(string, int64) int64); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Get(0).(int64) - } - - return r0 -} - -// IsVersionFromSameCluster provides a mock function with given fields: _a0, _a1 -func (_m *ClusterMetadata) IsVersionFromSameCluster(_a0 int64, _a1 int64) bool { - ret := _m.Called(_a0, _a1) - - var r0 bool - if rf, ok := ret.Get(0).(func(int64, int64) bool); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// IsPrimaryCluster provides a mock function with given fields: -func (_m *ClusterMetadata) IsPrimaryCluster() bool { - ret := _m.Called() - - var r0 bool - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} diff --git a/common/persistence/persistence-tests/persistenceTestBase.go b/common/persistence/persistence-tests/persistenceTestBase.go index 96d7a13352c..8787f67ff43 100644 --- a/common/persistence/persistence-tests/persistenceTestBase.go +++ b/common/persistence/persistence-tests/persistenceTestBase.go @@ -133,7 +133,7 @@ func NewTestBaseWithNoSQL(options *TestBaseOptions) TestBase { } testCluster := nosql.NewTestCluster(options.DBPluginName, options.DBName, options.DBUsername, options.DBPassword, options.DBHost, options.DBPort, options.ProtoVersion, "") metadata := options.ClusterMetadata - if metadata == nil { + if metadata.GetCurrentClusterName() == "" { metadata = cluster.GetTestClusterMetadata(false) } dc := persistence.DynamicConfiguration{ @@ -155,7 +155,7 @@ func NewTestBaseWithSQL(options *TestBaseOptions) TestBase { } testCluster := sql.NewTestCluster(options.DBPluginName, options.DBName, options.DBUsername, options.DBPassword, options.DBHost, options.DBPort, options.SchemaDir) metadata := options.ClusterMetadata - if metadata == nil { + if metadata.GetCurrentClusterName() == "" { metadata = cluster.GetTestClusterMetadata(false) } dc := persistence.DynamicConfiguration{ diff --git a/common/resource/resourceTest.go b/common/resource/resourceTest.go index 3f627014356..6a40b3552cf 100644 --- a/common/resource/resourceTest.go +++ b/common/resource/resourceTest.go @@ -56,7 +56,7 @@ type ( // Test is the test implementation used for testing Test struct { MetricsScope tally.TestScope - ClusterMetadata *cluster.MockMetadata + ClusterMetadata cluster.Metadata // other common resources @@ -151,8 +151,10 @@ func NewTest( scope := tally.NewTestScope("test", nil) return &Test{ - MetricsScope: scope, - ClusterMetadata: cluster.NewMockMetadata(controller), + MetricsScope: scope, + + // By default tests will run on active cluster unless overridden otherwise + ClusterMetadata: cluster.TestActiveClusterMetadata, // other common resources diff --git a/service/frontend/clusterRedirectionHandler_test.go b/service/frontend/clusterRedirectionHandler_test.go index 5dc4b30cd35..65e8715a794 100644 --- a/service/frontend/clusterRedirectionHandler_test.go +++ b/service/frontend/clusterRedirectionHandler_test.go @@ -49,7 +49,6 @@ type ( mockResource *resource.Test mockFrontendHandler *MockHandler mockRemoteFrontendClient *frontend.MockClient - mockClusterMetadata *cluster.MockMetadata mockClusterRedirectionPolicy *MockClusterRedirectionPolicy @@ -94,11 +93,8 @@ func (s *clusterRedirectionHandlerSuite) SetupTest() { s.controller = gomock.NewController(s.T()) s.mockResource = resource.NewTest(s.controller, metrics.Frontend) - s.mockClusterMetadata = s.mockResource.ClusterMetadata s.mockRemoteFrontendClient = s.mockResource.RemoteFrontendClient - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.currentClusterName).AnyTimes() - s.config = NewConfig( dynamicconfig.NewCollection( dynamicconfig.NewNopClient(), diff --git a/service/frontend/workflowHandler_test.go b/service/frontend/workflowHandler_test.go index 61f3132f1d0..8a1941396dd 100644 --- a/service/frontend/workflowHandler_test.go +++ b/service/frontend/workflowHandler_test.go @@ -66,11 +66,10 @@ type ( suite.Suite *require.Assertions - controller *gomock.Controller - mockResource *resource.Test - mockDomainCache *cache.MockDomainCache - mockHistoryClient *history.MockClient - mockClusterMetadata *cluster.MockMetadata + controller *gomock.Controller + mockResource *resource.Test + mockDomainCache *cache.MockDomainCache + mockHistoryClient *history.MockClient mockProducer *mocks.KafkaProducer mockMessagingClient messaging.Client @@ -109,7 +108,6 @@ func (s *workflowHandlerSuite) SetupTest() { s.mockResource = resource.NewTest(s.controller, metrics.Frontend) s.mockDomainCache = s.mockResource.DomainCache s.mockHistoryClient = s.mockResource.HistoryClient - s.mockClusterMetadata = s.mockResource.ClusterMetadata s.mockMetadataMgr = s.mockResource.MetadataMgr s.mockHistoryV2Mgr = s.mockResource.HistoryMgr s.mockVisibilityMgr = s.mockResource.VisibilityMgr @@ -125,7 +123,6 @@ func (s *workflowHandlerSuite) SetupTest() { mockMonitor := s.mockResource.MembershipResolver mockMonitor.EXPECT().MemberCount(service.Frontend).Return(5, nil).AnyTimes() s.mockVersionChecker.EXPECT().ClientSupported(gomock.Any(), gomock.Any()).Return(nil).AnyTimes() - s.mockClusterMetadata.EXPECT().IsPrimaryCluster().Return(true).AnyTimes() } func (s *workflowHandlerSuite) TearDownTest() { @@ -504,7 +501,6 @@ func (s *workflowHandlerSuite) TestRegisterDomain_Failure_MissingDomainDataKey() } func (s *workflowHandlerSuite) TestRegisterDomain_Failure_InvalidArchivalURI() { - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName) s.mockArchivalMetadata.On("GetHistoryConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "random URI")) s.mockArchivalMetadata.On("GetVisibilityConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "random URI")) s.mockMetadataMgr.On("GetDomain", mock.Anything, mock.Anything).Return(nil, &types.EntityNotExistsError{}) @@ -526,8 +522,6 @@ func (s *workflowHandlerSuite) TestRegisterDomain_Failure_InvalidArchivalURI() { } func (s *workflowHandlerSuite) TestRegisterDomain_Success_EnabledWithNoArchivalURI() { - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockArchivalMetadata.On("GetHistoryConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", testHistoryArchivalURI)) s.mockArchivalMetadata.On("GetVisibilityConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", testVisibilityArchivalURI)) s.mockMetadataMgr.On("GetDomain", mock.Anything, mock.Anything).Return(nil, &types.EntityNotExistsError{}) @@ -547,8 +541,6 @@ func (s *workflowHandlerSuite) TestRegisterDomain_Success_EnabledWithNoArchivalU } func (s *workflowHandlerSuite) TestRegisterDomain_Success_EnabledWithArchivalURI() { - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockArchivalMetadata.On("GetHistoryConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "invalidURI")) s.mockArchivalMetadata.On("GetVisibilityConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "invalidURI")) s.mockMetadataMgr.On("GetDomain", mock.Anything, mock.Anything).Return(nil, &types.EntityNotExistsError{}) @@ -573,8 +565,6 @@ func (s *workflowHandlerSuite) TestRegisterDomain_Success_EnabledWithArchivalURI } func (s *workflowHandlerSuite) TestRegisterDomain_Success_ClusterNotConfiguredForArchival() { - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockArchivalMetadata.On("GetHistoryConfig").Return(archiver.NewDisabledArchvialConfig()) s.mockArchivalMetadata.On("GetVisibilityConfig").Return(archiver.NewDisabledArchvialConfig()) s.mockMetadataMgr.On("GetDomain", mock.Anything, mock.Anything).Return(nil, &types.EntityNotExistsError{}) @@ -595,8 +585,6 @@ func (s *workflowHandlerSuite) TestRegisterDomain_Success_ClusterNotConfiguredFo } func (s *workflowHandlerSuite) TestRegisterDomain_Success_NotEnabled() { - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockArchivalMetadata.On("GetHistoryConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "some random URI")) s.mockArchivalMetadata.On("GetVisibilityConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "some random URI")) s.mockMetadataMgr.On("GetDomain", mock.Anything, mock.Anything).Return(nil, &types.EntityNotExistsError{}) @@ -718,8 +706,6 @@ func (s *workflowHandlerSuite) TestUpdateDomain_Success_ArchivalEnabledToArchiva ) s.mockMetadataMgr.On("GetDomain", mock.Anything, mock.Anything).Return(getDomainResp, nil) s.mockMetadataMgr.On("UpdateDomain", mock.Anything, mock.Anything).Return(nil) - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockArchivalMetadata.On("GetHistoryConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "some random URI")) s.mockArchivalMetadata.On("GetVisibilityConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "some random URI")) s.mockHistoryArchiver.On("ValidateURI", mock.Anything).Return(nil) @@ -754,8 +740,6 @@ func (s *workflowHandlerSuite) TestUpdateDomain_Success_ClusterNotConfiguredForA &domain.ArchivalState{Status: types.ArchivalStatusEnabled, URI: "some random visibility URI"}, ) s.mockMetadataMgr.On("GetDomain", mock.Anything, mock.Anything).Return(getDomainResp, nil) - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockArchivalMetadata.On("GetHistoryConfig").Return(archiver.NewDisabledArchvialConfig()) s.mockArchivalMetadata.On("GetVisibilityConfig").Return(archiver.NewDisabledArchvialConfig()) @@ -782,8 +766,6 @@ func (s *workflowHandlerSuite) TestUpdateDomain_Success_ArchivalEnabledToArchiva ) s.mockMetadataMgr.On("GetDomain", mock.Anything, mock.Anything).Return(getDomainResp, nil) s.mockMetadataMgr.On("UpdateDomain", mock.Anything, mock.Anything).Return(nil) - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockArchivalMetadata.On("GetHistoryConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "some random URI")) s.mockArchivalMetadata.On("GetVisibilityConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "some random URI")) s.mockHistoryArchiver.On("ValidateURI", mock.Anything).Return(nil) @@ -818,8 +800,6 @@ func (s *workflowHandlerSuite) TestUpdateDomain_Success_ArchivalEnabledToEnabled &domain.ArchivalState{Status: types.ArchivalStatusEnabled, URI: testVisibilityArchivalURI}, ) s.mockMetadataMgr.On("GetDomain", mock.Anything, mock.Anything).Return(getDomainResp, nil) - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockArchivalMetadata.On("GetHistoryConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "some random URI")) s.mockArchivalMetadata.On("GetVisibilityConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "some random URI")) s.mockHistoryArchiver.On("ValidateURI", mock.Anything).Return(nil) @@ -855,8 +835,6 @@ func (s *workflowHandlerSuite) TestUpdateDomain_Success_ArchivalNeverEnabledToEn ) s.mockMetadataMgr.On("GetDomain", mock.Anything, mock.Anything).Return(getDomainResp, nil) s.mockMetadataMgr.On("UpdateDomain", mock.Anything, mock.Anything).Return(nil) - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockArchivalMetadata.On("GetHistoryConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "some random URI")) s.mockArchivalMetadata.On("GetVisibilityConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("enabled"), dc.GetBoolPropertyFn(true), "disabled", "some random URI")) s.mockHistoryArchiver.On("ValidateURI", mock.Anything).Return(nil) @@ -892,9 +870,7 @@ func (s *workflowHandlerSuite) TestUpdateDomain_Success_FailOver() { s.mockMetadataMgr.On("GetDomain", mock.Anything, mock.Anything).Return(getDomainResp, nil) s.mockMetadataMgr.On("UpdateDomain", mock.Anything, mock.Anything).Return(nil) - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestAlternativeClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetNextFailoverVersion(gomock.Any(), gomock.Any()).Return(int64(123)).AnyTimes() + s.mockResource.ClusterMetadata = cluster.TestPassiveClusterMetadata s.mockArchivalMetadata.On("GetHistoryConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("disabled"), dc.GetBoolPropertyFn(false), "disabled", "some random URI")) s.mockArchivalMetadata.On("GetVisibilityConfig").Return(archiver.NewArchivalConfig("enabled", dc.GetStringPropertyFn("disabled"), dc.GetBoolPropertyFn(false), "disabled", "some random URI")) s.mockProducer.On("Publish", mock.Anything, mock.Anything).Return(nil).Once() diff --git a/service/history/constants/test_constants.go b/service/history/constants/test_constants.go index 327769970f9..c494394e889 100644 --- a/service/history/constants/test_constants.go +++ b/service/history/constants/test_constants.go @@ -29,7 +29,7 @@ import ( var ( // TestVersion is the workflow version for test - TestVersion = int64(1234) + TestVersion = cluster.TestCurrentClusterInitialFailoverVersion + (cluster.TestFailoverVersionIncrement * 5) // TestDomainID is the domainID for test TestDomainID = "deadbeef-0123-4567-890a-bcdef0123456" // TestDomainName is the domainName for test diff --git a/service/history/execution/history_builder_test.go b/service/history/execution/history_builder_test.go index bed6d9af119..90ebb8136e6 100644 --- a/service/history/execution/history_builder_test.go +++ b/service/history/execution/history_builder_test.go @@ -30,7 +30,6 @@ import ( "github.com/uber/cadence/common" "github.com/uber/cadence/common/cache" - "github.com/uber/cadence/common/cluster" "github.com/uber/cadence/common/log" "github.com/uber/cadence/common/persistence" "github.com/uber/cadence/common/types" @@ -101,7 +100,6 @@ func (s *historyBuilderSuite) SetupTest() { s.mockDomainCache.EXPECT().GetDomainID(s.targetDomainName).Return(s.targetDomainID, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainByID(s.targetDomainID).Return(s.targetDomainEntry, nil).AnyTimes() s.mockEventsCache.EXPECT().PutEvent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() - s.mockShard.Resource.ClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.msBuilder = NewMutableStateBuilder(s.mockShard, s.logger, s.domainEntry) s.builder = NewHistoryBuilder(s.msBuilder) diff --git a/service/history/execution/state_builder_test.go b/service/history/execution/state_builder_test.go index 19495c048b7..d76ef11cf8e 100644 --- a/service/history/execution/state_builder_test.go +++ b/service/history/execution/state_builder_test.go @@ -32,7 +32,6 @@ import ( "github.com/uber/cadence/common" "github.com/uber/cadence/common/backoff" "github.com/uber/cadence/common/cache" - "github.com/uber/cadence/common/cluster" "github.com/uber/cadence/common/log" "github.com/uber/cadence/common/persistence" "github.com/uber/cadence/common/types" @@ -47,13 +46,12 @@ type ( suite.Suite *require.Assertions - controller *gomock.Controller - mockShard *shard.TestContext - mockEventsCache *events.MockCache - mockDomainCache *cache.MockDomainCache - mockTaskGenerator *MockMutableStateTaskGenerator - mockMutableState *MockMutableState - mockClusterMetadata *cluster.MockMetadata + controller *gomock.Controller + mockShard *shard.TestContext + mockEventsCache *events.MockCache + mockDomainCache *cache.MockDomainCache + mockTaskGenerator *MockMutableStateTaskGenerator + mockMutableState *MockMutableState mockTaskGeneratorForNew *MockMutableStateTaskGenerator @@ -96,9 +94,7 @@ func (s *stateBuilderSuite) SetupTest() { ) s.mockDomainCache = s.mockShard.Resource.DomainCache - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata s.mockEventsCache = s.mockShard.MockEventsCache - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockEventsCache.EXPECT().PutEvent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() s.logger = s.mockShard.GetLogger() @@ -474,7 +470,6 @@ func (s *stateBuilderSuite) TestApplyEvents_EventTypeWorkflowExecutionContinuedA newRunStartedEvent, newRunSignalEvent, newRunDecisionEvent, } - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(continueAsNewEvent.Version).Return(s.sourceCluster).AnyTimes() s.mockMutableState.EXPECT().ReplicateWorkflowExecutionContinuedAsNewEvent( continueAsNewEvent.ID, constants.TestDomainID, diff --git a/service/history/failover/marker_notifier_test.go b/service/history/failover/marker_notifier_test.go index 703ae859df6..c6337a92ed0 100644 --- a/service/history/failover/marker_notifier_test.go +++ b/service/history/failover/marker_notifier_test.go @@ -47,12 +47,12 @@ type ( suite.Suite *require.Assertions - controller *gomock.Controller - coordinator *MockCoordinator - mockShard *shard.TestContext - mockDomainCache *cache.MockDomainCache - mockClusterMetadata *cluster.MockMetadata - markerNotifier *markerNotifierImpl + controller *gomock.Controller + coordinator *MockCoordinator + mockShard *shard.TestContext + mockDomainCache *cache.MockDomainCache + clusterMetadata cluster.Metadata + markerNotifier *markerNotifierImpl } ) @@ -77,9 +77,7 @@ func (s *markerNotifierSuite) SetupTest() { }, config, ) - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() + s.clusterMetadata = s.mockShard.Resource.ClusterMetadata mockShardManager := s.mockShard.Resource.ShardMgr mockShardManager.On("UpdateShard", mock.Anything, mock.Anything).Return(nil) s.mockDomainCache = s.mockShard.Resource.DomainCache @@ -117,10 +115,10 @@ func (s *markerNotifierSuite) TestNotifyPendingFailoverMarker() { EmitMetric: true, } replicationConfig := &persistence.DomainReplicationConfig{ - ActiveClusterName: s.mockClusterMetadata.GetCurrentClusterName(), + ActiveClusterName: s.clusterMetadata.GetCurrentClusterName(), Clusters: []*persistence.ClusterReplicationConfig{ { - ClusterName: s.mockClusterMetadata.GetCurrentClusterName(), + ClusterName: s.clusterMetadata.GetCurrentClusterName(), }, }, } diff --git a/service/history/historyEngine2_test.go b/service/history/historyEngine2_test.go index f025510a84b..0d2dc7d5365 100644 --- a/service/history/historyEngine2_test.go +++ b/service/history/historyEngine2_test.go @@ -37,7 +37,6 @@ import ( "github.com/uber/cadence/common" "github.com/uber/cadence/common/cache" "github.com/uber/cadence/common/clock" - "github.com/uber/cadence/common/cluster" "github.com/uber/cadence/common/log" "github.com/uber/cadence/common/log/loggerimpl" "github.com/uber/cadence/common/log/tag" @@ -63,13 +62,12 @@ type ( suite.Suite *require.Assertions - controller *gomock.Controller - mockShard *shard.TestContext - mockTxProcessor *queue.MockProcessor - mockTimerProcessor *queue.MockProcessor - mockEventsCache *events.MockCache - mockDomainCache *cache.MockDomainCache - mockClusterMetadata *cluster.MockMetadata + controller *gomock.Controller + mockShard *shard.TestContext + mockTxProcessor *queue.MockProcessor + mockTimerProcessor *queue.MockProcessor + mockEventsCache *events.MockCache + mockDomainCache *cache.MockDomainCache historyEngine *historyEngineImpl mockExecutionMgr *mocks.ExecutionManager @@ -117,7 +115,6 @@ func (s *engine2Suite) SetupTest() { s.mockExecutionMgr = s.mockShard.Resource.ExecutionMgr s.mockHistoryV2Mgr = s.mockShard.Resource.HistoryMgr s.mockShardManager = s.mockShard.Resource.ShardMgr - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata s.mockEventsCache = s.mockShard.MockEventsCache testDomainEntry := cache.NewLocalDomainCacheEntryForTest( &p.DomainInfo{ID: constants.TestDomainID}, &p.DomainConfig{}, "", @@ -126,16 +123,13 @@ func (s *engine2Suite) SetupTest() { s.mockDomainCache.EXPECT().GetDomainName(gomock.Any()).Return(constants.TestDomainID, nil).AnyTimes() s.mockEventsCache.EXPECT().PutEvent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(common.EmptyVersion).Return(cluster.TestCurrentClusterName).AnyTimes() - s.logger = s.mockShard.GetLogger() executionCache := execution.NewCache(s.mockShard) h := &historyEngineImpl{ currentClusterName: s.mockShard.GetClusterMetadata().GetCurrentClusterName(), shard: s.mockShard, - clusterMetadata: s.mockClusterMetadata, + clusterMetadata: s.mockShard.Resource.ClusterMetadata, executionManager: s.mockExecutionMgr, historyV2Mgr: s.mockHistoryV2Mgr, executionCache: executionCache, diff --git a/service/history/historyEngine3_eventsv2_test.go b/service/history/historyEngine3_eventsv2_test.go index 8ba4050ae41..25f959de975 100644 --- a/service/history/historyEngine3_eventsv2_test.go +++ b/service/history/historyEngine3_eventsv2_test.go @@ -35,7 +35,6 @@ import ( "github.com/uber/cadence/common" "github.com/uber/cadence/common/cache" "github.com/uber/cadence/common/clock" - "github.com/uber/cadence/common/cluster" "github.com/uber/cadence/common/log" "github.com/uber/cadence/common/log/loggerimpl" "github.com/uber/cadence/common/metrics" @@ -57,13 +56,12 @@ type ( suite.Suite *require.Assertions - controller *gomock.Controller - mockShard *shard.TestContext - mockTxProcessor *queue.MockProcessor - mockTimerProcessor *queue.MockProcessor - mockEventsCache *events.MockCache - mockDomainCache *cache.MockDomainCache - mockClusterMetadata *cluster.MockMetadata + controller *gomock.Controller + mockShard *shard.TestContext + mockTxProcessor *queue.MockProcessor + mockTimerProcessor *queue.MockProcessor + mockEventsCache *events.MockCache + mockDomainCache *cache.MockDomainCache historyEngine *historyEngineImpl mockExecutionMgr *mocks.ExecutionManager @@ -107,12 +105,9 @@ func (s *engine3Suite) SetupTest() { s.mockExecutionMgr = s.mockShard.Resource.ExecutionMgr s.mockHistoryV2Mgr = s.mockShard.Resource.HistoryMgr - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata s.mockDomainCache = s.mockShard.Resource.DomainCache s.mockEventsCache = s.mockShard.MockEventsCache - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(common.EmptyVersion).Return(cluster.TestCurrentClusterName).AnyTimes() s.mockEventsCache.EXPECT().PutEvent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() s.logger = s.mockShard.GetLogger() @@ -120,7 +115,7 @@ func (s *engine3Suite) SetupTest() { h := &historyEngineImpl{ currentClusterName: s.mockShard.GetClusterMetadata().GetCurrentClusterName(), shard: s.mockShard, - clusterMetadata: s.mockClusterMetadata, + clusterMetadata: s.mockShard.Resource.ClusterMetadata, executionManager: s.mockExecutionMgr, historyV2Mgr: s.mockHistoryV2Mgr, executionCache: execution.NewCache(s.mockShard), diff --git a/service/history/historyEngine_test.go b/service/history/historyEngine_test.go index 08ba6dd20ea..86759a6ebff 100644 --- a/service/history/historyEngine_test.go +++ b/service/history/historyEngine_test.go @@ -76,7 +76,6 @@ type ( mockDomainCache *cache.MockDomainCache mockHistoryClient *hclient.MockClient mockMatchingClient *matching.MockClient - mockClusterMetadata *cluster.MockMetadata mockEventsReapplier *ndc.MockEventsReapplier mockWorkflowResetter *reset.MockWorkflowResetter @@ -135,11 +134,7 @@ func (s *engineSuite) SetupTest() { s.mockExecutionMgr = s.mockShard.Resource.ExecutionMgr s.mockHistoryV2Mgr = s.mockShard.Resource.HistoryMgr s.mockShardManager = s.mockShard.Resource.ShardMgr - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata s.mockDomainCache = s.mockShard.Resource.DomainCache - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestSingleDCClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(common.EmptyVersion).Return(cluster.TestCurrentClusterName).AnyTimes() s.mockDomainCache.EXPECT().GetDomainByID(constants.TestDomainID).Return(constants.TestLocalDomainEntry, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainName(constants.TestDomainID).Return(constants.TestDomainName, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomain(constants.TestDomainName).Return(constants.TestLocalDomainEntry, nil).AnyTimes() @@ -157,7 +152,7 @@ func (s *engineSuite) SetupTest() { currentClusterName: s.mockShard.GetClusterMetadata().GetCurrentClusterName(), shard: s.mockShard, timeSource: s.mockShard.GetTimeSource(), - clusterMetadata: s.mockClusterMetadata, + clusterMetadata: s.mockShard.Resource.ClusterMetadata, executionManager: s.mockExecutionMgr, historyV2Mgr: s.mockHistoryV2Mgr, executionCache: execution.NewCache(s.mockShard), diff --git a/service/history/ndc/activity_replicator_test.go b/service/history/ndc/activity_replicator_test.go index a81d49df031..96f9a795ca1 100644 --- a/service/history/ndc/activity_replicator_test.go +++ b/service/history/ndc/activity_replicator_test.go @@ -52,12 +52,11 @@ type ( suite.Suite *require.Assertions - controller *gomock.Controller - mockShard *shard.TestContext - mockEngine *engine.MockEngine - mockDomainCache *cache.MockDomainCache - mockClusterMetadata *cluster.MockMetadata - mockMutableState *execution.MockMutableState + controller *gomock.Controller + mockShard *shard.TestContext + mockEngine *engine.MockEngine + mockDomainCache *cache.MockDomainCache + mockMutableState *execution.MockMutableState mockExecutionMgr *mocks.ExecutionManager @@ -99,10 +98,6 @@ func (s *activityReplicatorSuite) SetupTest() { s.mockDomainCache = s.mockShard.Resource.DomainCache s.mockExecutionMgr = s.mockShard.Resource.ExecutionMgr - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.logger = s.mockShard.GetLogger() s.executionCache = execution.NewCache(s.mockShard) @@ -902,7 +897,6 @@ func (s *activityReplicatorSuite) TestSyncActivity_ActivityRunning_Update_SameVe Attempt: attempt, } s.mockMutableState.EXPECT().GetActivityInfo(scheduleID).Return(activityInfo, true).AnyTimes() - s.mockClusterMetadata.EXPECT().IsVersionFromSameCluster(version, activityInfo.Version).Return(true).AnyTimes() expectedErr := errors.New("this is error is used to by pass lots of mocking") s.mockMutableState.EXPECT().ReplicateActivityInfo(request, false).Return(expectedErr).Times(1) @@ -978,7 +972,6 @@ func (s *activityReplicatorSuite) TestSyncActivity_ActivityRunning_Update_SameVe Attempt: attempt - 1, } s.mockMutableState.EXPECT().GetActivityInfo(scheduleID).Return(activityInfo, true).AnyTimes() - s.mockClusterMetadata.EXPECT().IsVersionFromSameCluster(version, activityInfo.Version).Return(true).AnyTimes() expectedErr := errors.New("this is error is used to by pass lots of mocking") s.mockMutableState.EXPECT().ReplicateActivityInfo(request, true).Return(expectedErr).Times(1) @@ -1054,7 +1047,6 @@ func (s *activityReplicatorSuite) TestSyncActivity_ActivityRunning_Update_Larger Attempt: attempt + 1, } s.mockMutableState.EXPECT().GetActivityInfo(scheduleID).Return(activityInfo, true).AnyTimes() - s.mockClusterMetadata.EXPECT().IsVersionFromSameCluster(version, activityInfo.Version).Return(false).AnyTimes() expectedErr := errors.New("this is error is used to by pass lots of mocking") s.mockMutableState.EXPECT().ReplicateActivityInfo(request, true).Return(expectedErr).Times(1) @@ -1131,7 +1123,6 @@ func (s *activityReplicatorSuite) TestSyncActivity_ActivityRunning() { s.mockMutableState.EXPECT().GetActivityInfo(scheduleID).Return(activityInfo, true).AnyTimes() activityInfos := map[int64]*persistence.ActivityInfo{activityInfo.ScheduleID: activityInfo} s.mockMutableState.EXPECT().GetPendingActivityInfos().Return(activityInfos).AnyTimes() - s.mockClusterMetadata.EXPECT().IsVersionFromSameCluster(version, activityInfo.Version).Return(false).AnyTimes() s.mockMutableState.EXPECT().ReplicateActivityInfo(request, true).Return(nil).Times(1) s.mockMutableState.EXPECT().UpdateActivity(activityInfo).Return(nil).Times(1) @@ -1219,7 +1210,6 @@ func (s *activityReplicatorSuite) TestSyncActivity_ActivityRunning_ZombieWorkflo s.mockMutableState.EXPECT().GetActivityInfo(scheduleID).Return(activityInfo, true).AnyTimes() activityInfos := map[int64]*persistence.ActivityInfo{activityInfo.ScheduleID: activityInfo} s.mockMutableState.EXPECT().GetPendingActivityInfos().Return(activityInfos).AnyTimes() - s.mockClusterMetadata.EXPECT().IsVersionFromSameCluster(version, activityInfo.Version).Return(false).AnyTimes() s.mockMutableState.EXPECT().ReplicateActivityInfo(request, true).Return(nil).Times(1) s.mockMutableState.EXPECT().UpdateActivity(activityInfo).Return(nil).Times(1) diff --git a/service/history/ndc/branch_manager_test.go b/service/history/ndc/branch_manager_test.go index d3873c58be2..9ae6b6fcc60 100644 --- a/service/history/ndc/branch_manager_test.go +++ b/service/history/ndc/branch_manager_test.go @@ -31,7 +31,6 @@ import ( "github.com/stretchr/testify/suite" "github.com/uber/cadence/common" - "github.com/uber/cadence/common/cluster" "github.com/uber/cadence/common/log" "github.com/uber/cadence/common/mocks" "github.com/uber/cadence/common/persistence" @@ -46,11 +45,10 @@ type ( suite.Suite *require.Assertions - controller *gomock.Controller - mockShard *shard.TestContext - mockContext *execution.MockContext - mockMutableState *execution.MockMutableState - mockClusterMetadata *cluster.MockMetadata + controller *gomock.Controller + mockShard *shard.TestContext + mockContext *execution.MockContext + mockMutableState *execution.MockMutableState mockHistoryV2Manager *mocks.HistoryV2Manager @@ -88,8 +86,6 @@ func (s *branchManagerSuite) SetupTest() { ) s.mockHistoryV2Manager = s.mockShard.Resource.HistoryMgr - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.logger = s.mockShard.GetLogger() @@ -204,9 +200,6 @@ func (s *branchManagerSuite) TestFlushBufferedEvents() { ).Return(&types.HistoryEvent{}, nil).Times(1) s.mockMutableState.EXPECT().FlushBufferedEvents().Return(nil).Times(1) - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(lastWriteVersion).Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockContext.EXPECT().UpdateWorkflowExecutionAsActive(gomock.Any(), gomock.Any()).Return(nil).Times(1) ctx := ctx.Background() diff --git a/service/history/ndc/transaction_manager_test.go b/service/history/ndc/transaction_manager_test.go index a3d590fb7a2..423e79384f0 100644 --- a/service/history/ndc/transaction_manager_test.go +++ b/service/history/ndc/transaction_manager_test.go @@ -56,7 +56,6 @@ type ( mockUpdateManager *MocktransactionManagerForExistingWorkflow mockEventsReapplier *MockEventsReapplier mockWorkflowResetter *reset.MockWorkflowResetter - mockClusterMetadata *cluster.MockMetadata mockExecutionManager *mocks.ExecutionManager @@ -91,7 +90,6 @@ func (s *transactionManagerSuite) SetupTest() { config.NewForTest(), ) - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata s.mockExecutionManager = s.mockShard.Resource.ExecutionMgr s.logger = s.mockShard.GetLogger() @@ -155,9 +153,6 @@ func (s *transactionManagerSuite) TestBackfillWorkflow_CurrentWorkflow_Active_Op workflow.EXPECT().GetMutableState().Return(mutableState).AnyTimes() workflow.EXPECT().GetReleaseFn().Return(releaseFn).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(s.domainEntry.GetFailoverVersion()).Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockEventsReapplier.EXPECT().ReapplyEvents(ctx, mutableState, workflowEvents.Events, runID).Return(workflowEvents.Events, nil).Times(1) mutableState.EXPECT().IsCurrentWorkflowGuaranteed().Return(true).AnyTimes() @@ -201,9 +196,6 @@ func (s *transactionManagerSuite) TestBackfillWorkflow_CurrentWorkflow_Active_Cl workflow.EXPECT().GetMutableState().Return(mutableState).AnyTimes() workflow.EXPECT().GetReleaseFn().Return(releaseFn).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(s.domainEntry.GetFailoverVersion()).Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - mutableState.EXPECT().IsCurrentWorkflowGuaranteed().Return(false).AnyTimes() mutableState.EXPECT().IsWorkflowExecutionRunning().Return(false).AnyTimes() mutableState.EXPECT().GetDomainEntry().Return(s.domainEntry).AnyTimes() @@ -266,9 +258,7 @@ func (s *transactionManagerSuite) TestBackfillWorkflow_CurrentWorkflow_Passive_O workflow.EXPECT().GetMutableState().Return(mutableState).AnyTimes() workflow.EXPECT().GetReleaseFn().Return(releaseFn).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(s.domainEntry.GetFailoverVersion()).Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestAlternativeClusterName).AnyTimes() - + s.transactionManager.clusterMetadata = cluster.TestPassiveClusterMetadata mutableState.EXPECT().IsCurrentWorkflowGuaranteed().Return(true).AnyTimes() mutableState.EXPECT().IsWorkflowExecutionRunning().Return(true).AnyTimes() mutableState.EXPECT().GetDomainEntry().Return(s.domainEntry).AnyTimes() @@ -303,9 +293,7 @@ func (s *transactionManagerSuite) TestBackfillWorkflow_CurrentWorkflow_Passive_C workflow.EXPECT().GetMutableState().Return(mutableState).AnyTimes() workflow.EXPECT().GetReleaseFn().Return(releaseFn).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(s.domainEntry.GetFailoverVersion()).Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestAlternativeClusterName).AnyTimes() - + s.transactionManager.clusterMetadata = cluster.TestPassiveClusterMetadata mutableState.EXPECT().IsCurrentWorkflowGuaranteed().Return(false).AnyTimes() mutableState.EXPECT().IsWorkflowExecutionRunning().Return(false).AnyTimes() mutableState.EXPECT().GetDomainEntry().Return(s.domainEntry).AnyTimes() @@ -358,9 +346,6 @@ func (s *transactionManagerSuite) TestBackfillWorkflow_NotCurrentWorkflow_Active workflow.EXPECT().GetMutableState().Return(mutableState).AnyTimes() workflow.EXPECT().GetReleaseFn().Return(releaseFn).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(s.domainEntry.GetFailoverVersion()).Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - mutableState.EXPECT().IsCurrentWorkflowGuaranteed().Return(false).AnyTimes() mutableState.EXPECT().IsWorkflowExecutionRunning().Return(false).AnyTimes() mutableState.EXPECT().GetDomainEntry().Return(s.domainEntry).AnyTimes() @@ -412,9 +397,6 @@ func (s *transactionManagerSuite) TestBackfillWorkflow_NotCurrentWorkflow_Passiv workflow.EXPECT().GetMutableState().Return(mutableState).AnyTimes() workflow.EXPECT().GetReleaseFn().Return(releaseFn).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(s.domainEntry.GetFailoverVersion()).Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestAlternativeClusterName).AnyTimes() - mutableState.EXPECT().IsCurrentWorkflowGuaranteed().Return(false).AnyTimes() mutableState.EXPECT().IsWorkflowExecutionRunning().Return(false).AnyTimes() mutableState.EXPECT().GetDomainEntry().Return(s.domainEntry).AnyTimes() diff --git a/service/history/queue/timer_queue_processor_base_test.go b/service/history/queue/timer_queue_processor_base_test.go index a6201f9211e..78666d88da2 100644 --- a/service/history/queue/timer_queue_processor_base_test.go +++ b/service/history/queue/timer_queue_processor_base_test.go @@ -94,9 +94,6 @@ func (s *timerQueueProcessorBaseSuite) TearDownTest() { } func (s *timerQueueProcessorBaseSuite) TestIsProcessNow() { - mockClusterMetadata := s.mockShard.Resource.ClusterMetadata - mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.clusterName).AnyTimes() - timerQueueProcessBase := s.newTestTimerQueueProcessorBase(nil, nil, nil, nil, nil) s.True(timerQueueProcessBase.isProcessNow(time.Time{})) @@ -189,9 +186,6 @@ func (s *timerQueueProcessorBaseSuite) TestGetTimerTasks_NoMore() { } func (s *timerQueueProcessorBaseSuite) TestReadLookAheadTask() { - mockClusterMetadata := s.mockShard.Resource.ClusterMetadata - mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.clusterName).AnyTimes() - shardMaxReadLevel := s.mockShard.UpdateTimerMaxReadLevel(s.clusterName) readLevel := newTimerTaskKey(shardMaxReadLevel, 0) maxReadLevel := newTimerTaskKey(shardMaxReadLevel.Add(10*time.Second), 0) @@ -231,9 +225,6 @@ func (s *timerQueueProcessorBaseSuite) TestReadLookAheadTask() { } func (s *timerQueueProcessorBaseSuite) TestReadAndFilterTasks_NoLookAhead_NoNextPage() { - mockClusterMetadata := s.mockShard.Resource.ClusterMetadata - mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.clusterName).AnyTimes() - readLevel := newTimerTaskKey(time.Now().Add(-10*time.Second), 0) maxReadLevel := newTimerTaskKey(time.Now().Add(1*time.Second), 0) @@ -281,9 +272,6 @@ func (s *timerQueueProcessorBaseSuite) TestReadAndFilterTasks_NoLookAhead_NoNext } func (s *timerQueueProcessorBaseSuite) TestReadAndFilterTasks_NoLookAhead_HasNextPage() { - mockClusterMetadata := s.mockShard.Resource.ClusterMetadata - mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.clusterName).AnyTimes() - readLevel := newTimerTaskKey(time.Now().Add(-10*time.Second), 0) maxReadLevel := newTimerTaskKey(time.Now().Add(1*time.Second), 0) @@ -323,9 +311,6 @@ func (s *timerQueueProcessorBaseSuite) TestReadAndFilterTasks_NoLookAhead_HasNex } func (s *timerQueueProcessorBaseSuite) TestReadAndFilterTasks_HasLookAhead_NoNextPage() { - mockClusterMetadata := s.mockShard.Resource.ClusterMetadata - mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.clusterName).AnyTimes() - readLevel := newTimerTaskKey(time.Now().Add(-10*time.Second), 0) maxReadLevel := newTimerTaskKey(time.Now().Add(1*time.Second), 0) @@ -376,9 +361,6 @@ func (s *timerQueueProcessorBaseSuite) TestReadAndFilterTasks_HasLookAhead_NoNex } func (s *timerQueueProcessorBaseSuite) TestReadAndFilterTasks_HasLookAhead_HasNextPage() { - mockClusterMetadata := s.mockShard.Resource.ClusterMetadata - mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.clusterName).AnyTimes() - readLevel := newTimerTaskKey(time.Now().Add(-10*time.Second), 0) maxReadLevel := newTimerTaskKey(time.Now().Add(1*time.Second), 0) @@ -429,9 +411,6 @@ func (s *timerQueueProcessorBaseSuite) TestReadAndFilterTasks_HasLookAhead_HasNe } func (s *timerQueueProcessorBaseSuite) TestReadAndFilterTasks_LookAheadFailed_NoNextPage() { - mockClusterMetadata := s.mockShard.Resource.ClusterMetadata - mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.clusterName).AnyTimes() - readLevel := newTimerTaskKey(time.Now().Add(-10*time.Second), 0) maxReadLevel := newTimerTaskKey(time.Now().Add(1*time.Second), 0) @@ -535,9 +514,6 @@ func (s *timerQueueProcessorBaseSuite) TestNotifyNewTimes() { } func (s *timerQueueProcessorBaseSuite) TestProcessQueueCollections_SkipRead() { - mockClusterMetadata := s.mockShard.Resource.ClusterMetadata - mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.clusterName).AnyTimes() - now := time.Now() queueLevel := 0 shardMaxReadLevel := newTimerTaskKey(now, 0) @@ -579,9 +555,6 @@ func (s *timerQueueProcessorBaseSuite) TestProcessQueueCollections_SkipRead() { } func (s *timerQueueProcessorBaseSuite) TestProcessBatch_HasNextPage() { - mockClusterMetadata := s.mockShard.Resource.ClusterMetadata - mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.clusterName).AnyTimes() - now := time.Now() queueLevel := 0 ackLevel := newTimerTaskKey(now.Add(-5*time.Second), 0) @@ -670,9 +643,6 @@ func (s *timerQueueProcessorBaseSuite) TestProcessBatch_HasNextPage() { } func (s *timerQueueProcessorBaseSuite) TestProcessBatch_NoNextPage_HasLookAhead() { - mockClusterMetadata := s.mockShard.Resource.ClusterMetadata - mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.clusterName).AnyTimes() - now := time.Now() queueLevel := 0 ackLevel := newTimerTaskKey(now.Add(-5*time.Second), 0) @@ -763,9 +733,6 @@ func (s *timerQueueProcessorBaseSuite) TestProcessBatch_NoNextPage_HasLookAhead( } func (s *timerQueueProcessorBaseSuite) TestProcessBatch_NoNextPage_NoLookAhead() { - mockClusterMetadata := s.mockShard.Resource.ClusterMetadata - mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(s.clusterName).AnyTimes() - now := time.Now() queueLevel := 0 ackLevel := newTimerTaskKey(now.Add(-5*time.Second), 0) diff --git a/service/history/replication/dlq_handler_test.go b/service/history/replication/dlq_handler_test.go index e06a26de0a5..9e4e139fe30 100644 --- a/service/history/replication/dlq_handler_test.go +++ b/service/history/replication/dlq_handler_test.go @@ -32,7 +32,6 @@ import ( "github.com/uber/cadence/client" "github.com/uber/cadence/client/admin" - "github.com/uber/cadence/common/cluster" "github.com/uber/cadence/common/mocks" "github.com/uber/cadence/common/persistence" "github.com/uber/cadence/common/types" @@ -50,7 +49,6 @@ type ( config *config.Config mockClientBean *client.MockBean adminClient *admin.MockClient - clusterMetadata *cluster.MockMetadata executionManager *mocks.ExecutionManager shardManager *mocks.ShardManager taskExecutor *MockTaskExecutor @@ -92,11 +90,9 @@ func (s *dlqHandlerSuite) SetupTest() { s.mockClientBean = s.mockShard.Resource.ClientBean s.adminClient = s.mockShard.Resource.RemoteAdminClient - s.clusterMetadata = s.mockShard.Resource.ClusterMetadata s.executionManager = s.mockShard.Resource.ExecutionMgr s.shardManager = s.mockShard.Resource.ShardMgr - s.clusterMetadata.EXPECT().GetCurrentClusterName().Return("active").AnyTimes() s.taskExecutors = make(map[string]TaskExecutor) s.taskExecutor = NewMockTaskExecutor(s.controller) s.sourceCluster = "test" diff --git a/service/history/replication/task_ack_manager_test.go b/service/history/replication/task_ack_manager_test.go index 422b9972f93..f1139981e21 100644 --- a/service/history/replication/task_ack_manager_test.go +++ b/service/history/replication/task_ack_manager_test.go @@ -52,11 +52,10 @@ type ( suite.Suite *require.Assertions - controller *gomock.Controller - mockShard *shard.TestContext - mockDomainCache *cache.MockDomainCache - mockMutableState *execution.MockMutableState - mockClusterMetadata *cluster.MockMetadata + controller *gomock.Controller + mockShard *shard.TestContext + mockDomainCache *cache.MockDomainCache + mockMutableState *execution.MockMutableState mockExecutionMgr *mocks.ExecutionManager mockHistoryMgr *mocks.HistoryV2Manager @@ -100,9 +99,6 @@ func (s *taskAckManagerSuite) SetupTest() { s.mockDomainCache = s.mockShard.Resource.DomainCache s.mockExecutionMgr = s.mockShard.Resource.ExecutionMgr s.mockHistoryMgr = s.mockShard.Resource.HistoryMgr - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() s.logger = s.mockShard.GetLogger() executionCache := execution.NewCache(s.mockShard) diff --git a/service/history/replication/task_executor_test.go b/service/history/replication/task_executor_test.go index d615aad0721..ac34203dcfe 100644 --- a/service/history/replication/task_executor_test.go +++ b/service/history/replication/task_executor_test.go @@ -34,7 +34,6 @@ import ( "github.com/uber/cadence/client/admin" historyClient "github.com/uber/cadence/client/history" "github.com/uber/cadence/common/cache" - "github.com/uber/cadence/common/cluster" "github.com/uber/cadence/common/metrics" "github.com/uber/cadence/common/mocks" "github.com/uber/cadence/common/ndc" @@ -58,7 +57,6 @@ type ( mockDomainCache *cache.MockDomainCache mockClientBean *client.MockBean adminClient *admin.MockClient - clusterMetadata *cluster.MockMetadata executionManager *mocks.ExecutionManager nDCHistoryResender *ndc.MockHistoryResender @@ -97,14 +95,11 @@ func (s *taskExecutorSuite) SetupTest() { s.mockDomainCache = s.mockShard.Resource.DomainCache s.mockClientBean = s.mockShard.Resource.ClientBean s.adminClient = s.mockShard.Resource.RemoteAdminClient - s.clusterMetadata = s.mockShard.Resource.ClusterMetadata s.executionManager = s.mockShard.Resource.ExecutionMgr s.nDCHistoryResender = ndc.NewMockHistoryResender(s.controller) s.mockEngine = engine.NewMockEngine(s.controller) s.historyClient = s.mockShard.Resource.HistoryClient - s.clusterMetadata.EXPECT().GetCurrentClusterName().Return("active").AnyTimes() - s.taskHandler = NewTaskExecutor( s.mockShard, s.mockDomainCache, diff --git a/service/history/replication/task_processor_test.go b/service/history/replication/task_processor_test.go index 8d1d7861cdc..ecedc13b2e9 100644 --- a/service/history/replication/task_processor_test.go +++ b/service/history/replication/task_processor_test.go @@ -40,7 +40,6 @@ import ( "github.com/uber/cadence/client/frontend" "github.com/uber/cadence/common" "github.com/uber/cadence/common/cache" - "github.com/uber/cadence/common/cluster" "github.com/uber/cadence/common/dynamicconfig" "github.com/uber/cadence/common/metrics" "github.com/uber/cadence/common/mocks" @@ -68,7 +67,6 @@ type ( mockClientBean *client.MockBean mockFrontendClient *frontend.MockClient adminClient *admin.MockClient - clusterMetadata *cluster.MockMetadata executionManager *mocks.ExecutionManager requestChan chan *request taskExecutor *MockTaskExecutor @@ -108,7 +106,6 @@ func (s *taskProcessorSuite) SetupTest() { s.mockClientBean = s.mockShard.Resource.ClientBean s.mockFrontendClient = s.mockShard.Resource.RemoteFrontendClient s.adminClient = s.mockShard.Resource.RemoteAdminClient - s.clusterMetadata = s.mockShard.Resource.ClusterMetadata s.executionManager = s.mockShard.Resource.ExecutionMgr s.taskExecutor = NewMockTaskExecutor(s.controller) @@ -125,7 +122,6 @@ func (s *taskProcessorSuite) SetupTest() { s.taskFetcher.EXPECT().GetSourceCluster().Return("standby").AnyTimes() s.taskFetcher.EXPECT().GetRequestChan().Return(s.requestChan).AnyTimes() s.taskFetcher.EXPECT().GetRateLimiter().Return(rateLimiter).AnyTimes() - s.clusterMetadata.EXPECT().GetCurrentClusterName().Return("active").AnyTimes() s.taskProcessor = NewTaskProcessor( s.mockShard, @@ -300,7 +296,6 @@ func (s *taskProcessorSuite) TestTriggerDataInconsistencyScan_Success() { s.Equal(reconciliation.CheckDataCorruptionWorkflowSignalName, request.GetSignalName()) s.Equal(jsArray, request.GetSignalInput()) }).Return(&types.StartWorkflowExecutionResponse{}, nil) - s.clusterMetadata.EXPECT().ClusterNameForFailoverVersion(int64(100)).Return("active") err = s.taskProcessor.triggerDataInconsistencyScan(task) s.NoError(err) diff --git a/service/history/shard/context_test.go b/service/history/shard/context_test.go index 72484899e04..b7510d6ac85 100644 --- a/service/history/shard/context_test.go +++ b/service/history/shard/context_test.go @@ -178,8 +178,6 @@ func (s *contextTestSuite) TestGetAndUpdateProcessingQueueStates() { } s.mockShardManager.On("UpdateShard", mock.Anything, mock.Anything).Return(nil) - s.mockResource.ClusterMetadata.EXPECT().GetCurrentClusterName().Return(clusterName).AnyTimes() - s.mockResource.ClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() updatedTransferQueueStates := []*types.ProcessingQueueState{ { Level: common.Int32Ptr(0), diff --git a/service/history/shard/controller_test.go b/service/history/shard/controller_test.go index 687c8af27a7..bf0ba0d93e8 100644 --- a/service/history/shard/controller_test.go +++ b/service/history/shard/controller_test.go @@ -56,7 +56,6 @@ type ( controller *gomock.Controller mockResource *resource.Test mockHistoryEngine *engine.MockEngine - mockClusterMetadata *cluster.MockMetadata mockMembershipResolver *membership.MockResolver hostInfo membership.HostInfo @@ -85,7 +84,6 @@ func (s *controllerSuite) SetupTest() { s.mockShardManager = s.mockResource.ShardMgr s.mockMembershipResolver = s.mockResource.MembershipResolver - s.mockClusterMetadata = s.mockResource.ClusterMetadata s.hostInfo = s.mockResource.GetHostInfo() s.logger = s.mockResource.Logger @@ -174,9 +172,6 @@ func (s *controllerSuite) TestAcquireShardSuccess() { } } - // when shard is initialized, it will use the 2 mock function below to initialize the "current" time of each cluster - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestSingleDCClusterInfo).AnyTimes() s.shardController.acquireShards() count := 0 for _, shardID := range myShards { @@ -264,9 +259,6 @@ func (s *controllerSuite) TestAcquireShardsConcurrently() { } } - // when shard is initialized, it will use the 2 mock function below to initialize the "current" time of each cluster - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestSingleDCClusterInfo).AnyTimes() s.shardController.acquireShards() count := 0 for _, shardID := range myShards { @@ -357,9 +349,6 @@ func (s *controllerSuite) TestAcquireShardRenewSuccess() { }).Return(nil).Once() } - // when shard is initialized, it will use the 2 mock function below to initialize the "current" time of each cluster - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestSingleDCClusterInfo).AnyTimes() s.shardController.acquireShards() for shardID := 0; shardID < numShards; shardID++ { @@ -439,9 +428,6 @@ func (s *controllerSuite) TestAcquireShardRenewLookupFailed() { }).Return(nil).Once() } - // when shard is initialized, it will use the 2 mock function below to initialize the "current" time of each cluster - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestSingleDCClusterInfo).AnyTimes() s.shardController.acquireShards() for shardID := 0; shardID < numShards; shardID++ { @@ -467,9 +453,6 @@ func (s *controllerSuite) TestHistoryEngineClosed() { s.mockMembershipResolver.EXPECT().Subscribe(service.History, shardControllerMembershipUpdateListenerName, gomock.Any()).Return(nil).AnyTimes() - // when shard is initialized, it will use the 2 mock function below to initialize the "current" time of each cluster - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestSingleDCClusterInfo).AnyTimes() s.shardController.Start() var workerWG sync.WaitGroup for w := 0; w < 10; w++ { @@ -554,9 +537,6 @@ func (s *controllerSuite) TestShardControllerClosed() { } s.mockMembershipResolver.EXPECT().Subscribe(service.History, shardControllerMembershipUpdateListenerName, gomock.Any()).Return(nil).AnyTimes() - // when shard is initialized, it will use the 2 mock function below to initialize the "current" time of each cluster - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestSingleDCClusterInfo).AnyTimes() s.shardController.Start() var workerWG sync.WaitGroup diff --git a/service/history/task/cross_cluster_source_task_executor_test.go b/service/history/task/cross_cluster_source_task_executor_test.go index 7511390ae9f..0aff3b562e1 100644 --- a/service/history/task/cross_cluster_source_task_executor_test.go +++ b/service/history/task/cross_cluster_source_task_executor_test.go @@ -50,14 +50,13 @@ type ( suite.Suite *require.Assertions - controller *gomock.Controller - mockShard *shard.TestContext - mockEngine *engine.MockEngine - mockDomainCache *cache.MockDomainCache - mockClusterMetadata *cluster.MockMetadata - mockExecutionMgr *mocks.ExecutionManager - mockHistoryV2Mgr *mocks.HistoryV2Manager - executionCache *execution.Cache + controller *gomock.Controller + mockShard *shard.TestContext + mockEngine *engine.MockEngine + mockDomainCache *cache.MockDomainCache + mockExecutionMgr *mocks.ExecutionManager + mockHistoryV2Mgr *mocks.HistoryV2Manager + executionCache *execution.Cache executor Executor } @@ -95,7 +94,6 @@ func (s *crossClusterSourceTaskExecutorSuite) SetupTest() { s.mockEngine.EXPECT().NotifyNewCrossClusterTasks(gomock.Any(), gomock.Any()).AnyTimes() s.mockShard.SetEngine(s.mockEngine) - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata s.mockDomainCache = s.mockShard.Resource.DomainCache s.mockExecutionMgr = s.mockShard.Resource.ExecutionMgr s.mockHistoryV2Mgr = s.mockShard.Resource.HistoryMgr @@ -112,8 +110,6 @@ func (s *crossClusterSourceTaskExecutorSuite) SetupTest() { s.mockDomainCache.EXPECT().GetDomainByID(constants.TestParentDomainID).Return(constants.TestGlobalParentDomainEntry, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainName(constants.TestParentDomainID).Return(constants.TestParentDomainName, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainID(constants.TestParentDomainName).Return(constants.TestParentDomainID, nil).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() s.executionCache = execution.NewCache(s.mockShard) s.executor = NewCrossClusterSourceTaskExecutor( @@ -168,7 +164,6 @@ func (s *crossClusterSourceTaskExecutorSuite) TestExecute_DomainNotActive() { return transferTask.GetType() == p.TransferTaskTypeCancelExecution }, )).Return(&p.UpdateWorkflowExecutionResponse{MutableStateUpdateSessionStats: &p.MutableStateUpdateSessionStats{}}, nil).Once() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(mutableState.GetCurrentVersion()).Return(cluster.TestAlternativeClusterName).AnyTimes() }, func(task *crossClusterSourceTask) { s.Equal(ctask.TaskStateAcked, task.state) @@ -250,8 +245,6 @@ func (s *crossClusterSourceTaskExecutorSuite) TestExecuteRecordChildCompleteExec s.NoError(err) s.mockExecutionMgr.On("GetWorkflowExecution", mock.Anything, mock.Anything).Return( &p.GetWorkflowExecutionResponse{State: persistenceMutableState}, nil) - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(mutableState.GetCurrentVersion()).Return( - s.mockClusterMetadata.GetCurrentClusterName()).AnyTimes() if tc.willGenerateNewTask { s.mockExecutionMgr.On("UpdateWorkflowExecution", mock.Anything, mock.MatchedBy( func(request *p.UpdateWorkflowExecutionRequest) bool { @@ -368,7 +361,6 @@ func (s *crossClusterSourceTaskExecutorSuite) TestApplyParentClosePolicy() { persistenceMutableState, err := test.CreatePersistenceMutableState(mutableState, lastEvent.ID, lastEvent.Version) s.NoError(err) s.mockExecutionMgr.On("GetWorkflowExecution", mock.Anything, mock.Anything).Return(&p.GetWorkflowExecutionResponse{State: persistenceMutableState}, nil) - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(mutableState.GetCurrentVersion()).Return(s.mockClusterMetadata.GetCurrentClusterName()).AnyTimes() if tc.willGenerateNewTask { s.mockExecutionMgr.On("UpdateWorkflowExecution", mock.Anything, mock.MatchedBy( func(request *p.UpdateWorkflowExecutionRequest) bool { @@ -575,7 +567,6 @@ func (s *crossClusterSourceTaskExecutorSuite) TestApplyParentClosePolicyPartialR persistenceMutableState, err := test.CreatePersistenceMutableState(mutableState, event.ID, event.Version) s.NoError(err) s.mockExecutionMgr.On("GetWorkflowExecution", mock.Anything, mock.Anything).Return(&p.GetWorkflowExecutionResponse{State: persistenceMutableState}, nil) - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(mutableState.GetCurrentVersion()).Return(s.mockClusterMetadata.GetCurrentClusterName()).AnyTimes() s.mockDomainCache.EXPECT().GetDomainByID("remote-domain-1").Return(constants.TestGlobalRemoteTargetDomainEntry, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainByID("remote-domain-2").Return(constants.TestGlobalRemoteTargetDomainEntry, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainByID("remote-domain-3").Return(constants.TestGlobalRemoteTargetDomainEntry, nil).AnyTimes() @@ -655,7 +646,6 @@ func (s *crossClusterSourceTaskExecutorSuite) TestExecuteCancelExecution_Success len(req.UpdateWorkflowMutation.TransferTasks) == 1 // one decision task }, )).Return(&p.UpdateWorkflowExecutionResponse{MutableStateUpdateSessionStats: &p.MutableStateUpdateSessionStats{}}, nil).Once() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(mutableState.GetCurrentVersion()).Return(cluster.TestCurrentClusterName).AnyTimes() }, func(task *crossClusterSourceTask) { s.Equal(ctask.TaskStateAcked, task.state) @@ -693,7 +683,6 @@ func (s *crossClusterSourceTaskExecutorSuite) TestExecuteCancelExecution_Failure len(req.UpdateWorkflowMutation.TransferTasks) == 1 // one decision task }, )).Return(&p.UpdateWorkflowExecutionResponse{MutableStateUpdateSessionStats: &p.MutableStateUpdateSessionStats{}}, nil).Once() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(mutableState.GetCurrentVersion()).Return(cluster.TestCurrentClusterName).AnyTimes() }, func(task *crossClusterSourceTask) { s.Equal(ctask.TaskStateAcked, task.state) @@ -822,7 +811,6 @@ func (s *crossClusterSourceTaskExecutorSuite) TestExecuteSignalExecution_InitSta len(req.UpdateWorkflowMutation.TransferTasks) == 1 // one decision task }, )).Return(&p.UpdateWorkflowExecutionResponse{MutableStateUpdateSessionStats: &p.MutableStateUpdateSessionStats{}}, nil).Once() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(mutableState.GetCurrentVersion()).Return(cluster.TestCurrentClusterName).AnyTimes() }, func(task *crossClusterSourceTask) { s.Equal(ctask.TaskStatePending, task.state) @@ -861,7 +849,6 @@ func (s *crossClusterSourceTaskExecutorSuite) TestExecuteSignalExecution_InitSta len(req.UpdateWorkflowMutation.TransferTasks) == 1 // one decision task }, )).Return(&p.UpdateWorkflowExecutionResponse{MutableStateUpdateSessionStats: &p.MutableStateUpdateSessionStats{}}, nil).Once() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(mutableState.GetCurrentVersion()).Return(cluster.TestCurrentClusterName).AnyTimes() }, func(task *crossClusterSourceTask) { s.Equal(ctask.TaskStateAcked, task.state) @@ -1023,7 +1010,6 @@ func (s *crossClusterSourceTaskExecutorSuite) TestExecuteStartChildExecution_Ini len(req.UpdateWorkflowMutation.TransferTasks) == 1 // one decision task }, )).Return(&p.UpdateWorkflowExecutionResponse{MutableStateUpdateSessionStats: &p.MutableStateUpdateSessionStats{}}, nil).Once() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(mutableState.GetCurrentVersion()).Return(cluster.TestCurrentClusterName).AnyTimes() }, func(task *crossClusterSourceTask) { s.Equal(ctask.TaskStatePending, task.state) @@ -1062,7 +1048,6 @@ func (s *crossClusterSourceTaskExecutorSuite) TestExecuteStartChildExecution_Ini len(req.UpdateWorkflowMutation.TransferTasks) == 1 // one decision task }, )).Return(&p.UpdateWorkflowExecutionResponse{MutableStateUpdateSessionStats: &p.MutableStateUpdateSessionStats{}}, nil).Once() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(mutableState.GetCurrentVersion()).Return(cluster.TestCurrentClusterName).AnyTimes() }, func(task *crossClusterSourceTask) { s.Equal(ctask.TaskStateAcked, task.state) diff --git a/service/history/task/cross_cluster_target_task_executor_test.go b/service/history/task/cross_cluster_target_task_executor_test.go index 4a883e05800..cdac00cb82c 100644 --- a/service/history/task/cross_cluster_target_task_executor_test.go +++ b/service/history/task/cross_cluster_target_task_executor_test.go @@ -34,7 +34,6 @@ import ( "github.com/uber/cadence/client/history" "github.com/uber/cadence/common" "github.com/uber/cadence/common/cache" - "github.com/uber/cadence/common/cluster" "github.com/uber/cadence/common/dynamicconfig" "github.com/uber/cadence/common/persistence" "github.com/uber/cadence/common/types" @@ -80,9 +79,6 @@ func (s *crossClusterTargetTaskExecutorSuite) SetupTest() { s.mockDomainCache.EXPECT().GetDomainName(constants.TestDomainID).Return(constants.TestDomainName, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainByID(constants.TestTargetDomainID).Return(constants.TestGlobalTargetDomainEntry, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainByID(constants.TestRemoteTargetDomainID).Return(constants.TestGlobalRemoteTargetDomainEntry, nil).AnyTimes() - mockClusterMetadata := s.mockShard.Resource.ClusterMetadata - mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() s.executor = NewCrossClusterTargetTaskExecutor(s.mockShard, s.mockShard.GetLogger(), config) } diff --git a/service/history/task/cross_cluster_task_processor_test.go b/service/history/task/cross_cluster_task_processor_test.go index ac9da067b3e..74a88860b0a 100644 --- a/service/history/task/cross_cluster_task_processor_test.go +++ b/service/history/task/cross_cluster_task_processor_test.go @@ -77,7 +77,6 @@ func (s *crossClusterTaskProcessorSuite) SetupTest() { config.NewForTest(), ) s.mockProcessor = NewMockProcessor(s.controller) - s.mockShard.Resource.ClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockShard.Resource.DomainCache.EXPECT().GetDomainName(constants.TestDomainID).Return(constants.TestDomainName, nil).AnyTimes() s.processorOptions = &CrossClusterTaskProcessorOptions{ diff --git a/service/history/task/cross_cluster_task_test.go b/service/history/task/cross_cluster_task_test.go index 10edc03d583..c62f3d1d66d 100644 --- a/service/history/task/cross_cluster_task_test.go +++ b/service/history/task/cross_cluster_task_test.go @@ -52,15 +52,14 @@ type ( suite.Suite *require.Assertions - controller *gomock.Controller - mockShard *shard.TestContext - mockDomainCache *cache.MockDomainCache - mockClusterMetadata *cluster.MockMetadata - mockExecutionMgr *mocks.ExecutionManager - mockExecutor *MockExecutor - mockProcessor *MockProcessor - mockRedispatcher *MockRedispatcher - executionCache *execution.Cache + controller *gomock.Controller + mockShard *shard.TestContext + mockDomainCache *cache.MockDomainCache + mockExecutionMgr *mocks.ExecutionManager + mockExecutor *MockExecutor + mockProcessor *MockProcessor + mockRedispatcher *MockRedispatcher + executionCache *execution.Cache } ) @@ -90,7 +89,6 @@ func (s *crossClusterTaskSuite) SetupTest() { s.mockShard.GetMetricsClient(), )) - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata s.mockDomainCache = s.mockShard.Resource.DomainCache s.mockExecutionMgr = s.mockShard.Resource.ExecutionMgr @@ -106,8 +104,6 @@ func (s *crossClusterTaskSuite) SetupTest() { s.mockDomainCache.EXPECT().GetDomainByID(constants.TestParentDomainID).Return(constants.TestGlobalParentDomainEntry, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainName(constants.TestParentDomainID).Return(constants.TestParentDomainName, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainID(constants.TestParentDomainName).Return(constants.TestParentDomainID, nil).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() s.mockExecutor = NewMockExecutor(s.controller) s.mockProcessor = NewMockProcessor(s.controller) diff --git a/service/history/task/timer_active_task_executor_test.go b/service/history/task/timer_active_task_executor_test.go index be22e15cd16..91259d34121 100644 --- a/service/history/task/timer_active_task_executor_test.go +++ b/service/history/task/timer_active_task_executor_test.go @@ -36,7 +36,6 @@ import ( "github.com/uber/cadence/common" "github.com/uber/cadence/common/cache" "github.com/uber/cadence/common/clock" - "github.com/uber/cadence/common/cluster" "github.com/uber/cadence/common/definition" "github.com/uber/cadence/common/dynamicconfig" "github.com/uber/cadence/common/log" @@ -57,12 +56,11 @@ type ( suite.Suite *require.Assertions - controller *gomock.Controller - mockShard *shard.TestContext - mockEngine *engine.MockEngine - mockDomainCache *cache.MockDomainCache - mockMatchingClient *matching.MockClient - mockClusterMetadata *cluster.MockMetadata + controller *gomock.Controller + mockShard *shard.TestContext + mockEngine *engine.MockEngine + mockDomainCache *cache.MockDomainCache + mockMatchingClient *matching.MockClient mockExecutionMgr *mocks.ExecutionManager mockHistoryV2Mgr *mocks.HistoryV2Manager @@ -127,13 +125,9 @@ func (s *timerActiveTaskExecutorSuite) SetupTest() { s.mockMatchingClient = s.mockShard.Resource.MatchingClient s.mockExecutionMgr = s.mockShard.Resource.ExecutionMgr s.mockHistoryV2Mgr = s.mockShard.Resource.HistoryMgr - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata // ack manager will use the domain information s.mockDomainCache.EXPECT().GetDomainByID(gomock.Any()).Return(constants.TestGlobalDomainEntry, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainName(gomock.Any()).Return(constants.TestDomainName, nil).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(s.version).Return(s.mockClusterMetadata.GetCurrentClusterName()).AnyTimes() s.logger = s.mockShard.GetLogger() s.executionCache = execution.NewCache(s.mockShard) diff --git a/service/history/task/timer_standby_task_executor_test.go b/service/history/task/timer_standby_task_executor_test.go index 2b90bf6d41d..e235675e454 100644 --- a/service/history/task/timer_standby_task_executor_test.go +++ b/service/history/task/timer_standby_task_executor_test.go @@ -58,7 +58,6 @@ type ( mockShard *shard.TestContext mockEngine *engine.MockEngine mockDomainCache *cache.MockDomainCache - mockClusterMetadata *cluster.MockMetadata mockNDCHistoryResender *ndc.MockHistoryResender mockExecutionMgr *mocks.ExecutionManager @@ -130,12 +129,8 @@ func (s *timerStandbyTaskExecutorSuite) SetupTest() { // ack manager will use the domain information s.mockDomainCache = s.mockShard.Resource.DomainCache s.mockExecutionMgr = s.mockShard.Resource.ExecutionMgr - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata s.mockDomainCache.EXPECT().GetDomainByID(gomock.Any()).Return(constants.TestGlobalDomainEntry, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainName(gomock.Any()).Return(constants.TestDomainName, nil).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(s.version).Return(s.clusterName).AnyTimes() s.logger = s.mockShard.GetLogger() s.timerStandbyTaskExecutor = NewTimerStandbyTaskExecutor( diff --git a/service/history/task/transfer_active_task_executor_test.go b/service/history/task/transfer_active_task_executor_test.go index 2f265f7433e..b06da960d3a 100644 --- a/service/history/task/transfer_active_task_executor_test.go +++ b/service/history/task/transfer_active_task_executor_test.go @@ -42,7 +42,6 @@ import ( "github.com/uber/cadence/common/archiver/provider" "github.com/uber/cadence/common/cache" "github.com/uber/cadence/common/clock" - "github.com/uber/cadence/common/cluster" dc "github.com/uber/cadence/common/dynamicconfig" "github.com/uber/cadence/common/log" "github.com/uber/cadence/common/mocks" @@ -64,13 +63,12 @@ type ( suite.Suite *require.Assertions - controller *gomock.Controller - mockShard *shard.TestContext - mockEngine *engine.MockEngine - mockDomainCache *cache.MockDomainCache - mockHistoryClient *hclient.MockClient - mockMatchingClient *matching.MockClient - mockClusterMetadata *cluster.MockMetadata + controller *gomock.Controller + mockShard *shard.TestContext + mockEngine *engine.MockEngine + mockDomainCache *cache.MockDomainCache + mockHistoryClient *hclient.MockClient + mockMatchingClient *matching.MockClient mockVisibilityMgr *mocks.VisibilityManager mockExecutionMgr *mocks.ExecutionManager @@ -167,7 +165,6 @@ func (s *transferActiveTaskExecutorSuite) SetupTest() { s.mockExecutionMgr = s.mockShard.Resource.ExecutionMgr s.mockHistoryV2Mgr = s.mockShard.Resource.HistoryMgr s.mockVisibilityMgr = s.mockShard.Resource.VisibilityMgr - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata s.mockArchivalMetadata = s.mockShard.Resource.ArchivalMetadata s.mockArchiverProvider = s.mockShard.Resource.ArchiverProvider s.mockDomainCache = s.mockShard.Resource.DomainCache @@ -191,9 +188,6 @@ func (s *transferActiveTaskExecutorSuite) SetupTest() { s.mockDomainCache.EXPECT().GetDomainName(s.childDomainID).Return(s.childDomainName, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainID(s.childDomainName).Return(s.childDomainID, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomain(s.childDomainName).Return(s.childDomainEntry, nil).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(s.version).Return(s.mockClusterMetadata.GetCurrentClusterName()).AnyTimes() s.logger = s.mockShard.GetLogger() s.transferActiveTaskExecutor = NewTransferActiveTaskExecutor( @@ -471,7 +465,6 @@ func (s *transferActiveTaskExecutorSuite) TestProcessCloseExecution_HasParentCro ) { s.mockVisibilityMgr.On("RecordWorkflowExecutionClosed", mock.Anything, mock.Anything).Return(nil).Once() s.mockArchivalMetadata.On("GetVisibilityConfig").Return(archiver.NewDisabledArchvialConfig()) - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(int64(common.EmptyVersion)).Return(s.mockClusterMetadata.GetCurrentClusterName()).AnyTimes() s.mockExecutionMgr.On("UpdateWorkflowExecution", mock.Anything, mock.MatchedBy(func(request *persistence.UpdateWorkflowExecutionRequest) bool { s.Equal(persistence.UpdateWorkflowModeIgnoreCurrent, request.Mode) crossClusterTasks := request.UpdateWorkflowMutation.CrossClusterTasks @@ -703,7 +696,6 @@ func (s *transferActiveTaskExecutorSuite) expectCrossClusterApplyParentPolicyCal s.Equal(persistence.CrossClusterTaskTypeApplyParentClosePolicy, crossClusterTasks[0].GetType()) return true })).Return(&persistence.UpdateWorkflowExecutionResponse{MutableStateUpdateSessionStats: &persistence.MutableStateUpdateSessionStats{}}, nil).Once() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(int64(common.EmptyVersion)).Return(s.mockClusterMetadata.GetCurrentClusterName()).AnyTimes() s.mockDomainCache.EXPECT().GetDomain(s.remoteTargetDomainName).Return(s.remoteTargetDomainEntry, nil).AnyTimes() } diff --git a/service/history/task/transfer_standby_task_executor_test.go b/service/history/task/transfer_standby_task_executor_test.go index 26726dabdf9..8d62cffc728 100644 --- a/service/history/task/transfer_standby_task_executor_test.go +++ b/service/history/task/transfer_standby_task_executor_test.go @@ -60,7 +60,6 @@ type ( controller *gomock.Controller mockShard *shard.TestContext mockDomainCache *cache.MockDomainCache - mockClusterMetadata *cluster.MockMetadata mockNDCHistoryResender *ndc.MockHistoryResender mockMatchingClient *matching.MockClient @@ -131,7 +130,6 @@ func (s *transferStandbyTaskExecutorSuite) SetupTest() { s.mockMatchingClient = s.mockShard.Resource.MatchingClient s.mockExecutionMgr = s.mockShard.Resource.ExecutionMgr s.mockVisibilityMgr = s.mockShard.Resource.VisibilityMgr - s.mockClusterMetadata = s.mockShard.Resource.ClusterMetadata s.mockArchivalClient = &warchiver.ClientMock{} s.mockArchivalMetadata = s.mockShard.Resource.ArchivalMetadata s.mockArchiverProvider = s.mockShard.Resource.ArchiverProvider @@ -148,9 +146,6 @@ func (s *transferStandbyTaskExecutorSuite) SetupTest() { s.mockDomainCache.EXPECT().GetDomainByID(constants.TestChildDomainID).Return(constants.TestGlobalChildDomainEntry, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainName(constants.TestChildDomainID).Return(constants.TestChildDomainName, nil).AnyTimes() s.mockDomainCache.EXPECT().GetDomainID(constants.TestChildDomainName).Return(constants.TestChildDomainID, nil).AnyTimes() - s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() - s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestAllClusterInfo).AnyTimes() - s.mockClusterMetadata.EXPECT().ClusterNameForFailoverVersion(s.version).Return(s.clusterName).AnyTimes() s.logger = s.mockShard.GetLogger() s.clusterName = cluster.TestAlternativeClusterName