• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / cadence / 0187fdd2-f4a4-4c9a-97b4-6604937bf7be

09 May 2023 12:23AM UTC coverage: 57.253% (-0.002%) from 57.255%
0187fdd2-f4a4-4c9a-97b4-6604937bf7be

Pull #5252

buildkite

David Porter
Merge branch 'master' into feature/zonal-partitioning
Pull Request #5252: Feature/zonal partitioning

1460 of 1460 new or added lines in 51 files covered. (100.0%)

86909 of 151799 relevant lines covered (57.25%)

2482.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/common/resource/resourceTest.go
1
// Copyright (c) 2019 Uber Technologies, Inc.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to deal
5
// in the Software without restriction, including without limitation the rights
6
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
// copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
// THE SOFTWARE.
20

21
package resource
22

23
import (
24
        "github.com/golang/mock/gomock"
25
        "github.com/stretchr/testify/mock"
26
        "github.com/uber-go/tally"
27
        "go.uber.org/cadence/.gen/go/cadence/workflowserviceclient"
28
        publicservicetest "go.uber.org/cadence/.gen/go/cadence/workflowservicetest"
29
        "go.uber.org/yarpc"
30
        "go.uber.org/zap"
31

32
        "github.com/uber/cadence/common/dynamicconfig/configstore"
33

34
        "github.com/uber/cadence/client"
35
        "github.com/uber/cadence/client/admin"
36
        "github.com/uber/cadence/client/frontend"
37
        "github.com/uber/cadence/client/history"
38
        "github.com/uber/cadence/client/matching"
39
        "github.com/uber/cadence/common/archiver"
40
        "github.com/uber/cadence/common/archiver/provider"
41
        "github.com/uber/cadence/common/blobstore"
42
        "github.com/uber/cadence/common/cache"
43
        "github.com/uber/cadence/common/clock"
44
        "github.com/uber/cadence/common/cluster"
45
        "github.com/uber/cadence/common/domain"
46
        "github.com/uber/cadence/common/isolationgroup"
47
        "github.com/uber/cadence/common/log"
48
        "github.com/uber/cadence/common/log/loggerimpl"
49
        "github.com/uber/cadence/common/membership"
50
        "github.com/uber/cadence/common/messaging"
51
        "github.com/uber/cadence/common/metrics"
52
        "github.com/uber/cadence/common/mocks"
53
        "github.com/uber/cadence/common/partition"
54
        "github.com/uber/cadence/common/persistence"
55
        persistenceClient "github.com/uber/cadence/common/persistence/client"
56
)
57

58
type (
59
        // Test is the test implementation used for testing
60
        Test struct {
61
                MetricsScope    tally.TestScope
62
                ClusterMetadata cluster.Metadata
63

64
                // other common resources
65

66
                DomainCache             *cache.MockDomainCache
67
                DomainMetricsScopeCache cache.DomainMetricsScopeCache
68
                DomainReplicationQueue  *domain.MockReplicationQueue
69
                TimeSource              clock.TimeSource
70
                PayloadSerializer       persistence.PayloadSerializer
71
                MetricsClient           metrics.Client
72
                ArchivalMetadata        *archiver.MockArchivalMetadata
73
                ArchiverProvider        *provider.MockArchiverProvider
74
                BlobstoreClient         *blobstore.MockClient
75

76
                // membership infos
77
                MembershipResolver *membership.MockResolver
78

79
                // internal services clients
80

81
                SDKClient            *publicservicetest.MockClient
82
                FrontendClient       *frontend.MockClient
83
                MatchingClient       *matching.MockClient
84
                HistoryClient        *history.MockClient
85
                RemoteAdminClient    *admin.MockClient
86
                RemoteFrontendClient *frontend.MockClient
87
                ClientBean           *client.MockBean
88

89
                // persistence clients
90

91
                MetadataMgr     *mocks.MetadataManager
92
                TaskMgr         *mocks.TaskManager
93
                VisibilityMgr   *mocks.VisibilityManager
94
                ShardMgr        *mocks.ShardManager
95
                HistoryMgr      *mocks.HistoryV2Manager
96
                ExecutionMgr    *mocks.ExecutionManager
97
                PersistenceBean *persistenceClient.MockBean
98

99
                IsolationGroups     *isolationgroup.MockState
100
                IsolationGroupStore configstore.Client
101
                Partitioner         *partition.MockPartitioner
102
                HostName            string
103
                Logger              log.Logger
104
        }
105
)
106

107
var _ Resource = (*Test)(nil)
108

