Exemplo n.º 1
1
 public void TestConcurrency()
 {
     var queue = new Loggers.Queue();
      var props = new List<String>()
      {
     "Event.Type",
     "Event.Source",
     "Event.Message",
     "Event.Exception",
     "Operation.ID",
     "Operation.Version",
     "Operation.Action",
     "Operation.Name",
     "Operation.From",
     "Operation.To",
     "Operation.Duration"
      };
      using (
     Log.RegisterInstance(
        new Instance()
        {
           Logger = queue,
           Synchronous = false,
           Buffer = 0,
           Properties = props
        }
     )
      )
      {
     Event evt;
     // client-side logging
     using (var server = StartService(false))
     using (var client = ConnectSimplex(true))
        Parallel.For(0, TestParallelIterations,
           i => client.Server.AutoLog()
        );
     Log.Flush();
     for (Int32 i = 0; i < TestParallelIterations; i++)
     {
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(ISimplexServer));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "AutoLog");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
     }
     Assert.IsFalse(queue.Dequeue().Any());
     // service-side logging
     using (var server = StartService(true))
     using (var client = ConnectSimplex(false))
        Parallel.For(0, TestParallelIterations,
           i => client.Server.AutoLog()
        );
     Log.Flush();
     for (Int32 i = 0; i < TestParallelIterations; i++)
     {
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(Server));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "AutoLog");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
     }
     Assert.IsFalse(queue.Dequeue().Any());
     // client-side callback logging
     using (var server = StartService(false))
     using (var client = ConnectDuplex(true))
        Parallel.For(0, TestParallelIterations,
           i => client.Server.CallbackAutoLog()
        );
     Log.Flush();
     for (Int32 i = 0; i < 2 * TestParallelIterations; i++)
     {
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
        if ((Type)evt["Event.Source"] == typeof(ICallback))
           Assert.AreEqual(evt["Operation.Name"], "AutoLog");
        else if ((Type)evt["Event.Source"] == typeof(IDuplexServer))
           Assert.AreEqual(evt["Operation.Name"], "CallbackAutoLog");
        else
           Assert.Fail("Invalid event source {0}", evt["Event.Source"]);
     }
     Assert.IsFalse(queue.Dequeue().Any());
     // service-side callback logging
     using (var server = StartService(true))
     using (var client = ConnectDuplex(false))
        Parallel.For(0, TestParallelIterations,
           i => client.Server.CallbackAutoLog()
        );
     Log.Flush();
     for (Int32 i = 0; i < 2 * TestParallelIterations; i++)
     {
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
        if ((Type)evt["Event.Source"] == typeof(ICallback))
           Assert.AreEqual(evt["Operation.Name"], "AutoLog");
        else if ((Type)evt["Event.Source"] == typeof(Server))
           Assert.AreEqual(evt["Operation.Name"], "CallbackAutoLog");
        else
           Assert.Fail("Invalid event source {0}", evt["Event.Source"]);
     }
     Assert.IsFalse(queue.Dequeue().Any());
      }
 }
Exemplo n.º 2
0
 public void TestConcurrency()
 {
     // start up the next log instance
      var queue = new Loggers.Queue();
      var props = new List<String>()
      {
     "Request.Duration"
      };
      using (
     Log.RegisterInstance(
        new Instance()
        {
           Logger = queue,
           Synchronous = false,
           Buffer = 0,
           Properties = props
        }
     )
      )
      {
     Log log = new Log(GetType());
     Parallel.For(0, TestParallelIterations,
        i => new MockHttp.Application().DispatchRequest()
     );
     Log.Flush();
     // verify event properties
     for (Int32 i = 0; i < TestParallelIterations; i++)
     {
        var evt = queue.Dequeue().First();
        Assert.IsTrue((Int64)evt["Request.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Request.Duration"] < 10000000);
     }
     Assert.IsFalse(queue.Dequeue().Any());
      }
 }
