示例#1
0
        private async Task RunTest(
            Func <OperationContext, ContentMetadataEventStream, IFailureController, IFailureController, Task> runTestAsync,
            ContentMetadataEventStreamConfiguration contentMetadataEventStreamConfiguration = null,
            RedisVolatileEventStorageConfiguration redisVolatileEventLogConfiguration       = null,
            FailureMode persistentStorageFailure = FailureMode.None,
            FailureMode volatileStorageFailure   = FailureMode.None)
        {
            var tracingContext   = new Context(Logger);
            var operationContext = new OperationContext(tracingContext);

            redisVolatileEventLogConfiguration ??= new RedisVolatileEventStorageConfiguration();
            using var database = LocalRedisProcessDatabase.CreateAndStartEmpty(_redisFixture, TestGlobal.Logger, SystemClock.Instance);
            var primaryFactory = await RedisDatabaseFactory.CreateAsync(
                operationContext,
                new LiteralConnectionStringProvider(database.ConnectionString),
                new RedisConnectionMultiplexerConfiguration()
            {
                LoggingSeverity = Severity.Error
            });

            var primaryDatabaseAdapter    = new RedisDatabaseAdapter(primaryFactory, "keyspace");
            var redisVolatileEventStorage = new RedisWriteAheadEventStorage(redisVolatileEventLogConfiguration, primaryDatabaseAdapter);

            var mockPersistentEventStorage = new MockPersistentEventStorage();

            var volatileEventStorage   = new FailingVolatileEventStorage(volatileStorageFailure, redisVolatileEventStorage);
            var persistentEventStorage = new FailingPersistentEventStorage(persistentStorageFailure, mockPersistentEventStorage);

            contentMetadataEventStreamConfiguration ??= new ContentMetadataEventStreamConfiguration();
            var contentMetadataEventStream = new ContentMetadataEventStream(contentMetadataEventStreamConfiguration, volatileEventStorage, persistentEventStorage);

            await contentMetadataEventStream.StartupAsync(operationContext).ThrowIfFailure();

            await contentMetadataEventStream.CompleteOrChangeLogAsync(operationContext, CheckpointLogId.InitialLogId);

            contentMetadataEventStream.SetIsLogging(true);
            await runTestAsync(operationContext, contentMetadataEventStream, volatileEventStorage, persistentEventStorage);

            await contentMetadataEventStream.ShutdownAsync(operationContext).ThrowIfFailure();
        }
示例#2
0
        private async Task RunTest(Func <OperationContext, RedisWriteAheadEventStorage, Task> runTestAsync, RedisVolatileEventStorageConfiguration configuration = null)
        {
            var tracingContext   = new Context(Logger);
            var operationContext = new OperationContext(tracingContext);

            using var database = LocalRedisProcessDatabase.CreateAndStartEmpty(_redisFixture, TestGlobal.Logger, SystemClock.Instance);

            var primaryFactory = await RedisDatabaseFactory.CreateAsync(
                operationContext,
                new LiteralConnectionStringProvider(database.ConnectionString),
                new RedisConnectionMultiplexerConfiguration()
            {
                LoggingSeverity = Severity.Error
            });

            var primaryDatabaseAdapter = new RedisDatabaseAdapter(primaryFactory, "keyspace");

            configuration ??= new RedisVolatileEventStorageConfiguration();
            var instance = new RedisWriteAheadEventStorage(configuration, primaryDatabaseAdapter);

            await instance.StartupAsync(operationContext).ThrowIfFailure();

            await runTestAsync(operationContext, instance);

            await instance.ShutdownAsync(operationContext).ThrowIfFailure();
        }