<commit_before>// Copyright 2004-2006 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace NVelocity
{
	using System;
	using System.Collections;
	using System.IO;
	using System.Text.RegularExpressions;
	using System.Threading;
	using NUnit.Framework;
	using NVelocity.App;
	using NVelocity.Test;

	[TestFixture/*, Explicit*/]
	public class MultiThreadTestCase
	{
		private ManualResetEvent startEvent = new ManualResetEvent(false);
		private ManualResetEvent stopEvent = new ManualResetEvent(false);
		private VelocityContext c;
		private ArrayList items;
		private VelocityEngine ve;

		[SetUp]
		public void Setup()
		{
			items = new ArrayList();

			items.Add("a");
			items.Add("b");
			items.Add("c");
			items.Add("d");

			c = new VelocityContext();
			c.Put("x", new Something());
			c.Put("items", items);

			ve = new VelocityEngine();
			ve.Init();
		}

		[Test]
		public void Multithreaded1()
		{
			const int threadCount = 20;

			Thread[] threads = new Thread[threadCount];
			
			for(int i = 0; i < threadCount; i++)
			{
				threads[i] = new Thread(new ThreadStart(ExecuteMethodUntilSignal1));
				threads[i].Start();
			}

			startEvent.Set();

			Thread.CurrentThread.Join(1 * 5000);

			stopEvent.Set();
		}

		[Test]
		public void Multithreaded2()
		{
			const int threadCount = 20;

			Thread[] threads = new Thread[threadCount];
			
			for(int i = 0; i < threadCount; i++)
			{
				threads[i] = new Thread(new ThreadStart(ExecuteMethodUntilSignal2));
				threads[i].Start();
			}

			startEvent.Set();

			Thread.CurrentThread.Join(1 * 5000);

			stopEvent.Set();
		}

		public void ExecuteMethodUntilSignal1()
		{
			startEvent.WaitOne(int.MaxValue, false);

			while (!stopEvent.WaitOne(1, false))
			{
				VelocityEngine ve = new VelocityEngine();
				ve.Init();

				StringWriter sw = new StringWriter();

				bool ok = ve.Evaluate(c, sw,
					"ContextTest.CaseInsensitive",
					@"
					#foreach( $item in $items )
						$item,
					#end
				");

				Assert.IsTrue(ok, "Evalutation returned failure");
				Assert.AreEqual("a,b,c,d,", Normalize(sw));
			}
		}

		public void ExecuteMethodUntilSignal2()
		{
			startEvent.WaitOne(int.MaxValue, false);

			while (!stopEvent.WaitOne(1, false))
			{
				StringWriter sw = new StringWriter();

				bool ok = ve.Evaluate(c, sw,
					"ContextTest.CaseInsensitive",
					@"
					#foreach( $item in $items )
						$item,
					#end
				");

				Assert.IsTrue(ok, "Evalutation returned failure");
				Assert.AreEqual("a,b,c,d,", Normalize(sw));
			}
		}
		
		private string Normalize(StringWriter sw)
		{
			return Regex.Replace(sw.ToString(), "\\s+", "");
		}
	}
}<commit_msg>Fixing MultiThreadTestCase: the context cannot be shared for obviously reasons<commit_after>// Copyright 2004-2006 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace NVelocity
{
	using System;
	using System.Collections;
	using System.IO;
	using System.Text.RegularExpressions;
	using System.Threading;
	using NUnit.Framework;
	using NVelocity.App;
	using NVelocity.Test;

	[TestFixture/*, Explicit*/]
	public class MultiThreadTestCase
	{
		private ManualResetEvent startEvent = new ManualResetEvent(false);
		private ManualResetEvent stopEvent = new ManualResetEvent(false);
		private ArrayList items;
		private VelocityEngine ve;

		[SetUp]
		public void Setup()
		{
			items = new ArrayList();

			items.Add("a");
			items.Add("b");
			items.Add("c");
			items.Add("d");

			ve = new VelocityEngine();
			ve.Init();
		}

		[Test]
		public void Multithreaded1()
		{
			const int threadCount = 20;

			Thread[] threads = new Thread[threadCount];
			
			for(int i = 0; i < threadCount; i++)
			{
				threads[i] = new Thread(new ThreadStart(ExecuteMethodUntilSignal1));
				threads[i].Start();
			}

			startEvent.Set();

			Thread.CurrentThread.Join(1 * 5000);

			stopEvent.Set();
		}

		[Test]
		public void Multithreaded2()
		{
			const int threadCount = 20;

			Thread[] threads = new Thread[threadCount];
			
			for(int i = 0; i < threadCount; i++)
			{
				threads[i] = new Thread(new ThreadStart(ExecuteMethodUntilSignal2));
				threads[i].Start();
			}

			startEvent.Set();

			Thread.CurrentThread.Join(1 * 5000);

			stopEvent.Set();
		}

		public void ExecuteMethodUntilSignal1()
		{
			startEvent.WaitOne(int.MaxValue, false);

			while (!stopEvent.WaitOne(1, false))
			{
				VelocityEngine ve = new VelocityEngine();
				ve.Init();

				StringWriter sw = new StringWriter();

				VelocityContext c = new VelocityContext();
				c.Put("x", new Something());
				c.Put("items", items);

				bool ok = ve.Evaluate(c, sw,
					"ContextTest.CaseInsensitive",
					@"
					#foreach( $item in $items )
						$item,
					#end
				");

				Assert.IsTrue(ok, "Evalutation returned failure");
				Assert.AreEqual("a,b,c,d,", Normalize(sw));
			}
		}

		public void ExecuteMethodUntilSignal2()
		{
			startEvent.WaitOne(int.MaxValue, false);

			while (!stopEvent.WaitOne(1, false))
			{
				StringWriter sw = new StringWriter();

				VelocityContext c = new VelocityContext();
				c.Put("x", new Something());
				c.Put("items", items);

				bool ok = ve.Evaluate(c, sw,
					"ContextTest.CaseInsensitive",
					@"
					#foreach( $item in $items )
						$item,
					#end
				");

				Assert.IsTrue(ok, "Evalutation returned failure");
				Assert.AreEqual("a,b,c,d,", Normalize(sw));
			}
		}
		
		private string Normalize(StringWriter sw)
		{
			return Regex.Replace(sw.ToString(), "\\s+", "");
		}
	}
}
{'fraction_non_alphanumeric': 0.13155096460580282, 'fraction_numerical': 0.010937262646209934, 'mean_word_length': 3.253229974160207, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7657470', 'n_tokens_mistral': 2558, 'n_tokens_neox': 2042, 'n_words': 563}