Exemplo n.º 3
0
 public void TestConcurrency()
 {
     // start up the next log instance
      var queue = new Loggers.Queue();
      var props = new List<String>()
      {
     "Http.Uri",
     "Http.Path",
     "Http.Method",
     "Http.StatusCode",
     "Http.Status",
     "Http.Timestamp",
     "Http.User",
     "Http.SessionID",
     "Http.IPAddress",
     "Http.Request.TestHeader",
     "Http.Session.TestVariable"
      };
      using (
     Log.RegisterInstance(
        new Instance()
        {
           Logger = queue,
           Synchronous = false,
           Buffer = 0,
           Properties = props
        }
     )
      )
      {
     Log log = new Log(GetType());
     Parallel.For(0, TestParallelIterations,
        i =>
        {
           HttpContext.Current = MockHttp.CreateHttpContext();
           log.Info("test");
        }
     );
     Log.Flush();
     // verify event properties
     for (Int32 i = 0; i < TestParallelIterations; i++)
     {
        var evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Http.Uri"], "http://www.tempuri.org/?Test=Value");
        Assert.AreEqual(evt["Http.Path"], "/?Test=Value");
        Assert.AreEqual(evt["Http.Method"], "HEAD");
        Assert.AreEqual(evt["Http.StatusCode"], 200);
        Assert.AreEqual(evt["Http.Status"], "200 OK");
        Assert.IsTrue((DateTime)evt["Http.Timestamp"] <= DateTime.Now);
        Assert.AreEqual(evt["Http.User"], "testuser");
        Assert.IsNotNull(evt["Http.SessionID"]);
        Assert.AreEqual(evt["Http.IPAddress"], Dns.GetHostAddresses("localhost")[0].ToString());
        Assert.AreEqual(evt["Http.Request.TestHeader"], "TestHeaderValue");
        Assert.AreEqual(evt["Http.Session.TestVariable"], "TestVariableValue");
     }
     Assert.IsFalse(queue.Dequeue().Any());
      }
 }
Exemplo n.º 4
0
 public void TestActionLog()
 {
     var queue = new Loggers.Queue();
      var props = new List<String>()
      {
     "Event.Type",
     "Event.Source",
     "Event.Message",
     "Event.Exception",
     "Action.Controller",
     "Action.Name",
     "Action.Duration",
     "Action.RouteParams"
      };
      using (
     Log.RegisterInstance(
        new Instance()
        {
           Logger = queue,
           Synchronous = true,
           Buffer = 0,
           Properties = props
        }
     )
      )
      {
     var controllerContext = CreateControllerContext();
     var actionDescriptor = CreateActionDescriptor();
     // enabled log
     for (Int32 i = 0; i < TestIterations; i++)
     {
        var actionContext = new HttpActionContext(controllerContext, actionDescriptor);
        new LogAttribute().OnActionExecuting(actionContext);
        System.Threading.Thread.Sleep(1);   // ensure duration > 0
        new LogAttribute().OnActionExecuted(
           new HttpActionExecutedContext(actionContext, null)
        );
     }
     for (Int32 i = 0; i < TestIterations; i++)
     {
        var evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(TestController));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.AreEqual(evt["Action.Controller"], "Test");
        Assert.AreEqual(evt["Action.Name"], "GetTest");
        Assert.IsTrue((Int64)evt["Action.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Action.Duration"] < 10000000);
        Assert.AreEqual(evt["Action.RouteParams"], "TestRouteParam=TestRouteValue");
     }
     Assert.IsFalse(queue.Dequeue().Any());
     // disabled log
     for (Int32 i = 0; i < TestIterations; i++)
     {
        var actionContext = new HttpActionContext(controllerContext, actionDescriptor);
        new LogAttribute() { Disabled = true }.OnActionExecuting(actionContext);
        new LogAttribute() { Disabled = true }.OnActionExecuted(
           new HttpActionExecutedContext(actionContext, null)
        );
     }
     Assert.IsFalse(queue.Dequeue().Any());
      }
 }
