コード例 #1
0
        public FirebirdJobQueueFacts()
        {
            _options = new FirebirdStorageOptions()
            {

            };
        }
コード例 #2
0
        public void Set_QueuePollInterval_ShouldThrowAnException_WhenGivenIntervalIsEqualToZero()
        {
            var options = new FirebirdStorageOptions();

            Assert.Throws <ArgumentException>(
                () => options.QueuePollInterval = TimeSpan.Zero);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        public void Set_QueuePollInterval_SetsTheValue()
        {
            var options = new FirebirdStorageOptions();

            options.QueuePollInterval = TimeSpan.FromSeconds(1);
            Assert.Equal(TimeSpan.FromSeconds(1), options.QueuePollInterval);
        }
コード例 #5
0
        public void Set_QueuePollInterval_ShouldThrowAnException_WhenGivenIntervalIsNegative()
        {
            var options = new FirebirdStorageOptions();

            Assert.Throws <ArgumentException>(
                () => options.QueuePollInterval = TimeSpan.FromSeconds(-1));
        }
コード例 #6
0
        public ExpirationManagerFacts()
        {
            var cts = new CancellationTokenSource();

            _token   = cts.Token;
            _options = new FirebirdStorageOptions();
        }
コード例 #7
0
        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);
        }
コード例 #8
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);
        }
コード例 #9
0
        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 }));
        }
コード例 #10
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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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;
        }
コード例 #17
0
        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);
        }
コード例 #19
0
        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()
            {
                
            };
        }
コード例 #20
0
        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()
            {
            };
        }
コード例 #21
0
        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);
            });
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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);
            });
        }
コード例 #24
0
        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 });
        }
コード例 #25
0
 public ExpirationManagerFacts()
 {
     var cts = new CancellationTokenSource();
     _token = cts.Token;
     _options = new FirebirdStorageOptions();
 }
コード例 #26
0
 public void Set_QueuePollInterval_SetsTheValue()
 {
     var options = new FirebirdStorageOptions();
     options.QueuePollInterval = TimeSpan.FromSeconds(1);
     Assert.Equal(TimeSpan.FromSeconds(1), options.QueuePollInterval);
 }
コード例 #27
0
 public FirebirdJobQueueFacts()
 {
     _options = new FirebirdStorageOptions()
     {
     };
 }
コード例 #28
0
 public FirebirdFetchedJobFacts()
 {
     _connection = new Mock<IDbConnection>();
     _options = new FirebirdStorageOptions();
 }
コード例 #29
0
        /*[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());
        }
コード例 #30
0
        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;
        }
コード例 #31
0
 public FirebirdStorageFacts()
 {
     _options = new FirebirdStorageOptions { PrepareSchemaIfNecessary = false };
 }
コード例 #32
0
        /*[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();
        }
コード例 #33
0
        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();
        }
コード例 #34
0
 public void Set_QueuePollInterval_ShouldThrowAnException_WhenGivenIntervalIsEqualToZero()
 {
     var options = new FirebirdStorageOptions();
     Assert.Throws<ArgumentException>(
         () => options.QueuePollInterval = TimeSpan.Zero);
 }
コード例 #35
0
 public FirebirdFetchedJobFacts()
 {
     _connection = new Mock <IDbConnection>();
     _options    = new FirebirdStorageOptions();
 }
コード例 #36
0
 public void Set_QueuePollInterval_ShouldThrowAnException_WhenGivenIntervalIsNegative()
 {
     var options = new FirebirdStorageOptions();
     Assert.Throws<ArgumentException>(
         () => options.QueuePollInterval = TimeSpan.FromSeconds(-1));
 }
コード例 #37
0
 public FirebirdStorageFacts()
 {
     _options = new FirebirdStorageOptions {
         PrepareSchemaIfNecessary = false
     };
 }
コード例 #38
0
 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;
 }