private MsSqlStreamStoreV3Fixture( string schema, bool disableDeletionTracking = false, bool deleteDatabaseOnDispose = true, bool createSchema = true) { _schema = schema; _deleteDatabaseOnDispose = deleteDatabaseOnDispose; _createSchema = createSchema; _databaseName = $"sss-v3-{Guid.NewGuid():n}"; _databaseInstance = new DockerMsSqlServerDatabase(_databaseName); var connectionStringBuilder = _databaseInstance.CreateConnectionStringBuilder(); connectionStringBuilder.MultipleActiveResultSets = true; connectionStringBuilder.InitialCatalog = _databaseName; ConnectionString = connectionStringBuilder.ToString(); _settings = new MsSqlStreamStoreV3Settings(ConnectionString) { Schema = _schema, GetUtcNow = () => GetUtcNow(), DisableDeletionTracking = disableDeletionTracking }; }
public async Task <IStreamStore> GetStreamStore(string schema) { var settings = new MsSqlStreamStoreV3Settings(ConnectionString) { Schema = schema, GetUtcNow = () => GetUtcNow(), DisableDeletionTracking = _disableDeletionTracking }; var store = new MsSqlStreamStoreV3(settings); await store.CreateSchema(); return(store); }
public async Task <MsSqlStreamStoreV3> GetMsSqlStreamStore() { await CreateDatabase(); var settings = new MsSqlStreamStoreV3Settings(ConnectionString) { Schema = _schema, GetUtcNow = () => GetUtcNow() }; var store = new MsSqlStreamStoreV3(settings); await store.CreateSchema(); return(store); }
private async Task Init() { await _databaseInstance.CreateDatabase(); var settings = new MsSqlStreamStoreV3Settings(ConnectionString) { Schema = _schema, GetUtcNow = () => GetUtcNow(), DisableDeletionTracking = _disableDeletionTracking }; Store = new MsSqlStreamStoreV3(settings); if (_createSchema) { await Store.CreateSchemaIfNotExists(); } }
public async Task Can_migrate() { // Set up an old schema + data. var schema = "baz"; var v2Fixture = new MsSqlStreamStoreFixture(schema, deleteDatabaseOnDispose: false); var v2Store = await v2Fixture.GetMsSqlStreamStore(); await v2Store.AppendToStream("stream-1", ExpectedVersion.NoStream, StreamStoreAcceptanceTests.CreateNewStreamMessages(1, 2, 3)); await v2Store.AppendToStream("stream-2", ExpectedVersion.NoStream, StreamStoreAcceptanceTests.CreateNewStreamMessages(1, 2, 3)); await v2Store.SetStreamMetadata("stream-1", ExpectedVersion.Any, maxAge : 10, maxCount : 20); v2Store.Dispose(); v2Fixture.Dispose(); var settings = new MsSqlStreamStoreV3Settings(v2Fixture.ConnectionString) { Schema = schema, }; var v3Store = new MsSqlStreamStoreV3(settings); var checkSchemaResult = await v3Store.CheckSchema(); checkSchemaResult.IsMatch().ShouldBeFalse(); var progress = new Progress <MigrateProgress>(); progress.ProgressChanged += (_, migrateProgress) => _testOutputHelper.WriteLine($"Migration stage complete: {migrateProgress.Stage}"); await v3Store.Migrate(progress, CancellationToken.None); checkSchemaResult = await v3Store.CheckSchema(); checkSchemaResult.IsMatch().ShouldBeTrue(); var listStreamsResult = await v3Store.ListStreams(Pattern.EndsWith("1")); listStreamsResult.StreamIds.Length.ShouldBe(2); v3Store.Dispose(); }
public IStreamStore StoreFor(string user) { var connectionStringBuilder = new SqlConnectionStringBuilder(_settings.ConnectionString) { UserID = user, Password = Password(user), }; var connectionString = connectionStringBuilder.ToString(); var settings = new MsSqlStreamStoreV3Settings(connectionString) { Schema = _settings.Schema, GetUtcNow = () => _settings.GetUtcNow(), CommandTimeout = _settings.CommandTimeout, CreateStreamStoreNotifier = _settings.CreateStreamStoreNotifier, DisableDeletionTracking = _settings.DisableDeletionTracking, LogName = _settings.LogName, }; return(new MsSqlStreamStoreV3(settings)); }
public MsSqlStreamStoreV3Fixture( string schema, SqlServerContainer dockerInstance, string databaseName, Action onDispose) { _onDispose = onDispose; DatabaseName = databaseName; var connectionStringBuilder = dockerInstance.CreateConnectionStringBuilder(); connectionStringBuilder.MultipleActiveResultSets = true; connectionStringBuilder.InitialCatalog = DatabaseName; var connectionString = connectionStringBuilder.ToString(); _settings = new MsSqlStreamStoreV3Settings(connectionString) { Schema = schema, GetUtcNow = () => GetUtcNow(), DisableDeletionTracking = false }; }
public async Task Can_migrate() { // Set up an old schema + data. var schema = "baz"; var v2Fixture = new MsSqlStreamStoreFixture(schema, deleteDatabaseOnDispose: false); var v2Store = await v2Fixture.GetMsSqlStreamStore(); await v2Store.AppendToStream("stream-1", ExpectedVersion.NoStream, StreamStoreAcceptanceTests.CreateNewStreamMessages(1, 2, 3)); await v2Store.AppendToStream("stream-2", ExpectedVersion.NoStream, StreamStoreAcceptanceTests.CreateNewStreamMessages(1, 2, 3)); await v2Store.SetStreamMetadata("stream-1", ExpectedVersion.Any, maxAge : 10, maxCount : 20); v2Store.Dispose(); v2Fixture.Dispose(); var settings = new MsSqlStreamStoreV3Settings(v2Fixture.ConnectionString) { Schema = schema, }; var v3Store = new MsSqlStreamStoreV3(settings); var checkSchemaResult = await v3Store.CheckSchema(); checkSchemaResult.IsMatch().ShouldBeFalse(); await v3Store.Migrate(CancellationToken.None); checkSchemaResult = await v3Store.CheckSchema(); checkSchemaResult.IsMatch().ShouldBeTrue(); v3Store.Dispose(); }
/// <summary> /// Initializes a new instance of <see cref="MsSqlStreamStoreV3"/> /// </summary> /// <param name="settings">A settings class to configure this instance.</param> public MsSqlStreamStoreV3(MsSqlStreamStoreV3Settings settings) : base(settings.GetUtcNow, settings.LogName) { Ensure.That(settings, nameof(settings)).IsNotNull(); _settings = settings; _createConnection = () => settings.ConnectionFactory(settings.ConnectionString); _streamStoreNotifier = new Lazy <IStreamStoreNotifier>(() => { if (settings.CreateStreamStoreNotifier == null) { throw new InvalidOperationException( "Cannot create notifier because supplied createStreamStoreNotifier was null"); } return(settings.CreateStreamStoreNotifier.Invoke(this)); }); _scripts = new Scripts(settings.Schema); var sqlMetaData = new List <SqlMetaData> { new SqlMetaData("StreamVersion", SqlDbType.Int, true, false, SortOrder.Unspecified, -1), new SqlMetaData("Id", SqlDbType.UniqueIdentifier), new SqlMetaData("Created", SqlDbType.DateTime, true, false, SortOrder.Unspecified, -1), new SqlMetaData("Type", SqlDbType.NVarChar, 128), new SqlMetaData("JsonData", SqlDbType.NVarChar, SqlMetaData.Max), new SqlMetaData("JsonMetadata", SqlDbType.NVarChar, SqlMetaData.Max) }; if (settings.GetUtcNow != null) { // Created column value will be client supplied so should prevent using of the column default function sqlMetaData[2] = new SqlMetaData("Created", SqlDbType.DateTime); } _appendToStreamSqlMetadata = sqlMetaData.ToArray(); _commandTimeout = settings.CommandTimeout; }