Exemplo n.º 5
0
 public void TestException()
 {
     var queue = new Loggers.Queue();
      var props = new List<String>()
      {
     "Event.Type",
     "Event.Source",
     "Event.Message",
     "Event.Exception",
     "Action.Controller",
     "Action.Name",
     "Action.Duration",
     "Action.RouteParams"
      };
      using (
     Log.RegisterInstance(
        new Instance()
        {
           Logger = queue,
           Synchronous = true,
           Buffer = 0,
           Properties = props
        }
     )
      )
      {
     var controllerContext = CreateControllerContext();
     var actionDescriptor = CreateActionDescriptor();
     for (Int32 i = 0; i < TestIterations; i++)
     {
        new LogAttribute().OnActionExecuting(
           new ActionExecutingContext(
              controllerContext,
              actionDescriptor,
              new Dictionary<String, Object>()
           )
        );
        System.Threading.Thread.Sleep(1);   // ensure duration > 0
        new LogAttribute().OnActionExecuted(
           new ActionExecutedContext(
              controllerContext,
              actionDescriptor,
              false,
              new Exception("testmessage")
           )
        );
     }
     for (Int32 i = 0; i < TestIterations; i++)
     {
        var evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(TestController));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.AreEqual(evt["Action.Controller"], "Test");
        Assert.AreEqual(evt["Action.Name"], "Test");
        Assert.IsTrue((Int64)evt["Action.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Action.Duration"] < 10000000);
        Assert.AreEqual(evt["Action.RouteParams"], "TestRouteParam=TestRouteValue");
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Error);
        Assert.AreEqual(evt["Event.Source"], typeof(TestController));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsInstanceOfType(evt["Event.Exception"], typeof(Exception));
        Assert.AreEqual(((Exception)evt["Event.Exception"]).Message, "testmessage");
        Assert.AreEqual(evt["Action.Controller"], "Test");
        Assert.AreEqual(evt["Action.Name"], "Test");
        Assert.IsTrue((Int64)evt["Action.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Action.Duration"] < 10000000);
        Assert.AreEqual(evt["Action.RouteParams"], "TestRouteParam=TestRouteValue");
     }
     Assert.IsFalse(queue.Dequeue().Any());
      }
 }
Exemplo n.º 6
0
 public void TestBehavior()
 {
     var queue = new Loggers.Queue();
      var props = new List<String>()
      {
     "Event.Type",
     "Event.Source",
     "Event.Message",
     "Event.Exception",
     "Operation.ID",
     "Operation.Version",
     "Operation.Action",
     "Operation.Name",
     "Operation.From",
     "Operation.To",
     "Operation.Duration"
      };
      using (
     Log.RegisterInstance(
        new Instance()
        {
           Logger = queue,
           Synchronous = true,
           Buffer = 0,
           Properties = props
        }
     )
      )
      {
     Event evt;
     // client-side logging
     using (var server = StartService(false))
     using (var client = ConnectSimplex(true))
        for (Int32 i = 0; i < TestIterations; i++)
           client.Server.AutoLog();
     for (Int32 i = 0; i < TestIterations; i++)
     {
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(ISimplexServer));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "AutoLog");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
     }
     Assert.IsFalse(queue.Dequeue().Any());
     // service-side logging
     using (var server = StartService(true))
     using (var client = ConnectSimplex(false))
        for (Int32 i = 0; i < TestIterations; i++)
           client.Server.AutoLog();
     for (Int32 i = 0; i < TestIterations; i++)
     {
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(Server));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "AutoLog");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
     }
     Assert.IsFalse(queue.Dequeue().Any());
     // client-side logging (one-way)
     using (var server = StartService(false))
     using (var client = ConnectSimplex(true))
        for (Int32 i = 0; i < TestIterations; i++)
           client.Server.FireAndForget();
     for (Int32 i = 0; i < TestIterations; i++)
     {
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(ISimplexServer));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "FireAndForget");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] >= 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
     }
     Assert.IsFalse(queue.Dequeue().Any());
     // client-side exception logging
     using (var server = StartService(false))
        for (Int32 i = 0; i < TestIterations; i++)
           using (var client = ConnectSimplex(true))
           {
              try
              {
                 client.Server.Throw("test");
                 Assert.Fail("Expected: exception");
              }
              catch { }
           }
     for (Int32 i = 0; i < TestIterations; i++)
     {
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(ISimplexServer));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "Throw");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Error);
        Assert.AreEqual(evt["Event.Source"], typeof(ISimplexServer));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNotNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "Throw");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
     }
     Assert.IsFalse(queue.Dequeue().Any());
     // service-side exception logging
     using (var server = StartService(true))
        for (Int32 i = 0; i < TestIterations; i++)
           using (var client = ConnectSimplex(false))
           {
              try
              {
                 client.Server.Throw("test");
                 Assert.Fail("Expected: exception");
              }
              catch { }
           }
     for (Int32 i = 0; i < TestIterations; i++)
     {
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(Server));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "Throw");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Error);
        Assert.AreEqual(evt["Event.Source"], typeof(Server));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNotNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "Throw");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
     }
     Assert.IsFalse(queue.Dequeue().Any());
     // client-side callback logging
     using (var server = StartService(false))
     using (var client = ConnectDuplex(true))
        for (Int32 i = 0; i < TestIterations; i++)
           client.Server.CallbackAutoLog();
     for (Int32 i = 0; i < TestIterations; i++)
     {
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(ICallback));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "AutoLog");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(IDuplexServer));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "CallbackAutoLog");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
     }
     Assert.IsFalse(queue.Dequeue().Any());
     // server-side callback logging
     using (var server = StartService(true))
     using (var client = ConnectDuplex(false))
        for (Int32 i = 0; i < TestIterations; i++)
           client.Server.CallbackAutoLog();
     for (Int32 i = 0; i < TestIterations; i++)
     {
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(ICallback));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "AutoLog");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
        evt = queue.Dequeue().First();
        Assert.AreEqual(evt["Event.Type"], EventType.Trace);
        Assert.AreEqual(evt["Event.Source"], typeof(Server));
        Assert.IsNotNull(evt["Event.Message"]);
        Assert.IsNull(evt["Event.Exception"]);
        Assert.IsNotNull(evt["Operation.ID"]);
        Assert.IsNotNull(evt["Operation.Version"]);
        Assert.IsNotNull(evt["Operation.Action"]);
        Assert.AreEqual(evt["Operation.Name"], "CallbackAutoLog");
        Assert.IsNull(evt["Operation.From"]);
        Assert.IsNotNull(evt["Operation.To"]);
        Assert.IsTrue((Int64)evt["Operation.Duration"] > 0);
        Assert.IsTrue((Int64)evt["Operation.Duration"] < 10000000);
     }
     Assert.IsFalse(queue.Dequeue().Any());
      }
 }
