public FirebirdJobQueueFacts() { _options = new FirebirdStorageOptions() { }; }
public void Set_QueuePollInterval_ShouldThrowAnException_WhenGivenIntervalIsEqualToZero() { var options = new FirebirdStorageOptions(); Assert.Throws <ArgumentException>( () => options.QueuePollInterval = TimeSpan.Zero); }
public void Ctor_ThrowsAnException_IfLockCanNotBeGranted_WithoutUseNativeDatabaseTransactions() { FirebirdStorageOptions options = new FirebirdStorageOptions() { //UseNativeDatabaseTransactions = false }; var releaseLock = new ManualResetEventSlim(false); var lockAcquired = new ManualResetEventSlim(false); var thread = new Thread( () => UseConnection(connection1 => { using (new FirebirdDistributedLock("exclusive", _timeout, connection1, options)) { lockAcquired.Set(); releaseLock.Wait(); } })); thread.Start(); lockAcquired.Wait(); UseConnection(connection2 => Assert.Throws <FirebirdDistributedLockException>( () => new FirebirdDistributedLock("exclusive", _timeout, connection2, options))); releaseLock.Set(); thread.Join(); }
public void Set_QueuePollInterval_SetsTheValue() { var options = new FirebirdStorageOptions(); options.QueuePollInterval = TimeSpan.FromSeconds(1); Assert.Equal(TimeSpan.FromSeconds(1), options.QueuePollInterval); }
public void Set_QueuePollInterval_ShouldThrowAnException_WhenGivenIntervalIsNegative() { var options = new FirebirdStorageOptions(); Assert.Throws <ArgumentException>( () => options.QueuePollInterval = TimeSpan.FromSeconds(-1)); }
public ExpirationManagerFacts() { var cts = new CancellationTokenSource(); _token = cts.Token; _options = new FirebirdStorageOptions(); }
private static bool IsEntryExpired(FbConnection connection, FirebirdStorageOptions options, int entryId) { var count = connection.Query <long>(string.Format(@" SELECT COUNT(*) FROM ""{0}.COUNTER"" WHERE id = @id;", options.Prefix), new { id = entryId }).Single(); return(count == 0); }
public void Ctor_SetsTheDefaultOptions() { var options = new FirebirdStorageOptions(); Assert.True(options.QueuePollInterval > TimeSpan.Zero); Assert.True(options.InvisibilityTimeout > TimeSpan.Zero); Assert.True(options.PrepareSchemaIfNecessary); }
private static int CreateJobQueueRecord(IDbConnection connection, FirebirdStorageOptions options, string jobId, string queue) { string arrangeSql = string.Format(CultureInfo.InvariantCulture, @" INSERT INTO ""{0}.JOBQUEUE"" (jobid, queue, fetchedat) VALUES (@id, @queue, DATEADD(minute, -{1:N5}*60, current_timestamp)) RETURNING id", options.Prefix, options.UtcOffset); return(connection.ExecuteScalar <int>(arrangeSql, new { id = Convert.ToInt32(jobId, CultureInfo.InvariantCulture), queue = queue })); }
public void Ctor_ThrowsAnException_WhenResourceIsNullOrEmpty() { FirebirdStorageOptions options = new FirebirdStorageOptions(); var exception = Assert.Throws <ArgumentNullException>( () => new FirebirdDistributedLock("", _timeout, new Mock <IDbConnection>().Object, options)); Assert.Equal("resource", exception.ParamName); }
public void Ctor_ThrowsAnException_WhenConnectionIsNull() { FirebirdStorageOptions options = new FirebirdStorageOptions(); var exception = Assert.Throws <ArgumentNullException>( () => new FirebirdDistributedLock("hello", _timeout, null, options)); Assert.Equal("connection", exception.ParamName); }
public void Ctor_ThrowsAnException_WhenConnectionIsNull() { FirebirdStorageOptions options = new FirebirdStorageOptions(); var exception = Assert.Throws<ArgumentNullException>( () => new FirebirdDistributedLock("hello", _timeout, null, options)); Assert.Equal("connection", exception.ParamName); }
public void Ctor_ThrowsAnException_WhenResourceIsNullOrEmpty() { FirebirdStorageOptions options = new FirebirdStorageOptions(); var exception = Assert.Throws<ArgumentNullException>( () => new FirebirdDistributedLock("", _timeout, new Mock<IDbConnection>().Object, options)); Assert.Equal("resource", exception.ParamName); }
public FirebirdWriteOnlyTransactionFacts() { var defaultProvider = new Mock<IPersistentJobQueueProvider>(); defaultProvider.Setup(x => x.GetJobQueue(It.IsNotNull<IDbConnection>())) .Returns(new Mock<IPersistentJobQueue>().Object); _queueProviders = new PersistentJobQueueProviderCollection(defaultProvider.Object); _options = new FirebirdStorageOptions(); }
/// <summary> /// Tells the bootstrapper to use Firebird as a job storage /// with the given options, that can be accessed using the specified /// connection string or its name. /// </summary> /// <param name="configuration">Configuration</param> /// <param name="nameOrConnectionString">Connection string or its name</param> /// <param name="options">Advanced options</param> public static FirebirdStorage UseFirebirdStorage( this IBootstrapperConfiguration configuration, string nameOrConnectionString, FirebirdStorageOptions options) { var storage = new FirebirdStorage(nameOrConnectionString, options); configuration.UseStorage(storage); return storage; }
public FirebirdWriteOnlyTransactionFacts() { var defaultProvider = new Mock <IPersistentJobQueueProvider>(); defaultProvider.Setup(x => x.GetJobQueue(It.IsNotNull <IDbConnection>())) .Returns(new Mock <IPersistentJobQueue>().Object); _queueProviders = new PersistentJobQueueProviderCollection(defaultProvider.Object); _options = new FirebirdStorageOptions(); }
/// <summary> /// Tells the bootstrapper to use Firebird as a job storage /// with the given options, that can be accessed using the specified /// connection string or its name. /// </summary> /// <param name="configuration">Configuration</param> /// <param name="nameOrConnectionString">Connection string or its name</param> /// <param name="options">Advanced options</param> public static FirebirdStorage UseFirebirdStorage( this IBootstrapperConfiguration configuration, string nameOrConnectionString, FirebirdStorageOptions options) { var storage = new FirebirdStorage(nameOrConnectionString, options); configuration.UseStorage(storage); return(storage); }
public FirebirdConnectionFacts() { _queue = new Mock<IPersistentJobQueue>(); var provider = new Mock<IPersistentJobQueueProvider>(); provider.Setup(x => x.GetJobQueue(It.IsNotNull<IDbConnection>())) .Returns(_queue.Object); _providers = new PersistentJobQueueProviderCollection(provider.Object); _options = new FirebirdStorageOptions() { }; }
public FirebirdConnectionFacts() { _queue = new Mock <IPersistentJobQueue>(); var provider = new Mock <IPersistentJobQueueProvider>(); provider.Setup(x => x.GetJobQueue(It.IsNotNull <IDbConnection>())) .Returns(_queue.Object); _providers = new PersistentJobQueueProviderCollection(provider.Object); _options = new FirebirdStorageOptions() { }; }
public void Ctor_AcquiresExclusiveApplicationLock_WithoutUseNativeDatabaseTransactions_OnSession() { FirebirdStorageOptions options = new FirebirdStorageOptions() { //UseNativeDatabaseTransactions = false }; UseConnection(connection => { var distributedLock = new FirebirdDistributedLock("hello", _timeout, connection, options); var lockCount = connection.Query <long>( string.Format(@"SELECT COUNT(*) FROM ""{0}.LOCK"" WHERE resource = @resource;", options.Prefix), new { resource = "hello" }).Single(); Assert.Equal(lockCount, 1); //Assert.Equal("Exclusive", lockMode); }); }
private static int CreateExpirationEntry(FbConnection connection, FirebirdStorageOptions options, DateTime?expireAt) { string insertSqlNull = @" INSERT INTO """ + options.Prefix + @".COUNTER"" (""KEY"", ""VALUE"", expireat) VALUES ('key', 1, null) RETURNING id;"; string insertSqlValue = @" INSERT INTO """ + options.Prefix + @".COUNTER"" (""KEY"", ""VALUE"", expireat) VALUES ('key', 1, DATEADD(second, {0:N5}, " + string.Format(CultureInfo.InvariantCulture, @"DATEADD(minute, -{0:N5}*60, current_timestamp))) ", options.UtcOffset) + "RETURNING id;"; string insertSql = expireAt == null ? insertSqlNull : string.Format(insertSqlValue, ((long)(expireAt.Value - DateTime.UtcNow).TotalSeconds).ToString(CultureInfo.InvariantCulture)); var recordId = connection.ExecuteScalar <int>(insertSql); return(recordId); }
public void Ctor_AcquiresExclusiveApplicationLock_WithoutUseNativeDatabaseTransactions_OnSession() { FirebirdStorageOptions options = new FirebirdStorageOptions() { //UseNativeDatabaseTransactions = false }; UseConnection(connection => { var distributedLock = new FirebirdDistributedLock("hello", _timeout, connection, options); var lockCount = connection.Query<long>( string.Format(@"SELECT COUNT(*) FROM ""{0}.LOCK"" WHERE resource = @resource;", options.Prefix) , new { resource = "hello" }).Single(); Assert.Equal(lockCount, 1); //Assert.Equal("Exclusive", lockMode); }); }
private static int CreateJobQueueRecord(IDbConnection connection, FirebirdStorageOptions options, string jobId, string queue) { string arrangeSql = string.Format(CultureInfo.InvariantCulture, @" INSERT INTO ""{0}.JOBQUEUE"" (jobid, queue, fetchedat) VALUES (@id, @queue, DATEADD(minute, -{1:N5}*60, current_timestamp)) RETURNING id", options.Prefix, options.UtcOffset); return connection.ExecuteScalar<int>(arrangeSql, new { id = Convert.ToInt32(jobId, CultureInfo.InvariantCulture), queue = queue }); }
public FirebirdFetchedJobFacts() { _connection = new Mock<IDbConnection>(); _options = new FirebirdStorageOptions(); }
/*[Fact, CleanDatabase] * public void AddToQueue_CallsEnqueue_OnTargetPersistentQueue() * { * UseConnection(sql => * { * var correctJobQueue = new Mock<IPersistentJobQueue>(); * var correctProvider = new Mock<IPersistentJobQueueProvider>(); * correctProvider.Setup(x => x.GetJobQueue(It.IsNotNull<IDbConnection>())) * .Returns(correctJobQueue.Object); * * _queueProviders.Add(correctProvider.Object, new[] { "default" }); * * Commit(sql, x => x.AddToQueue("default", "1")); * * IDbTransaction trans = sql.BeginTransaction(); * correctJobQueue.Verify(x => x.Enqueue(trans, "default", "1")); * trans.Commit(); * }); * }*/ private static dynamic GetTestJob(IDbConnection connection, FirebirdStorageOptions options, string jobId) { return(connection .Query(string.Format(@"SELECT * FROM ""{0}.JOB"" WHERE id = @id", options.Prefix), new { id = Convert.ToInt32(jobId, CultureInfo.InvariantCulture) }) .Single()); }
private static int CreateExpirationEntry(FbConnection connection, FirebirdStorageOptions options, DateTime? expireAt) { string insertSqlNull = @" INSERT INTO """ + options.Prefix + @".COUNTER"" (""KEY"", ""VALUE"", expireat) VALUES ('key', 1, null) RETURNING id;"; string insertSqlValue = @" INSERT INTO """ + options.Prefix + @".COUNTER"" (""KEY"", ""VALUE"", expireat) VALUES ('key', 1, DATEADD(second, {0:N5}, " + string.Format(CultureInfo.InvariantCulture, @"DATEADD(minute, -{0:N5}*60, current_timestamp))) ", options.UtcOffset) + "RETURNING id;"; string insertSql = expireAt == null ? insertSqlNull : string.Format(insertSqlValue, ((long)(expireAt.Value - DateTime.UtcNow).TotalSeconds).ToString(CultureInfo.InvariantCulture)); var recordId = connection.ExecuteScalar<int>(insertSql); return recordId; }
public FirebirdStorageFacts() { _options = new FirebirdStorageOptions { PrepareSchemaIfNecessary = false }; }
/*[Fact, CleanDatabase] public void AddToQueue_CallsEnqueue_OnTargetPersistentQueue() { UseConnection(sql => { var correctJobQueue = new Mock<IPersistentJobQueue>(); var correctProvider = new Mock<IPersistentJobQueueProvider>(); correctProvider.Setup(x => x.GetJobQueue(It.IsNotNull<IDbConnection>())) .Returns(correctJobQueue.Object); _queueProviders.Add(correctProvider.Object, new[] { "default" }); Commit(sql, x => x.AddToQueue("default", "1")); IDbTransaction trans = sql.BeginTransaction(); correctJobQueue.Verify(x => x.Enqueue(trans, "default", "1")); trans.Commit(); }); }*/ private static dynamic GetTestJob(IDbConnection connection, FirebirdStorageOptions options, string jobId) { return connection .Query(string.Format(@"SELECT * FROM ""{0}.JOB"" WHERE id = @id", options.Prefix), new { id = Convert.ToInt32(jobId, CultureInfo.InvariantCulture) }) .Single(); }
public void Ctor_ThrowsAnException_IfLockCanNotBeGranted_WithoutUseNativeDatabaseTransactions() { FirebirdStorageOptions options = new FirebirdStorageOptions() { //UseNativeDatabaseTransactions = false }; var releaseLock = new ManualResetEventSlim(false); var lockAcquired = new ManualResetEventSlim(false); var thread = new Thread( () => UseConnection(connection1 => { using (new FirebirdDistributedLock("exclusive", _timeout, connection1, options)) { lockAcquired.Set(); releaseLock.Wait(); } })); thread.Start(); lockAcquired.Wait(); UseConnection(connection2 => Assert.Throws<FirebirdDistributedLockException>( () => new FirebirdDistributedLock("exclusive", _timeout, connection2, options))); releaseLock.Set(); thread.Join(); }
public void Set_QueuePollInterval_ShouldThrowAnException_WhenGivenIntervalIsEqualToZero() { var options = new FirebirdStorageOptions(); Assert.Throws<ArgumentException>( () => options.QueuePollInterval = TimeSpan.Zero); }
public FirebirdFetchedJobFacts() { _connection = new Mock <IDbConnection>(); _options = new FirebirdStorageOptions(); }
public void Set_QueuePollInterval_ShouldThrowAnException_WhenGivenIntervalIsNegative() { var options = new FirebirdStorageOptions(); Assert.Throws<ArgumentException>( () => options.QueuePollInterval = TimeSpan.FromSeconds(-1)); }
private static bool IsEntryExpired(FbConnection connection, FirebirdStorageOptions options, int entryId) { var count = connection.Query<long>(string.Format(@" SELECT COUNT(*) FROM ""{0}.COUNTER"" WHERE id = @id;", options.Prefix), new { id = entryId }).Single(); return count == 0; }