You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by sc...@apache.org on 2008/12/01 16:35:15 UTC

svn commit: r722098 - in /incubator/etch/trunk/binding-csharp/runtime/src: main/csharp/Etch/Support/Mailbox.cs main/csharp/Etch/Transport/PlainMailbox.cs test/csharp/Etch/Transport/TestPlainMailbox.cs

Author: sccomer
Date: Mon Dec  1 07:35:14 2008
New Revision: 722098

URL: http://svn.apache.org/viewvc?rev=722098&view=rev
Log:
fix the fix for ETCH-8: canceling mailbox notification registration throws exception if not registered.

unit tests for fix for ETCH-8.

Modified:
    incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Support/Mailbox.cs
    incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Transport/PlainMailbox.cs
    incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/Etch/Transport/TestPlainMailbox.cs

Modified: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Support/Mailbox.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Support/Mailbox.cs?rev=722098&r1=722097&r2=722098&view=diff
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Support/Mailbox.cs (original)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Support/Mailbox.cs Mon Dec  1 07:35:14 2008
@@ -54,7 +54,7 @@
 
        ///<summary>Registers a Notify interface implementation to receive a callback
 	   ///when a mailbox's status is changed.</summary>
-	   ///<param> notify a Notify interface implementation to report the
+	   ///<param> newNotify a Notify interface implementation to report the
 	   ///delivery status to. </param>
 	   ///<param> state a state value to pass thru to the Notify interface
 	   /// implementation. </param>
@@ -62,14 +62,14 @@
 	   ///wait for delivery of a message to the mailbox. 0 means wait
 	   ///forever. The mailbox is closed upon timeout.<param>
     	
-	   void RegisterNotify( Notify notify, Object state, int maxDelay );
+	   void RegisterNotify( Notify newNotify, Object state, int maxDelay );
 	
 	
 	   /// <summary>Unregisters a Notify interface implementation from receiving a callback
 	   /// when a mailbox's status is changed. Cancels any timeout. </summary>
-	   ///<param> notify a Notify interface implementation which was previously
+       ///<param> oldNotify a Notify interface implementation which was previously
 	   ///registered. </param>    	
-	   void UnregisterNotify( Notify notify );
+	   void UnregisterNotify( Notify oldNotify );
 
 
         bool Message(Who sender, Message msg);

Modified: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Transport/PlainMailbox.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Transport/PlainMailbox.cs?rev=722098&r1=722097&r2=722098&view=diff
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Transport/PlainMailbox.cs (original)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Transport/PlainMailbox.cs Mon Dec  1 07:35:14 2008
@@ -198,10 +198,10 @@
             return 0;
         }
 
-        public void RegisterNotify(Notify notify, Object state, int maxDelay)
+        public void RegisterNotify(Notify newNotify, Object state, int maxDelay)
         {
-            if (notify == null)
-                throw new NullReferenceException("notify == null");
+            if (newNotify == null)
+                throw new ArgumentNullException("newNotify == null");
 
             if (maxDelay < 0)
                 throw new ArgumentException("maxDelay < 0");
@@ -213,7 +213,7 @@
                 if (this.notify != null)
                     throw new Exception("this.notify != null");
 
-                this.notify = notify;
+                this.notify = newNotify;
                 this.state = state;
 
                 if (maxDelay > 0)
@@ -229,18 +229,18 @@
                 fireNotify();
         }
 
