@@ -34,6 +34,8 @@ import (
3434 "github.com/stretchr/testify/require"
3535 "github.com/stretchr/testify/suite"
3636 enumspb "go.temporal.io/api/enums/v1"
37+ "go.temporal.io/api/serviceerror"
38+ "go.temporal.io/api/workflow/v1"
3739
3840 "go.temporal.io/server/common/searchattribute"
3941
@@ -47,8 +49,11 @@ import (
4749)
4850
4951const (
50- testWorkflowTypeName = "test-workflow-type"
51- exampleVisibilityRecord = `{"namespaceId":"test-namespace-id","namespace":"test-namespace","workflowId":"test-workflow-id","runId":"test-run-id","workflowTypeName":"test-workflow-type","startTime":"2020-02-05T09:56:14.804475Z","closeTime":"2020-02-05T09:56:15.946478Z","status":"Completed","historyLength":36,"memo":null,"searchAttributes":null,"historyArchivalUri":"gs://my-bucket-cad/temporal_archival/development"}`
52+ testWorkflowTypeName = "test-workflow-type"
53+ exampleVisibilityRecord = `{"namespaceId":"test-namespace-id","namespace":"test-namespace","workflowId":"test-workflow-id","runId":"test-run-id","workflowTypeName":"test-workflow-type","startTime":"2020-02-05T09:56:14.804475Z","closeTime":"2020-02-05T09:56:15.946478Z","status":"Completed","historyLength":36,"memo":null,"searchAttributes":null,"historyArchivalUri":"gs://my-bucket-cad/temporal_archival/development"}`
54+ exampleVisibilityRecord2 = `{"namespaceId":"test-namespace-id","namespace":"test-namespace",
55+ "workflowId":"test-workflow-id2","runId":"test-run-id","workflowTypeName":"test-workflow-type",
56+ "startTime":"2020-02-05T09:56:14.804475Z","closeTime":"2020-02-05T09:56:15.946478Z","status":"Completed","historyLength":36,"memo":null,"searchAttributes":null,"historyArchivalUri":"gs://my-bucket-cad/temporal_archival/development"}`
5257)
5358
5459func (s * visibilityArchiverSuite ) SetupTest () {
@@ -228,9 +233,11 @@ func (s *visibilityArchiverSuite) TestQuery_Fail_InvalidToken() {
228233 mockParser := NewMockQueryParser (s .controller )
229234 startTime , _ := time .Parse (time .RFC3339 , "2019-10-04T11:00:00+00:00" )
230235 closeTime := startTime .Add (time .Hour )
236+ precision := PrecisionDay
231237 mockParser .EXPECT ().Parse (gomock .Any ()).Return (& parsedQuery {
232- closeTime : closeTime ,
233- startTime : startTime ,
238+ closeTime : closeTime ,
239+ startTime : startTime ,
240+ searchPrecision : & precision ,
234241 }, nil )
235242 visibilityArchiver .queryParser = mockParser
236243 request := & archiver.QueryVisibilityRequest {
@@ -257,7 +264,7 @@ func (s *visibilityArchiverSuite) TestQuery_Success_NoNextPageToken() {
257264 s .NoError (err )
258265
259266 mockParser := NewMockQueryParser (s .controller )
260- dayPrecision := string ( "Day" )
267+ dayPrecision := "Day"
261268 closeTime , _ := time .Parse (time .RFC3339 , "2019-10-04T11:00:00+00:00" )
262269 mockParser .EXPECT ().Parse (gomock .Any ()).Return (& parsedQuery {
263270 closeTime : closeTime ,
@@ -339,3 +346,122 @@ func (s *visibilityArchiverSuite) TestQuery_Success_SmallPageSize() {
339346 s .NoError (err )
340347 s .Equal (ei , response .Executions [0 ])
341348}
349+
350+ func (s * visibilityArchiverSuite ) TestQuery_EmptyQuery_InvalidNamespace () {
351+ URI , err := archiver .NewURI ("gs://my-bucket-cad/temporal_archival/visibility" )
352+ s .NoError (err )
353+ storageWrapper := connector .NewMockClient (s .controller )
354+ storageWrapper .EXPECT ().Exist (gomock .Any (), URI , gomock .Any ()).Return (false , nil )
355+ arc := newVisibilityArchiver (s .container , storageWrapper )
356+ req := & archiver.QueryVisibilityRequest {
357+ NamespaceID : "" ,
358+ PageSize : 1 ,
359+ NextPageToken : nil ,
360+ Query : "" ,
361+ }
362+ _ , err = arc .Query (context .Background (), URI , req , searchattribute .TestNameTypeMap )
363+
364+ var svcErr * serviceerror.InvalidArgument
365+
366+ s .ErrorAs (err , & svcErr )
367+ }
368+
369+ func (s * visibilityArchiverSuite ) TestQuery_EmptyQuery_ZeroPageSize () {
370+ URI , err := archiver .NewURI ("gs://my-bucket-cad/temporal_archival/visibility" )
371+ s .NoError (err )
372+ storageWrapper := connector .NewMockClient (s .controller )
373+ storageWrapper .EXPECT ().Exist (gomock .Any (), URI , gomock .Any ()).Return (false , nil )
374+ arc := newVisibilityArchiver (s .container , storageWrapper )
375+
376+ req := & archiver.QueryVisibilityRequest {
377+ NamespaceID : testNamespaceID ,
378+ PageSize : 0 ,
379+ NextPageToken : nil ,
380+ Query : "" ,
381+ }
382+ _ , err = arc .Query (context .Background (), URI , req , searchattribute .TestNameTypeMap )
383+
384+ var svcErr * serviceerror.InvalidArgument
385+
386+ s .ErrorAs (err , & svcErr )
387+ }
388+
389+ func (s * visibilityArchiverSuite ) TestQuery_EmptyQuery_Pagination () {
390+ URI , err := archiver .NewURI ("gs://my-bucket-cad/temporal_archival/visibility" )
391+ s .NoError (err )
392+ storageWrapper := connector .NewMockClient (s .controller )
393+ storageWrapper .EXPECT ().Exist (gomock .Any (), URI , gomock .Any ()).Return (true , nil ).Times (2 )
394+ storageWrapper .EXPECT ().QueryWithFilters (
395+ gomock .Any (),
396+ URI ,
397+ gomock .Any (),
398+ 1 ,
399+ 0 ,
400+ gomock .Any (),
401+ ).Return (
402+ []string {"closeTimeout_2020-02-05T09:56:14Z_test-workflow-id_MobileOnlyWorkflow::processMobileOnly_test-run-id.visibility" },
403+ false ,
404+ 1 ,
405+ nil ,
406+ )
407+ storageWrapper .EXPECT ().QueryWithFilters (
408+ gomock .Any (),
409+ URI ,
410+ gomock .Any (),
411+ 1 ,
412+ 1 ,
413+ gomock .Any (),
414+ ).Return (
415+ []string {"closeTimeout_2020-02-05T09:56:14Z_test-workflow-id2_MobileOnlyWorkflow::processMobileOnly_test-run" +
416+ "-id.visibility" },
417+ true ,
418+ 2 ,
419+ nil ,
420+ )
421+ storageWrapper .EXPECT ().Get (
422+ gomock .Any (),
423+ URI ,
424+ "test-namespace-id/closeTimeout_2020-02-05T09:56:14Z_test-workflow-id_MobileOnlyWorkflow::processMobileOnly_test-run-id.visibility" ,
425+ ).Return ([]byte (exampleVisibilityRecord ), nil )
426+ storageWrapper .EXPECT ().Get (gomock .Any (), URI ,
427+ "test-namespace-id/closeTimeout_2020-02-05T09:56:14Z_test-workflow-id2_MobileOnlyWorkflow" +
428+ "::processMobileOnly_test-run-id.visibility" ).Return ([]byte (exampleVisibilityRecord2 ), nil )
429+
430+ arc := newVisibilityArchiver (s .container , storageWrapper )
431+
432+ response := & archiver.QueryVisibilityResponse {
433+ Executions : nil ,
434+ NextPageToken : nil ,
435+ }
436+
437+ limit := 10
438+ executions := make (map [string ]* workflow.WorkflowExecutionInfo , limit )
439+
440+ numPages := 2
441+ for i := 0 ; i < numPages ; i ++ {
442+ req := & archiver.QueryVisibilityRequest {
443+ NamespaceID : testNamespaceID ,
444+ PageSize : 1 ,
445+ NextPageToken : response .NextPageToken ,
446+ Query : "" ,
447+ }
448+ response , err = arc .Query (context .Background (), URI , req , searchattribute .TestNameTypeMap )
449+ s .NoError (err )
450+ s .NotNil (response )
451+ s .Len (response .Executions , 1 )
452+
453+ s .Equal (
454+ i == numPages - 1 ,
455+ response .NextPageToken == nil ,
456+ "should have no next page token on the last iteration" ,
457+ )
458+
459+ for _ , execution := range response .Executions {
460+ key := execution .Execution .GetWorkflowId () +
461+ "/" + execution .Execution .GetRunId () +
462+ "/" + execution .CloseTime .String ()
463+ executions [key ] = execution
464+ }
465+ }
466+ s .Len (executions , 2 , "there should be exactly 2 unique executions" )
467+ }
0 commit comments