예제 #1
0
 /// <summary>
 /// Try to acquire the sync before the timeout
 /// </summary>
 /// <exception cref="TimeoutException">In case a time out occurred</exception>
 public virtual void  Acquire()
 {
     if (!sync_.Attempt(timeout_))
     {
         throw new TimeoutException(timeout_);
     }
 }
예제 #2
0
 public bool TryToCauseAnError (ISync sync, long msecs)
 {
     new Thread(new ThreadStart(Go)).Start();
     bool got = sync.Attempt(msecs);
     _resetEvent.Set();
     return got;
 }
예제 #3
0
        /// <summary>
        /// Attempt to get outer and then inner sync.
        /// Release outer, if gor, on interruption while
        /// attempting inner
        /// </summary>
        public virtual bool Attempt(long msecs)
        {
            long start    = (msecs <= 0)?0:Utils.CurrentTimeMillis;
            long waitTime = msecs;

            if (outer_.Attempt(waitTime))
            {
                try
                {
                    if (msecs > 0)
                    {
                        waitTime = msecs - (Utils.CurrentTimeMillis - start);
                    }
                    if (inner_.Attempt(waitTime))
                    {
                        return(true);
                    }
                    else
                    {
                        outer_.Release();
                        return(false);
                    }
                }
                catch (System.Threading.ThreadInterruptedException ex)
                {
                    outer_.Release();
                    throw ex;
                }
            }
            else
            {
                return(false);
            }
        }
예제 #4
0
        public bool TryToCauseAnError(ISync sync, long msecs)
        {
            new Thread(new ThreadStart(Go)).Start();
            bool got = sync.Attempt(msecs);

            _resetEvent.Set();
            return(got);
        }
예제 #5
0
        public void CanBeStoppedOnAnEvent()
        {
            //TODO: test with a buffer of capacity 1 to have blocked thread
            // when shut down

            monitor.Created += new FileSystemEventHandler(ShutDownOnCreated);

            // TODO: simulate a big number of
            // events and randomly shut down
            tester.CreateFile(aFile);
            tester.CreateFile("buzzWords");
            Assert.IsTrue(sync.Attempt(msecs), "created event timed out");

            tester.DeleteFile(aFile);

            // no more events: the monitor is stopped
            sync = new Latch();
            tester.CreateFile(aFile);
            Assert.IsFalse(sync.Attempt(msecs), "created event NOT timed out");
        }
예제 #6
0
        public void CanBeStoppedOnAnEvent ()
        {
            //TODO: test with a buffer of capacity 1 to have blocked thread 
            // when shut down

            monitor.Created += new FileSystemEventHandler(ShutDownOnCreated);

            // TODO: simulate a big number of 
            // events and randomly shut down
            tester.CreateFile(aFile);
            tester.CreateFile("buzzWords");
            Assert.IsTrue(sync.Attempt(msecs), "created event timed out");            

            tester.DeleteFile(aFile);

            // no more events: the monitor is stopped
            sync = new Latch(); 
            tester.CreateFile(aFile);
            Assert.IsFalse(sync.Attempt(msecs), "created event NOT timed out");            
        }
예제 #7
0
 public void AllowRegisteringToCreatedEvents()
 {
     monitor.Created += new FileSystemEventHandler(OnCreated);
     tester.CreateFile(aFile);
     Assert.IsTrue(sync.Attempt(msecs), "created event timed out");
 }