Ejemplo n.º 1
0
        private static void VerifySnapshotTime(
            VolatileLogicalTimeManager timeManager,
            double lowerBound)
        {
            var snapshot = timeManager.Test_GetCurrentSnapshot();
            var lower    = GetTimestamp(lowerBound - LowerBoundBuffer);
            var upper    = GetTimestamp(lowerBound + UpperBoundBuffer);

            FailTestIf(snapshot < lower, "snapshot={0} < lower={1}", snapshot, lower);
            FailTestIf(snapshot > upper, "snapshot={0} > upper={1}", snapshot, upper);
        }
Ejemplo n.º 2
0
        private static void VerifyCurrentTime(
            VolatileLogicalTimeManager timeManager,
            double lowerBound)
        {
            var current = timeManager.CurrentLogicalTime;
            var lower   = GetTimestamp(lowerBound - LowerBoundBuffer);
            var upper   = GetTimestamp(lowerBound + UpperBoundBuffer);

            FailTestIf(current < lower, "current={0} < lower={1}", current, lower);
            FailTestIf(current > upper, "current={0} > upper={1}", current, upper);
        }
Ejemplo n.º 3
0
        public void SnapshotTest()
        {
            TestCase("### SnapshotTest ###");

            var snapshotHandler  = new SnapshotHandler();
            var snapshotInterval = UpperBoundBuffer * 2;
            var timeManager      = new VolatileLogicalTimeManager(snapshotHandler, GetTimestamp(snapshotInterval));

            VerifySnapshotTime(timeManager, 0);
            VerifySnapshotCount(snapshotHandler, 0);

            timeManager.Start();

            WaitForSnapshotCount(snapshotHandler, 1, true, GetTimestamp(snapshotInterval + UpperBoundBuffer));

            VerifyCurrentTime(timeManager, snapshotInterval);
            VerifySnapshotTime(timeManager, snapshotInterval);

            WaitForSnapshotCount(snapshotHandler, 2, true, GetTimestamp(snapshotInterval + UpperBoundBuffer));

            VerifyCurrentTime(timeManager, snapshotInterval * 2);
            VerifySnapshotTime(timeManager, snapshotInterval * 2);

            timeManager.Stop();

            WaitForSnapshotCount(snapshotHandler, 2, false, GetTimestamp(snapshotInterval));

            VerifyCurrentTime(timeManager, snapshotInterval * 3);
            VerifySnapshotTime(timeManager, snapshotInterval * 2);

            timeManager.Start();

            WaitForSnapshotCount(snapshotHandler, 3, true, GetTimestamp(snapshotInterval + UpperBoundBuffer));

            VerifyCurrentTime(timeManager, snapshotInterval * 3);
            VerifySnapshotTime(timeManager, snapshotInterval * 3);

            timeManager.Stop();

            WaitForSnapshotCount(snapshotHandler, 3, false, GetTimestamp(snapshotInterval));

            VerifyCurrentTime(timeManager, snapshotInterval * 4);
            VerifySnapshotTime(timeManager, snapshotInterval * 3);
        }
Ejemplo n.º 4
0
        public void CurrentLogicalTimeTest()
        {
            TestCase("### CurrentLogicalTimeTest ###");

            var snapshotHandler  = new SnapshotHandler();
            var snapshotInterval = UpperBoundBuffer;
            var timeManager      = new VolatileLogicalTimeManager(snapshotHandler, GetTimestamp(snapshotInterval));

            VerifyCurrentTime(timeManager, 0);
            VerifySnapshotTime(timeManager, 0);

            Thread.Sleep(GetTimestamp(2));

            VerifyCurrentTime(timeManager, 2);
            VerifySnapshotTime(timeManager, 0);

            Thread.Sleep(GetTimestamp(3));

            VerifyCurrentTime(timeManager, 5);
            VerifySnapshotTime(timeManager, 0);

            Thread.Sleep(GetTimestamp(3));

            VerifyCurrentTime(timeManager, 8);
            VerifySnapshotTime(timeManager, 0);

            timeManager.CurrentLogicalTime = GetTimestamp(1);

            VerifyCurrentTime(timeManager, 1);
            VerifySnapshotTime(timeManager, 1);

            timeManager.CurrentLogicalTime = GetTimestamp(5);

            VerifyCurrentTime(timeManager, 5);
            VerifySnapshotTime(timeManager, 5);

            timeManager.CurrentLogicalTime = GetTimestamp(15);

            Thread.Sleep(GetTimestamp(1));

            VerifyCurrentTime(timeManager, 16);
            VerifySnapshotTime(timeManager, 15);
        }