From 67f56f0795ac0214f9828c42f8face229e204c1d Mon Sep 17 00:00:00 2001 From: David Miller Date: Sat, 21 Feb 2009 06:55:20 +0000 Subject: ClojureCLR: added ClojureCLR project to repo. --- .../LibTests/LockingTransactionTests.cs | 194 +++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 ClojureCLR/Clojure/Clojure.Tests/LibTests/LockingTransactionTests.cs (limited to 'ClojureCLR/Clojure/Clojure.Tests/LibTests/LockingTransactionTests.cs') diff --git a/ClojureCLR/Clojure/Clojure.Tests/LibTests/LockingTransactionTests.cs b/ClojureCLR/Clojure/Clojure.Tests/LibTests/LockingTransactionTests.cs new file mode 100644 index 00000000..23682559 --- /dev/null +++ b/ClojureCLR/Clojure/Clojure.Tests/LibTests/LockingTransactionTests.cs @@ -0,0 +1,194 @@ +/** + * Copyright (c) David Miller. All rights reserved. + * The use and distribution terms for this software are covered by the + * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) + * which can be found in the file epl-v10.html at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + **/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + + +using NUnit.Framework; +using Rhino.Mocks; + +using clojure.lang; + +using RMExpect = Rhino.Mocks.Expect; +using System.Threading; + +namespace Clojure.Tests.LibTests +{ + // TODO: Add tests for LockingTransaction + [TestFixture] + public class LockingTransactionTests : AssertionHelper + { + + + //// TODO: Make this work. + + //// This test is taken from the Java code. + //[Test] + //public void BigTest() + //{ + // // We have to start the main work unit on its own thread because + // // the main during testing is STA and so does not support waiting on multiple handles. + + // BigTester tester = new BigTester(5, 10, 2000); + // EventWaitHandle h = new EventWaitHandle(false, EventResetMode.ManualReset); + // Thread t = new Thread(tester.Work); + // t.Start(h); + // h.WaitOne(); + // Console.WriteLine("Done"); + //} + + //class BigTester where T : LockingTransactionTests.RefTester + //{ + // int _nthreads; + // int _niters; + // int _nitems; + + // public BigTester(int nthreads, int nitems, int niters) + // { + // _nthreads = nthreads; + // _nitems = nitems; + // _niters = niters; + // } + + // public void Work(object o) + // { + // List refs = new List(); + + // for (int i = 0; i < _nitems; i++) + // refs.Add(new Ref(0)); + + // List threads = new List(_nthreads); + // List handles = new List(_nthreads); + // List tasks = new List(_nthreads); + + // for (int i = 0; i < _nthreads; i++) + // { + // List copy = refs.GetRange(0, refs.Count); + // Shuffle(copy); + // tasks.Add(new Incrementer(i, _niters, copy)); + // threads.Add(new Thread(tasks[i].Work)); + // handles.Add(new EventWaitHandle(false, EventResetMode.ManualReset)); + // } + + + // for (int i = 0; i < _nthreads; i++) + // { + // threads[i].Name = "Thr " + i; + // threads[i].Start(handles[i]); + // } + + // EventWaitHandle.WaitAll(handles.ToArray()); + + // foreach (Incrementer task in tasks) + // Console.WriteLine("Task {0}: {1} millisecs", task.Id, task.Nanos / 10000.0); + + // foreach (Ref r in refs) + // Console.WriteLine("Ref is {0}", r.get()); + + // EventWaitHandle ewh = (EventWaitHandle)o; + // ewh.Set(); + + // } + + + // void Shuffle(List refs) + // { + // } + //} + + //public abstract class RefTester + //{ + // readonly int _id; + // public int Id + // { + // get { return _id; } + // } + + // protected readonly int _niters; + // protected readonly List _items; + + // long _nanos = 0; + // public long Nanos + // { + // get { return _nanos; } + // } + + + // public RefTester(int id, int niters, List items) + // { + // _id = id; + // _niters = niters; + // _items = items; + // } + + // public void Work(object o) + // { + // for (int i = 0; i < _niters; i++) + // { + // long startTime = DateTime.Now.Ticks; + // LockingTransaction.runInTransaction(this.TxUnit); + // long finishTime = DateTime.Now.Ticks; + // _nanos += finishTime - startTime; + // } + + // EventWaitHandle h = (EventWaitHandle)o; + // h.Set(); + // } + + // public abstract object TxUnit(object[] args); + //} + + //class Incrementer : RefTester + //{ + // public Incrementer(int id, int niters, List items) + // : base(id, niters, items) + // { + // } + + // public override object TxUnit(object[] args) + // { + // foreach (Ref r in _items) + // { + // int val = (int)r.get(); + // r.set(val + 1); + // } + // return null; + // } + //} + + + //class Commuter : RefTester + //{ + // public Commuter(int id, int niters, List items) + // : base(id, niters, items) + // { + // } + + // public override object TxUnit(object[] args) + // { + // foreach (Ref r in _items) + // { + // r.commute(Commuter.Incr,null); + // } + // return null; + // } + + // static object Incr(object[] args) + // { + // int val = (int)args[0]; + // return val + 1; + // } + //} + + } +} -- cgit v1.2.3-18-g5258