Esempio n. 1
0
        public void LeavingAnActionSetsTheEndTimestamp()
        {
            // given
            mockTimingProvider.ProvideTimestampInMilliseconds().Returns(123L, 321L, 322L, 323L);
            var target = new Action(logger, beacon, "test", new SynchronizedQueue <IAction>());

            // when leaving the action
            target.LeaveAction();

            // then
            Assert.That(target.EndTime, Is.EqualTo(322L));
            mockTimingProvider.Received(4).ProvideTimestampInMilliseconds();
        }
        public void CanGetCurrentTimestamp()
        {
            var expected = 12356789;

            timingProvider.ProvideTimestampInMilliseconds().Returns(expected);

            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            var actual = target.CurrentTimestamp;

            Assert.AreEqual(expected, actual);
            timingProvider.Received(1).ProvideTimestampInMilliseconds();
        }
Esempio n. 3
0
        public void LastRuntimeStampIsAdjustedDuringFirstExecution()
        {
            // given
            var configuration = new BeaconCacheConfiguration(1000L, 1000L, 2000L);
            var target        = new TimeEvictionStrategy(mockLogger, mockBeaconCache, configuration, mockTimingProvider, isShutdownFunc);

            mockTimingProvider.ProvideTimestampInMilliseconds().Returns(1000L, 1001L);

            // when executing the first time
            target.Execute();

            // then
            Assert.That(target.LastRunTimestamp, Is.EqualTo(1000L));
            mockTimingProvider.Received(2).ProvideTimestampInMilliseconds();

            // when executing the second time
            target.Execute();

            // then
            Assert.That(target.LastRunTimestamp, Is.EqualTo(1000L));
            mockTimingProvider.Received(3).ProvideTimestampInMilliseconds();
        }
        public void CurrentTimeStampGet()
        {
            // given
            const long expected = 12356789;

            mockTimingProvider.ProvideTimestampInMilliseconds().Returns(expected);

            var target = CreateSendingContext().Build();

            Assert.That(mockTimingProvider.ReceivedCalls(), Is.Empty);

            // when
            var obtained = target.CurrentTimestamp;

            // then
            Assert.That(obtained, Is.EqualTo(expected));
            mockTimingProvider.Received(1).ProvideTimestampInMilliseconds();
        }
        public void CanInterruptLongSleep()
        {
            // given
            var expected = 101717;
            var target   = new BeaconSendingContext(logger, config, clientProvider, timingProvider);

            target.RequestShutdown();
            target.Sleep(expected);

            // then
#if !NETCOREAPP1_0 || !NETCOREAPP1_1
            // normal sleep as thread interrupt exception exists
            timingProvider.Received(1).Sleep(expected);
#else
            // no interrupt exception exists, therefore "sliced" sleep break after first iteration
            timingProvider.Received(1).Sleep(Arg.Any <int>());
            timingProvider.Received(1).Sleep(BeaconSendingContext.DEFAULT_SLEEP_TIME_MILLISECONDS);
#endif
        }
        public void GetId_Get65537Ids_DelaysToNextMillisecond()
        {
            // Arrange
            // When delay is called, start moving the millisecond timer.
            _timingProvider.When(x => x.DelayMilliseconds(Arg.Any <int>()))
            .Do(arg => _wasDelayed = true);
            _timingProvider.GetNowMilliseconds()
            .ReturnsForAnyArgs(x => _wasDelayed ? ++_nowMilliseconds : _nowMilliseconds);

            // Act
            int    numberOfIds = 0x10001;
            Int128 id          = null;

            for (int i = 0; i < numberOfIds; i++)
            {
                id = _generator.GenId();
            }

            // Assert
            _timingProvider.Received(1).DelayMilliseconds(Arg.Any <int>());
            Assert.That(id?.Lo & 0xffff, Is.EqualTo(0), "Count part of ID");
        }
        public void InitializeTimeSyncDelegatesToTimingProvider()
        {
            // given
            var target = new BeaconSendingContext(logger, config, clientProvider, timingProvider);

            // when
            target.InitializeTimeSync(1L, true);

            // then
            timingProvider.Received(1).Initialze(1L, true);
        }