Example #1
0
 public virtual void  TestModifyResolution()
 {
     try
     {
         // increase and test
         uint resolution = 20 * TimeLimitedCollector.DEFAULT_RESOLUTION;                 //400
         TimeLimitedCollector.SetResolution(resolution);
         Assert.AreEqual(resolution, TimeLimitedCollector.GetResolution());
         DoTestTimeout(false, true);
         // decrease much and test
         resolution = 5;
         TimeLimitedCollector.SetResolution(resolution);
         Assert.AreEqual(resolution, TimeLimitedCollector.GetResolution());
         DoTestTimeout(false, true);
         // return to default and test
         resolution = TimeLimitedCollector.DEFAULT_RESOLUTION;
         TimeLimitedCollector.SetResolution(resolution);
         Assert.AreEqual(resolution, TimeLimitedCollector.GetResolution());
         DoTestTimeout(false, true);
     }
     finally
     {
         TimeLimitedCollector.SetResolution(TimeLimitedCollector.DEFAULT_RESOLUTION);
     }
 }
Example #2
0
        private HitCollector CreateTimedCollector(MyHitCollector hc, long timeAllowed, bool greedy)
        {
            TimeLimitedCollector res = new TimeLimitedCollector(hc, timeAllowed);

            res.SetGreedy(greedy);             // set to true to make sure at least one doc is collected.
            return(res);
        }
Example #3
0
        private long MaxTime(bool multiThreaded)
        {
            long res = 2 * TimeLimitedCollector.GetResolution() + TIME_ALLOWED + SLOW_DOWN;             // some slack for less noise in this test

            if (multiThreaded)
            {
                res = (long)(res * MULTI_THREAD_SLACK);                  // larger slack
            }
            return(res);
        }
Example #4
0
        private void  DoTestTimeout(bool multiThreaded, bool greedy)
        {
            // setup
            MyHitCollector myHc = new MyHitCollector(this);

            myHc.SetSlowDown(SLOW_DOWN);
            HitCollector tlCollector = CreateTimedCollector(myHc, TIME_ALLOWED, greedy);

            // search
            TimeLimitedCollector.TimeExceededException timoutException = null;
            try
            {
                Search(tlCollector);
            }
            catch (TimeLimitedCollector.TimeExceededException x)
            {
                timoutException = x;
            }
            catch (System.Exception e)
            {
                Assert.IsTrue(false, "Unexpected exception: " + e);                 //==fail
            }

            // must get exception
            Assert.IsNotNull(timoutException, "Timeout expected!");

            // greediness affect last doc collected
            int exceptionDoc  = timoutException.GetLastDocCollected();
            int lastCollected = myHc.GetLastDocCollected();

            Assert.IsTrue(exceptionDoc > 0, "doc collected at timeout must be > 0!");
            if (greedy)
            {
                Assert.IsTrue(exceptionDoc == lastCollected, "greedy=" + greedy + " exceptionDoc=" + exceptionDoc + " != lastCollected=" + lastCollected);
                Assert.IsTrue(myHc.HitCount() > 0, "greedy, but no hits found!");
            }
            else
            {
                Assert.IsTrue(exceptionDoc > lastCollected, "greedy=" + greedy + " exceptionDoc=" + exceptionDoc + " not > lastCollected=" + lastCollected);
            }

            // verify that elapsed time at exception is within valid limits
            Assert.AreEqual(timoutException.GetTimeAllowed(), TIME_ALLOWED);
            // a) Not too early
            Assert.IsTrue(timoutException.GetTimeElapsed() > TIME_ALLOWED - TimeLimitedCollector.GetResolution(), "elapsed=" + timoutException.GetTimeElapsed() + " <= (allowed-resolution)=" + (TIME_ALLOWED - TimeLimitedCollector.GetResolution()));
            // b) Not too late.
            //    This part is problematic in a busy test system, so we just print a warning.
            //    We already verified that a timeout occurred, we just can't be picky about how long it took.
            if (timoutException.GetTimeElapsed() > MaxTime(multiThreaded))
            {
                System.Console.Out.WriteLine("Informative: timeout exceeded (no action required: most probably just " + " because the test machine is slower than usual):  " + "lastDoc=" + exceptionDoc + " ,&& allowed=" + timoutException.GetTimeAllowed() + " ,&& elapsed=" + timoutException.GetTimeElapsed() + " >= " + MaxTimeStr(multiThreaded));
            }
        }
		private HitCollector CreateTimedCollector(MyHitCollector hc, long timeAllowed, bool greedy)
		{
			TimeLimitedCollector res = new TimeLimitedCollector(hc, timeAllowed);
			res.SetGreedy(greedy); // set to true to make sure at least one doc is collected.
			return res;
		}
Example #6
0
 private System.String MaxTimeStr(bool multiThreaded)
 {
     System.String s = "( " + "2*resolution +  TIME_ALLOWED + SLOW_DOWN = " + "2*" + TimeLimitedCollector.GetResolution() + " + " + TIME_ALLOWED + " + " + SLOW_DOWN + ")";
     if (multiThreaded)
     {
         s = MULTI_THREAD_SLACK + " * " + s;
     }
     return(MaxTime(multiThreaded) + " = " + s);
 }