コード例 #1
0
 private void UseConnection(Action <RedisConnection> action)
 {
     using (var connection = new RedisConnection(RedisUtils.CreateClient()))
     {
         action(connection);
     }
 }
コード例 #2
0
 private static void UseConnection(Action <IRedisClient> action)
 {
     using (var redis = RedisUtils.CreateClient())
     {
         action(redis);
     }
 }
コード例 #3
0
        public void Execute_EnqueuesTimedOutJobs_AndDeletesThemFromFetchedList()
        {
            using (var redis = RedisUtils.CreateClient())
            {
                // Arrange
                redis.AddItemToSet("hangfire:queues", "my-queue");
                redis.AddItemToList("hangfire:queue:my-queue:dequeued", "my-job");
                redis.SetEntryInHash("hangfire:job:my-job", "Fetched",
                                     JobHelper.SerializeDateTime(DateTime.UtcNow.AddDays(-1)));

                var watcher = CreateWatcher();

                // Act
                watcher.Execute(_cts.Token);

                // Assert
                Assert.Equal(0, redis.GetListCount("hangfire:queue:my-queue:dequeued"));

                var listEntry = redis.DequeueItemFromList("hangfire:queue:my-queue");
                Assert.Equal("my-job", listEntry);

                var job = redis.GetAllEntriesFromHash("hangfire:job:my-job");
                Assert.False(job.ContainsKey("Fetched"));
            }
        }
コード例 #4
0
 private void UseConnections(Action <IRedisClient, RedisConnection> action)
 {
     using (var redis = RedisUtils.CreateClient())
         using (var connection = new RedisConnection(redis))
         {
             action(redis, connection);
         }
 }
コード例 #5
0
        public override void Before(MethodInfo methodUnderTest)
        {
            Monitor.Enter(GlobalLock);

            using (var client = RedisUtils.CreateClient())
            {
                client.FlushDb();
            }
        }
コード例 #6
0
        public void Execute_MarksDequeuedJobAsChecked_IfItHasNoFetchedFlagSet()
        {
            using (var redis = RedisUtils.CreateClient())
            {
                // Arrange
                redis.AddItemToSet("hangfire:queues", "my-queue");
                redis.AddItemToList("hangfire:queue:my-queue:dequeued", "my-job");

                var watcher = CreateWatcher();

                // Act
                watcher.Execute(_cts.Token);

                Assert.NotNull(JobHelper.DeserializeNullableDateTime(
                                   redis.GetValueFromHash("hangfire:job:my-job", "Checked")));
            }
        }
コード例 #7
0
        public void Execute_DoesNotEnqueueTimedOutByCheckedFlagJob_IfFetchedFlagSet()
        {
            using (var redis = RedisUtils.CreateClient())
            {
                // Arrange
                redis.AddItemToSet("hangfire:queues", "my-queue");
                redis.AddItemToList("hangfire:queue:my-queue:dequeued", "my-job");
                redis.SetEntryInHash("hangfire:job:my-job", "Checked",
                                     JobHelper.SerializeDateTime(DateTime.UtcNow.AddDays(-1)));
                redis.SetEntryInHash("hangfire:job:my-job", "Fetched",
                                     JobHelper.SerializeDateTime(DateTime.UtcNow));

                var watcher = CreateWatcher();

                // Act
                watcher.Execute(_cts.Token);

                // Assert
                Assert.Equal(1, redis.GetListCount("hangfire:queue:my-queue:dequeued"));
            }
        }
コード例 #8
0
        public void Execute_EnqueuesCheckedAndTimedOutJob_IfNoFetchedFlagSet()
        {
            using (var redis = RedisUtils.CreateClient())
            {
                // Arrange
                redis.AddItemToSet("hangfire:queues", "my-queue");
                redis.AddItemToList("hangfire:queue:my-queue:dequeued", "my-job");
                redis.SetEntryInHash("hangfire:job:my-job", "Checked",
                                     JobHelper.ToStringTimestamp(DateTime.UtcNow.AddDays(-1)));

                var watcher = CreateWatcher();

                // Act
                watcher.Execute(_token);

                // Arrange
                Assert.Equal(0, redis.GetListCount("hangfire:queue:my-queue:dequeued"));
                Assert.Equal(1, redis.GetListCount("hangfire:queue:my-queue"));

                var job = redis.GetAllEntriesFromHash("hangfire:job:my-job");
                Assert.False(job.ContainsKey("Checked"));
            }
        }
コード例 #9
0
ファイル: RedisTest.cs プロジェクト: nodoherty/HangFire
 public RedisTest()
 {
     _redis = RedisUtils.CreateClient();
 }