184
}
185
187
>
numCreateBatch := 32
188
>
createBatchSize := 32
189
>
numTasks := int64(createBatchSize * numCreateBatch)
190
>
minTaskID := rand.Int63()
191
>
maxTaskID := minTaskID + numTasks
192
>
193
>
rangeID := rand.Int63()
194
>
taskQueue := s.createTaskQueue(rangeID)
195
>
196
>
for i := range numCreateBatch {
197
>
var tasks []*persistencespb.AllocatedTaskInfo
198
>
for j := range createBatchSize {
199
>
taskID := minTaskID + int64(i*numCreateBatch+j)
200
>
task := s.randomTask(taskID)
201
>
tasks = append(tasks, task)
202
>
}
203
>
_, err := s.taskManager.CreateTasks(s.ctx, &p.CreateTasksRequest{
204
>
TaskQueueInfo: &p.PersistedTaskQueueInfo{
205
>
RangeID: rangeID,
206
>
Data: taskQueue,
207
>
},
208
>
Tasks: tasks,
209
>
})
210
>
s.NoError(err)
211
}
212
213
>
_, err := s.taskManager.CompleteTasksLessThan(s.ctx, &p.CompleteTasksLessThanRequest{
task_queue_task.go
214
>
NamespaceID: s.namespaceID,
215
>
TaskQueueName: s.taskQueueName,
216
>
TaskType: s.taskQueueType,
217
>
ExclusiveMaxTaskID: maxTaskID + 1,
218
>
Limit: int(numTasks),
219
>
})
220
>
s.NoError(err)
221
>
222
>
resp, err := s.taskManager.GetTasks(s.ctx, &p.GetTasksRequest{
223
>
NamespaceID: s.namespaceID,
224
>
TaskQueue: s.taskQueueName,
225
>
TaskType: s.taskQueueType,
226
>
InclusiveMinTaskID: minTaskID,
227
>
ExclusiveMaxTaskID: maxTaskID + 1,
228
>
PageSize: 100,
229
>
NextPageToken: nil,
230
>
})
231
>
s.NoError(err)
232
>
protorequire.ProtoSliceEqual(s.T(), []*persistencespb.AllocatedTaskInfo{}, resp.Tasks)
233
>
s.Nil(resp.NextPageToken)
234
}
235
236
func (s *TaskQueueTaskSuite) createTaskQueue(
237
rangeID int64,
239
>
taskQueueKind := enumspb.TaskQueueKind(rand.Int31n(
240
>
int32(len(enumspb.TaskQueueKind_name)) + 1),
241
>
)
242
>
taskQueue := s.randomTaskQueueInfo(taskQueueKind)
243
>
_, err := s.taskManager.CreateTaskQueue(s.ctx, &p.CreateTaskQueueRequest{
244
>
RangeID: rangeID,
245
>
TaskQueueInfo: taskQueue,
246
>
})
247
>
s.NoError(err)
248
>
return taskQueue
249
>
}
250
251
func (s *TaskQueueTaskSuite) randomTaskQueueInfo(
252
taskQueueKind enumspb.TaskQueueKind,
254
>
now := time.Now().UTC()
255
>
var expiryTime *timestamppb.Timestamp
256
>
if taskQueueKind == enumspb.TASK_QUEUE_KIND_STICKY {
258
>
}
259
261
>
NamespaceId: s.namespaceID,
262
>
Name: s.taskQueueName,
263
>
TaskType: s.taskQueueType,
264
>
Kind: taskQueueKind,
265
>
AckLevel: rand.Int63(),
266
>
ExpiryTime: expiryTime,
267
>
LastUpdateTime: timestamppb.New(now),
268
>
}
269
}
270
271
func (s *TaskQueueTaskSuite) randomTask(
272
taskID int64,
274
>
now := time.Now().UTC()
275
>
return &persistencespb.AllocatedTaskInfo{
276
>
TaskId: taskID,
277
>
Data: &persistencespb.TaskInfo{
278
>
NamespaceId: s.namespaceID,
279
>
WorkflowId: uuid.New().String(),
280
>
RunId: uuid.New().String(),
281
>
ScheduledEventId: rand.Int63(),
282
>
CreateTime: timestamppb.New(now),
283
>
ExpiryTime: timestamppb.New(now.Add(s.taskTTL)),
284
>
Clock: &clockspb.VectorClock{
285
>
ClusterId: rand.Int63(),
286
>
ShardId: rand.Int31(),
287
>
Clock: rand.Int63(),
288
>
},
289
>
},
290
>
}
291
>
}