logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1166059 - in /logging/log4net/trunk/tests/src: Context/ThreadContextTest.cs Layout/PatternLayoutTest.cs Utils.cs
Date Wed, 07 Sep 2011 08:46:05 GMT
Author: bodewig
Date: Wed Sep  7 08:46:05 2011
New Revision: 1166059

URL: http://svn.apache.org/viewvc?rev=1166059&view=rev
Log:
ThreadContextTest and PatternLayoutTest influence each other via contexts, reset the contexts.
 LOG4NET-301

Modified:
    logging/log4net/trunk/tests/src/Context/ThreadContextTest.cs
    logging/log4net/trunk/tests/src/Layout/PatternLayoutTest.cs
    logging/log4net/trunk/tests/src/Utils.cs

Modified: logging/log4net/trunk/tests/src/Context/ThreadContextTest.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Context/ThreadContextTest.cs?rev=1166059&r1=1166058&r2=1166059&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/Context/ThreadContextTest.cs (original)
+++ logging/log4net/trunk/tests/src/Context/ThreadContextTest.cs Wed Sep  7 08:46:05 2011
@@ -39,11 +39,16 @@ namespace log4net.Tests.Context
 	[TestFixture]
 	public class ThreadContextTest
 	{
-		[Test]
+        [TearDown]
+        public void TearDown() {
+            Utils.RemovePropertyFromAllContexts();
+        }
+
+        [Test]
 		public void TestThreadPropertiesPattern()
 		{
 			StringAppender stringAppender = new StringAppender();
-			stringAppender.Layout = new PatternLayout("%property{prop1}");
+			stringAppender.Layout = new PatternLayout("%property{" +  Utils.PROPERTY_KEY + "}");
 
 			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
 			BasicConfigurator.Configure(rep, stringAppender);
@@ -54,13 +59,13 @@ namespace log4net.Tests.Context
 			Assert.AreEqual(SystemInfo.NullText, stringAppender.GetString(), "Test no thread properties
value set");
 			stringAppender.Reset();
 
-			ThreadContext.Properties["prop1"] = "val1";
+			ThreadContext.Properties[Utils.PROPERTY_KEY] = "val1";
 
 			log1.Info("TestMessage");
 			Assert.AreEqual("val1", stringAppender.GetString(), "Test thread properties value set");
 			stringAppender.Reset();
 
-			ThreadContext.Properties.Remove("prop1");
+			ThreadContext.Properties.Remove(Utils.PROPERTY_KEY);
 
 			log1.Info("TestMessage");
 			Assert.AreEqual(SystemInfo.NullText, stringAppender.GetString(), "Test thread properties
value removed");
@@ -71,7 +76,7 @@ namespace log4net.Tests.Context
 		public void TestThreadStackPattern()
 		{
 			StringAppender stringAppender = new StringAppender();
-			stringAppender.Layout = new PatternLayout("%property{prop1}");
+            stringAppender.Layout = new PatternLayout("%property{" + Utils.PROPERTY_KEY +
"}");
 
 			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
 			BasicConfigurator.Configure(rep, stringAppender);
@@ -82,7 +87,7 @@ namespace log4net.Tests.Context
 			Assert.AreEqual(SystemInfo.NullText, stringAppender.GetString(), "Test no thread stack
value set");
 			stringAppender.Reset();
 
-			using(ThreadContext.Stacks["prop1"].Push("val1"))
+			using(ThreadContext.Stacks[Utils.PROPERTY_KEY].Push("val1"))
 			{
 				log1.Info("TestMessage");
 				Assert.AreEqual("val1", stringAppender.GetString(), "Test thread stack value set");
@@ -98,7 +103,7 @@ namespace log4net.Tests.Context
 		public void TestThreadStackPattern2()
 		{
 			StringAppender stringAppender = new StringAppender();
-			stringAppender.Layout = new PatternLayout("%property{prop1}");
+            stringAppender.Layout = new PatternLayout("%property{" + Utils.PROPERTY_KEY +
"}");
 
 			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
 			BasicConfigurator.Configure(rep, stringAppender);
@@ -109,13 +114,13 @@ namespace log4net.Tests.Context
 			Assert.AreEqual(SystemInfo.NullText, stringAppender.GetString(), "Test no thread stack
value set");
 			stringAppender.Reset();
 
-			using(ThreadContext.Stacks["prop1"].Push("val1"))
+			using(ThreadContext.Stacks[Utils.PROPERTY_KEY].Push("val1"))
 			{
 				log1.Info("TestMessage");
 				Assert.AreEqual("val1", stringAppender.GetString(), "Test thread stack value set");
 				stringAppender.Reset();
 
-				using(ThreadContext.Stacks["prop1"].Push("val2"))
+				using(ThreadContext.Stacks[Utils.PROPERTY_KEY].Push("val2"))
 				{
 					log1.Info("TestMessage");
 					Assert.AreEqual("val1 val2", stringAppender.GetString(), "Test thread stack value pushed
2nd val");
@@ -132,7 +137,7 @@ namespace log4net.Tests.Context
 		public void TestThreadStackPatternNullVal()
 		{
 			StringAppender stringAppender = new StringAppender();
-			stringAppender.Layout = new PatternLayout("%property{prop1}");
+            stringAppender.Layout = new PatternLayout("%property{" + Utils.PROPERTY_KEY +
"}");
 
 			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
 			BasicConfigurator.Configure(rep, stringAppender);
@@ -143,7 +148,7 @@ namespace log4net.Tests.Context
 			Assert.AreEqual(SystemInfo.NullText, stringAppender.GetString(), "Test no thread stack
value set");
 			stringAppender.Reset();
 
-			using(ThreadContext.Stacks["prop1"].Push(null))
+			using(ThreadContext.Stacks[Utils.PROPERTY_KEY].Push(null))
 			{
 				log1.Info("TestMessage");
 				Assert.AreEqual(SystemInfo.NullText, stringAppender.GetString(), "Test thread stack value
set");
@@ -159,7 +164,7 @@ namespace log4net.Tests.Context
 		public void TestThreadStackPatternNullVal2()
 		{
 			StringAppender stringAppender = new StringAppender();
-			stringAppender.Layout = new PatternLayout("%property{prop1}");
+            stringAppender.Layout = new PatternLayout("%property{" + Utils.PROPERTY_KEY +
"}");
 
 			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
 			BasicConfigurator.Configure(rep, stringAppender);
@@ -170,13 +175,13 @@ namespace log4net.Tests.Context
 			Assert.AreEqual(SystemInfo.NullText, stringAppender.GetString(), "Test no thread stack
value set");
 			stringAppender.Reset();
 
-			using(ThreadContext.Stacks["prop1"].Push("val1"))
+			using(ThreadContext.Stacks[Utils.PROPERTY_KEY].Push("val1"))
 			{
 				log1.Info("TestMessage");
 				Assert.AreEqual("val1", stringAppender.GetString(), "Test thread stack value set");
 				stringAppender.Reset();
 
-				using(ThreadContext.Stacks["prop1"].Push(null))
+				using(ThreadContext.Stacks[Utils.PROPERTY_KEY].Push(null))
 				{
 					log1.Info("TestMessage");
 					Assert.AreEqual("val1 ", stringAppender.GetString(), "Test thread stack value pushed
null");
@@ -189,13 +194,15 @@ namespace log4net.Tests.Context
 			stringAppender.Reset();
 		}
 
+        private static string TestBackgroundThreadContextPropertyRepository;
+
 		[Test]
 		public void TestBackgroundThreadContextProperty()
 		{
 			StringAppender stringAppender = new StringAppender();
 			stringAppender.Layout = new PatternLayout("%property{DateTimeTodayToString}");
 
-			ILoggerRepository rep = LogManager.CreateRepository("TestBackgroundThreadContextPropertyRepository");
+            ILoggerRepository rep = LogManager.CreateRepository(TestBackgroundThreadContextPropertyRepository
= "TestBackgroundThreadContextPropertyRepository" + Guid.NewGuid().ToString());
 			BasicConfigurator.Configure(rep, stringAppender);
 
 			Thread thread = new Thread(new ThreadStart(ExecuteBackgroundThread));
@@ -206,7 +213,7 @@ namespace log4net.Tests.Context
 
 		private static void ExecuteBackgroundThread()
 		{
-			ILog log = LogManager.GetLogger("TestBackgroundThreadContextPropertyRepository", "ExecuteBackGroundThread");
+            ILog log = LogManager.GetLogger(TestBackgroundThreadContextPropertyRepository,
"ExecuteBackGroundThread");
 			ThreadContext.Properties["DateTimeTodayToString"] = DateTime.Today.ToString();
 
 			log.Info("TestMessage");

Modified: logging/log4net/trunk/tests/src/Layout/PatternLayoutTest.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Layout/PatternLayoutTest.cs?rev=1166059&r1=1166058&r2=1166059&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/Layout/PatternLayoutTest.cs (original)
+++ logging/log4net/trunk/tests/src/Layout/PatternLayoutTest.cs Wed Sep  7 08:46:05 2011
@@ -41,11 +41,17 @@ namespace log4net.Tests.Layout
 	[TestFixture]
 	public class PatternLayoutTest
 	{
+
+        [TearDown]
+        public void TearDown() {
+            Utils.RemovePropertyFromAllContexts();
+        }
+
 		[Test]
 		public void TestThreadPropertiesPattern()
 		{
 			StringAppender stringAppender = new StringAppender();
-			stringAppender.Layout = new PatternLayout("%property{prop1}");
+            stringAppender.Layout = new PatternLayout("%property{" + Utils.PROPERTY_KEY +
"}");
 
 			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
 			BasicConfigurator.Configure(rep, stringAppender);
@@ -56,13 +62,13 @@ namespace log4net.Tests.Layout
 			Assert.AreEqual(SystemInfo.NullText, stringAppender.GetString(), "Test no thread properties
value set");
 			stringAppender.Reset();
 
-			ThreadContext.Properties["prop1"] = "val1";
+			ThreadContext.Properties[Utils.PROPERTY_KEY] = "val1";
 
 			log1.Info("TestMessage");
 			Assert.AreEqual("val1", stringAppender.GetString(), "Test thread properties value set");
 			stringAppender.Reset();
 
-			ThreadContext.Properties.Remove("prop1");
+			ThreadContext.Properties.Remove(Utils.PROPERTY_KEY);
 
 			log1.Info("TestMessage");
 			Assert.AreEqual(SystemInfo.NullText, stringAppender.GetString(), "Test thread properties
value removed");
@@ -89,7 +95,7 @@ namespace log4net.Tests.Layout
 		public void TestGlobalPropertiesPattern()
 		{
 			StringAppender stringAppender = new StringAppender();
-			stringAppender.Layout = new PatternLayout("%property{prop1}");
+            stringAppender.Layout = new PatternLayout("%property{" + Utils.PROPERTY_KEY +
"}");
 
 			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
 			BasicConfigurator.Configure(rep, stringAppender);
@@ -100,13 +106,13 @@ namespace log4net.Tests.Layout
 			Assert.AreEqual(SystemInfo.NullText, stringAppender.GetString(), "Test no global properties
value set");
 			stringAppender.Reset();
 
-			GlobalContext.Properties["prop1"] = "val1";
+			GlobalContext.Properties[Utils.PROPERTY_KEY] = "val1";
 
 			log1.Info("TestMessage");
 			Assert.AreEqual("val1", stringAppender.GetString(), "Test global properties value set");
 			stringAppender.Reset();
 
-			GlobalContext.Properties.Remove("prop1");
+			GlobalContext.Properties.Remove(Utils.PROPERTY_KEY);
 
 			log1.Info("TestMessage");
 			Assert.AreEqual(SystemInfo.NullText, stringAppender.GetString(), "Test global properties
value removed");

Modified: logging/log4net/trunk/tests/src/Utils.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Utils.cs?rev=1166059&r1=1166058&r2=1166059&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/Utils.cs (original)
+++ logging/log4net/trunk/tests/src/Utils.cs Wed Sep  7 08:46:05 2011
@@ -99,5 +99,12 @@ namespace log4net.Tests
 
 			return types;
 		}
+
+        internal const string PROPERTY_KEY = "prop1";
+
+        internal static void RemovePropertyFromAllContexts() {
+            GlobalContext.Properties.Remove(PROPERTY_KEY);
+            ThreadContext.Properties.Remove(PROPERTY_KEY);
+        }
 	}
 }
\ No newline at end of file



Mime
View raw message