void GetNextChunk(InMemoryTimeoutPersister inMemoryTimeoutPersister)
 {
     for (var i = 0; i < 10; i++)
     {
         DateTime nextTimeToRunQuery;
         inMemoryTimeoutPersister.GetNextChunk(DateTime.MinValue, out nextTimeToRunQuery).ToList();   
     }
 }
 void Add(InMemoryTimeoutPersister inMemoryTimeoutPersister)
 {
     inMemoryTimeoutPersister.Add(new TimeoutData
     {
         Time = DateTime.Now,
         Id = Thread.CurrentThread.Name
     });
 }
 public void When_existing_is_removed_existing_is_outted()
 {
     var persister = new InMemoryTimeoutPersister();
     var inputTimeout = new TimeoutData();
     persister.Add(inputTimeout);
     TimeoutData removedTimeout;
     var removed = persister.TryRemove(inputTimeout.Id, out removedTimeout);
     Assert.IsTrue(removed);
     Assert.AreSame(inputTimeout, removedTimeout);
 }
 void Runner(InMemoryTimeoutPersister inMemoryTimeoutPersister)
 {
     for (var i = 0; i < 10000; i++)
     {
         GetNextChunk(inMemoryTimeoutPersister);
         Add(inMemoryTimeoutPersister);
         GetNextChunk(inMemoryTimeoutPersister);
         TryRemove(inMemoryTimeoutPersister);
         GetNextChunk(inMemoryTimeoutPersister);
         RemoveTimeoutBy(inMemoryTimeoutPersister);
         GetNextChunk(inMemoryTimeoutPersister);
     }
 }
        public void Run()
        {
            var stopwatch = Stopwatch.StartNew();
            var inMemoryTimeoutPersister = new InMemoryTimeoutPersister();

            for (var i = 0; i < 10; i++)
            {
                var thread = new Thread(() => Runner(inMemoryTimeoutPersister));
                thread.Start();
                thread.Join();
            }
            Debug.WriteLine(stopwatch.ElapsedMilliseconds);
        }
        public void When_existing_is_removed_by_saga_id()
        {
            var persister = new InMemoryTimeoutPersister();
            var newGuid = Guid.NewGuid();
            var inputTimeout = new TimeoutData
                               {
                                   SagaId = newGuid
                               };
            persister.Add(inputTimeout);

            persister.RemoveTimeoutBy(newGuid);
            TimeoutData removedTimeout;
            var removed = persister.TryRemove(inputTimeout.Id, out removedTimeout);
            Assert.False(removed);
        }
 public void When_multiple_NextTimeToRunQuery_is_min_date()
 {
     DateTime nextTimeToRunQuery;
     var now = DateTime.UtcNow;
     var persister = new InMemoryTimeoutPersister();
     persister.Add(new TimeoutData
                   {
                       Time = DateTime.Now.AddDays(2)
                   });
     var expectedDate = DateTime.Now.AddDays(1);
     persister.Add(new TimeoutData
                   {
                       Time = expectedDate
                   });
     persister.GetNextChunk(now, out nextTimeToRunQuery);
     Assert.AreEqual(expectedDate, nextTimeToRunQuery);
 }
 public void When_multiple_future_are_returned()
 {
     DateTime nextTime;
     var persister = new InMemoryTimeoutPersister();
     persister.Add(new TimeoutData
                   {
                       Time = DateTime.Now.AddDays(-2)
                   });
     persister.Add(new TimeoutData
                   {
                       Time = DateTime.Now.AddDays(-4)
                   });
     persister.Add(new TimeoutData
                   {
                       Time = DateTime.Now.AddDays(-1)
                   });
     var nextChunk = persister.GetNextChunk(DateTime.Now.AddDays(-3), out nextTime);
     Assert.AreEqual(2, nextChunk.Count());
 }
 public void When_all_in_past_NextTimeToRunQuery_is_1_minute()
 {
     DateTime nextTimeToRunQuery;
     var now = DateTime.UtcNow;
     var persister = new InMemoryTimeoutPersister();
     persister.Add(new TimeoutData
                   {
                       Time = DateTime.Now.AddDays(-1)
                   });
     persister.Add(new TimeoutData
                   {
                       Time = DateTime.Now.AddDays(-3)
                   });
     persister.Add(new TimeoutData
                   {
                       Time = DateTime.Now.AddDays(-2)
                   });
     persister.GetNextChunk(now, out nextTimeToRunQuery);
     Assert.That(nextTimeToRunQuery, Is.EqualTo(now.AddMinutes(1)).Within(100).Milliseconds);
 }
 void TryRemove(InMemoryTimeoutPersister inMemoryTimeoutPersister)
 {
     TimeoutData timeout;
     inMemoryTimeoutPersister.TryRemove(Thread.CurrentThread.Name, out timeout);
 }
 void RemoveTimeoutBy(InMemoryTimeoutPersister inMemoryTimeoutPersister)
 {
     var sagaId = sagaIdGuids.GetOrAdd(Thread.CurrentThread.ManagedThreadId, new Guid());
     inMemoryTimeoutPersister.RemoveTimeoutBy(sagaId);
 }