public void FallbackGroupTargetSyncTest1() { var myTarget1 = new MyTarget(); var myTarget2 = new MyTarget(); var myTarget3 = new MyTarget(); var wrapper = new FallbackGroupTarget() { Targets = { myTarget1, myTarget2, myTarget3 }, }; ((ISupportsInitialize)myTarget1).Initialize(); ((ISupportsInitialize)myTarget2).Initialize(); ((ISupportsInitialize)myTarget3).Initialize(); ((ISupportsInitialize)wrapper).Initialize(); List<Exception> exceptions = new List<Exception>(); // no exceptions for (int i = 0; i < 10; ++i) { wrapper.WriteLogEvent(LogEventInfo.CreateNullEvent(), exceptions.Add); } Assert.AreEqual(10, exceptions.Count); foreach (var e in exceptions) { Assert.IsNull(e); } Assert.AreEqual(10, myTarget1.WriteCount); Assert.AreEqual(0, myTarget2.WriteCount); Assert.AreEqual(0, myTarget3.WriteCount); Exception flushException = null; var flushHit = new ManualResetEvent(false); wrapper.Flush(ex => { flushException = ex; flushHit.Set(); }); flushHit.WaitOne(); if (flushException != null) { Assert.Fail(flushException.ToString()); } }
public void FallbackGroupTargetSyncTest6() { // fail once var myTarget1 = new MyTarget() { FailCounter = 10 }; var myTarget2 = new MyTarget() { FailCounter = 3 }; var myTarget3 = new MyTarget() { FailCounter = 3 }; var wrapper = new FallbackGroupTarget() { Targets = { myTarget1, myTarget2, myTarget3 }, ReturnToFirstOnSuccess = true, }; ((ISupportsInitialize)myTarget1).Initialize(); ((ISupportsInitialize)myTarget2).Initialize(); ((ISupportsInitialize)myTarget3).Initialize(); ((ISupportsInitialize)wrapper).Initialize(); List<Exception> exceptions = new List<Exception>(); // no exceptions for (int i = 0; i < 10; ++i) { wrapper.WriteLogEvent(LogEventInfo.CreateNullEvent(), exceptions.Add); } Assert.AreEqual(10, exceptions.Count); for (int i = 0; i < 10; ++i) { if (i < 3) { // for the first 3 rounds, no target is available Assert.IsNotNull(exceptions[i]); Assert.IsInstanceOfType(exceptions[i], typeof(InvalidOperationException)); Assert.AreEqual("Some failure.", exceptions[i].Message); } else { Assert.IsNull(exceptions[i]); } } Assert.AreEqual(10, myTarget1.WriteCount); Assert.AreEqual(10, myTarget2.WriteCount); Assert.AreEqual(3, myTarget3.WriteCount); Exception flushException = null; var flushHit = new ManualResetEvent(false); wrapper.Flush(ex => { flushException = ex; flushHit.Set(); }); flushHit.WaitOne(); if (flushException != null) { Assert.Fail(flushException.ToString()); } Assert.AreEqual(1, myTarget1.FlushCount); Assert.AreEqual(1, myTarget2.FlushCount); Assert.AreEqual(1, myTarget3.FlushCount); }
public void FallbackGroupTargetSyncTest4() { // fail once var myTarget1 = new MyTarget() { FailCounter = 1 }; var myTarget2 = new MyTarget(); var myTarget3 = new MyTarget(); var wrapper = new FallbackGroupTarget() { Targets = { myTarget1, myTarget2, myTarget3 }, ReturnToFirstOnSuccess = true, }; ((ISupportsInitialize)myTarget1).Initialize(); ((ISupportsInitialize)myTarget2).Initialize(); ((ISupportsInitialize)myTarget3).Initialize(); ((ISupportsInitialize)wrapper).Initialize(); List<Exception> exceptions = new List<Exception>(); // no exceptions for (int i = 0; i < 10; ++i) { wrapper.WriteLogEvent(LogEventInfo.CreateNullEvent(), exceptions.Add); } // sequence is like this: // t1(fail), t2(success), t1(success), ... t1(success) Assert.AreEqual(10, exceptions.Count); foreach (var e in exceptions) { Assert.IsNull(e); } Assert.AreEqual(10, myTarget1.WriteCount); Assert.AreEqual(1, myTarget2.WriteCount); Assert.AreEqual(0, myTarget3.WriteCount); Exception flushException = null; var flushHit = new ManualResetEvent(false); wrapper.Flush(ex => { flushException = ex; flushHit.Set(); }); flushHit.WaitOne(); if (flushException != null) { Assert.Fail(flushException.ToString()); } }