@@ -984,14 +984,11 @@ public async Task FilterOrchestrationsByName()
984984 {
985985 // Setup a worker with an Orchestration Filter.
986986 TaskName orchestratorName = nameof ( EmptyOrchestration ) ;
987- ISet < string > orchestratorNames = new HashSet < string > ( ) ;
987+ var orchestrationFilter = new OrchestrationFilter ( ) ;
988988 await using HostTestLifetime server = await this . StartWorkerAsync ( b =>
989989 {
990990 b . AddTasks ( tasks => tasks . AddOrchestratorFunc ( orchestratorName , ctx => Task . FromResult < object ? > ( null ) ) ) ;
991- b . UseOrchestrationFilter ( ( info ) =>
992- {
993- return ! orchestratorNames . Contains ( info . Name ) ;
994- } ) ;
991+ b . UseOrchestrationFilter ( orchestrationFilter ) ;
995992 } ) ;
996993
997994 // Nothing in the filter set, the orchestration should complete.
@@ -1004,7 +1001,7 @@ public async Task FilterOrchestrationsByName()
10041001 Assert . Equal ( OrchestrationRuntimeStatus . Completed , metadata . RuntimeStatus ) ;
10051002
10061003 // Update the filter and re-enqueue. We should see the orchestration denied.
1007- orchestratorNames . Add ( orchestratorName ) ;
1004+ orchestrationFilter . NameDenySet . Add ( orchestratorName ) ;
10081005
10091006 // This should throw as the work is denied.
10101007 instanceId = await server . Client . ScheduleNewOrchestrationInstanceAsync ( orchestratorName ) ;
@@ -1020,14 +1017,11 @@ public async Task FilterOrchestrationsByTag()
10201017 {
10211018 { "test" , "true" }
10221019 } ;
1023- IDictionary < string , string > orchestratorTagFilter = new Dictionary < string , string > ( ) ;
1020+ var orchestrationFilter = new OrchestrationFilter ( ) ;
10241021 await using HostTestLifetime server = await this . StartWorkerAsync ( b =>
10251022 {
10261023 b . AddTasks ( tasks => tasks . AddOrchestratorFunc ( orchestratorName , ctx => Task . FromResult < object ? > ( null ) ) ) ;
1027- b . UseOrchestrationFilter ( ( info ) =>
1028- {
1029- return ! orchestratorTagFilter . Any ( kvp => info . Tags . ContainsKey ( kvp . Key ) && info . Tags [ kvp . Key ] == kvp . Value ) ;
1030- } ) ;
1024+ b . UseOrchestrationFilter ( orchestrationFilter ) ;
10311025 } ) ;
10321026
10331027 // Nothing in the filter set, the orchestration should complete.
@@ -1043,7 +1037,7 @@ public async Task FilterOrchestrationsByTag()
10431037 Assert . Equal ( OrchestrationRuntimeStatus . Completed , metadata . RuntimeStatus ) ;
10441038
10451039 // Update the filter and re-enqueue. We should see the orchestration denied.
1046- orchestratorTagFilter . Add ( "test" , "true" ) ;
1040+ orchestrationFilter . TagDenyDict . Add ( "test" , "true" ) ;
10471041
10481042 // This should throw as the work is denied.
10491043 instanceId = await server . Client . ScheduleNewOrchestrationInstanceAsync ( orchestratorName , new StartOrchestrationOptions
@@ -1053,6 +1047,19 @@ public async Task FilterOrchestrationsByTag()
10531047 await Assert . ThrowsAsync < OperationCanceledException > ( async ( ) => await server . Client . WaitForInstanceCompletionAsync ( instanceId , new CancellationTokenSource ( TimeSpan . FromSeconds ( 5 ) ) . Token ) ) ;
10541048 }
10551049
1050+ class OrchestrationFilter : IOrchestrationFilter
1051+ {
1052+ public ISet < string > NameDenySet { get ; set ; } = new HashSet < string > ( ) ;
1053+ public IDictionary < string , string > TagDenyDict = new Dictionary < string , string > ( ) ;
1054+
1055+ public Task < bool > IsOrchestrationValidAsync ( OrchestrationInfo info , CancellationToken cancellationToken = default )
1056+ {
1057+ return Task . FromResult (
1058+ ! this . NameDenySet . Contains ( info . Name )
1059+ && ! this . TagDenyDict . Any ( kvp => info . Tags . ContainsKey ( kvp . Key ) && info . Tags [ kvp . Key ] == kvp . Value ) ) ;
1060+ }
1061+ }
1062+
10561063 // TODO: Test for multiple external events with the same name
10571064 // TODO: Test for ContinueAsNew with external events that carry over
10581065 // TODO: Test for catching activity exceptions of specific types
0 commit comments