コード例 #1
0
        public async Task Should_clear_dispatched_messages_after_given_expiry()
        {
            var storage = new InMemoryOutboxStorage();

            var messageId = "myId";

            var beforeStore = DateTime.UtcNow;

            var messageToStore = new OutboxMessage(messageId, new[] { new TransportOperation("x", null, null, null) });
            using (var transaction = await storage.BeginTransaction(new ContextBag()))
            {
                await storage.Store(messageToStore, transaction, new ContextBag());

                await transaction.Commit();
            }

            // Account for the low resolution of DateTime.UtcNow.
            var afterStore = DateTime.UtcNow.AddTicks(1);

            await storage.SetAsDispatched(messageId, new ContextBag());

            storage.RemoveEntriesOlderThan(beforeStore);

            var message = await storage.Get(messageId, new ContextBag());
            Assert.NotNull(message);

            storage.RemoveEntriesOlderThan(afterStore);

            message = await storage.Get(messageId, new ContextBag());
            Assert.Null(message);
        }
コード例 #2
0
        public async Task Should_clear_dispatched_messages_after_given_expiry()
        {
            var storage = new InMemoryOutboxStorage();

            var messageId = "myId";

            var beforeStore = DateTime.UtcNow;

            var messageToStore = new OutboxMessage(messageId, new[] { new TransportOperation("x", null, null, null) });

            using (var transaction = await storage.BeginTransaction(new ContextBag()))
            {
                await storage.Store(messageToStore, transaction, new ContextBag());

                await transaction.Commit();
            }

            // Account for the low resolution of DateTime.UtcNow.
            var afterStore = DateTime.UtcNow.AddTicks(1);

            await storage.SetAsDispatched(messageId, new ContextBag());

            storage.RemoveEntriesOlderThan(beforeStore);

            var message = await storage.Get(messageId, new ContextBag());

            Assert.NotNull(message);

            storage.RemoveEntriesOlderThan(afterStore);

            message = await storage.Get(messageId, new ContextBag());

            Assert.Null(message);
        }
コード例 #3
0
        /// <summary>
        /// See <see cref="Feature.Setup" />.
        /// </summary>
        protected internal override void Setup(FeatureConfigurationContext context)
        {
            var outboxStorage = new InMemoryOutboxStorage();
            context.Container.RegisterSingleton<IOutboxStorage>(outboxStorage);

            var timeSpan = context.Settings.Get<TimeSpan>(TimeToKeepDeduplicationEntries);

            context.RegisterStartupTask(new OutboxCleaner(outboxStorage, timeSpan));
        }
コード例 #4
0
        /// <summary>
        /// See <see cref="Feature.Setup" />.
        /// </summary>
        protected internal override void Setup(FeatureConfigurationContext context)
        {
            var outboxStorage = new InMemoryOutboxStorage();

            context.Container.RegisterSingleton <IOutboxStorage>(outboxStorage);

            var timeSpan = context.Settings.Get <TimeSpan>(TimeToKeepDeduplicationEntries);

            context.RegisterStartupTask(new OutboxCleaner(outboxStorage, timeSpan));
        }
コード例 #5
0
        public void Should_not_remove_non_dispatched_messages()
        {
            var storage = new InMemoryOutboxStorage();

            var messageId = "myId";

            storage.Store(messageId, new List <TransportOperation> {
                new TransportOperation("x", null, null, null)
            });

            OutboxMessage message;

            storage.RemoveEntriesOlderThan(DateTime.UtcNow);

            Assert.True(storage.TryGet(messageId, out message));
        }
コード例 #6
0
        public void Should_clear_operations_on_dispatched_messages()
        {
            var storage = new InMemoryOutboxStorage();

            var messageId = "myId";

            storage.Store(messageId, new List <TransportOperation> {
                new TransportOperation("x", null, null, null)
            });

            OutboxMessage message;

            storage.SetAsDispatched(messageId);

            storage.TryGet(messageId, out message);


            Assert.False(message.TransportOperations.Any());
        }
コード例 #7
0
        public async Task Should_not_store_when_transaction_not_commited()
        {
            var storage = new InMemoryOutboxStorage();

            var messageId = "myId";

            var contextBag = new ContextBag();

            using (var transaction = await storage.BeginTransaction(contextBag))
            {
                var messageToStore = new OutboxMessage(messageId, new[] { new TransportOperation("x", null, null, null) });
                await storage.Store(messageToStore, transaction, contextBag);

                // do not commit
            }

            var message = await storage.Get(messageId, new ContextBag());

            Assert.Null(message);
        }
