33using Microsoft . Extensions . Configuration ;
44using Microsoft . Extensions . Logging . Abstractions ;
55using Orleans . Hosting ;
6+ using Orleans . Persistence . FileStorage ;
67using Orleans . TestingHost ;
78using OrleansAWSUtils . Streams ;
89using TestExtensions ;
@@ -20,8 +21,10 @@ namespace AWSUtils.Tests.Streaming;
2021public sealed class SQSAspireLiveStreamTests : TestClusterPerTest
2122{
2223 private const string ProviderName = "AspireSQS" ;
24+ private const string PubSubStoreRootDirectoryKey = "AspireSQS:PubSubStoreRootDirectory" ;
2325 private SqsAspireTestApp _app = null ! ;
2426 private EnvironmentVariableScope _environment = null ! ;
27+ private string ? _ownedDirectory ;
2528 private SingleStreamTestRunner _runner = null ! ;
2629
2730 protected override void CheckPreconditionsOrThrow ( )
@@ -34,13 +37,24 @@ protected override void CheckPreconditionsOrThrow()
3437
3538 protected override void ConfigureTestCluster ( TestClusterBuilder builder )
3639 {
40+ var ownedDirectory = _ownedDirectory
41+ ?? throw new InvalidOperationException ( "The PubSubStore directory has not been initialized." ) ;
42+ builder . Options . InitialSilosCount = 1 ;
43+ builder . Properties [ PubSubStoreRootDirectoryKey ] = Path . Combine (
44+ ownedDirectory ,
45+ "PubSubStore" ) ;
3746 builder . ConfigureHostConfiguration ( configuration => configuration . AddEnvironmentVariables ( ) ) ;
3847 builder . AddSiloBuilderConfigurator < SiloConfigurator > ( ) ;
3948 }
4049
4150 public override async ValueTask InitializeAsync ( )
4251 {
4352 EnsurePreconditionsMet ( ) ;
53+ _ownedDirectory = Path . Combine (
54+ Path . GetTempPath ( ) ,
55+ nameof ( SQSAspireLiveStreamTests ) ,
56+ Guid . NewGuid ( ) . ToString ( "N" ) ) ;
57+ Directory . CreateDirectory ( _ownedDirectory ) ;
4458 _app = await SqsAspireTestApp . CreateAsync (
4559 ProviderName ,
4660 [
@@ -87,13 +101,23 @@ await SQSStreamProviderUtils.DeleteAllUsedQueues(
87101 {
88102 await _app . DisposeAsync ( ) ;
89103 }
104+
105+ if ( _ownedDirectory is not null && Directory . Exists ( _ownedDirectory ) )
106+ {
107+ Directory . Delete ( _ownedDirectory , recursive : true ) ;
108+ }
90109 }
91110 }
92111
93112 private sealed class SiloConfigurator : ISiloConfigurator
94113 {
95114 public void Configure ( ISiloBuilder siloBuilder )
96- => siloBuilder . AddMemoryGrainStorage ( "PubSubStore" ) ;
115+ => siloBuilder . AddFileGrainStorage (
116+ "PubSubStore" ,
117+ options => options . RootDirectory =
118+ siloBuilder . Configuration [ PubSubStoreRootDirectoryKey ]
119+ ?? throw new InvalidOperationException (
120+ $ "Missing { PubSubStoreRootDirectoryKey } configuration.") ) ;
97121 }
98122}
99123#endif
0 commit comments