Esempio n. 1
0
        public void TestAddTwice()
        {
            _service.Add(100, _callbacks[0], _slots[0][0]);
            Assert.IsTrue(_service.IsScheduled(_callbacks[0]));
            _service.Add(100, _callbacks[0], _slots[0][0]);

            _service.Add(ScheduleComputeHelper.ComputeNextOccurance(new ScheduleSpec(), _service.Time, TimeZoneInfo.Local, TimeAbacusMilliseconds.INSTANCE), _callbacks[1], _slots[0][0]);
            _service.Add(ScheduleComputeHelper.ComputeNextOccurance(new ScheduleSpec(), _service.Time, TimeZoneInfo.Local, TimeAbacusMilliseconds.INSTANCE), _callbacks[1], _slots[0][0]);
        }
Esempio n. 2
0
        public void CheckCorrect(ScheduleSpec spec, String now, String expected)
        {
            var provider     = Thread.CurrentThread.CurrentCulture;
            var nowDate      = DateTimeOffset.ParseExact(now, "yyyy-MM-d H:mm:ss", provider);
            var expectedDate = DateTimeOffset.ParseExact(expected, "yyyy-MM-d H:mm:ss", provider);

            var result     = ScheduleComputeHelper.ComputeNextOccurance(spec, nowDate.TimeInMillis(), TimeZoneInfo.Local);
            var resultDate = result.TimeFromMillis(expectedDate.Offset);

            if (resultDate != expectedDate)
            {
                Log.Debug(".checkCorrect Difference in result found, spec=" + spec);
                Log.Debug(".checkCorrect      now=" + nowDate.ToString(TimeFormat) + " long=" + nowDate.TimeInMillis());
                Log.Debug(".checkCorrect expected=" + expectedDate.ToString(TimeFormat) + " long=" + expectedDate.TimeInMillis());
                Log.Debug(".checkCorrect   result=" + resultDate.ToString(TimeFormat) + " long=" + resultDate.TimeInMillis());
                Assert.Fail();
            }
        }
Esempio n. 3
0
        public void CheckCorrectWZone(ScheduleSpec spec, String nowWZone, String expectedWZone)
        {
            var nowDate      = DateTimeParser.ParseDefaultMSecWZone(nowWZone);
            var nowDateJava  = DateTimeOffsetHelper.MillisToJavaMillis(nowDate);
            var expectedDate = DateTimeParser.ParseDefaultMSecWZone(expectedWZone);

            var result = ScheduleComputeHelper.ComputeNextOccurance(spec, nowDate, TimeZoneInfo.Local);

            var resultDate = result.TimeFromMillis(null);

            if (result != expectedDate)
            {
                Log.Debug(".checkCorrect Difference in result found, spec=" + spec);
                Log.Debug(".checkCorrect      now=" + nowDate.ToString(TimeFormat) + " long=" + nowDate);
                Log.Debug(".checkCorrect expected=" + expectedDate.ToString(TimeFormat) + " long=" + expectedDate);
                Log.Debug(".checkCorrect   result=" + resultDate.ToString(TimeFormat) + " long=" + resultDate);
                Assert.Fail();
            }
        }
Esempio n. 4
0
        public void CheckCorrectWZone(ScheduleSpec spec, String nowWZone, String expectedWZone)
        {
            var nowDateEx = DateTimeParser.ParseDefaultExWZone(nowWZone);
            var nowDate   = nowDateEx.TimeInMillis;
            //var nowDateJava = DateTimeOffsetHelper.MillisToJavaMillis(nowDate);

            var expectedDateEx = DateTimeParser.ParseDefaultExWZone(expectedWZone);
            var expectedDate   = expectedDateEx.TimeInMillis;

            var result   = ScheduleComputeHelper.ComputeNextOccurance(spec, nowDate, nowDateEx.TimeZone, TimeAbacusMilliseconds.INSTANCE);
            var resultEx = DateTimeEx.GetInstance(expectedDateEx.TimeZone, result);

            var resultDate = result.TimeFromMillis(null);

            if (result != expectedDate)
            {
                Log.Debug(".checkCorrect Difference in result found, spec=" + spec);
                Log.Debug(".checkCorrect      now=" + nowDate.ToString(TimeFormat) + " long=" + nowDate);
                Log.Debug(".checkCorrect expected=" + expectedDate.ToString(TimeFormat) + " long=" + expectedDate);
                Log.Debug(".checkCorrect   result=" + resultDate.ToString(TimeFormat) + " long=" + resultDate);
                Assert.Fail();
            }
        }
Esempio n. 5
0
        public void TestWaitAndSpecTogether()
        {
            var startDate = new DateTime(2004, 12, 9, 15, 27, 10, 500, DateTimeKind.Local);
            var startTime = startDate.UtcMillis();

            _service.Time = startTime;

            // Add a specification
            var spec = new ScheduleSpec();

            spec.AddValue(ScheduleUnit.MONTHS, 12);
            spec.AddValue(ScheduleUnit.DAYS_OF_MONTH, 9);
            spec.AddValue(ScheduleUnit.HOURS, 15);
            spec.AddValue(ScheduleUnit.MINUTES, 27);
            spec.AddValue(ScheduleUnit.SECONDS, 20);

            _service.Add(ScheduleComputeHelper.ComputeDeltaNextOccurance(spec, _service.Time, TimeZoneInfo.Local, TimeAbacusMilliseconds.INSTANCE), _callbacks[3], _slots[1][1]);

            spec.AddValue(ScheduleUnit.SECONDS, 15);
            _service.Add(ScheduleComputeHelper.ComputeDeltaNextOccurance(spec, _service.Time, TimeZoneInfo.Local, TimeAbacusMilliseconds.INSTANCE), _callbacks[4], _slots[2][0]);

            // Add some more callbacks
            _service.Add(5000, _callbacks[0], _slots[0][0]);
            _service.Add(10000, _callbacks[1], _slots[0][1]);
            _service.Add(15000, _callbacks[2], _slots[1][0]);

            // GetInstance send a times reflecting various seconds later and check who got a callback
            _service.Time = startTime + 1000;
            SupportScheduleCallback.SetCallbackOrderNum(0);
            EvaluateSchedule();
            CheckCallbacks(_callbacks, new[] { 0, 0, 0, 0, 0 });

            _service.Time = startTime + 2000;
            EvaluateSchedule();
            CheckCallbacks(_callbacks, new[] { 0, 0, 0, 0, 0 });

            _service.Time = startTime + 4000;
            EvaluateSchedule();
            CheckCallbacks(_callbacks, new[] { 0, 0, 0, 0, 0 });

            _service.Time = startTime + 5000;
            EvaluateSchedule();
            CheckCallbacks(_callbacks, new[] { 1, 0, 0, 0, 2 });

            _service.Time = startTime + 9000;
            EvaluateSchedule();
            CheckCallbacks(_callbacks, new[] { 0, 0, 0, 0, 0 });

            _service.Time = startTime + 10000;
            EvaluateSchedule();
            CheckCallbacks(_callbacks, new[] { 0, 3, 0, 4, 0 });

            _service.Time = startTime + 11000;
            EvaluateSchedule();
            CheckCallbacks(_callbacks, new[] { 0, 0, 0, 0, 0 });

            _service.Time = startTime + 15000;
            EvaluateSchedule();
            CheckCallbacks(_callbacks, new[] { 0, 0, 5, 0, 0 });

            _service.Time = startTime + int.MaxValue;
            EvaluateSchedule();
            CheckCallbacks(_callbacks, new[] { 0, 0, 0, 0, 0 });
        }