Exemplo n.º 7
0
 public void TestConcurrency()
 {
     var queue = new Loggers.Queue();
      var props = new List<String>()
      {
     "Event.Type",
     "Event.Source",
     "Event.Message",
     "Wcf.SessionID",
     "Wcf.LocalAddress",
     "Wcf.RemoteAddress",
      };
      using (
     Log.RegisterInstance(
        new Instance()
        {
           Logger = queue,
           Synchronous = false,
           Buffer = 0,
           Properties = props
        }
     )
      )
      {
     Event evt;
     // service context
     using (var client = new SimplexClient(binding, TestServiceUri))
     {
        Parallel.For(0, TestParallelIterations,
           i => client.Server.ManualLog("test")
        );
        Log.Flush();
        for (Int32 i = 0; i < TestParallelIterations; i++)
        {
           evt = queue.Dequeue().First();
           Assert.AreEqual(evt["Event.Type"], EventType.Info);
           Assert.AreEqual(evt["Event.Source"], typeof(Server));
           Assert.AreEqual(evt["Event.Message"], "test");
           Assert.AreEqual(evt["Wcf.SessionID"], client.Context.SessionId);
           Assert.AreEqual(evt["Wcf.LocalAddress"].ToString(), TestServiceUri);
           Assert.IsNotNull(evt["Wcf.RemoteAddress"]);
        }
     }
     Assert.IsFalse(queue.Dequeue().Any());
     // callback context
     using (var client = new DuplexClient(binding, TestServiceUri))
     {
        Parallel.For(0, TestParallelIterations,
           i => client.Server.CallbackManualLog("test")
        );
        Log.Flush();
        for (Int32 i = 0; i < TestParallelIterations; i++)
        {
           evt = queue.Dequeue().First();
           Assert.AreEqual(evt["Event.Type"], EventType.Info);
           Assert.AreEqual(evt["Event.Source"], typeof(DuplexClient.Callback));
           Assert.AreEqual(evt["Event.Message"], "test");
           Assert.AreEqual(evt["Wcf.SessionID"], client.Context.SessionId);
           Assert.IsNotNull(evt["Wcf.LocalAddress"]);
           Assert.AreEqual(evt["Wcf.RemoteAddress"].ToString(), TestServiceUri);
        }
     }
     Assert.IsFalse(queue.Dequeue().Any());
      }
 }