public void GivenUnPomodoroNoIniciado() { var timer = new FakeTimer(null); var pomodoro = new Pomodoro(timer); ScenarioContext.Current.Set(pomodoro); ScenarioContext.Current.Set(timer); }
public void If_triggers_critical_action_after_10_failures() { var criticalActionTriggered = false; var timer = new FakeTimer(); var cleaner = new DedupeCleaner(_ => Task.FromResult(0), _ => criticalActionTriggered = true, TimeSpan.Zero, timer); cleaner.Start(); for (var i = 0; i < 9; i++) { timer.OnError(new Exception("Simulated!")); } Assert.False(criticalActionTriggered); //Trigger the 10th time timer.OnError(new Exception("Simulated!")); Assert.True(criticalActionTriggered); criticalActionTriggered = false; //Trigger again -- the counter should be reset timer.OnError(new Exception("Simulated!")); Assert.False(criticalActionTriggered); }
public async Task It_logs_error_when_file_access_fails_during_runtime() { var errorCallbackInvoked = false; var timer = new FakeTimer(ex => { errorCallbackInvoked = true; }); var fail = false; var fileAccess = new FakeFileAccess(() => { // ReSharper disable once AccessToModifiedClosure if (fail) { throw new Exception("Simulated"); } return(XDocument.Parse(@"<endpoints><endpoint name=""A""><instance/></endpoint></endpoints>")); }); var monitor = new InstanceMappingFileMonitor("unused", TimeSpan.Zero, timer, fileAccess, new EndpointInstances()); await monitor.PerformStartup(null); fail = true; await timer.Trigger(); Assert.IsTrue(errorCallbackInvoked); }
public void WhenCreoUnNuevoPomodoroSinEspecificarSuDuracion() { var timer = new FakeTimer(null); var pomodoro = new Pomodoro(timer); ScenarioContext.Current.Set(pomodoro); ScenarioContext.Current.Set(timer); }
public void WhenCreoUnNuevoPomodoroEspedificandounaDuracion(int minutes) { var timer = new FakeTimer(null); var pomodoro = new Pomodoro(timer, minutes); ScenarioContext.Current.Set(pomodoro); ScenarioContext.Current.Set(timer); }
public async Task If_triggers_critical_action_after_10_failures() { var criticalActionTriggered = false; var timer = new FakeTimer(); var cleaner = new TestableCleaner((time, token) => Task.FromResult(0), (m, e) => criticalActionTriggered = true, TimeSpan.FromDays(7), TimeSpan.Zero, timer); await cleaner.Start().ConfigureAwait(false); for (var i = 0; i < 9; i++) { timer.OnError(new Exception("Simulated!")); } Assert.IsFalse(criticalActionTriggered); //Trigger the 10th time timer.OnError(new Exception("Simulated!")); Assert.IsTrue(criticalActionTriggered); criticalActionTriggered = false; //Trigger again -- the counter should be reset timer.OnError(new Exception("Simulated!")); Assert.IsFalse(criticalActionTriggered); }
public async Task It_logs_error_when_file_access_fails_during_runtime() { var errorCallbackInvoked = false; var timer = new FakeTimer(ex => { errorCallbackInvoked = true; }); var fail = false; var fileAccess = new FakeFileAccess(() => { // ReSharper disable once AccessToModifiedClosure if (fail) { throw new Exception("Simulated"); } return XDocument.Parse(@"<endpoints><endpoint name=""A""><instance/></endpoint></endpoints>"); }); var monitor = new InstanceMappingFileMonitor("unused", TimeSpan.Zero, timer, fileAccess, new EndpointInstances()); await monitor.PerformStartup(null); fail = true; await timer.Trigger(); Assert.IsTrue(errorCallbackInvoked); }
public void Setup() { _arduino = A.Fake <IArduino>(); _timer = new FakeTimer(); _led = new LedPwm(_arduino, Pin, _timer); _led.Intensity.ShouldEqual(0); }
public async Task It_logs_error_when_file_access_fails_during_runtime() { var errorCallbackInvoked = false; var timer = new FakeTimer(ex => { errorCallbackInvoked = true; }); var fail = false; var loader = new FakeLoader(() => { if (fail) { throw new Exception("Simulated"); } return(XDocument.Parse(@"<endpoints><endpoint name=""A""><instance/></endpoint></endpoints>")); }); var monitor = new InstanceMappingFileMonitor(TimeSpan.Zero, timer, loader, new EndpointInstances()); await monitor.Start(null); fail = true; await timer.Trigger(); Assert.IsTrue(errorCallbackInvoked); }
public void GivenUnPomodoroIniciado() { var timer = new FakeTimer(null); var pomodoro = new Pomodoro(timer); SystemTime.Now = () => TestConstants.GeneralStartTime; pomodoro.Start(); ScenarioContext.Current.Set(pomodoro); ScenarioContext.Current.Set(timer); }
public void SetUp() { _output = Substitute.For <IOutput>(); _fakeTimer = new FakeTimer(); _display = new Display(_output); //_timer = Substitute.For<ITimer>(); _powertube = Substitute.For <IPowerTube>(); _uut = new CookController(_fakeTimer, _display, _powertube); }
public virtual void TestNegativeGroupCaching() { string user = "******"; string failMessage = "Did not throw IOException: "; conf.SetLong(CommonConfigurationKeys.HadoopSecurityGroupsNegativeCacheSecs, 2); FakeTimer timer = new FakeTimer(); Groups groups = new Groups(conf, timer); groups.CacheGroupsAdd(Arrays.AsList(myGroups)); groups.Refresh(); TestGroupsCaching.FakeGroupMapping.AddToBlackList(user); // In the first attempt, the user will be put in the negative cache. try { groups.GetGroups(user); NUnit.Framework.Assert.Fail(failMessage + "Failed to obtain groups from FakeGroupMapping." ); } catch (IOException e) { // Expects to raise exception for the first time. But the user will be // put into the negative cache GenericTestUtils.AssertExceptionContains("No groups found for user", e); } // The second time, the user is in the negative cache. try { groups.GetGroups(user); NUnit.Framework.Assert.Fail(failMessage + "The user is in the negative cache."); } catch (IOException e) { GenericTestUtils.AssertExceptionContains("No groups found for user", e); } // Brings back the backend user-group mapping service. TestGroupsCaching.FakeGroupMapping.ClearBlackList(); // It should still get groups from the negative cache. try { groups.GetGroups(user); NUnit.Framework.Assert.Fail(failMessage + "The user is still in the negative cache, even " + "FakeGroupMapping has resumed."); } catch (IOException e) { GenericTestUtils.AssertExceptionContains("No groups found for user", e); } // Let the elements in the negative cache expire. timer.Advance(4 * 1000); // The groups for the user is expired in the negative cache, a new copy of // groups for the user is fetched. Assert.Equal(Arrays.AsList(myGroups), groups.GetGroups(user)); }
public void Reload_should_throw_when_file_does_not_exist() { var timer = new FakeTimer(); var fileAccessException = new Exception("Simulated"); var loader = new FakeLoader(() => throw fileAccessException); var monitor = new InstanceMappingFileMonitor(TimeSpan.Zero, timer, loader, new EndpointInstances()); var exception = Assert.Throws <Exception>(() => monitor.ReloadData()); Assert.That(exception.Message, Does.Contain("An error occurred while reading the endpoint instance mapping (NServiceBus.Transport.Msmq.Tests.InstanceMappingFileMonitorTests+FakeLoader). See the inner exception for more details.")); Assert.That(exception.InnerException, Is.EqualTo(fileAccessException)); }
public void SetUp() { _timeSlotObserver = new FakeTimeSlotObserver(); _timeProvider = new FakeTimeProvider(); _timer = new FakeTimer(); var timeSlotStore = new Mock <ITimeSlotStore>(); _timeSlots = new List <PowerTimeSlot>(); timeSlotStore.Setup(x => x.GetTimeSlots()).Returns(_timeSlots); _timeSlotManager = new TimeSlotManager(_timeSlotObserver, _timer, _timeProvider, timeSlotStore.Object); }
public virtual void TestNegativeCacheEntriesExpire() { conf.SetLong(CommonConfigurationKeys.HadoopSecurityGroupsNegativeCacheSecs, 2); FakeTimer timer = new FakeTimer(); // Ensure that stale entries are removed from negative cache every 2 seconds Groups groups = new Groups(conf, timer); groups.CacheGroupsAdd(Arrays.AsList(myGroups)); groups.Refresh(); // Add both these users to blacklist so that they // can be added to negative cache TestGroupsCaching.FakeGroupMapping.AddToBlackList("user1"); TestGroupsCaching.FakeGroupMapping.AddToBlackList("user2"); // Put user1 in negative cache. try { groups.GetGroups("user1"); NUnit.Framework.Assert.Fail("Did not throw IOException : Failed to obtain groups" + " from FakeGroupMapping."); } catch (IOException e) { GenericTestUtils.AssertExceptionContains("No groups found for user", e); } // Check if user1 exists in negative cache Assert.True(groups.GetNegativeCache().Contains("user1")); // Advance fake timer timer.Advance(1000); // Put user2 in negative cache try { groups.GetGroups("user2"); NUnit.Framework.Assert.Fail("Did not throw IOException : Failed to obtain groups" + " from FakeGroupMapping."); } catch (IOException e) { GenericTestUtils.AssertExceptionContains("No groups found for user", e); } // Check if user2 exists in negative cache Assert.True(groups.GetNegativeCache().Contains("user2")); // Advance timer. Only user2 should be present in negative cache. timer.Advance(1100); NUnit.Framework.Assert.IsFalse(groups.GetNegativeCache().Contains("user1")); Assert.True(groups.GetNegativeCache().Contains("user2")); // Advance timer. Even user2 should not be present in negative cache. timer.Advance(1000); NUnit.Framework.Assert.IsFalse(groups.GetNegativeCache().Contains("user2")); }
public OnPostSave() { now = DateTime.UtcNow; sagaStore = new Mock<IStoreSagas>(); eventPublisher = new Mock<IPublishEvents>(); timeoutDispatcher = new TimeoutDispatcher(new Lazy<IStoreSagas>(() => sagaStore.Object), new Lazy<IPublishEvents>(() => eventPublisher.Object), callback => timer = new FakeTimer(callback)); sagaTimeout = new SagaTimeout(typeof(FakeSaga), GuidStrategy.NewGuid(), now.AddMinutes(5)); SystemTime.OverrideWith(() => now); sagaStore.Setup(mock => mock.GetScheduledTimeouts(It.IsAny<DateTime>())).Returns(new[] { sagaTimeout }); timer.InvokeCallback(); timer.Reset(); }
private Executor CreateSut( FakeWindower windower, FakePlayer player, FakeTimer timer) { var memory = new FakeMemoryAPI(); memory.Player = player; memory.Windower = windower; memory.Timer = timer; var sut = new Executor(memory); return(sut); }
public void Reload_should_throw_when_file_does_not_exist() { const string filePath = "some file path"; var timer = new FakeTimer(); var fileAccessException = new Exception("Simulated"); var fileAccess = new FakeFileAccess(() => { throw fileAccessException; }); var monitor = new InstanceMappingFileMonitor(filePath, TimeSpan.Zero, timer, fileAccess, new EndpointInstances()); var exception = Assert.Throws <Exception>(() => monitor.ReloadData()); Assert.That(exception.Message, Does.Contain($"An error occurred while reading the endpoint instance mapping file at {filePath}. See the inner exception for more details.")); Assert.That(exception.InnerException, Is.EqualTo(fileAccessException)); }
public void Reload_should_throw_when_file_does_not_exist() { const string filePath = "some file path"; var timer = new FakeTimer(); var fileAccessException = new Exception("Simulated"); var fileAccess = new FakeFileAccess(() => { throw fileAccessException; }); var monitor = new InstanceMappingFileMonitor(filePath, TimeSpan.Zero, timer, fileAccess, new EndpointInstances()); var exception = Assert.Throws<Exception>(() => monitor.ReloadData()); Assert.That(exception.Message, Does.Contain($"An error occurred while reading the endpoint instance mapping file at {filePath}. See the inner exception for more details.")); Assert.That(exception.InnerException, Is.EqualTo(fileAccessException)); }
public async Task It_uses_correct_cut_off_time() { var timer = new FakeTimer(); var cutOffTime = DateTime.MinValue; var cleaner = new TestableCleaner((time, token) => { cutOffTime = time; return(Task.FromResult(0)); }, (m, e) => { }, TimeSpan.FromDays(7), TimeSpan.Zero, timer); await cleaner.Start().ConfigureAwait(false); var now = new DateTime(2017, 3, 31, 0, 0, 0); await timer.Tick(now, CancellationToken.None).ConfigureAwait(false); var expected = new DateTime(2017, 3, 24, 0, 0, 0); Assert.AreEqual(expected, cutOffTime); }
public virtual void TestCacheEntriesExpire() { conf.SetLong(CommonConfigurationKeys.HadoopSecurityGroupsCacheSecs, 1); FakeTimer timer = new FakeTimer(); Groups groups = new Groups(conf, timer); groups.CacheGroupsAdd(Arrays.AsList(myGroups)); groups.Refresh(); TestGroupsCaching.FakeGroupMapping.ClearBlackList(); // We make an entry groups.GetGroups("me"); int startingRequestCount = TestGroupsCaching.FakeGroupMapping.GetRequestCount(); timer.Advance(20 * 1000); // Cache entry has expired so it results in a new fetch groups.GetGroups("me"); Assert.Equal(startingRequestCount + 1, TestGroupsCaching.FakeGroupMapping .GetRequestCount()); }
public async Task It_resets_the_failure_counter_after_successful_attempt() { var criticalActionTriggered = false; var timer = new FakeTimer(); var cleaner = new TestableCleaner((time, token) => Task.FromResult(0), (m, e) => criticalActionTriggered = true, TimeSpan.FromDays(7), TimeSpan.Zero, timer); await cleaner.Start().ConfigureAwait(false); for (var i = 0; i < 100; i++) { if (i % 9 == 0) //Succeed every 9th attempt { await timer.Tick(DateTime.UtcNow, CancellationToken.None).ConfigureAwait(false); } else { timer.OnError(new Exception("Simulated!")); } } Assert.IsFalse(criticalActionTriggered); }
public async Task It_resets_the_failure_counter_after_successful_attempt() { var criticalActionTriggered = false; var timer = new FakeTimer(); var cleaner = new DedupeCleaner(_ => Task.FromResult(0), _ => criticalActionTriggered = true, TimeSpan.Zero, timer); cleaner.Start(); for (var i = 0; i < 100; i++) { if (i % 9 == 0) //Succeed every 9th attempt { await timer.Tick(DateTime.UtcNow, CancellationToken.None); } else { timer.OnError(new("Simulated!")); } } Assert.False(criticalActionTriggered); }
public virtual void TestOnlyOneRequestWhenExpiredEntryExists() { conf.SetLong(CommonConfigurationKeys.HadoopSecurityGroupsCacheSecs, 1); FakeTimer timer = new FakeTimer(); Groups groups = new Groups(conf, timer); groups.CacheGroupsAdd(Arrays.AsList(myGroups)); groups.Refresh(); TestGroupsCaching.FakeGroupMapping.ClearBlackList(); TestGroupsCaching.FakeGroupMapping.SetGetGroupsDelayMs(100); // We make an initial request to populate the cache groups.GetGroups("me"); int startingRequestCount = TestGroupsCaching.FakeGroupMapping.GetRequestCount(); // Then expire that entry timer.Advance(400 * 1000); Thread.Sleep(100); AList <Thread> threads = new AList <Thread>(); for (int i = 0; i < 10; i++) { threads.AddItem(new _Thread_382(groups)); } // We start a bunch of threads who all see the cached value foreach (Thread t in threads) { t.Start(); } foreach (Thread t_1 in threads) { t_1.Join(); } // Only one extra request is made Assert.Equal(startingRequestCount + 1, TestGroupsCaching.FakeGroupMapping .GetRequestCount()); }
public OnPostSave() { now = DateTime.UtcNow; sagaStore = new Mock <IStoreSagas>(); eventPublisher = new Mock <IPublishEvents>(); timeoutDispatcher = new TimeoutDispatcher(new Lazy <IStoreSagas>(() => sagaStore.Object), new Lazy <IPublishEvents>(() => eventPublisher.Object), callback => timer = new FakeTimer(callback)); sagaTimeout = new SagaTimeout(typeof(FakeSaga), GuidStrategy.NewGuid(), now.AddMinutes(5)); SystemTime.OverrideWith(() => now); sagaStore.Setup(mock => mock.GetScheduledTimeouts(It.IsAny <DateTime>())).Returns(new[] { sagaTimeout }); timer.InvokeCallback(); timer.Reset(); }
public void RescheduleTimer() { var dispatcher = new TimeoutDispatcher(new Lazy<IStoreSagas>(() => sagaStore.Object), new Lazy<IPublishEvents>(() => eventPublisher.Object), callback => timer = new FakeTimer(callback)); sagaStore.Setup(mock => mock.GetScheduledTimeouts(It.IsAny<DateTime>())).Returns(new SagaTimeout[0]); eventPublisher.Setup(mock => mock.Publish(It.IsAny<IEnumerable<Header>>(), It.IsAny<EventEnvelope>())).Throws(new InvalidOperationException()); dispatcher.EnsureElapsedTimeoutsDispatched(); timer.InvokeCallback(); Assert.True(timer.Changed); sagaStore.Verify(mock => mock.GetScheduledTimeouts(It.IsAny<DateTime>()), Times.Once()); }
public void Setup() { _arduino = A.Fake <IArduino>(); _timer = new FakeTimer(); _led = new Led(_arduino, Pin, _timer); }
public void Setup() { _arduino = A.Fake <IArduino>(); _timer = new FakeTimer(); _button = new PushButton(_arduino, Pin, _timer); }
public void RescheduleTimer() { var dispatcher = new TimeoutDispatcher(new Lazy <IStoreSagas>(() => sagaStore.Object), new Lazy <IPublishEvents>(() => eventPublisher.Object), callback => timer = new FakeTimer(callback)); sagaStore.Setup(mock => mock.GetScheduledTimeouts(It.IsAny <DateTime>())).Returns(new SagaTimeout[0]); eventPublisher.Setup(mock => mock.Publish(It.IsAny <IEnumerable <Header> >(), It.IsAny <EventEnvelope>())).Throws(new InvalidOperationException()); dispatcher.EnsureElapsedTimeoutsDispatched(); timer.InvokeCallback(); Assert.True(timer.Changed); sagaStore.Verify(mock => mock.GetScheduledTimeouts(It.IsAny <DateTime>()), Times.Once()); }