-        public void UnregisterNotify(Notify notify)
+        public void UnregisterNotify(Notify oldNotify)
         {
-            if (notify == null)
-                throw new ArgumentNullException("notify == null");
+            if (oldNotify == null)
+                throw new ArgumentNullException("oldNotify == null");
+
+            if (this.notify == null)
+                return;
 
             lock (queue)
             {
-                if (notify != this.notify)
-                    throw new ArgumentException("notify != this.notify");
-
-                if (this.notify == null)
-                    return;
+                if (oldNotify != this.notify)
+                    throw new ArgumentException("oldNotify != this.notify");
 
                 if (alarmSet)
                 {

Modified: incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/Etch/Transport/TestPlainMailbox.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/Etch/Transport/TestPlainMailbox.cs?rev=722098&r1=722097&r2=722098&view=diff
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/Etch/Transport/TestPlainMailbox.cs (original)
+++ incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/Etch/Transport/TestPlainMailbox.cs Mon Dec  1 07:35:14 2008
@@ -27,37 +27,34 @@
 namespace Etch.Transport
 {
     [TestFixture]
-    public class TestPlainMailbox : MailboxManager, Notify
+    public class TestPlainMailbox : MailboxManager
     {
-
         [SetUp]
         public void Init()
         {
-            mailboxStatus1 = false;
-             mailbox = null;
-
-             state = null;
-
-            closed = false;
             unregistered = false;
 
-       //     AlarmManager.SetAlarmManager(null);
+            //     AlarmManager.SetAlarmManager(null);
 
             redelivered = new List<Element>();
 
             vf = new MyValueFactory();
-	
-            mt_foo = new XType( "foo" );
-	
-            foo_msg = new Message( mt_foo, vf );
+
+            mt_foo = new XType("foo");
+
+            foo_msg = new Message(mt_foo, vf);
 
             fred_who = new WhoAmI();
-	
-            mt_bar = new XType( "bar" );
-	
-            bar_msg = new Message( mt_bar, vf );
-	
-            alice_who = new WhoAmI(); 
+
+            mt_bar = new XType("bar");
+
+            bar_msg = new Message(mt_bar, vf);
+
+            alice_who = new WhoAmI();
+
+            notify = new MyNotify();
+
+            notify1x = new MyNotify();
         }
         
         [Test]
@@ -350,15 +347,15 @@
         public void notify1()
         {
             PlainMailbox mb = new PlainMailbox(this, 1L);
-            checkMailboxStatus(false, null, null, false);
+            notify.checkMailboxStatus(false, null, null, false);
 
             Object state = new Object();
 
-            mb.RegisterNotify(this, state, 0);
-            checkMailboxStatus(false, null, null, false);
+            mb.RegisterNotify(notify, state, 0);
+            notify.checkMailboxStatus(false, null, null, false);
 
             checkCloseDelivery(mb, true);
-            checkMailboxStatus(true, mb, state, true);
+            notify.checkMailboxStatus(true, mb, state, true);
         }
 
 
@@ -366,15 +363,15 @@
         public void notify2()
         {
             PlainMailbox mb = new PlainMailbox(this, 1L);
-            checkMailboxStatus(false, null, null, false);
+            notify.checkMailboxStatus(false, null, null, false);
 
             Object state = new Object();
 
-            mb.RegisterNotify(this, state, 1000);
-            checkMailboxStatus(false, null, null, false);
+            mb.RegisterNotify(notify, state, 1000);
+            notify.checkMailboxStatus(false, null, null, false);
 
             Thread.Sleep(2000);
-            checkMailboxStatus(true, mb, state, true);
+            notify.checkMailboxStatus(true, mb, state, true);
         }
 
 
@@ -382,15 +379,15 @@
         public void notify3()
         {
             PlainMailbox mb = new PlainMailbox(this, 1L);
-            checkMailboxStatus(false, null, null, false);
+            notify.checkMailboxStatus(false, null, null, false);
 
             Object state = new Object();
 
-            mb.RegisterNotify(this, state, 0);
-            checkMailboxStatus(false, null, null, false);
+            mb.RegisterNotify(notify, state, 0);
+            notify.checkMailboxStatus(false, null, null, false);
 
-            Thread.Sleep(20);
-            checkMailboxStatus(false, null, null, false);
+            Thread.Sleep(2000);
+            notify.checkMailboxStatus(false, null, null, false);
         }
 
 
@@ -398,15 +395,115 @@
         public void notify4()
         {
             PlainMailbox mb = new PlainMailbox(this, 1L);
-            checkMailboxStatus(false, null, null, false);
+            notify.checkMailboxStatus(false, null, null, false);
 
             Object state = new Object();
 
-            mb.RegisterNotify(this, state, 0);
-            checkMailboxStatus(false, null, null, false);
+            mb.RegisterNotify(notify, state, 0);
+            notify.checkMailboxStatus(false, null, null, false);
 
             mb.Message(alice_who, foo_msg);
-            checkMailboxStatus(true, mb, state, false);
+            notify.checkMailboxStatus(true, mb, state, false);
+        }
+
+        [Test]
+        [ExpectedException(typeof(ArgumentNullException))]
+        public void reg1()
+        {
+            // notify == null
+            PlainMailbox mb = new PlainMailbox(this, 1L);
+            mb.RegisterNotify(null, null, 0);
+        }
+
+        [Test]
+        [ExpectedException(typeof(ArgumentException))]
+        public void reg2()
+        {
+            // maxDelay < 0
+            PlainMailbox mb = new PlainMailbox(this, 1L);
+            mb.RegisterNotify(notify, null, -1);
+        }
+
+        [Test]
+        public void reg3()
+        {
+            PlainMailbox mb = new PlainMailbox(this, 1L);
+            mb.RegisterNotify(notify, null, 0);
+        }
+
+        [Test]
+        [ExpectedException(typeof(Exception))]
+        public void reg4()
+        {
+            // this.notify != null
+            PlainMailbox mb = new PlainMailbox(this, 1L);
+            mb.RegisterNotify(notify, null, 0);
+            mb.RegisterNotify(notify, null, 0);
+        }
+
+        [Test]
+        [ExpectedException(typeof(Exception))]
+        public void reg5()
+        {
+            // this.notify != null
+            PlainMailbox mb = new PlainMailbox(this, 1L);
+            mb.RegisterNotify(notify, null, 0);
+            mb.RegisterNotify(notify1x, null, 0);
+        }
+
+        [Test]
+        public void unreg1()
+        {
+            PlainMailbox mb = new PlainMailbox(this, 1L);
+            mb.UnregisterNotify(notify);
+        }
+
+        [Test]
+        public void unreg2()
+        {
+            PlainMailbox mb = new PlainMailbox(this, 1L);
+            mb.RegisterNotify(notify, null, 0);
+            mb.UnregisterNotify(notify);
+        }
+
+        [Test]
+        public void unreg3()
+        {
+            PlainMailbox mb = new PlainMailbox(this, 1L);
+            mb.RegisterNotify(notify, null, 0);
+            mb.UnregisterNotify(notify);
+            mb.UnregisterNotify(notify);
+            mb.UnregisterNotify(notify1x);
+        }
+
+        [Test]
+        public void unreg4()
+        {
+            PlainMailbox mb = new PlainMailbox(this, 1L);
+            mb.RegisterNotify(notify, null, 0);
+            mb.UnregisterNotify(notify);
+            mb.RegisterNotify(notify, null, 0);
+            mb.UnregisterNotify(notify);
+            mb.RegisterNotify(notify1x, null, 0);
+            mb.UnregisterNotify(notify1x);
+        }
+
+        [Test]
+        [ExpectedException(typeof(ArgumentException))]
+        public void unreg5()
+        {
+            // notify != this.notify
+            PlainMailbox mb = new PlainMailbox(this, 1L);
+            mb.RegisterNotify(notify, null, 0);
+            mb.UnregisterNotify(notify1x);
+        }
+
+        [Test]
+        public void unreg6()
+        {
+            PlainMailbox mb = new PlainMailbox(this, 1L);
+            mb.RegisterNotify(notify, null, 30);
+            mb.UnregisterNotify(notify);
         }
 
         ///////////////////
@@ -427,6 +524,10 @@
 
         private Who alice_who;
 
+        private MyNotify notify;
+
+        private MyNotify notify1x;
+
         private void testConstruct(long messageId)
         {
             PlainMailbox mb = new PlainMailbox(this, messageId);
@@ -511,35 +612,6 @@
         private bool unregistered;
 
         ////////////////////
-        // Notify methods //
-        ////////////////////
-
-        public void mailboxStatus(Mailbox mb, Object state, bool closed)
-        {
-            mailboxStatus1 = true;
-            this.mailbox = mb;
-            this.state = state;
-            this.closed = closed;
-        }
-
-        private bool mailboxStatus1;
-
-        private Mailbox mailbox;
-
-        private Object state;
-
-        private bool closed;
-
-        private void checkMailboxStatus(bool mailboxStatus, Mailbox mailbox,
-            Object state, bool closed)
-        {
-            Assert.AreEqual(mailboxStatus, this.mailboxStatus1);
-            Assert.AreSame(mailbox, this.mailbox);
-            Assert.AreSame(state, this.state);
-            Assert.AreEqual(closed, this.closed);
-        }
-
-        ////////////////////
         // MyValueFactory //
         ////////////////////
 
@@ -658,11 +730,40 @@
                 throw new Exception("The method or operation is not implemented.");
             }
         }
+
         public class WhoAmI : Who
         {
             
         }
 
+        public class MyNotify : Notify
+        {
+            public void mailboxStatus(Mailbox mb, Object state, bool closed)
+            {
+                mailboxStatus1 = true;
+                this.mailbox = mb;
+                this.state = state;
+                this.closed = closed;
+            }
+
+            private bool mailboxStatus1;
+
+            private Mailbox mailbox;
+
+            private Object state;
+
+            private bool closed;
+
+            public void checkMailboxStatus(bool mailboxStatus, Mailbox mailbox,
+                Object state, bool closed)
+            {
+                Assert.AreEqual(mailboxStatus, this.mailboxStatus1);
+                Assert.AreSame(mailbox, this.mailbox);
+                Assert.AreSame(state, this.state);
+                Assert.AreEqual(closed, this.closed);
+            }
+        }
+
         #region MailboxManager Members