コード例 #8
0
        public async Task Should_not_remove_non_dispatched_messages()
        {
            var storage = new InMemoryOutboxStorage();

            var messageId = "myId";

            var messageToStore = new OutboxMessage(messageId, new[] { new TransportOperation("x", null, null, null) });

            using (var transaction = await storage.BeginTransaction(new ContextBag()))
            {
                await storage.Store(messageToStore, transaction, new ContextBag());

                await transaction.Commit();
            }

            storage.RemoveEntriesOlderThan(DateTime.UtcNow);

            var message = await storage.Get(messageId, new ContextBag());
            Assert.NotNull(message);
        }
コード例 #9
0
        public async Task Should_clear_operations_on_dispatched_messages()
        {
            var storage = new InMemoryOutboxStorage();

            var messageId = "myId";

            var messageToStore = new OutboxMessage(messageId, new[] { new TransportOperation("x", null, null, null) });
            using (var transaction = await storage.BeginTransaction(new ContextBag()))
            {
                await storage.Store(messageToStore, transaction, new ContextBag());

                await transaction.Commit();
            }

            await storage.SetAsDispatched(messageId, new ContextBag());

            var message = await storage.Get(messageId, new ContextBag());

            Assert.False(message.TransportOperations.Any());
        }
コード例 #10
0
        public async Task Should_not_remove_non_dispatched_messages()
        {
            var storage = new InMemoryOutboxStorage();

            var messageId = "myId";

            var messageToStore = new OutboxMessage(messageId, new[] { new TransportOperation("x", null, null, null) });

            using (var transaction = await storage.BeginTransaction(new ContextBag()))
            {
                await storage.Store(messageToStore, transaction, new ContextBag());

                await transaction.Commit();
            }

            storage.RemoveEntriesOlderThan(DateTime.UtcNow);

            var message = await storage.Get(messageId, new ContextBag());

            Assert.NotNull(message);
        }
コード例 #11
0
        public async Task Should_clear_operations_on_dispatched_messages()
        {
            var storage = new InMemoryOutboxStorage();

            var messageId = "myId";

            var messageToStore = new OutboxMessage(messageId, new[] { new TransportOperation("x", null, null, null) });

            using (var transaction = await storage.BeginTransaction(new ContextBag()))
            {
                await storage.Store(messageToStore, transaction, new ContextBag());

                await transaction.Commit();
            }

            await storage.SetAsDispatched(messageId, new ContextBag());

            var message = await storage.Get(messageId, new ContextBag());

            Assert.False(message.TransportOperations.Any());
        }
コード例 #12
0
        public void Should_clear_dispatched_messages_after_given_expiry()
        {
            var storage = new InMemoryOutboxStorage();

            var messageId = "myId";

            var beforeStore = DateTime.UtcNow;

            storage.Store(messageId, new List <TransportOperation> {
                new TransportOperation("x", null, null, null)
            });

            OutboxMessage message;

            storage.SetAsDispatched(messageId);

            storage.RemoveEntriesOlderThan(beforeStore);

            Assert.True(storage.TryGet(messageId, out message));

            storage.RemoveEntriesOlderThan(DateTime.UtcNow);

            Assert.False(storage.TryGet(messageId, out message));
        }
コード例 #13
0
 public OutboxCleaner(InMemoryOutboxStorage storage, TimeSpan timeToKeepDeduplicationData)
 {
     this.timeToKeepDeduplicationData = timeToKeepDeduplicationData;
     inMemoryOutboxStorage            = storage;
 }
コード例 #14
0
 void PerformCleanup(object state)
 {
     InMemoryOutboxStorage.RemoveEntriesOlderThan(DateTime.UtcNow - TimeToKeepDeduplicationData);
 }
コード例 #15
0
 public OutboxCleaner(InMemoryOutboxStorage storage, TimeSpan timeToKeepDeduplicationData)
 {
     this.timeToKeepDeduplicationData = timeToKeepDeduplicationData;
     inMemoryOutboxStorage = storage;
 }
コード例 #16
0
        public async Task Should_not_store_when_transaction_not_commited()
        {
            var storage = new InMemoryOutboxStorage();

            var messageId = "myId";

            var contextBag = new ContextBag();
            using (var transaction = await storage.BeginTransaction(contextBag))
            {
                var messageToStore = new OutboxMessage(messageId, new[] { new TransportOperation("x", null, null, null) });
                await storage.Store(messageToStore, transaction, contextBag);

                // do not commit
            }

            var message = await storage.Get(messageId, new ContextBag());
            Assert.Null(message);
        }