Ejemplo n.º 1
0
        public void DownloadSuccessfulTest()
        {
            //Arrange
            string localFilePath = null;

            _videoiRepository.Setup(m => m.DownloadOriginalVideo(It.IsAny <string>(), It.IsAny <string>())).Callback <string, string>((hash, filePath) => localFilePath = filePath);

            _fileSystemWrapper.Setup(m => m.GetTempPath()).Returns("my temp path");
            _fileSystemWrapper.Setup(m => m.PathCombine(It.IsAny <string>(), It.IsAny <string>())).Returns <string, string>(Path.Combine);

            var queueInformation = new QueueInformation()
            {
                VideoMessage = new VideoMessage()
            };


            var downloadProcess = new DownloadProcess(5, _videoiRepository.Object, _fileSystemWrapper.Object);

            //Act
            var downloadInfo = downloadProcess.ProcessMethod(queueInformation, new CancellationToken());

            //Assert
            Assert.AreEqual(queueInformation.VideoMessage, downloadInfo.QueueInformation.VideoMessage);
            Assert.AreEqual(localFilePath, downloadInfo.LocalFilePath);
            Assert.AreEqual(Path.GetDirectoryName(localFilePath), downloadInfo.LocalPath);
        }
Ejemplo n.º 2
0
        public void DownloadSuccessfulTest()
        {
            //Arrange
            string localFilePath = null;

            _videoiRepository.Setup(m => m.DownloadOriginalVideo(It.IsAny<string>(), It.IsAny<string>())).Callback<string, string>((hash, filePath) => localFilePath = filePath);
            
            _fileSystemWrapper.Setup(m => m.GetTempPath()).Returns("my temp path");
            _fileSystemWrapper.Setup(m => m.PathCombine(It.IsAny<string>(), It.IsAny<string>())).Returns<string,string>(Path.Combine);
            
            var queueInformation = new QueueInformation()
                                       {
                                           VideoMessage = new VideoMessage()
                                       };
            

            var downloadProcess = new DownloadProcess(5, _videoiRepository.Object, _fileSystemWrapper.Object);
            
            //Act
            var downloadInfo =  downloadProcess.ProcessMethod(queueInformation, new CancellationToken());

            //Assert
            Assert.AreEqual(queueInformation.VideoMessage, downloadInfo.QueueInformation.VideoMessage);
            Assert.AreEqual(localFilePath, downloadInfo.LocalFilePath);
            Assert.AreEqual(Path.GetDirectoryName(localFilePath), downloadInfo.LocalPath);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="QueueStatusProviderNoOp" /> class.
 /// </summary>
 /// <param name="connectionInformation">The connection information.</param>
 public QueueStatusProviderNoOp(IConnectionInformation connectionInformation)
 {
     Name = connectionInformation.QueueName;
     Server = connectionInformation.Server;
     _queueInformation = new QueueInformation(Name, Server, DateTime.MinValue, string.Empty,
         Enumerable.Empty<SystemEntry>());
 }
Ejemplo n.º 4
0
        public void DownloadNotExistVideoTest()
        {
            //Arrange
            string localFilePath = null;
            
            _fileSystemWrapper.Setup(m => m.GetTempPath()).Returns("my temp path");
            _fileSystemWrapper.Setup(m => m.PathCombine(It.IsAny<string>(), It.IsAny<string>())).Returns<string, string>(Path.Combine);

            _videoiRepository.Setup(m => m.ExistsEncodedVideo(It.IsAny<string>())).Returns(false);
            _videoiRepository.Setup(m => m.DownloadOriginalVideo(It.IsAny<string>(), It.IsAny<string>())).Callback<string, string>((hash, filePath) => localFilePath = filePath);

            var queueInformation = new QueueInformation()
            {
                VideoMessage = new VideoMessage()
            };
            
            var downloadProcess = new DownloadProcess(5, _videoiRepository.Object, _fileSystemWrapper.Object);

            //Act
            downloadProcess.ProcessMethod(queueInformation, new CancellationToken());

            //Assert
            _videoiRepository.Verify(m => m.SetEncodingState(It.IsAny<string>(), EncodingState.InProcess, EncodingStage.Downloading, null), Times.Once());
            _videoiRepository.Verify(m=>m.ExistsEncodedVideo(It.IsAny<string>()), Times.Once());
            _videoiRepository.Verify(m => m.DownloadOriginalVideo(It.IsAny<string>(), localFilePath), Times.Once());
        }
Ejemplo n.º 5
0
        public void DownloadNotExistVideoTest()
        {
            //Arrange
            string localFilePath = null;

            _fileSystemWrapper.Setup(m => m.GetTempPath()).Returns("my temp path");
            _fileSystemWrapper.Setup(m => m.PathCombine(It.IsAny <string>(), It.IsAny <string>())).Returns <string, string>(Path.Combine);

            _videoiRepository.Setup(m => m.ExistsEncodedVideo(It.IsAny <string>())).Returns(false);
            _videoiRepository.Setup(m => m.DownloadOriginalVideo(It.IsAny <string>(), It.IsAny <string>())).Callback <string, string>((hash, filePath) => localFilePath = filePath);

            var queueInformation = new QueueInformation()
            {
                VideoMessage = new VideoMessage()
            };

            var downloadProcess = new DownloadProcess(5, _videoiRepository.Object, _fileSystemWrapper.Object);

            //Act
            downloadProcess.ProcessMethod(queueInformation, new CancellationToken());

            //Assert
            _videoiRepository.Verify(m => m.SetEncodingState(It.IsAny <string>(), EncodingState.InProcess, EncodingStage.Downloading, null), Times.Once());
            _videoiRepository.Verify(m => m.ExistsEncodedVideo(It.IsAny <string>()), Times.Once());
            _videoiRepository.Verify(m => m.DownloadOriginalVideo(It.IsAny <string>(), localFilePath), Times.Once());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PostQueueInformation([FromBody] QueueInformation queueInformation)
        {
            queueInformation.IsActive = true;
            _context.QueueInformations.Add(queueInformation);
            await _context.SaveChangesAsync();

            await hubContext.Clients.All.SendAsync("AddQueue", queueInformation);

            return(CreatedAtAction("GetQueueInformation", new { id = queueInformation.Id }, queueInformation.ToQueueInformationLight()));
        }
 public void Create(string name,
     string server,
     DateTime currentDateTime,
     string dateTimeProvider,
     IEnumerable<SystemEntry> data)
 {
     var systemEntries = data as IList<SystemEntry> ?? data.ToList();
     IQueueInformation test = new QueueInformation(name, server, currentDateTime, dateTimeProvider, systemEntries);
     Assert.Equal(name, test.Name);
     Assert.Equal(server, test.Server);
     Assert.Equal(currentDateTime, test.CurentDateTime);
     Assert.Equal(dateTimeProvider, test.DateTimeProvider);
     Assert.Equal(systemEntries, test.Data);
 }
        public void Create(string name,
                           string server,
                           DateTime currentDateTime,
                           string dateTimeProvider,
                           IEnumerable <SystemEntry> data)
        {
            var systemEntries      = data as IList <SystemEntry> ?? data.ToList();
            IQueueInformation test = new QueueInformation(name, server, currentDateTime, dateTimeProvider, systemEntries);

            Assert.Equal(name, test.Name);
            Assert.Equal(server, test.Server);
            Assert.Equal(currentDateTime, test.CurrentDateTime);
            Assert.Equal(dateTimeProvider, test.DateTimeProvider);
            Assert.Equal(systemEntries, test.Data);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            var queueInformation = new QueueInformation
            {
                ConnectionString = @"Endpoint=sb://pinpon-test.servicebus.windows.net/;SharedAccessKeyName=build-consumer;SharedAccessKey=Oa3j00w6XDWfrfNvI6gGYJG6EtQhJyOip2bxtudL674=",
                Topic            = @"build",
                Subscription     = @"pinpon",
            };
            var queuePoller = new QueuePoller(queueInformation);

            queuePoller.LogError      += (o, e) => Console.Error.WriteLine(e);
            queuePoller.LogVerbose    += (o, m) => Console.WriteLine(m);
            queuePoller.PinponChanged += (o, b) => Console.WriteLine(b);
            queuePoller.StartPolling();
            Console.ReadKey();
        }
Ejemplo n.º 10
0
        public void SubscribeTo(QueueInformation queueInformation)
        {
            if (pollers.ContainsKey(queueInformation))
            {
                return;
            }

            var queuePoller = new QueuePoller(queueInformation);

            queuePoller.LogError      += (o, m) => logger.LogError(m);
            queuePoller.LogVerbose    += (o, m) => logger.LogDebug(m);
            queuePoller.PinponChanged += QueuePoller_PinponChanged;
            queuePoller.StartPolling();

            logger.LogInformation($"Subscribe to new queue : sub [{queueInformation.Subscription }], Topic [{queueInformation.Topic}]");

            pollers.Add(queueInformation, queuePoller);
        }
Ejemplo n.º 11
0
        public void DownloadExistVideoTest()
        {
            //Arrange
            var downloadProcess = new DownloadProcess(5, _videoiRepository.Object, _fileSystemWrapper.Object);

            _videoiRepository.Setup(m => m.ExistsEncodedVideo(It.IsAny <string>())).Returns(true);

            var queueInformation = new QueueInformation()
            {
                VideoMessage = new VideoMessage()
            };

            //Act
            downloadProcess.ProcessMethod(queueInformation, new CancellationToken());

            //Assert
            _videoiRepository.Verify(m => m.SetEncodingState(It.IsAny <string>(), EncodingState.InProcess, EncodingStage.Downloading, null), Times.Once());
            _videoiRepository.Verify(m => m.ExistsEncodedVideo(It.IsAny <string>()), Times.Once());
            _videoiRepository.Verify(m => m.DownloadOriginalVideo(It.IsAny <string>(), It.IsAny <string>()), Times.Never());
        }
Ejemplo n.º 12
0
        public void BrunchOfDeleteTest()
        {
            //Arragnge
            var downloadProcess = new DownloadProcess(5, _videoiRepository.Object, _fileSystemWrapper.Object);

            var queueInformation = new QueueInformation()
            {
                VideoMessage = new VideoMessage()
                {
                    Delete = true
                }
            };

            //Act
            var downloadInfo = downloadProcess.ProcessMethod(queueInformation, new CancellationToken());

            //Assert
            _videoiRepository.Verify(m => m.SetEncodingState(It.IsAny <string>(), EncodingState.InProcess, EncodingStage.Downloading, null), Times.Never());
            _videoiRepository.Verify(m => m.DownloadOriginalVideo(It.IsAny <string>(), It.IsAny <string>()), Times.Never());

            Assert.AreEqual(queueInformation.VideoMessage, downloadInfo.QueueInformation.VideoMessage);
        }
Ejemplo n.º 13
0
        public void DownloadExceptionHandlerTest()
        {
            //Arrange
            var downloadProcess = new DownloadProcess(5, _videoiRepository.Object, _fileSystemWrapper.Object);

            var queueInformation = new QueueInformation()
            {
                VideoMessage = new VideoMessage()
                {
                    Delete = true
                }
            };

            _fileSystemWrapper.Setup(m => m.DirectoryExists(It.IsAny <string>())).Returns(true);

            //Act
            downloadProcess.ExceptionHandler(new Exception(), queueInformation);

            //Asert
            _videoiRepository.Verify(m => m.SetEncodingState(It.IsAny <string>(), EncodingState.Failed, EncodingStage.Downloading, null), Times.Once());

            _fileSystemWrapper.Verify(m => m.DirectoryExists(It.IsAny <string>()), Times.Once());
            _fileSystemWrapper.Verify(m => m.DirectoryDelete(It.IsAny <string>()), Times.Once());
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Finds the queue and sends the information
        /// </summary>
        private async Task GetQueueInformation(MqClient client, TmqMessage message)
        {
            if (_server.AdminAuthorization == null)
            {
                if (message.ResponseRequired)
                {
                    await client.SendAsync(MessageBuilder.ResponseStatus(message, KnownContentTypes.Unauthorized));
                }

                return;
            }

            Channel channel = _server.FindChannel(message.Target);

            if (channel == null)
            {
                await client.SendAsync(MessageBuilder.ResponseStatus(message, KnownContentTypes.NotFound));

                return;
            }

            bool grant = await _server.AdminAuthorization.CanReceiveChannelQueues(client, channel);

            if (!grant)
            {
                if (message.ResponseRequired)
                {
                    await client.SendAsync(MessageBuilder.ResponseStatus(message, KnownContentTypes.Unauthorized));
                }

                return;
            }

            byte[] bytes = new byte[2];
            await message.Content.ReadAsync(bytes);

            ushort       id    = BitConverter.ToUInt16(bytes);
            ChannelQueue queue = channel.FindQueue(id);

            if (queue == null)
            {
                await client.SendAsync(MessageBuilder.ResponseStatus(message, KnownContentTypes.NotFound));

                return;
            }

            QueueInformation information = new QueueInformation
            {
                Channel = channel.Name,
                Id      = id,
                Status  = queue.Status.ToString().ToLower(),
                InQueueHighPriorityMessages = queue.HighPriorityLinkedList.Count,
                InQueueRegularMessages      = queue.RegularLinkedList.Count,
                OnlyFirstAcquirer           = channel.Options.SendOnlyFirstAcquirer,
                RequestAcknowledge          = channel.Options.RequestAcknowledge,
                AcknowledgeTimeout          = Convert.ToInt32(channel.Options.AcknowledgeTimeout.TotalMilliseconds),
                MessageTimeout      = Convert.ToInt32(channel.Options.MessageTimeout.TotalMilliseconds),
                WaitForAcknowledge  = channel.Options.WaitForAcknowledge,
                HideClientNames     = channel.Options.HideClientNames,
                ReceivedMessages    = queue.Info.ReceivedMessages,
                SentMessages        = queue.Info.SentMessages,
                Deliveries          = queue.Info.Deliveries,
                Unacknowledges      = queue.Info.Unacknowledges,
                Acknowledges        = queue.Info.Acknowledges,
                TimeoutMessages     = queue.Info.TimedOutMessages,
                SavedMessages       = queue.Info.MessageSaved,
                RemovedMessages     = queue.Info.MessageRemoved,
                Errors              = queue.Info.ErrorCount,
                LastMessageReceived = queue.Info.GetLastMessageReceiveUnix(),
                LastMessageSent     = queue.Info.GetLastMessageSendUnix(),
                MessageLimit        = queue.Options.MessageLimit,
                MessageSizeLimit    = queue.Options.MessageSizeLimit
            };

            TmqMessage response = message.CreateResponse();

            message.ContentType = KnownContentTypes.QueueInformation;
            await response.SetJsonContent(information);

            await client.SendAsync(response);
        }
Ejemplo n.º 15
0
        public void DownloadExistVideoTest()
        {
            //Arrange
            var downloadProcess = new DownloadProcess(5, _videoiRepository.Object, _fileSystemWrapper.Object);

            _videoiRepository.Setup(m => m.ExistsEncodedVideo(It.IsAny<string>())).Returns(true);

            var queueInformation = new QueueInformation()
            {
                VideoMessage = new VideoMessage()
            };
            
            //Act
            downloadProcess.ProcessMethod(queueInformation, new CancellationToken());

            //Assert
            _videoiRepository.Verify(m => m.SetEncodingState(It.IsAny<string>(), EncodingState.InProcess, EncodingStage.Downloading, null), Times.Once());
            _videoiRepository.Verify(m => m.ExistsEncodedVideo(It.IsAny<string>()), Times.Once());
            _videoiRepository.Verify(m => m.DownloadOriginalVideo(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
        }
Ejemplo n.º 16
0
 private void AddQueuePoller(QueueInformation obj)
 {
     logger.LogDebug($"Websocket : add new poller {obj.Subscription} / {obj.Topic}");
     queuePollerService.SubscribeTo(obj);
 }
Ejemplo n.º 17
0
        public void DownloadExceptionHandlerTest()
        {
            //Arrange
            var downloadProcess = new DownloadProcess(5, _videoiRepository.Object, _fileSystemWrapper.Object);

            var queueInformation = new QueueInformation()
                                       {
                                           VideoMessage = new VideoMessage()
                                                              {
                                                                  Delete = true
                                                              }
                                       };

            _fileSystemWrapper.Setup(m => m.DirectoryExists(It.IsAny<string>())).Returns(true);

            //Act
            downloadProcess.ExceptionHandler(new Exception(), queueInformation);
            
            //Asert
            _videoiRepository.Verify(m => m.SetEncodingState(It.IsAny<string>(), EncodingState.Failed, EncodingStage.Downloading, null), Times.Once());

            _fileSystemWrapper.Verify(m => m.DirectoryExists(It.IsAny<string>()), Times.Once());
            _fileSystemWrapper.Verify(m => m.DirectoryDelete(It.IsAny<string>()), Times.Once());
        }
Ejemplo n.º 18
0
        public void BrunchOfDeleteTest()
        {
            //Arragnge
            var downloadProcess = new DownloadProcess(5, _videoiRepository.Object, _fileSystemWrapper.Object);

            var queueInformation = new QueueInformation()
                                       {
                                           VideoMessage = new VideoMessage()
                                                              {
                                                                  Delete = true
                                                              }
                                       };
            
            //Act
            var downloadInfo = downloadProcess.ProcessMethod(queueInformation, new CancellationToken());

            //Assert
            _videoiRepository.Verify(m => m.SetEncodingState(It.IsAny<string>(), EncodingState.InProcess, EncodingStage.Downloading, null), Times.Never());
            _videoiRepository.Verify(m => m.DownloadOriginalVideo(It.IsAny<string>(), It.IsAny<string>()), Times.Never());

            Assert.AreEqual(queueInformation.VideoMessage, downloadInfo.QueueInformation.VideoMessage);
        }