public void ReceivesAndSendsMessage() { var configuration = new ConfigurationEntry { Alias = "#1", RedriveUrl = "http://here.com/", Active = true }; var queueClientMock = new Mock <IQueueClient>(MockBehavior.Strict); queueClientMock.Setup(x => x.GetMessage()).Returns(new SqsMessage("id", "content")).Verifiable(); var messageProcessorMock = new Mock <IMessageProcessor>(MockBehavior.Strict); messageProcessorMock.Setup(x => x.ProcessMessage(It.IsAny <string>(), It.IsAny <ConfigurationEntry>())).Verifiable(); queueClientMock.Setup(x => x.DeleteMessage(It.IsAny <IMessage>())).Callback(() => Thread.Sleep(2000)); var processorFactoryMock = new Mock <IMessageProcessorFactory>(MockBehavior.Strict); processorFactoryMock.Setup(x => x.CreateMessageProcessor(It.IsAny <ConfigurationEntry>())).Returns(messageProcessorMock.Object).Verifiable(); var processor = new QueueProcessor(); processor.Init(queueClientMock.Object, processorFactoryMock.Object, configuration); processor.Start(); Thread.Sleep(1000); processor.Stop(); queueClientMock.Verify(x => x.GetMessage(), Times.Exactly(1)); messageProcessorMock.Verify(x => x.ProcessMessage(It.IsAny <string>(), It.IsAny <ConfigurationEntry>()), Times.Exactly(1)); queueClientMock.Verify(x => x.DeleteMessage(It.IsAny <IMessage>()), Times.Exactly(1)); processorFactoryMock.Verify(x => x.CreateMessageProcessor(It.IsAny <ConfigurationEntry>()), Times.Exactly(1)); }
public void StartStopTest() { var queueReceiverAdapter = Substitute.For <IQueueReceiveAdapter>(); var queueProcessor = new QueueProcessor(queueReceiverAdapter, null); queueProcessor.Start(); queueReceiverAdapter.ReceivedWithAnyArgs().Start(null); queueReceiverAdapter.DidNotReceive().Stop(); queueProcessor.Stop(); queueReceiverAdapter.Received().Stop(); }
public void DoesNothingWithoutQueuedMessage() { var configuration = new ConfigurationEntry { Alias = "#1", RedriveUrl = "http://here.com/", Active = true }; var queueClientMock = new Mock <IQueueClient>(MockBehavior.Strict); queueClientMock.Setup(x => x.GetMessage()).Callback(() => Thread.Sleep(2000)).Returns((SqsMessage)null).Verifiable(); var processor = new QueueProcessor(); processor.Init(queueClientMock.Object, null, configuration); processor.Start(); Thread.Sleep(1000); processor.Stop(); queueClientMock.Verify(x => x.GetMessage(), Times.Exactly(1)); }
internal void CloseApp(object obj) { var window = (Window)obj; if (_ctsUpdatingList != null) { if (_displayMessage.Invoke( "Background operation in progress. Cancel and exit program?", "Exit", MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.No) == MessageBoxResult.No) { return; } window.IsEnabled = false; window.Title = "Quitting, please wait..."; _ctsUpdatingList.Cancel(); } this.Status = "Saving data..."; RaisePropertyChanged(nameof(this.Status)); if (QueueProcessor.IsBusy) { QueueProcessor.Stop(); } Task t = Task.Run(async() => { await _semaphoreUpdatingList.WaitAsync(); try { Directory.CreateDirectory(AppPaths.LocalAppData); var writer = new XmlSerializer(typeof(SerializableDownloaderObjectModelList)); var list = new SerializableDownloaderObjectModelList(); var index = 0; foreach (var item in DownloadItemsList) { if (item.IsBeingDownloaded) { item.Pause(); } if (item.Status == DownloadStatus.Finished && Settings.Default.ClearFinishedOnExit) { continue; } var sItem = new SerializableDownloaderObjectModel { Index = index++, Url = item.Url, Destination = item.Destination, TotalBytesToDownload = item.TotalBytesToDownload, IsQueued = item.IsQueued, IsCompleted = item.IsCompleted, DateCreated = item.DateCreated, StatusCode = item.StatusCode }; list.Objects.Add(sItem); } using (var streamWriter = new StreamWriter(AppPaths.DownloadsHistoryFile, false)) { writer.Serialize(streamWriter, list); } } catch { return; } finally { _semaphoreUpdatingList.Release(); } }).ContinueWith(t => { Settings.Default.Save(); try { Application.Current?.Dispatcher.Invoke(Application.Current.Shutdown); } catch { } }); }
internal void StopQueue(object obj) { QueueProcessor.Stop(); }
public void ProcessElementTest() { var environmentFactory = EnvironmentFactoryFactory.Create(); var queueSendAdapter = environmentFactory.QueueEnvironment.QueueSendAdapter; queueSendAdapter.Clear(); var queueReceiverAdapter = environmentFactory.QueueEnvironment.QueueReceiveAdapter; var directTelemetryDataService = Substitute.For <IDirectTelemetryDataService>(); int COUNT = 50; var outputList = new List <TelemetryData>(COUNT); directTelemetryDataService.When(d => d.RecordTelemetryData(Arg.Any <TelemetryData>())).Do(call => outputList.Add((TelemetryData)call.Args()[0])); var queueProcessor = new QueueProcessor(queueReceiverAdapter, directTelemetryDataService); queueProcessor.Start(); var inputList = new List <TelemetryData>(COUNT); for (var i = 0; i < COUNT; i++) { var inputTd = new TelemetryData((i % 5).ToString(), $"{{\"p\": {i}}}", DateTime.UtcNow); inputList.Add(inputTd); queueSendAdapter.Send(inputTd); } var ok = false; for (var r = 0; r < 30; r++) { if (outputList.Count == COUNT) { bool isOk = true; for (var i = 0; i < COUNT; i++) { var input = inputList[i]; var output = outputList[i]; if (input.DeviceId != output.DeviceId.Trim() || input.Payload != output.Payload) { isOk = false; break; } } if (isOk) { ok = true; break; } } Thread.Sleep(100); } queueProcessor.Stop(); Assert.IsTrue(ok); }
protected override void OnStop() { _queueProcessor.Stop(); }