109
const (
110
        testHostName = "test_host"
111
)
112

113
var (
114
        testHostInfo = membership.NewHostInfo(testHostName)
115
)
116

117
// NewTest returns a new test resource instance
118
func NewTest(
119
        controller *gomock.Controller,
120
        serviceMetricsIndex metrics.ServiceIdx,
121
) *Test {
×
122

×
123
        zapLogger, err := zap.NewDevelopment()
×
124
        if err != nil {
×
125
                panic(err)
×
126
        }
127
        logger := loggerimpl.NewLogger(zapLogger)
×
128

×
129
        frontendClient := frontend.NewMockClient(controller)
×
130
        matchingClient := matching.NewMockClient(controller)
×
131
        historyClient := history.NewMockClient(controller)
×
132
        remoteAdminClient := admin.NewMockClient(controller)
×
133
        remoteFrontendClient := frontend.NewMockClient(controller)
×
134
        clientBean := client.NewMockBean(controller)
×
135
        clientBean.EXPECT().GetFrontendClient().Return(frontendClient).AnyTimes()
×
136
        clientBean.EXPECT().GetMatchingClient(gomock.Any()).Return(matchingClient, nil).AnyTimes()
×
137
        clientBean.EXPECT().GetHistoryClient().Return(historyClient).AnyTimes()
×
138
        clientBean.EXPECT().GetRemoteAdminClient(gomock.Any()).Return(remoteAdminClient).AnyTimes()
×
139
        clientBean.EXPECT().GetRemoteFrontendClient(gomock.Any()).Return(remoteFrontendClient).AnyTimes()
×
140

×
141
        metadataMgr := &mocks.MetadataManager{}
×
142
        taskMgr := &mocks.TaskManager{}
×
143
        visibilityMgr := &mocks.VisibilityManager{}
×
144
        shardMgr := &mocks.ShardManager{}
×
145
        historyMgr := &mocks.HistoryV2Manager{}
×
146
        executionMgr := &mocks.ExecutionManager{}
×
147
        domainReplicationQueue := domain.NewMockReplicationQueue(controller)
×
148
        domainReplicationQueue.EXPECT().Start().AnyTimes()
×
149
        domainReplicationQueue.EXPECT().Stop().AnyTimes()
×
150
        persistenceBean := persistenceClient.NewMockBean(controller)
×
151
        persistenceBean.EXPECT().GetDomainManager().Return(metadataMgr).AnyTimes()
×
152
        persistenceBean.EXPECT().GetTaskManager().Return(taskMgr).AnyTimes()
×
153
        persistenceBean.EXPECT().GetVisibilityManager().Return(visibilityMgr).AnyTimes()
×
154
        persistenceBean.EXPECT().GetHistoryManager().Return(historyMgr).AnyTimes()
×
155
        persistenceBean.EXPECT().GetShardManager().Return(shardMgr).AnyTimes()
×
156
        persistenceBean.EXPECT().GetExecutionManager(gomock.Any()).Return(executionMgr, nil).AnyTimes()
×
157

×
158
        isolationGroupMock := isolationgroup.NewMockState(controller)
×
159
        isolationGroupMock.EXPECT().Stop().AnyTimes()
×
160

×
161
        partitionMock := partition.NewMockPartitioner(controller)
×
162
        mockZone := "zone1"
×
163
        partitionMock.EXPECT().GetIsolationGroupByDomainID(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(mockZone, nil)
×
164

×
165
        scope := tally.NewTestScope("test", nil)
×
166

×
167
        return &Test{
×
168
                MetricsScope: scope,
×
169

×
170
                // By default tests will run on active cluster unless overridden otherwise
×
171
                ClusterMetadata: cluster.TestActiveClusterMetadata,
×
172

×
173
                // other common resources
×
174

×
175
                DomainCache:             cache.NewMockDomainCache(controller),
×
176
                DomainMetricsScopeCache: cache.NewDomainMetricsScopeCache(),
×
177
                DomainReplicationQueue:  domainReplicationQueue,
×
178
                TimeSource:              clock.NewRealTimeSource(),
×
179
                PayloadSerializer:       persistence.NewPayloadSerializer(),
×
180
                MetricsClient:           metrics.NewClient(scope, serviceMetricsIndex),
×
181
                ArchivalMetadata:        &archiver.MockArchivalMetadata{},
×
182
                ArchiverProvider:        &provider.MockArchiverProvider{},
×
183
                BlobstoreClient:         &blobstore.MockClient{},
×
184

×
185
                // membership infos
×
186
                MembershipResolver: membership.NewMockResolver(controller),
×
187

×
188
                // internal services clients
×
189

×
190
                SDKClient:            publicservicetest.NewMockClient(controller),
×
191
                FrontendClient:       frontendClient,
×
192
                MatchingClient:       matchingClient,
×
193
                HistoryClient:        historyClient,
×
194
                RemoteAdminClient:    remoteAdminClient,
×
195
                RemoteFrontendClient: remoteFrontendClient,
×
196
                ClientBean:           clientBean,
×
197

×
198
                // persistence clients
×
199

×
200
                MetadataMgr:     metadataMgr,
×
201
                TaskMgr:         taskMgr,
×
202
                VisibilityMgr:   visibilityMgr,
×
203
                ShardMgr:        shardMgr,
×
204
                HistoryMgr:      historyMgr,
×
205
                ExecutionMgr:    executionMgr,
×
206
                PersistenceBean: persistenceBean,
×
207
                IsolationGroups: isolationGroupMock,
×
208
                Partitioner:     partitionMock,
×
209

×
210
                // logger
×
211

×
212
                Logger: logger,
×
213
        }
×
214
}
215

216
// Start for testing
217
func (s *Test) Start() {
×
218

×
219
}
×
220

221
// Stop for testing
222
func (s *Test) Stop() {
×
223

×
224
}
×
225

226
// static infos
227

228
// GetServiceName for testing
229
func (s *Test) GetServiceName() string {
×
230
        panic("user should implement this method for test")
×
231
}
232

233
// GetHostInfo for testing
234
func (s *Test) GetHostInfo() membership.HostInfo {
×
235
        return testHostInfo
×
236
}
×
237

238
// GetClusterMetadata for testing
239
func (s *Test) GetClusterMetadata() cluster.Metadata {
×
240
        return s.ClusterMetadata
×
241
}
×
242

243
// other common resources
244

245
// GetDomainCache for testing
246
func (s *Test) GetDomainCache() cache.DomainCache {
×
247
        return s.DomainCache
×
248
}
×
249

250
// GetDomainMetricsScopeCache for testing
251
func (s *Test) GetDomainMetricsScopeCache() cache.DomainMetricsScopeCache {
×
252
        return s.DomainMetricsScopeCache
×
253
}
×
254

255
// GetDomainReplicationQueue for testing
256
func (s *Test) GetDomainReplicationQueue() domain.ReplicationQueue {
×
257
        // user should implement this method for test
×
258
        return s.DomainReplicationQueue
×
259
}
×
260

261
// GetTimeSource for testing
262
func (s *Test) GetTimeSource() clock.TimeSource {
×
263
        return s.TimeSource
×
264
}
×
265

266
// GetPayloadSerializer for testing
267
func (s *Test) GetPayloadSerializer() persistence.PayloadSerializer {
×
268
        return s.PayloadSerializer
×
269
}
×
270

271
// GetMetricsClient for testing
272
func (s *Test) GetMetricsClient() metrics.Client {
×
273
        return s.MetricsClient
×
274
}
×
275

276
// GetMessagingClient for testing
277
func (s *Test) GetMessagingClient() messaging.Client {
×
278
        panic("user should implement this method for test")
×
279
}
280

281
// GetBlobstoreClient for testing
282
func (s *Test) GetBlobstoreClient() blobstore.Client {
×
283
        return s.BlobstoreClient
×
284
}
×
285

286
// GetArchivalMetadata for testing
287
func (s *Test) GetArchivalMetadata() archiver.ArchivalMetadata {
×
288
        return s.ArchivalMetadata
×
289
}
×
290

291
// GetArchiverProvider for testing
292
func (s *Test) GetArchiverProvider() provider.ArchiverProvider {
×
293
        return s.ArchiverProvider
×
294
}
×
295

296
// GetMembershipResolver for testing
297
func (s *Test) GetMembershipResolver() membership.Resolver {
×
298
        return s.MembershipResolver
×
299
}
×
300

301
// internal services clients
302

303
// GetSDKClient for testing
304
func (s *Test) GetSDKClient() workflowserviceclient.Interface {
×
305
        return s.SDKClient
×
306
}
×
307

308
// GetFrontendRawClient for testing
309
func (s *Test) GetFrontendRawClient() frontend.Client {
×
310
        return s.FrontendClient
×
311
}
×
312

313
// GetFrontendClient for testing
314
func (s *Test) GetFrontendClient() frontend.Client {
×
315
        return s.FrontendClient
×
316
}
×
317

318
// GetMatchingRawClient for testing
319
func (s *Test) GetMatchingRawClient() matching.Client {
×
320
        return s.MatchingClient
×
321
}
×
322

323
// GetMatchingClient for testing
324
func (s *Test) GetMatchingClient() matching.Client {
×
325
        return s.MatchingClient
×
326
}
×
327

328
// GetHistoryRawClient for testing
329
func (s *Test) GetHistoryRawClient() history.Client {
×
330
        return s.HistoryClient
×
331
}
×
332

333
// GetHistoryClient for testing
334
func (s *Test) GetHistoryClient() history.Client {
×
335
        return s.HistoryClient
×
336
}
×
337

338
// GetRemoteAdminClient for testing
339
func (s *Test) GetRemoteAdminClient(
340
        cluster string,
341
) admin.Client {
×
342

×
343
        return s.RemoteAdminClient
×
344
}
×
345

346
// GetRemoteFrontendClient for testing
347
func (s *Test) GetRemoteFrontendClient(
348
        cluster string,
349
) frontend.Client {
×
350

×
351
        return s.RemoteFrontendClient
×
352
}
×
353

354
// GetClientBean for testing
355
func (s *Test) GetClientBean() client.Bean {
×
356
        return s.ClientBean
×
357
}
×
358

359
// persistence clients
360

361
// GetMetadataManager for testing
362
func (s *Test) GetDomainManager() persistence.DomainManager {
×
363
        return s.MetadataMgr
×
364
}
×
365

366
// GetTaskManager for testing
367
func (s *Test) GetTaskManager() persistence.TaskManager {
×
368
        return s.TaskMgr
×
369
}
×
370

371
// GetVisibilityManager for testing
372
func (s *Test) GetVisibilityManager() persistence.VisibilityManager {
×
373
        return s.VisibilityMgr
×
374
}
×
375

376
// GetShardManager for testing
377
func (s *Test) GetShardManager() persistence.ShardManager {
×
378
        return s.ShardMgr
×
379
}
×
380

381
// GetHistoryManager for testing
382
func (s *Test) GetHistoryManager() persistence.HistoryManager {
×
383
        return s.HistoryMgr
×
384
}
×
385

386
// GetExecutionManager for testing
387
func (s *Test) GetExecutionManager(
388
        shardID int,
389
) (persistence.ExecutionManager, error) {
×
390

×
391
        return s.ExecutionMgr, nil
×
392
}
×
393

394
// GetPersistenceBean for testing
395
func (s *Test) GetPersistenceBean() persistenceClient.Bean {
×
396
        return s.PersistenceBean
×
397
}
×
398

399
// GetHostName for testing
400
func (s *Test) GetHostName() string {
×
401
        return s.HostName
×
402
}
×
403

404
// loggers
405

406
// GetLogger for testing
407
func (s *Test) GetLogger() log.Logger {
×
408
        return s.Logger
×
409
}
×
410

411
// GetThrottledLogger for testing
412
func (s *Test) GetThrottledLogger() log.Logger {
×
413
        return s.Logger
×
414
}
×
415

416
// GetDispatcher for testing
417
func (s *Test) GetDispatcher() *yarpc.Dispatcher {
×
418
        panic("user should implement this method for test")
×
419
}
420

421
// GetIsolationGroupState returns the isolationGroupState for testing
422
func (s *Test) GetIsolationGroupState() isolationgroup.State {
×
423
        return s.IsolationGroups
×
424
}
×
425

426
// GetPartitioner returns the partitioner
427
func (s *Test) GetPartitioner() partition.Partitioner {
×
428
        return s.Partitioner
×
429
}
×
430

431
// GetIsolationGroupStore returns the config store for their
432
// isolation-group stores
433
func (s *Test) GetIsolationGroupStore() configstore.Client {
×
434
        return s.IsolationGroupStore
×
435
}
×
436

437
// Finish checks whether expectations are met
438
func (s *Test) Finish(
439
        t mock.TestingT,
440
) {
×
441
        s.ArchivalMetadata.AssertExpectations(t)
×
442
        s.ArchiverProvider.AssertExpectations(t)
×
443

×
444
        s.MetadataMgr.AssertExpectations(t)
×
445
        s.TaskMgr.AssertExpectations(t)
×
446
        s.VisibilityMgr.AssertExpectations(t)
×
447
        s.ShardMgr.AssertExpectations(t)
×
448
        s.HistoryMgr.AssertExpectations(t)
×
449
        s.ExecutionMgr.AssertExpectations(t)
×
450
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc