コード例 #1
0
 public async Task C130_AllowMultipleMessages()
 {
     await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), new TestSub()).UseLoggerForAuditing()).AllowMultipleMessages().ReceiveAsync(new EventData {
         Subject = "X"
     }, new EventData {
         Subject = "X"
     });
 }
コード例 #2
0
        public void Ctor_SubscribersInAssembly()
        {
            var args = new EventSubscriberHostArgs(TestSetUp.CreateLogger(), this.GetType().Assembly);

            Assert.AreEqual(2, args.EventSubscribers.Count());

            args = new EventSubscriberHostArgs(TestSetUp.CreateLogger());
            Assert.AreEqual(2, args.EventSubscribers.Count());
        }
コード例 #3
0
        public async Task A120_Unknown_Action()
        {
            var ts = new TestSub();
            var ed = new EventData {
                Subject = "Test.Blah.123", Action = "OTHER", Username = "******"
            };
            await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), ts)).ReceiveAsync(ed);

            Assert.IsFalse(ts.MessageReceived);
        }
コード例 #4
0
        public async Task A110_Unknown_Subject()
        {
            var ts = new TestSub();
            var ed = new EventData {
                Subject = "Other.Something", Action = "CREATE", Username = "******"
            };
            await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), ts).UseLoggerForAuditing()).ReceiveAsync(ed);

            Assert.IsFalse(ts.MessageReceived);
        }
コード例 #5
0
        public async Task B120_Unknown_Action()
        {
            var ts = new TestSubS();
            var ed = new EventData <string> {
                Subject = "Test.Blah.123", Action = "OTHER", Username = "******", Value = "TEST"
            };
            await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), ts).UseLoggerForAuditing()).ReceiveAsync(ed);

            Assert.IsFalse(ts.MessageReceived);
        }
コード例 #6
0
        public async Task A150_Receive_OK_ExceptionContinue()
        {
            var ts = new TestSub(@throw: true, unhandledExceptionHandling: UnhandledExceptionHandling.Continue);
            var ed = new EventData {
                Subject = "Test.Blah.123", Action = "UPDATE", Username = "******"
            };
            await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), ts).UseLoggerForAuditing()).ReceiveAsync(ed);

            Assert.IsTrue(ts.MessageReceived);
        }
コード例 #7
0
        public async Task A130_Receive_OK_OriginatingUser()
        {
            var ts = new TestSub(RunAsUser.Originating);
            var ed = new EventData {
                Subject = "Test.Blah.123", Action = "CREATE", Username = "******"
            };
            await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), ts).UseLoggerForAuditing()).ReceiveAsync(ed);

            Assert.IsTrue(ts.MessageReceived);
            Assert.AreEqual("TestUser", ts.Username);
        }
コード例 #8
0
        public async Task B150_Receive_OK_ExceptionContinue()
        {
            var ts = new TestSubS(@throw: true, unhandledExceptionHandling: UnhandledExceptionHandling.Continue);
            var ed = new EventData <string> {
                Subject = "Test.Blah.123", Action = "CREATE", Username = "******", Value = "TEST"
            };
            await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), ts).UseLoggerForAuditing()).ReceiveAsync(ed);

            Assert.IsTrue(ts.MessageReceived);
            Assert.AreEqual("TEST", ts.Value);
            Assert.AreEqual(typeof(string), ts.ValueType);
        }
コード例 #9
0
        public async Task A140_Receive_OK_SystemUser()
        {
            EventSubscriberHost.SystemUsername = "******";
            var ts = new TestSub(RunAsUser.System);
            var ed = new EventData {
                Subject = "Test.Blah.123", Action = "CREATE", Username = "******"
            };
            await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), ts)).ReceiveAsync(ed);

            Assert.IsTrue(ts.MessageReceived);
            Assert.AreEqual("SystemUser", ts.Username);
        }
コード例 #10
0
        public async Task B130_Receive_OK_OriginatingUser()
        {
            var ts = new TestSubS(RunAsUser.Originating);
            var ed = new EventData <string> {
                Subject = "Test.Blah.123", Action = "CREATE", Username = "******", Value = "TEST"
            };
            await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), ts)).ReceiveAsync(ed);

            Assert.IsTrue(ts.MessageReceived);
            Assert.AreEqual("TestUser", ts.Username);
            Assert.AreEqual("TEST", ts.Value);
            Assert.AreEqual(typeof(string), ts.ValueType);
        }
コード例 #11
0
        public async Task B140_Receive_OK_SystemUser()
        {
            EventSubscriberHost.SystemUsername = "******";
            var ts = new TestSubS(RunAsUser.System);
            var ed = new EventData <string> {
                Subject = "Test.Blah.123", Action = "UPDATE", Username = "******", Value = "TEST"
            };
            await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), ts).UseLoggerForAuditing()).ReceiveAsync(ed);

            Assert.IsTrue(ts.MessageReceived);
            Assert.AreEqual("SystemUser", ts.Username);
            Assert.AreEqual("TEST", ts.Value);
            Assert.AreEqual(typeof(string), ts.ValueType);
        }
コード例 #12
0
        public async Task A160_Receive_OK_ExceptionStop()
        {
            var ts = new TestSub(@throw: true, unhandledExceptionHandling: UnhandledExceptionHandling.Stop);
            var ed = new EventData {
                Subject = "Test.Blah.123", Action = "CREATE", Username = "******"
            };

            try
            {
                await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), ts).UseLoggerForAuditing()).ReceiveAsync(ed);
            }
            catch (DivideByZeroException)
            {
                Assert.IsTrue(ts.MessageReceived);
                return;
            }

            Assert.Fail();
        }
コード例 #13
0
        public async Task A120_SkipAudit()
        {
            var tn = GetConfig().GetValue <string>("EventHubPoisonMessageTable");

            PoisonMessagePersistence.DefaultTableName = tn;

            var cs  = GetConfig().GetValue <string>("AzureWebJobsStorage");
            var cst = await PoisonMessagePersistence.GetPoisonMessageSkippedTable(cs);

            var smc = (await GetSkippedMessages(cst)).Count;

            var pp = new PoisonMessagePersistence(new PoisonMessageCreatePersistenceArgs
            {
                Config  = GetConfig(),
                Context = ResilientEventHubProcessorTest.CreatePartitionContext(),
                Logger  = TestSetUp.CreateLogger(),
                Options = ResilientEventHubProcessorTest.CreateOptions()
            });

            var ed = CreateEventData("200", 2);

            await pp.SkipAuditAsync(ed, "Explicit audit.");

            var smca = (await GetSkippedMessages(cst)).Count;

            Assert.AreEqual(smc + 1, smca);

            var msgs = await PoisonMessagePersistence.GetAllMessagesAsync(cst);

            var msg = msgs.Last();

            Assert.AreEqual("path-eventhub", msg.PartitionKey);
            Assert.IsTrue(msg.RowKey.EndsWith("consumergroup-0"));
            Assert.AreEqual("200", msg.Body);
            Assert.AreEqual("Explicit audit.", msg.Exception);
            Assert.AreEqual("200", msg.Offset);
            Assert.AreEqual(2, msg.SequenceNumber);
            Assert.AreEqual(false, msg.SkipMessage);
            Assert.AreEqual("ns.class", msg.FunctionType);
            Assert.AreEqual("testfunc", msg.FunctionName);
            Assert.IsNotNull(msg.SkippedTimeUtc);
        }
コード例 #14
0
        public async Task B160_Receive_OK_ExceptionStop()
        {
            var ts = new TestSubS(@throw: true, unhandledExceptionHandling: UnhandledExceptionHandling.Stop);
            var ed = new EventData <string> {
                Subject = "Test.Blah.123", Action = "CREATE", Username = "******", Value = "TEST"
            };

            try
            {
                await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), ts)).ReceiveAsync(ed);
            }
            catch (DivideByZeroException)
            {
                Assert.IsTrue(ts.MessageReceived);
                Assert.AreEqual("TEST", ts.Value);
                Assert.AreEqual(typeof(string), ts.ValueType);
                return;
            }

            Assert.Fail();
        }
コード例 #15
0
        public async Task A110_PoisonMaxAttempts()
        {
            var cfg = GetConfig();
            var lgr = TestSetUp.CreateLogger();

            var asr = new EventHubAzureStorageRepository(cfg.GetWebJobsConnectionString(ConnectionStringNames.Storage))
            {
                PoisonTableName = cfg.GetValue <string>("EventHubPoisonMessagesTable"),
                AuditTableName  = cfg.GetValue <string>("EventHubAuditMessagesTable")
            };

            ((IUseLogger)asr).UseLogger(lgr);

            // Make sure there are no AuditRecords to begin with.
            var pmt = await asr.GetPoisonMessageTableAsync().ConfigureAwait(false);

            await DeleteAuditRecords(pmt).ConfigureAwait(false);

            var amt = await asr.GetAuditMessageTableAsync().ConfigureAwait(false);

            await DeleteAuditRecords(amt).ConfigureAwait(false);

            var ed = await CreateEventDataAsync(100, 1);

            // Add events as poison.
            await asr.MarkAsPoisonedAsync(ed, HandleResult(Result.DataNotFound("Data not found.")), 3).ConfigureAwait(false);

            var ar = await asr.CheckPoisonedAsync(ed).ConfigureAwait(false);

            Assert.AreEqual(PoisonMessageAction.PoisonRetry, ar.Action);
            Assert.AreEqual(1, ar.Attempts);

            await asr.MarkAsPoisonedAsync(ed, HandleResult(Result.DataNotFound("Data not found.")), 3).ConfigureAwait(false);

            ar = await asr.CheckPoisonedAsync(ed).ConfigureAwait(false);

            Assert.AreEqual(PoisonMessageAction.PoisonRetry, ar.Action);
            Assert.AreEqual(2, ar.Attempts);

            await asr.MarkAsPoisonedAsync(ed, HandleResult(Result.DataNotFound("Data not found.")), 3).ConfigureAwait(false);

            ar = await asr.CheckPoisonedAsync(ed).ConfigureAwait(false);

            Assert.AreEqual(PoisonMessageAction.NotPoison, ar.Action);
            Assert.AreEqual(0, ar.Attempts);

            var ear = (await GetAuditRecords(amt).ConfigureAwait(false)).Last();

            Assert.AreEqual("testhub-$Default", ear.PartitionKey);
            Assert.IsTrue(ear.RowKey.EndsWith("-0"));
            Assert.NotNull(ear.Body);
            Assert.NotNull(ear.PoisonedTimeUtc);
            Assert.NotNull(ear.SkippedTimeUtc);
            Assert.AreEqual("PoisonMaxAttempts", ear.Status);
            Assert.AreEqual("EventData was identified as Poison and has been configured to automatically SkipMessage after 3 attempts; this event is skipped (i.e. not processed).", ear.Reason);
            Assert.AreEqual("DataNotFound", ear.OriginatingStatus);
            Assert.AreEqual("Data not found.", ear.OriginatingReason);
            Assert.AreEqual(100, ear.Offset);
            Assert.AreEqual(1, ear.SequenceNumber);
            Assert.AreEqual(false, ear.SkipProcessing);
            Assert.AreEqual(3, ear.Attempts);
        }
コード例 #16
0
 private ResilientEventHubProcessor CreateProcessor(FuncExe exe, List <EventHubs.EventData> checkpoints) => new ResilientEventHubProcessor(exe, CreateOptions(), null, TestSetUp.CreateLogger())
 {
     Checkpointer = (c, e) =>
     {
         checkpoints.Add(e);
         return(Task.CompletedTask);
     }
 };
コード例 #17
0
 public void Ctor_NoSubscribersInAssembly()
 {
     ExpectException.Throws <ArgumentException>("*", () => new EventSubscriberHostArgs(TestSetUp.CreateLogger(), typeof(TestAttribute).Assembly));
 }
コード例 #18
0
 public void C120_DoNotAllowMultipleMessages()
 {
     ExpectException.Throws <EventSubscriberException>(
         "The EventDataSubscriberHost does not AllowMultipleMessages; there were 2 event messages.",
         async() => await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), new TestSub()).UseLoggerForAuditing()).ReceiveAsync(new EventData(), new EventData()));
 }
コード例 #19
0
        public void C110_TooManySubjectSubscribers()
        {
            var ed = new EventData <string> {
                Subject = "Test.Blah.123", Action = "CREATE", Username = "******", Value = "TEST"
            };

            ExpectException.Throws <EventSubscriberException>(
                "There are 2 IEventSubscriber instances subscribing to Subject 'Test.Blah.123' and Action 'CREATE'; there must be only a single subscriber.",
                async() => await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), new TestSub(), new TestSubS()).UseLoggerForAuditing()).ReceiveAsync(ed));
        }
コード例 #20
0
        public async Task A100_EndToEnd()
        {
            var tn = GetConfig().GetValue <string>("EventHubPoisonMessageTable");

            PoisonMessagePersistence.DefaultTableName = tn;

            var cs = GetConfig().GetValue <string>("AzureWebJobsStorage");
            var ct = await PoisonMessagePersistence.GetPoisonMessageTable(cs);

            var cst = await PoisonMessagePersistence.GetPoisonMessageSkippedTable(cs);

            var smc = (await GetSkippedMessages(cst)).Count;

            // Make sure there are no messages to begin with.
            var msgs = await PoisonMessagePersistence.GetAllMessagesAsync(ct);

            foreach (var m in msgs)
            {
                await ct.ExecuteAsync(TableOperation.Delete(m));
            }

            var pp = new PoisonMessagePersistence(new PoisonMessageCreatePersistenceArgs
            {
                Config  = GetConfig(),
                Context = ResilientEventHubProcessorTest.CreatePartitionContext(),
                Logger  = TestSetUp.CreateLogger(),
                Options = ResilientEventHubProcessorTest.CreateOptions()
            });

            var ed = CreateEventData("100", 1);

            // Checking and removing with unknown is a-ok.
            Assert.AreEqual(PoisonMessageAction.NotPoison, await pp.CheckAsync(ed));
            await pp.RemoveAsync(ed, PoisonMessageAction.NotPoison);

            Assert.AreEqual(smc, (await GetSkippedMessages(cst)).Count);

            // Add an event as poison.
            await pp.SetAsync(ed, new DivideByZeroException("My bad."));

            Assert.AreEqual(PoisonMessageAction.PoisonRetry, await pp.CheckAsync(ed));
            Assert.AreEqual(smc, (await GetSkippedMessages(cst)).Count);

            msgs = await PoisonMessagePersistence.GetAllMessagesAsync(ct);

            Assert.AreEqual(1, msgs.Count());

            var msg = msgs.First();

            Assert.AreEqual("path-eventhub", msg.PartitionKey);
            Assert.AreEqual("consumergroup-0", msg.RowKey);
            Assert.AreEqual("100", msg.Body);
            Assert.AreEqual("System.DivideByZeroException: My bad.", msg.Exception);
            Assert.AreEqual("100", msg.Offset);
            Assert.AreEqual(1, msg.SequenceNumber);
            Assert.AreEqual(false, msg.SkipMessage);
            Assert.AreEqual("ns.class", msg.FunctionType);
            Assert.AreEqual("testfunc", msg.FunctionName);

            // Update to skip.
            await PoisonMessagePersistence.SkipMessageAsync(ct, msg.PartitionKey, msg.RowKey);

            Assert.AreEqual(PoisonMessageAction.PoisonSkip, await pp.CheckAsync(ed));
            Assert.AreEqual(smc, (await GetSkippedMessages(cst)).Count);

            msgs = await PoisonMessagePersistence.GetAllMessagesAsync(ct);

            Assert.AreEqual(1, msgs.Count());

            msg = msgs.First();
            Assert.AreEqual("path-eventhub", msg.PartitionKey);
            Assert.AreEqual("consumergroup-0", msg.RowKey);
            Assert.AreEqual("100", msg.Body);
            Assert.AreEqual("System.DivideByZeroException: My bad.", msg.Exception);
            Assert.AreEqual("100", msg.Offset);
            Assert.AreEqual(1, msg.SequenceNumber);
            Assert.AreEqual(true, msg.SkipMessage);
            Assert.AreEqual("ns.class", msg.FunctionType);
            Assert.AreEqual("testfunc", msg.FunctionName);
            Assert.IsNull(msg.SkippedTimeUtc);

            // Remove the poison as no longer poison.
            await pp.RemoveAsync(ed, PoisonMessageAction.NotPoison);

            Assert.AreEqual(PoisonMessageAction.NotPoison, await pp.CheckAsync(ed));
            Assert.AreEqual(smc, (await GetSkippedMessages(cst)).Count);

            msgs = await PoisonMessagePersistence.GetAllMessagesAsync(ct);

            Assert.AreEqual(0, msgs.Count());

            // Create a new poison message.
            ed = CreateEventData("200", 2);
            await pp.SetAsync(ed, new DivideByZeroException("My bad."));

            Assert.AreEqual(PoisonMessageAction.PoisonRetry, await pp.CheckAsync(ed));
            Assert.AreEqual(smc, (await GetSkippedMessages(cst)).Count);

            msgs = await PoisonMessagePersistence.GetAllMessagesAsync(ct);

            Assert.AreEqual(1, msgs.Count());
            msg = msgs.First();

            // Remove the poison as skipped (poison).
            await pp.RemoveAsync(ed, PoisonMessageAction.PoisonSkip);

            Assert.AreEqual(PoisonMessageAction.NotPoison, await pp.CheckAsync(ed));

            var sms = await GetSkippedMessages(cst);

            Assert.AreEqual(smc + 1, sms.Count);

            var sm = sms.Where(pm => pm.PartitionKey == msg.PartitionKey && pm.RowKey.EndsWith(msg.RowKey)).OrderByDescending(pm => pm.RowKey).FirstOrDefault();

            Assert.IsNotNull(sm.SkippedTimeUtc);
        }
コード例 #21
0
        public async Task A120_PoisonMismatch()
        {
            var cfg = GetConfig();
            var lgr = TestSetUp.CreateLogger();

            var asr = new EventHubAzureStorageRepository(cfg.GetWebJobsConnectionString(ConnectionStringNames.Storage))
            {
                PoisonTableName = cfg.GetValue <string>("EventHubPoisonMessagesTable"),
                AuditTableName  = cfg.GetValue <string>("EventHubAuditMessagesTable")
            };

            ((IUseLogger)asr).UseLogger(lgr);

            // Make sure there are no AuditRecords to begin with.
            var pmt = await asr.GetPoisonMessageTableAsync().ConfigureAwait(false);

            await DeleteAuditRecords(pmt).ConfigureAwait(false);

            var amt = await asr.GetAuditMessageTableAsync().ConfigureAwait(false);

            await DeleteAuditRecords(amt).ConfigureAwait(false);

            var ed = await CreateEventDataAsync(100, 1);

            // Add an event as poison.
            await asr.MarkAsPoisonedAsync(ed, HandleResult(Result.DataNotFound("Data not found."))).ConfigureAwait(false);

            var ar = await asr.CheckPoisonedAsync(ed).ConfigureAwait(false);

            Assert.AreEqual(PoisonMessageAction.PoisonRetry, ar.Action);
            Assert.AreEqual(1, ar.Attempts);
            Assert.AreEqual(1, (await GetAuditRecords(pmt).ConfigureAwait(false)).Count);
            Assert.AreEqual(0, (await GetAuditRecords(amt).ConfigureAwait(false)).Count);

            var ear = (await GetAuditRecords(pmt).ConfigureAwait(false)).First();

            Assert.AreEqual("testhub-$Default", ear.PartitionKey);
            Assert.AreEqual("0", ear.RowKey);
            Assert.NotNull(ear.Body);
            Assert.NotNull(ear.PoisonedTimeUtc);
            Assert.IsNull(ear.SkippedTimeUtc);
            Assert.AreEqual("DataNotFound", ear.Status);
            Assert.AreEqual("Data not found.", ear.Reason);
            Assert.IsNull(ear.OriginatingStatus);
            Assert.IsNull(ear.OriginatingReason);
            Assert.AreEqual(100, ear.Offset);
            Assert.AreEqual(1, ear.SequenceNumber);
            Assert.AreEqual(false, ear.SkipProcessing);
            Assert.AreEqual(1, ear.Attempts);

            // Pretend to check a different event to that poisoned.
            ed = await CreateEventDataAsync(200, 2);

            ar = await asr.CheckPoisonedAsync(ed).ConfigureAwait(false);

            Assert.AreEqual(PoisonMessageAction.NotPoison, ar.Action);
            Assert.AreEqual(0, ar.Attempts);
            Assert.AreEqual(0, (await GetAuditRecords(pmt)).Count);
            Assert.AreEqual(1, (await GetAuditRecords(amt)).Count);

            ear = (await GetAuditRecords(amt).ConfigureAwait(false)).First();
            Assert.AreEqual("testhub-$Default", ear.PartitionKey);
            Assert.IsTrue(ear.RowKey.EndsWith("-0"));
            Assert.NotNull(ear.Body);
            Assert.NotNull(ear.PoisonedTimeUtc);
            Assert.IsNull(ear.SkippedTimeUtc);
            Assert.AreEqual("PoisonMismatch", ear.Status);
            Assert.AreEqual("Current EventData (Seq#: '2' Offset#: '200') being processed is out of sync with previous Poison (Seq#: '1' Offset#: '100'); current assumed correct with previous Poison now deleted.", ear.Reason);
            Assert.AreEqual("DataNotFound", ear.OriginatingStatus);
            Assert.AreEqual("Data not found.", ear.OriginatingReason);
            Assert.AreEqual(100, ear.Offset);
            Assert.AreEqual(1, ear.SequenceNumber);
            Assert.AreEqual(false, ear.SkipProcessing);
            Assert.AreEqual(1, ear.Attempts);

            await Task.CompletedTask;
        }
コード例 #22
0
 public void Ctor_NoIEventSubscriber()
 {
     ExpectException.Throws <ArgumentNullException>("*", () => new EventSubscriberHostArgs(TestSetUp.CreateLogger(), (IEventSubscriber[])null));
     ExpectException.Throws <ArgumentException>("*", () => new EventSubscriberHostArgs(TestSetUp.CreateLogger(), new IEventSubscriber[] { }));
 }
コード例 #23
0
        public async Task A100_EndToEnd()
        {
            var cfg = GetConfig();
            var lgr = TestSetUp.CreateLogger();

            var asr = new EventHubAzureStorageRepository(cfg.GetWebJobsConnectionString(ConnectionStringNames.Storage))
            {
                PoisonTableName = cfg.GetValue <string>("EventHubPoisonMessagesTable"),
                AuditTableName  = cfg.GetValue <string>("EventHubAuditMessagesTable")
            };

            ((IUseLogger)asr).UseLogger(lgr);

            // Make sure there are no AuditRecords to begin with.
            var pmt = await asr.GetPoisonMessageTableAsync().ConfigureAwait(false);

            await DeleteAuditRecords(pmt).ConfigureAwait(false);

            var amt = await asr.GetAuditMessageTableAsync().ConfigureAwait(false);

            await DeleteAuditRecords(amt).ConfigureAwait(false);

            var ed = await CreateEventDataAsync(100, 1);

            // Checking and removing with unknown is a-ok.
            var ar = await asr.CheckPoisonedAsync(ed).ConfigureAwait(false);

            Assert.AreEqual(PoisonMessageAction.NotPoison, ar.Action);
            Assert.AreEqual(0, ar.Attempts);
            await asr.RemovePoisonedAsync(ed).ConfigureAwait(false);

            Assert.AreEqual(0, (await GetAuditRecords(pmt)).Count);
            Assert.AreEqual(0, (await GetAuditRecords(amt)).Count);

            // Add an event as poison.
            await asr.MarkAsPoisonedAsync(ed, HandleResult(Result.DataNotFound("Data not found."))).ConfigureAwait(false);

            ar = await asr.CheckPoisonedAsync(ed).ConfigureAwait(false);

            Assert.AreEqual(PoisonMessageAction.PoisonRetry, ar.Action);
            Assert.AreEqual(1, ar.Attempts);
            Assert.AreEqual(1, (await GetAuditRecords(pmt).ConfigureAwait(false)).Count);
            Assert.AreEqual(0, (await GetAuditRecords(amt).ConfigureAwait(false)).Count);

            var ear = (await GetAuditRecords(pmt).ConfigureAwait(false)).First();

            Assert.AreEqual("testhub-$Default", ear.PartitionKey);
            Assert.AreEqual("0", ear.RowKey);
            Assert.NotNull(ear.Body);
            Assert.NotNull(ear.PoisonedTimeUtc);
            Assert.IsNull(ear.SkippedTimeUtc);
            Assert.AreEqual("DataNotFound", ear.Status);
            Assert.AreEqual("Data not found.", ear.Reason);
            Assert.IsNull(ear.OriginatingStatus);
            Assert.IsNull(ear.OriginatingReason);
            Assert.AreEqual(100, ear.Offset);
            Assert.AreEqual(1, ear.SequenceNumber);
            Assert.AreEqual(false, ear.SkipProcessing);
            Assert.AreEqual(1, ear.Attempts);

            // Update again an event as poison.
            await asr.MarkAsPoisonedAsync(ed, HandleResult(Result.InvalidData("Bad data."))).ConfigureAwait(false);

            ar = await asr.CheckPoisonedAsync(ed).ConfigureAwait(false);

            Assert.AreEqual(PoisonMessageAction.PoisonRetry, ar.Action);
            Assert.AreEqual(2, ar.Attempts);
            Assert.AreEqual(1, (await GetAuditRecords(pmt).ConfigureAwait(false)).Count);
            Assert.AreEqual(0, (await GetAuditRecords(amt).ConfigureAwait(false)).Count);

            ear = (await GetAuditRecords(pmt).ConfigureAwait(false)).First();
            Assert.AreEqual("testhub-$Default", ear.PartitionKey);
            Assert.AreEqual("0", ear.RowKey);
            Assert.NotNull(ear.Body);
            Assert.NotNull(ear.PoisonedTimeUtc);
            Assert.IsNull(ear.SkippedTimeUtc);
            Assert.AreEqual("InvalidData", ear.Status);
            Assert.AreEqual("Bad data.", ear.Reason);
            Assert.IsNull(ear.OriginatingStatus);
            Assert.IsNull(ear.OriginatingReason);
            Assert.AreEqual(100, ear.Offset);
            Assert.AreEqual(1, ear.SequenceNumber);
            Assert.AreEqual(false, ear.SkipProcessing);
            Assert.AreEqual(2, ear.Attempts);

            // Update to skip.
            await asr.SkipPoisonedAsync(ed).ConfigureAwait(false);

            Assert.AreEqual(1, (await GetAuditRecords(pmt).ConfigureAwait(false)).Count);
            Assert.AreEqual(0, (await GetAuditRecords(amt).ConfigureAwait(false)).Count);

            ear = (await GetAuditRecords(pmt).ConfigureAwait(false)).First();
            Assert.AreEqual("testhub-$Default", ear.PartitionKey);
            Assert.AreEqual("0", ear.RowKey);
            Assert.NotNull(ear.Body);
            Assert.NotNull(ear.PoisonedTimeUtc);
            Assert.IsNull(ear.SkippedTimeUtc);
            Assert.AreEqual("InvalidData", ear.Status);
            Assert.AreEqual("Bad data.", ear.Reason);
            Assert.IsNull(ear.OriginatingStatus);
            Assert.IsNull(ear.OriginatingReason);
            Assert.AreEqual(100, ear.Offset);
            Assert.AreEqual(1, ear.SequenceNumber);
            Assert.AreEqual(true, ear.SkipProcessing);
            Assert.AreEqual(2, ear.Attempts);

            // Check poisoned which will remove and audit.
            ar = await asr.CheckPoisonedAsync(ed).ConfigureAwait(false);

            Assert.AreEqual(PoisonMessageAction.PoisonSkip, ar.Action);
            Assert.AreEqual(2, ar.Attempts);
            Assert.AreEqual(0, (await GetAuditRecords(pmt).ConfigureAwait(false)).Count);
            Assert.AreEqual(1, (await GetAuditRecords(amt).ConfigureAwait(false)).Count);

            ear = (await GetAuditRecords(amt).ConfigureAwait(false)).Last();
            Assert.AreEqual("testhub-$Default", ear.PartitionKey);
            Assert.IsTrue(ear.RowKey.EndsWith("-0"));
            Assert.NotNull(ear.Body);
            Assert.NotNull(ear.PoisonedTimeUtc);
            Assert.NotNull(ear.SkippedTimeUtc);
            Assert.AreEqual("PoisonSkipped", ear.Status);
            Assert.AreEqual("EventData was identified as Poison and was marked as SkipMessage; this event is skipped (i.e. not processed).", ear.Reason);
            Assert.AreEqual("InvalidData", ear.OriginatingStatus);
            Assert.AreEqual("Bad data.", ear.OriginatingReason);
            Assert.AreEqual(100, ear.Offset);
            Assert.AreEqual(1, ear.SequenceNumber);
            Assert.AreEqual(true, ear.SkipProcessing);
            Assert.AreEqual(2, ear.Attempts);
        }
コード例 #24
0
        private EventDataSubscriberHost CreateTestHost <T>(Func <T> create) where T : class
        {
            var sp = TestSetUp.CreateServiceProvider(sc => sc.AddTransient(_ => create()));

            return(new EventDataSubscriberHost(EventSubscriberHostArgs.Create(typeof(T)).UseServiceProvider(sp)).UseLogger(TestSetUp.CreateLogger()));
        }