You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by dp...@apache.org on 2018/10/03 18:40:44 UTC
[1/8] logging-log4net git commit: Added tests for the
RollingLockStrategy
Repository: logging-log4net
Updated Branches:
refs/heads/feature/rfa-configurable-rolling-mutex ecabb910e -> 8bb7286a4
Added tests for the RollingLockStrategy
Project: http://git-wip-us.apache.org/repos/asf/logging-log4net/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4net/commit/6935940d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4net/tree/6935940d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4net/diff/6935940d
Branch: refs/heads/feature/rfa-configurable-rolling-mutex
Commit: 6935940dd0d345b395268c95283bf03e6d31ab03
Parents: ecabb91
Author: Andrei Stryia <An...@epam.com>
Authored: Mon Oct 1 13:36:47 2018 +0300
Committer: Andrei Stryia <An...@epam.com>
Committed: Mon Oct 1 13:36:47 2018 +0300
----------------------------------------------------------------------
tests/src/Appender/RollingFileAppenderTest.cs | 41 +++++++++++++++++++---
1 file changed, 36 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4net/blob/6935940d/tests/src/Appender/RollingFileAppenderTest.cs
----------------------------------------------------------------------
diff --git a/tests/src/Appender/RollingFileAppenderTest.cs b/tests/src/Appender/RollingFileAppenderTest.cs
index 1db7b74..bb185c9 100644
--- a/tests/src/Appender/RollingFileAppenderTest.cs
+++ b/tests/src/Appender/RollingFileAppenderTest.cs
@@ -1407,8 +1407,9 @@ namespace log4net.Tests.Appender
/// <param name="handler">The error handler to use.</param>
/// <param name="maxFileSize">Maximum file size for roll</param>
/// <param name="maxSizeRollBackups">Maximum number of roll backups</param>
+ /// <param name="rollingLockStrategy">Rolling lock strategy</param>
/// <returns>A configured ILogger</returns>
- private static ILogger CreateLogger(string filename, FileAppender.LockingModelBase lockModel, IErrorHandler handler, int maxFileSize, int maxSizeRollBackups)
+ private static ILogger CreateLogger(string filename, FileAppender.LockingModelBase lockModel, IErrorHandler handler, int maxFileSize, int maxSizeRollBackups, RollingFileAppender.RollingLockStrategyKind rollingLockStrategy = RollingFileAppender.RollingLockStrategyKind.None)
{
Repository.Hierarchy.Hierarchy h = (Repository.Hierarchy.Hierarchy)LogManager.CreateRepository("TestRepository");
@@ -1421,6 +1422,7 @@ namespace log4net.Tests.Appender
appender.Encoding = Encoding.ASCII;
appender.ErrorHandler = handler;
appender.MaxSizeRollBackups = maxSizeRollBackups;
+ appender.RollingLockStrategy = rollingLockStrategy;
if (lockModel != null)
{
appender.LockingModel = lockModel;
@@ -1747,18 +1749,47 @@ namespace log4net.Tests.Appender
DestroyLogger();
}
- [Test, Ignore("Not Implemented: this test should assert that the rolling file appender works when configured with rolling lock strategy none")]
+ /// <summary>
+ /// Verifies that the rolling file appender works when configured with rolling lock strategy none
+ /// </summary>
+ [Test]
public void TestRollingLockStrategyNone()
{
- // TODO
+ TestRollingLockStrategy(RollingFileAppender.RollingLockStrategyKind.None);
}
- [Test, Ignore("Not Implemented: this test should assert that the rolling file appender works when configured with rolling lock strategy local mutex")]
+ /// <summary>
+ /// Verifies that the rolling file appender works when configured with rolling lock strategy local mutex
+ /// </summary>
+ [Test]
public void TestRollingLockStrategyLocalMutex()
{
- // TODO
+ TestRollingLockStrategy(RollingFileAppender.RollingLockStrategyKind.LocalMutex);
}
+ private void TestRollingLockStrategy(RollingFileAppender.RollingLockStrategyKind strategy)
+ {
+ String filename = c_fileName;
+ SilentErrorHandler sh = new SilentErrorHandler();
+ ILogger log = CreateLogger(filename, null, sh, maxFileSize: 1, maxSizeRollBackups: 2, rollingLockStrategy: strategy);
+
+ IAppender[] appenders = log.Repository.GetAppenders();
+ Assert.AreEqual(1, appenders.Length, "The wrong number of appenders are configured");
+
+ RollingFileAppender rfa = (RollingFileAppender)(appenders[0]);
+ Assert.AreEqual(strategy, rfa.RollingLockStrategy, string.Format("The RollingLockStrategy should be {0}", strategy.ToString()));
+
+ Assert.DoesNotThrow(delegate { log.Log(GetType(), Level.Info, "1", null); });
+ Assert.DoesNotThrow(delegate { log.Log(GetType(), Level.Info, "2", null); });
+
+ DestroyLogger();
+
+ AssertFileEquals(filename, "2" + Environment.NewLine);
+ AssertFileEquals(filename + ".1", "1" + Environment.NewLine);
+ Assert.IsEmpty(sh.Message);
+ }
+
+
/// <summary>
/// Tests the count up case, with infinite max backups , to see that
/// initialization of the rolling file appender results in the expected value
[8/8] logging-log4net git commit: Update text in comment
Posted by dp...@apache.org.
Update text in comment
Project: http://git-wip-us.apache.org/repos/asf/logging-log4net/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4net/commit/8bb7286a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4net/tree/8bb7286a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4net/diff/8bb7286a
Branch: refs/heads/feature/rfa-configurable-rolling-mutex
Commit: 8bb7286a42cf741de851fcbaa0114dc8d7ef331e
Parents: e0b9782
Author: Andrei Stryia <An...@epam.com>
Authored: Tue Oct 2 11:55:00 2018 +0300
Committer: Andrei Stryia <An...@epam.com>
Committed: Tue Oct 2 11:55:00 2018 +0300
----------------------------------------------------------------------
tests/src/Appender/RollingFileAppenderTest.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4net/blob/8bb7286a/tests/src/Appender/RollingFileAppenderTest.cs
----------------------------------------------------------------------
diff --git a/tests/src/Appender/RollingFileAppenderTest.cs b/tests/src/Appender/RollingFileAppenderTest.cs
index afe9634..b5bcb47 100644
--- a/tests/src/Appender/RollingFileAppenderTest.cs
+++ b/tests/src/Appender/RollingFileAppenderTest.cs
@@ -1774,7 +1774,7 @@ namespace log4net.Tests.Appender
}
/// <summary>
- /// Verifies that the rolling file appender works when configured with rolling lock strategy none and local mutex
+ /// Verifies that the rolling file appender works when configured with rolling lock strategy
/// </summary>
[TestCase(RollingFileAppender.RollingLockStrategyKind.LocalMutex)]
[TestCase(RollingFileAppender.RollingLockStrategyKind.None)]
[3/8] logging-log4net git commit: Added test to check LocalMutex
LockStrategy actually perform lock
Posted by dp...@apache.org.
Added test to check LocalMutex LockStrategy actually perform lock
Project: http://git-wip-us.apache.org/repos/asf/logging-log4net/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4net/commit/1782679c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4net/tree/1782679c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4net/diff/1782679c
Branch: refs/heads/feature/rfa-configurable-rolling-mutex
Commit: 1782679c94fe90ca8d9248cee5850d05b1bd6ad1
Parents: f22025f
Author: Andrei Stryia <An...@epam.com>
Authored: Mon Oct 1 15:46:35 2018 +0300
Committer: Andrei Stryia <An...@epam.com>
Committed: Mon Oct 1 15:46:35 2018 +0300
----------------------------------------------------------------------
tests/src/Appender/RollingFileAppenderTest.cs | 62 +++++++++++++++++++++-
1 file changed, 60 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4net/blob/1782679c/tests/src/Appender/RollingFileAppenderTest.cs
----------------------------------------------------------------------
diff --git a/tests/src/Appender/RollingFileAppenderTest.cs b/tests/src/Appender/RollingFileAppenderTest.cs
index 46bce8d..b9c2ed0 100644
--- a/tests/src/Appender/RollingFileAppenderTest.cs
+++ b/tests/src/Appender/RollingFileAppenderTest.cs
@@ -32,6 +32,8 @@ using log4net.Util;
using NUnit.Framework;
using System.Globalization;
+using System.Threading;
+using System.Threading.Tasks;
namespace log4net.Tests.Appender
{
@@ -1453,19 +1455,21 @@ namespace log4net.Tests.Appender
LoggerManager.RepositorySelector = new DefaultRepositorySelector(typeof(log4net.Repository.Hierarchy.Hierarchy));
}
- private static void AssertFileEquals(string filename, string contents)
+ private static void AssertFileEquals(string filename, string contents, bool cleanup = true)
{
#if NETSTANDARD1_3
StreamReader sr = new StreamReader(File.Open(filename, FileMode.Open));
#else
StreamReader sr = new StreamReader(filename);
#endif
+
string logcont = sr.ReadToEnd();
sr.Close();
Assert.AreEqual(contents, logcont, "Log contents is not what is expected");
- File.Delete(filename);
+ if (cleanup)
+ File.Delete(filename);
}
/// <summary>
@@ -1776,6 +1780,60 @@ namespace log4net.Tests.Appender
Assert.IsEmpty(sh.Message);
}
+#if !NETCF
+ /// <summary>
+ /// Verifies that the local mutex rolling lock strategy works
+ /// </summary>
+ [Test]
+ public void TestRollingLockStrategyLocalMutex()
+ {
+ String filename = c_fileName;
+ SilentErrorHandler sh = new SilentErrorHandler();
+
+ ILogger log = CreateLogger(filename, new FileAppender.MinimalLock(), sh, maxFileSize: 1, maxSizeRollBackups: 2, rollingLockStrategy: RollingFileAppender.RollingLockStrategyKind.LocalMutex);
+ RollingFileAppender appender = (RollingFileAppender) log.Repository.GetAppenders()[0];
+
+ Mutex syncObject = null;
+ try
+ {
+ syncObject = new Mutex(false, appender.File.Replace("\\", "_").Replace(":", "_").Replace("/", "_"));
+ syncObject.WaitOne();
+
+ // Logger should acquire Mutex in different thread
+ var write1 = Task.Factory.StartNew(()=> Assert.DoesNotThrow(delegate { log.Log(GetType(), Level.Info, "1", null); }));
+ // Wait some time
+ WaitForStart(write1);
+
+ // Since Mutex already locked, log file should be empty
+ AssertFileEquals(filename, string.Empty, cleanup: false);
+
+ syncObject.ReleaseMutex();
+ write1.Wait();
+
+ DestroyLogger();
+ AssertFileEquals(filename, "1" + Environment.NewLine);
+ Assert.IsEmpty(sh.Message);
+ }
+ finally
+ {
+ if (syncObject != null)
+ {
+ syncObject.Dispose();
+ }
+
+ }
+ }
+ private void WaitForStart(Task write1)
+ {
+ while (write1.Status != TaskStatus.Running)
+ {
+ Thread.Sleep(100);
+ }
+
+ Thread.Sleep(800);
+ }
+#endif
+
/// <summary>
/// Tests the count up case, with infinite max backups , to see that
/// initialization of the rolling file appender results in the expected value
[6/8] logging-log4net git commit: Removed argumnets naming to support
net2.0
Posted by dp...@apache.org.
Removed argumnets naming to support net2.0
Project: http://git-wip-us.apache.org/repos/asf/logging-log4net/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4net/commit/122eb731
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4net/tree/122eb731
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4net/diff/122eb731
Branch: refs/heads/feature/rfa-configurable-rolling-mutex
Commit: 122eb731ca6c69828d4de8215dc4e9c4ef60333e
Parents: 028e36f
Author: Andrei Stryia <An...@epam.com>
Authored: Mon Oct 1 18:52:50 2018 +0300
Committer: Andrei Stryia <An...@epam.com>
Committed: Mon Oct 1 18:52:50 2018 +0300
----------------------------------------------------------------------
tests/src/Appender/RollingFileAppenderTest.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4net/blob/122eb731/tests/src/Appender/RollingFileAppenderTest.cs
----------------------------------------------------------------------
diff --git a/tests/src/Appender/RollingFileAppenderTest.cs b/tests/src/Appender/RollingFileAppenderTest.cs
index 0a026a0..a56c3e3 100644
--- a/tests/src/Appender/RollingFileAppenderTest.cs
+++ b/tests/src/Appender/RollingFileAppenderTest.cs
@@ -1782,7 +1782,7 @@ namespace log4net.Tests.Appender
{
String filename = c_fileName;
SilentErrorHandler sh = new SilentErrorHandler();
- ILogger log = CreateLogger(filename, null, sh, maxFileSize: 1, maxSizeRollBackups: 2, rollingLockStrategy: strategy);
+ ILogger log = CreateLogger(filename, null, sh, 1, 2, strategy);
IAppender[] appenders = log.Repository.GetAppenders();
Assert.AreEqual(1, appenders.Length, "The wrong number of appenders are configured");
@@ -1813,7 +1813,7 @@ namespace log4net.Tests.Appender
Mutex syncObject = null;
try
{
- ILogger log = CreateLogger(filename, new FileAppender.MinimalLock(), sh, maxFileSize: 1, maxSizeRollBackups: 2, rollingLockStrategy: RollingFileAppender.RollingLockStrategyKind.LocalMutex);
+ ILogger log = CreateLogger(filename, new FileAppender.MinimalLock(), sh, 1, 2, RollingFileAppender.RollingLockStrategyKind.LocalMutex);
RollingFileAppender appender = (RollingFileAppender)log.Repository.GetAppenders()[0];
syncObject = new Mutex(false, appender.File.Replace("\\", "_").Replace(":", "_").Replace("/", "_"));
@@ -1837,7 +1837,7 @@ namespace log4net.Tests.Appender
Thread.Sleep(2000);
// Since Mutex already locked, log file should be empty
- AssertFileEquals(filename, string.Empty, cleanup: false);
+ AssertFileEquals(filename, string.Empty, false);
syncObject.ReleaseMutex();
[7/8] logging-log4net git commit: Added Mutex.Close to support net2.0
Posted by dp...@apache.org.
Added Mutex.Close to support net2.0
Project: http://git-wip-us.apache.org/repos/asf/logging-log4net/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4net/commit/e0b97826
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4net/tree/e0b97826
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4net/diff/e0b97826
Branch: refs/heads/feature/rfa-configurable-rolling-mutex
Commit: e0b978268856a08557e4a3f565a2130a6d46a7c6
Parents: 122eb73
Author: Andrei Stryia <An...@epam.com>
Authored: Mon Oct 1 21:42:43 2018 +0300
Committer: Andrei Stryia <An...@epam.com>
Committed: Mon Oct 1 21:42:43 2018 +0300
----------------------------------------------------------------------
tests/src/Appender/RollingFileAppenderTest.cs | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4net/blob/e0b97826/tests/src/Appender/RollingFileAppenderTest.cs
----------------------------------------------------------------------
diff --git a/tests/src/Appender/RollingFileAppenderTest.cs b/tests/src/Appender/RollingFileAppenderTest.cs
index a56c3e3..afe9634 100644
--- a/tests/src/Appender/RollingFileAppenderTest.cs
+++ b/tests/src/Appender/RollingFileAppenderTest.cs
@@ -1820,7 +1820,7 @@ namespace log4net.Tests.Appender
syncObject.WaitOne();
// Logger should acquire Mutex in different thread
- var loggerThread = new Thread
+ Thread loggerThread = new Thread
(
delegate(object o)
{
@@ -1850,7 +1850,13 @@ namespace log4net.Tests.Appender
finally
{
if (syncObject != null)
+ {
+#if NET_4_0 || MONO_4_0 || NETSTANDARD1_3
syncObject.Dispose();
+#else
+ syncObject.Close();
+#endif
+ }
}
}
#endif
[2/8] logging-log4net git commit: Code was simplified with TestCase
Posted by dp...@apache.org.
Code was simplified with TestCase
Project: http://git-wip-us.apache.org/repos/asf/logging-log4net/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4net/commit/f22025fd
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4net/tree/f22025fd
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4net/diff/f22025fd
Branch: refs/heads/feature/rfa-configurable-rolling-mutex
Commit: f22025fd4d6657019577606a4813953cb0137be2
Parents: 6935940
Author: Andrei Stryia <An...@epam.com>
Authored: Mon Oct 1 13:42:43 2018 +0300
Committer: Andrei Stryia <An...@epam.com>
Committed: Mon Oct 1 13:42:43 2018 +0300
----------------------------------------------------------------------
tests/src/Appender/RollingFileAppenderTest.cs | 22 ++++------------------
1 file changed, 4 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4net/blob/f22025fd/tests/src/Appender/RollingFileAppenderTest.cs
----------------------------------------------------------------------
diff --git a/tests/src/Appender/RollingFileAppenderTest.cs b/tests/src/Appender/RollingFileAppenderTest.cs
index bb185c9..46bce8d 100644
--- a/tests/src/Appender/RollingFileAppenderTest.cs
+++ b/tests/src/Appender/RollingFileAppenderTest.cs
@@ -1750,24 +1750,11 @@ namespace log4net.Tests.Appender
}
/// <summary>
- /// Verifies that the rolling file appender works when configured with rolling lock strategy none
+ /// Verifies that the rolling file appender works when configured with rolling lock strategy none and local mutex
/// </summary>
- [Test]
- public void TestRollingLockStrategyNone()
- {
- TestRollingLockStrategy(RollingFileAppender.RollingLockStrategyKind.None);
- }
-
- /// <summary>
- /// Verifies that the rolling file appender works when configured with rolling lock strategy local mutex
- /// </summary>
- [Test]
- public void TestRollingLockStrategyLocalMutex()
- {
- TestRollingLockStrategy(RollingFileAppender.RollingLockStrategyKind.LocalMutex);
- }
-
- private void TestRollingLockStrategy(RollingFileAppender.RollingLockStrategyKind strategy)
+ [TestCase(RollingFileAppender.RollingLockStrategyKind.LocalMutex)]
+ [TestCase(RollingFileAppender.RollingLockStrategyKind.None)]
+ public void TestRollingLockStrategy(RollingFileAppender.RollingLockStrategyKind strategy)
{
String filename = c_fileName;
SilentErrorHandler sh = new SilentErrorHandler();
@@ -1789,7 +1776,6 @@ namespace log4net.Tests.Appender
Assert.IsEmpty(sh.Message);
}
-
/// <summary>
/// Tests the count up case, with infinite max backups , to see that
/// initialization of the rolling file appender results in the expected value
[5/8] logging-log4net git commit: Removed default arguments to be
compatible with net2.0
Posted by dp...@apache.org.
Removed default arguments to be compatible with net2.0
Project: http://git-wip-us.apache.org/repos/asf/logging-log4net/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4net/commit/028e36f1
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4net/tree/028e36f1
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4net/diff/028e36f1
Branch: refs/heads/feature/rfa-configurable-rolling-mutex
Commit: 028e36f10ab45e39f45d6bdf41877ea112d1a7c7
Parents: 8fccdd3
Author: Andrei Stryia <An...@epam.com>
Authored: Mon Oct 1 18:02:34 2018 +0300
Committer: Andrei Stryia <An...@epam.com>
Committed: Mon Oct 1 18:02:34 2018 +0300
----------------------------------------------------------------------
tests/src/Appender/RollingFileAppenderTest.cs | 38 ++++++++++++++++++++--
1 file changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4net/blob/028e36f1/tests/src/Appender/RollingFileAppenderTest.cs
----------------------------------------------------------------------
diff --git a/tests/src/Appender/RollingFileAppenderTest.cs b/tests/src/Appender/RollingFileAppenderTest.cs
index e3cf04d..0a026a0 100644
--- a/tests/src/Appender/RollingFileAppenderTest.cs
+++ b/tests/src/Appender/RollingFileAppenderTest.cs
@@ -1408,9 +1408,25 @@ namespace log4net.Tests.Appender
/// <param name="handler">The error handler to use.</param>
/// <param name="maxFileSize">Maximum file size for roll</param>
/// <param name="maxSizeRollBackups">Maximum number of roll backups</param>
+ /// <returns>A configured ILogger</returns>
+ private static ILogger CreateLogger(string filename, FileAppender.LockingModelBase lockModel, IErrorHandler handler,
+ int maxFileSize, int maxSizeRollBackups)
+ {
+ return CreateLogger(filename, lockModel, handler, maxFileSize, maxSizeRollBackups,
+ RollingFileAppender.RollingLockStrategyKind.None);
+ }
+
+ /// <summary>
+ /// Creates a logger hierarchy, configures a rolling file appender and returns an ILogger
+ /// </summary>
+ /// <param name="filename">The filename to log to</param>
+ /// <param name="lockModel">The locking model to use.</param>
+ /// <param name="handler">The error handler to use.</param>
+ /// <param name="maxFileSize">Maximum file size for roll</param>
+ /// <param name="maxSizeRollBackups">Maximum number of roll backups</param>
/// <param name="rollingLockStrategy">Rolling lock strategy</param>
/// <returns>A configured ILogger</returns>
- private static ILogger CreateLogger(string filename, FileAppender.LockingModelBase lockModel, IErrorHandler handler, int maxFileSize, int maxSizeRollBackups, RollingFileAppender.RollingLockStrategyKind rollingLockStrategy = RollingFileAppender.RollingLockStrategyKind.None)
+ private static ILogger CreateLogger(string filename, FileAppender.LockingModelBase lockModel, IErrorHandler handler, int maxFileSize, int maxSizeRollBackups, RollingFileAppender.RollingLockStrategyKind rollingLockStrategy)
{
Repository.Hierarchy.Hierarchy h = (Repository.Hierarchy.Hierarchy)LogManager.CreateRepository("TestRepository");
@@ -1454,7 +1470,12 @@ namespace log4net.Tests.Appender
LoggerManager.RepositorySelector = new DefaultRepositorySelector(typeof(log4net.Repository.Hierarchy.Hierarchy));
}
- private static void AssertFileEquals(string filename, string contents, bool cleanup = true)
+ private static void AssertFileEquals(string filename, string contents)
+ {
+ AssertFileEquals(filename, contents, true);
+ }
+
+ private static void AssertFileEquals(string filename, string contents, bool cleanup)
{
#if NETSTANDARD1_3
StreamReader sr = new StreamReader(File.Open(filename, FileMode.Open));
@@ -1799,7 +1820,18 @@ namespace log4net.Tests.Appender
syncObject.WaitOne();
// Logger should acquire Mutex in different thread
- var loggerThread = new Thread(o => Assert.DoesNotThrow(delegate { log.Log(GetType(), Level.Info, "1", null); }));
+ var loggerThread = new Thread
+ (
+ delegate(object o)
+ {
+ Assert.DoesNotThrow(
+ delegate
+ {
+ log.Log(GetType(), Level.Info, "1", null);
+ });
+
+ }
+ );
loggerThread.Start();
// Wait some time
Thread.Sleep(2000);
[4/8] logging-log4net git commit: Added method to test if LocalMutex
LockStrategy actually perform lock
Posted by dp...@apache.org.
Added method to test if LocalMutex LockStrategy actually perform lock
Project: http://git-wip-us.apache.org/repos/asf/logging-log4net/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4net/commit/8fccdd34
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4net/tree/8fccdd34
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4net/diff/8fccdd34
Branch: refs/heads/feature/rfa-configurable-rolling-mutex
Commit: 8fccdd3492a965ed49e09d8c95ceb683b0a64377
Parents: 1782679
Author: Andrei Stryia <An...@epam.com>
Authored: Mon Oct 1 16:20:58 2018 +0300
Committer: Andrei Stryia <An...@epam.com>
Committed: Mon Oct 1 16:20:58 2018 +0300
----------------------------------------------------------------------
tests/src/Appender/RollingFileAppenderTest.cs | 29 +++++++---------------
1 file changed, 9 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4net/blob/8fccdd34/tests/src/Appender/RollingFileAppenderTest.cs
----------------------------------------------------------------------
diff --git a/tests/src/Appender/RollingFileAppenderTest.cs b/tests/src/Appender/RollingFileAppenderTest.cs
index b9c2ed0..e3cf04d 100644
--- a/tests/src/Appender/RollingFileAppenderTest.cs
+++ b/tests/src/Appender/RollingFileAppenderTest.cs
@@ -33,7 +33,6 @@ using log4net.Util;
using NUnit.Framework;
using System.Globalization;
using System.Threading;
-using System.Threading.Tasks;
namespace log4net.Tests.Appender
{
@@ -1787,28 +1786,30 @@ namespace log4net.Tests.Appender
[Test]
public void TestRollingLockStrategyLocalMutex()
{
- String filename = c_fileName;
+ String filename = "test_lock.log";
SilentErrorHandler sh = new SilentErrorHandler();
- ILogger log = CreateLogger(filename, new FileAppender.MinimalLock(), sh, maxFileSize: 1, maxSizeRollBackups: 2, rollingLockStrategy: RollingFileAppender.RollingLockStrategyKind.LocalMutex);
- RollingFileAppender appender = (RollingFileAppender) log.Repository.GetAppenders()[0];
-
Mutex syncObject = null;
try
{
+ ILogger log = CreateLogger(filename, new FileAppender.MinimalLock(), sh, maxFileSize: 1, maxSizeRollBackups: 2, rollingLockStrategy: RollingFileAppender.RollingLockStrategyKind.LocalMutex);
+ RollingFileAppender appender = (RollingFileAppender)log.Repository.GetAppenders()[0];
+
syncObject = new Mutex(false, appender.File.Replace("\\", "_").Replace(":", "_").Replace("/", "_"));
syncObject.WaitOne();
// Logger should acquire Mutex in different thread
- var write1 = Task.Factory.StartNew(()=> Assert.DoesNotThrow(delegate { log.Log(GetType(), Level.Info, "1", null); }));
+ var loggerThread = new Thread(o => Assert.DoesNotThrow(delegate { log.Log(GetType(), Level.Info, "1", null); }));
+ loggerThread.Start();
// Wait some time
- WaitForStart(write1);
+ Thread.Sleep(2000);
// Since Mutex already locked, log file should be empty
AssertFileEquals(filename, string.Empty, cleanup: false);
syncObject.ReleaseMutex();
- write1.Wait();
+
+ loggerThread.Join(1000);
DestroyLogger();
AssertFileEquals(filename, "1" + Environment.NewLine);
@@ -1817,20 +1818,8 @@ namespace log4net.Tests.Appender
finally
{
if (syncObject != null)
- {
syncObject.Dispose();
- }
-
- }
- }
- private void WaitForStart(Task write1)
- {
- while (write1.Status != TaskStatus.Running)
- {
- Thread.Sleep(100);
}
-
- Thread.Sleep(800);
}
#endif