public void AddToQueue_AddsAJobToTheQueue_UsingStorageConnection_WithTransactionScopeEnlistment() { string jobId; var storage = new PostgreSqlStorage(ConnectionUtils.GetConnectionString(), new PostgreSqlStorageOptions { EnableTransactionScopeEnlistment = true }); using (var storageConnection = storage.GetConnection()) { using (var writeTransaction = storageConnection.CreateWriteTransaction()) { // Explicitly call multiple write commands here, as AddToQueue previously opened an own connection. // This triggered a prepared transaction which should be avoided. jobId = storageConnection.CreateExpiredJob(Job.FromExpression(() => Console.Write("Hi")), new Dictionary <string, string>(), DateTime.UtcNow, TimeSpan.FromMinutes(1)); writeTransaction.SetJobState(jobId, new ScheduledState(DateTime.UtcNow)); writeTransaction.AddToQueue("default", jobId); writeTransaction.PersistJob(jobId); writeTransaction.Commit(); } } UseConnection(connection => { var record = connection.Query(@"select * from """ + GetSchemaName() + @""".""jobqueue""").Single(); Assert.Equal(jobId, record.jobid.ToString()); Assert.Equal("default", record.queue); Assert.Null(record.FetchedAt); }); }
public void GetConnection_ReturnsExistingConnection_WhenStorageUsesIt() { var connection = ConnectionUtils.CreateConnection(); var storage = new PostgreSqlStorage(connection, _options); using (var storageConnection = (PostgreSqlConnection)storage.GetConnection()) { Assert.Same(connection, storageConnection.Connection); Assert.False(storageConnection.OwnsConnection); } }
public void GetConnection_ReturnsExistingConnection_WhenStorageUsesIt() { var connection = ConnectionUtils.CreateConnection(); var storage = new PostgreSqlStorage(connection, _options); using (var storageConnection = (PostgreSqlConnection) storage.GetConnection()) { Assert.Same(connection, storageConnection.Connection); Assert.False(storageConnection.OwnsConnection); } }