@@ -147,12 +147,13 @@ public FunctionsSyncManagerTests()
147147 _functionsSyncManager = new FunctionsSyncManager ( configuration , hostIdProviderMock . Object , optionsMonitor , loggerFactory . CreateLogger < FunctionsSyncManager > ( ) , httpClientFactory , _secretManagerProviderMock . Object , _mockWebHostEnvironment . Object , _mockEnvironment . Object , _hostNameProvider , functionMetadataManager , azureBlobStorageProvider ) ;
148148 }
149149
150- private string GetExpectedSyncTriggersPayload ( string postedConnection = DefaultTestConnection , string postedTaskHub = DefaultTestTaskHub )
150+ private string GetExpectedSyncTriggersPayload ( string postedConnection = DefaultTestConnection , string postedTaskHub = DefaultTestTaskHub , string durableVersion = "V2" )
151151 {
152152 string taskHubSegment = postedTaskHub != null ? $ ",\" taskHubName\" :\" { postedTaskHub } \" " : "" ;
153+ string storageProviderSegment = postedConnection != null && durableVersion == "V2" ? $ ",\" storageProvider\" :{{\" connectionStringName\" :\" DurableConnection\" }}" : "" ;
153154 return "[{\" authLevel\" :\" anonymous\" ,\" type\" :\" httpTrigger\" ,\" direction\" :\" in\" ,\" name\" :\" req\" ,\" functionName\" :\" function1\" }," +
154- $ "{{\" name\" :\" myQueueItem\" ,\" type\" :\" orchestrationTrigger\" ,\" direction\" :\" in\" ,\" queueName\" :\" myqueue-items\" ,\" connection\" :\" { postedConnection } \" ,\" functionName\" :\" function2\" { taskHubSegment } }}," +
155- $ "{{\" name\" :\" myQueueItem\" ,\" type\" :\" activityTrigger\" ,\" direction\" :\" in\" ,\" queueName\" :\" myqueue-items\" ,\" connection\" :\" { postedConnection } \" ,\" functionName\" :\" function3\" { taskHubSegment } }}]";
155+ $ "{{\" name\" :\" myQueueItem\" ,\" type\" :\" orchestrationTrigger\" ,\" direction\" :\" in\" ,\" queueName\" :\" myqueue-items\" ,\" connection\" :\" { postedConnection } \" ,\" functionName\" :\" function2\" { taskHubSegment } { storageProviderSegment } }}," +
156+ $ "{{\" name\" :\" myQueueItem\" ,\" type\" :\" activityTrigger\" ,\" direction\" :\" in\" ,\" queueName\" :\" myqueue-items\" ,\" connection\" :\" { postedConnection } \" ,\" functionName\" :\" function3\" { taskHubSegment } { storageProviderSegment } }}]";
156157 }
157158
158159 private void ResetMockFileSystem ( string hostJsonContent = null , string extensionsJsonContent = null )
@@ -239,18 +240,18 @@ public async Task TrySyncTriggers_PostsExpectedContent(bool cacheEnabled)
239240
240241 if ( cacheEnabled )
241242 {
242- VerifyResultWithCacheOn ( ) ;
243+ VerifyResultWithCacheOn ( durableVersion : "V1" ) ;
243244 }
244245 else
245246 {
246- VerifyResultWithCacheOff ( ) ;
247+ VerifyResultWithCacheOff ( durableVersion : "V1" ) ;
247248 }
248249 }
249250 }
250251
251- private void VerifyResultWithCacheOn ( string connection = DefaultTestConnection , string expectedTaskHub = "TestHubValue" )
252+ private void VerifyResultWithCacheOn ( string connection = DefaultTestConnection , string expectedTaskHub = "TestHubValue" , string durableVersion = "V2" )
252253 {
253- string expectedSyncTriggersPayload = GetExpectedSyncTriggersPayload ( postedConnection : connection , postedTaskHub : expectedTaskHub ) ;
254+ string expectedSyncTriggersPayload = GetExpectedSyncTriggersPayload ( postedConnection : connection , postedTaskHub : expectedTaskHub , durableVersion ) ;
254255 // verify triggers
255256 var result = JObject . Parse ( _contentBuilder . ToString ( ) ) ;
256257 var triggers = result [ "triggers" ] ;
@@ -290,9 +291,9 @@ private void VerifyResultWithCacheOn(string connection = DefaultTestConnection,
290291 Assert . False ( triggersLog . Contains ( "secrets" ) ) ;
291292 }
292293
293- private void VerifyResultWithCacheOff ( )
294+ private void VerifyResultWithCacheOff ( string durableVersion )
294295 {
295- string expectedSyncTriggersPayload = GetExpectedSyncTriggersPayload ( ) ;
296+ string expectedSyncTriggersPayload = GetExpectedSyncTriggersPayload ( durableVersion : durableVersion ) ;
296297 var triggers = JArray . Parse ( _contentBuilder . ToString ( ) ) ;
297298 Assert . Equal ( expectedSyncTriggersPayload , triggers . ToString ( Formatting . None ) ) ;
298299
@@ -367,7 +368,7 @@ public async Task TrySyncTriggers_BackgroundSync_PostsExpectedContent()
367368 Assert . Equal ( 1 , _mockHttpHandler . RequestCount ) ;
368369 var result = JObject . Parse ( _contentBuilder . ToString ( ) ) ;
369370 var triggers = result [ "triggers" ] ;
370- Assert . Equal ( GetExpectedSyncTriggersPayload ( ) , triggers . ToString ( Formatting . None ) ) ;
371+ Assert . Equal ( GetExpectedSyncTriggersPayload ( durableVersion : "V1" ) , triggers . ToString ( Formatting . None ) ) ;
371372
372373 string hash = string . Empty ;
373374 var downloadResponse = await hashBlob . DownloadAsync ( ) ;
@@ -433,7 +434,7 @@ public async Task TrySyncTriggers_BackgroundSync_SetTriggersFailure_HashNotUpdat
433434 Assert . Equal ( 1 , _mockHttpHandler . RequestCount ) ;
434435 var result = JObject . Parse ( _contentBuilder . ToString ( ) ) ;
435436 var triggers = result [ "triggers" ] ;
436- Assert . Equal ( GetExpectedSyncTriggersPayload ( ) , triggers . ToString ( Formatting . None ) ) ;
437+ Assert . Equal ( GetExpectedSyncTriggersPayload ( durableVersion : "V1" ) , triggers . ToString ( Formatting . None ) ) ;
437438 bool hashBlobExists = await hashBlob . ExistsAsync ( ) ;
438439 Assert . False ( hashBlobExists ) ;
439440
@@ -492,7 +493,7 @@ public async Task TrySyncTriggers_NoDurableTaskHub_DurableV1ExtensionJson_V1Defa
492493 Assert . True ( syncResult . Success , "SyncTriggers should return success true" ) ;
493494 Assert . True ( string . IsNullOrEmpty ( syncResult . Error ) , "Error should be null or empty" ) ;
494495
495- VerifyResultWithCacheOn ( expectedTaskHub : null , connection : null ) ;
496+ VerifyResultWithCacheOn ( expectedTaskHub : null , connection : null , durableVersion : "V1" ) ;
496497 }
497498 }
498499
@@ -571,7 +572,7 @@ public async Task TrySyncTriggers_DurableV1ExtensionJson_V1ConfigPosted()
571572 Assert . True ( syncResult . Success , "SyncTriggers should return success true" ) ;
572573 Assert . True ( string . IsNullOrEmpty ( syncResult . Error ) , "Error should be null or empty" ) ;
573574
574- VerifyResultWithCacheOn ( expectedTaskHub : "DurableTask" , connection : "DurableConnection" ) ;
575+ VerifyResultWithCacheOn ( expectedTaskHub : "DurableTask" , connection : "DurableConnection" , durableVersion : "V1" ) ;
575576 }
576577 }
577578
@@ -606,6 +607,92 @@ public async Task TrySyncTriggers_DurableV2ExtensionJson_V2ConfigPosted()
606607 }
607608 }
608609
610+ [ Theory ]
611+ [ InlineData ( "DurableMsSQLProviderPayload" , "DurableMsSQLProviderPayload" ) ]
612+ [ InlineData ( "DurableAdditionalPayload" , "DurableMsSQLProviderPayload" ) ] // Payload trimed to the minimum payload
613+ [ InlineData ( "DurableHasHubNameAndOrchestrationConfig" , "DurableHasHubNameAndOrchestrationConfigPayload" ) ]
614+ [ InlineData ( "DurableHasStorageAndActivityConfig" , "DurableHasStorageAndActivityConfigPayload" ) ]
615+ [ InlineData ( "Empty" , "EmptyDurablePayload" ) ]
616+ public async Task TrySyncTriggers_DurableV2ExtensionJson_StorageProviderPosted ( string scenarioName , string expectedPayload )
617+ {
618+ _mockEnvironment . Setup ( p => p . GetEnvironmentVariable ( EnvironmentSettingNames . AzureWebsiteName ) ) . Returns ( "TestHubValue" ) ;
619+ using ( var env = new TestScopedEnvironmentVariable ( _vars ) )
620+ {
621+ var durableConfig = GetDurableConfig ( scenarioName ) ;
622+
623+ var hostConfig = GetHostConfig ( durableConfig , useBundles : false ) ;
624+
625+ // See what happens when extension.json is not present but bundles are used.
626+ SetupDurableExtension ( hostConfig . ToString ( ) , durableExtensionJsonVersion : "2.0.0.0" ) ;
627+
628+ // Act
629+ var syncResult = await _functionsSyncManager . TrySyncTriggersAsync ( ) ;
630+
631+ // Assert
632+ Assert . True ( syncResult . Success , "SyncTriggers should return success true" ) ;
633+ Assert . True ( string . IsNullOrEmpty ( syncResult . Error ) , "Error should be null or empty" ) ;
634+
635+ //Verify Result
636+ var result = JObject . Parse ( _contentBuilder . ToString ( ) ) ;
637+ var triggers = result [ "triggers" ] ;
638+ var triggersString = triggers . ToString ( ) ;
639+ Assert . Equal ( GetPayloadFromFile ( $ "{ expectedPayload } .json") , triggers . ToString ( ) ) ;
640+ }
641+ }
642+
643+ private JObject GetDurableConfig ( string scenarioName )
644+ {
645+ var durableConfig = new JObject ( ) ;
646+ durableConfig [ "hubName" ] = "DurableTask" ;
647+
648+ var azureStorageConfig = new JObject ( ) ;
649+ azureStorageConfig [ "type" ] = "mssql" ;
650+ azureStorageConfig [ "connectionStringName" ] = "SQLDB_Connection" ;
651+ azureStorageConfig [ "taskEventLockTimeout" ] = "00:02:00" ;
652+ azureStorageConfig [ "createDatabaseIfNotExists" ] = true ;
653+ durableConfig [ "storageProvider" ] = azureStorageConfig ;
654+ durableConfig [ "maxConcurrentActivityFunctions" ] = 12 ;
655+ durableConfig [ "maxConcurrentOrchestratorFunctions" ] = 10 ;
656+
657+ switch ( scenarioName )
658+ {
659+ case "DurableMsSQLProviderPayload" :
660+ return durableConfig ;
661+ case "DurableAdditionalPayload" :
662+ // These additional parameters are exptected to be ignored.
663+ durableConfig [ "extendedSessionsEnabled" ] = true ;
664+ durableConfig [ "extendedSessionIdleTimeoutInSeconds" ] = 30 ;
665+ return durableConfig ;
666+ case "DurableHasHubNameAndOrchestrationConfig" :
667+ durableConfig = new JObject ( ) ;
668+ durableConfig [ "hubName" ] = "DurableTask" ;
669+ durableConfig [ "maxConcurrentOrchestratorFunctions" ] = 10 ;
670+ return durableConfig ;
671+ case "DurableHasStorageAndActivityConfig" :
672+ durableConfig = new JObject ( ) ;
673+ azureStorageConfig = new JObject ( ) ;
674+ azureStorageConfig [ "type" ] = "mssql" ;
675+ azureStorageConfig [ "connectionStringName" ] = "SQLDB_Connection" ;
676+ azureStorageConfig [ "taskEventLockTimeout" ] = "00:02:00" ;
677+ azureStorageConfig [ "createDatabaseIfNotExists" ] = true ;
678+ durableConfig [ "storageProvider" ] = azureStorageConfig ;
679+ durableConfig [ "maxConcurrentActivityFunctions" ] = 12 ;
680+ return durableConfig ;
681+ case "Empty" :
682+ return new JObject ( ) ;
683+ default : return new JObject ( ) ;
684+ }
685+
686+ }
687+
688+
689+ private string GetPayloadFromFile ( string fileName )
690+ {
691+ var fullPath = Path . Combine ( "Management" , "Payload" , fileName ) ;
692+ return File . ReadAllText ( fullPath ) ;
693+ }
694+
695+
609696 [ Fact ]
610697 public async Task UpdateHashAsync_Succeeds ( )
611698 {
0 commit comments