Dominik P avatar Dominik P committed b836a22

Added a test to test the index rolling strategy

Comments (0)

Files changed (1)

 
 diff -r f50b41656da1 src/Appender/Rolling/CronRollingCondition.cs
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/src/Appender/Rolling/CronRollingCondition.cs	Fri Sep 23 22:31:43 2011 +0200
++++ b/src/Appender/Rolling/CronRollingCondition.cs	Sat Sep 24 05:58:22 2011 +0200
 @@ -0,0 +1,222 @@
 +#region Apache License
 +//
 +}
 diff -r f50b41656da1 src/Appender/Rolling/IRollingCondition.cs
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/src/Appender/Rolling/IRollingCondition.cs	Fri Sep 23 22:31:43 2011 +0200
++++ b/src/Appender/Rolling/IRollingCondition.cs	Sat Sep 24 05:58:22 2011 +0200
 @@ -0,0 +1,38 @@
 +#region Apache License
 +//
 +}
 diff -r f50b41656da1 src/Appender/Rolling/IRollingStrategy.cs
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/src/Appender/Rolling/IRollingStrategy.cs	Fri Sep 23 22:31:43 2011 +0200
++++ b/src/Appender/Rolling/IRollingStrategy.cs	Sat Sep 24 05:58:22 2011 +0200
 @@ -0,0 +1,32 @@
 +#region Apache License
 +//
 +}
 diff -r f50b41656da1 src/Appender/Rolling/IndexRollingStrategy.cs
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/src/Appender/Rolling/IndexRollingStrategy.cs	Fri Sep 23 22:31:43 2011 +0200
++++ b/src/Appender/Rolling/IndexRollingStrategy.cs	Sat Sep 24 05:58:22 2011 +0200
 @@ -0,0 +1,77 @@
 +#region Apache License
 +//
 +}
 diff -r f50b41656da1 src/Appender/RollingFileAppenderNG.cs
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/src/Appender/RollingFileAppenderNG.cs	Fri Sep 23 22:31:43 2011 +0200
++++ b/src/Appender/RollingFileAppenderNG.cs	Sat Sep 24 05:58:22 2011 +0200
 @@ -0,0 +1,143 @@
 +#region Apache License
 +//
 +}
 diff -r f50b41656da1 src/log4net.vs2010.csproj
 --- a/src/log4net.vs2010.csproj	Fri Sep 23 14:54:29 2011 +0000
-+++ b/src/log4net.vs2010.csproj	Fri Sep 23 22:31:43 2011 +0200
++++ b/src/log4net.vs2010.csproj	Sat Sep 24 05:58:22 2011 +0200
 @@ -1,4 +1,4 @@
 -<?xml version="1.0" encoding="utf-8"?>
 +<?xml version="1.0" encoding="utf-8"?>
 \ No newline at end of file
 diff -r f50b41656da1 tests/src/Appender/Rolling/CronRollingConditionTest.cs
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/tests/src/Appender/Rolling/CronRollingConditionTest.cs	Fri Sep 23 22:31:43 2011 +0200
++++ b/tests/src/Appender/Rolling/CronRollingConditionTest.cs	Sat Sep 24 05:58:22 2011 +0200
 @@ -0,0 +1,45 @@
 +using System;
 +using System.Collections.Generic;
 +		}
 +	}
 +}
+diff -r f50b41656da1 tests/src/Appender/Rolling/IndexRollingStrategyTest.cs
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/tests/src/Appender/Rolling/IndexRollingStrategyTest.cs	Sat Sep 24 05:58:22 2011 +0200
+@@ -0,0 +1,83 @@
++using System;
++using System.Collections.Generic;
++using System.Linq;
++using System.Text;
++using NUnit.Framework;
++using log4net.Appender.Rolling;
++using System.IO;
++
++namespace log4net.Tests.Appender.Rolling
++{
++	[TestFixture]
++	public class IndexRollingStrategyTest
++	{
++		[Test]
++		public void RollTest()
++		{
++			IndexRollingStrategy strategy = new IndexRollingStrategy();
++			List<string> tmpFiles = new List<string>();
++			try
++			{
++				// create a dummy temp file
++				string filename = "logfile.log";
++				// add the file
++				tmpFiles.Add(filename);
++				for (int i = 0; i <= 10; i++)
++				{
++					Console.WriteLine("Now at rolling iteration {0}", i);
++					// roll the file once
++					strategy.Roll(filename);
++					// create filename again
++					using (File.Create(filename))
++					{
++						// we don't need the filestream anymore
++					}
++					tmpFiles.Add(filename + "." + i);
++					// test if there are rolled files for [0..i]
++					for (int j = 0; j < i; j++)
++					{
++						if (!File.Exists(filename + "." + j))
++						{
++							// fail
++							Assert.Fail("The file '{0}' was not rolled correctly at iteration i={1}; j={2}", filename, i, j);
++						}
++					}
++				}
++
++				Console.WriteLine("Now at rolling iteration {0}, this should not create another file", 11);
++				// roll the file once
++				strategy.Roll(filename);
++				// test if there are rolled files for [0..i]
++				for (int j = 0; j <= 10; j++)
++				{
++					if (!File.Exists(filename + "." + j))
++					{
++						// fail
++						Assert.Fail("The file '{0}' was not rolled correctly at iteration j={2}", filename, j);
++					}
++				}
++				if (File.Exists(filename + ".11"))
++				{
++					Assert.Fail("The file '{0}' should not have been rolled further iteration 10", filename);
++				}
++
++			}
++			catch (Exception e)
++			{
++				Assert.Fail("Exception: {0}", e);
++			}
++			finally
++			{
++				// cleanup
++				while (tmpFiles.Count > 0)
++				{
++					if (File.Exists(tmpFiles[0]))
++					{
++						File.Delete(tmpFiles[0]);
++					}
++					tmpFiles.RemoveAt(0);
++				}
++			}
++		}
++	}
++}
 diff -r f50b41656da1 tests/src/log4net.Tests.vs2010.csproj
 --- a/tests/src/log4net.Tests.vs2010.csproj	Fri Sep 23 14:54:29 2011 +0000
-+++ b/tests/src/log4net.Tests.vs2010.csproj	Fri Sep 23 22:31:43 2011 +0200
-@@ -140,6 +140,7 @@
++++ b/tests/src/log4net.Tests.vs2010.csproj	Sat Sep 24 05:58:22 2011 +0200
+@@ -140,6 +140,8 @@
      <Compile Include="Appender\AdoNet\Log4NetParameter.cs" />
      <Compile Include="Appender\AdoNet\Log4NetParameterCollection.cs" />
      <Compile Include="Appender\AdoNet\Log4NetTransaction.cs" />
 +    <Compile Include="Appender\Rolling\CronRollingConditionTest.cs" />
++    <Compile Include="Appender\Rolling\IndexRollingStrategyTest.cs" />
      <Compile Include="Appender\BufferingAppenderTest.cs">
        <SubType>Code</SubType>
      </Compile>
-@@ -240,4 +241,4 @@
+@@ -240,4 +242,4 @@
      <PostBuildEvent>
      </PostBuildEvent>
    </PropertyGroup>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.