Exemplo n.º 1
0
 public FilePuller(string fileStorePath, int interval, int downloadTimeout, int retryTimes, IPersistentQueue queue) : base(interval)
 {
     _fileStorePath   = fileStorePath;
     _downloadTimeout = downloadTimeout;
     _maxRetryTimes   = retryTimes;
     _queue           = queue;
 }
        public void EnqueueDequeueTest(IPersistentQueue <int> empty)
        {
            int count = 100;

            IEnumerable <int> items = Enumerable.Range(0, count);

            IPersistentQueue <int> queue = empty;

            foreach (int item in items)
            {
                int countBefore = queue.Count;

                queue = queue.Enqueue(item);
                Assert.Equal(countBefore + 1, queue.Count);

                (int head, IPersistentQueue <int> tail) = queue.Dequeue();
                Assert.Equal(items.First(), head);
                Assert.Equal(countBefore, tail.Count);
            }

            foreach (int item in items)
            {
                int countBefore = queue.Count;

                int head;
                (head, queue) = queue.Dequeue();
                Assert.Equal(item, head);
            }

            CheckEmptyBehaviour(queue);
        }
Exemplo n.º 3
0
 private static String BuildMessage(IPersistentQueue queue, IPersistentQueueItem invalidQueueItem)
 {
     return(String.Format("Queue Item of type {0} stores data to a table named \"{1}\". Queue of type {2} stores data to a table names \"{3}\"",
                          invalidQueueItem.GetType(),
                          invalidQueueItem.TableName(),
                          queue.GetType(),
                          queue.TableName()));
 }
Exemplo n.º 4
0
 public FileServer(int port, string fileStorePath, IPersistentQueue queue) : base(-1)
 {
     _port = port;
     Startup._fileStorePath = fileStorePath;
     FileServerApiController._fileStorePath = fileStorePath;
     FileServerApiController._port          = port;
     RedirectMiddleware._fileStorePath      = fileStorePath;
     RedirectMiddleware._queue = queue;
 }
 protected override void InitializeTarget()
 {
     // we setup thread here so that config is in place
     base.InitializeTarget();
     if (this.queuePath == null)
     {
         throw new NLog.NLogConfigurationException("no filesystem queue path provided to BatchedWebService target");
     }
     if (this.url == null)
     {
         throw new NLog.NLogConfigurationException("no URL was provided to BatchedWebService target");
     }
     this.webService.setUrl(this.url);
     this.queue            = new PersistentQueue(this.queuePath);
     this.backgroundThread = new Thread(new ThreadStart(runThread));
     this.backgroundThread.Start();
 }
        public void CreateQueueTest()
        {
            int count = 100;

            IEnumerable <int>      items = Enumerable.Range(0, count);
            IPersistentQueue <int> queue = PersistentQueue <int> .Of(items);

            int itemsLeft = count;

            foreach (int expectedItem in items)
            {
                Assert.Equal(itemsLeft, queue.Count);

                int head;
                (head, queue) = queue.Dequeue();
                itemsLeft--;

                Assert.Equal(expectedItem, head);
            }

            CheckEmptyBehaviour(queue);
        }
        public void EnumeratorTest()
        {
            int count = 100;

            IEnumerable <int> items = Enumerable.Range(0, count);

            IPersistentQueue <int> queue = PersistentQueue <int> .Empty;

            foreach (int item in items)
            {
                queue = queue.Enqueue(item);
            }

            foreach (IEnumerator enumerator in
                     new IEnumerator[] { queue.GetEnumerator(), ((IEnumerable)queue).GetEnumerator() })
            {
                foreach (int item in items)
                {
                    Assert.True(enumerator.MoveNext());
                    Assert.Equal(item, enumerator.Current);
                }
                Assert.False(enumerator.MoveNext());
            }
        }
Exemplo n.º 8
0
 public MessageStorageService()
 {
     //_messages = new ConcurrentQueue<Message>();
     _diskQueue = new PersistentQueue("messagesQueue");
 }
Exemplo n.º 9
0
 public QueueStorageMismatchException(IPersistentQueue queue, IPersistentQueueItem invalidQueueItem)
     : base(BuildMessage(queue, invalidQueueItem))
 {
 }
		public void setup()
		{
			_a_message = new byte[]{1,2,3,4};
			_b_message = new byte[] { 4, 3, 2, 1 };

			_session = Substitute.For<IPersistentQueueSession>();

			_queue = Substitute.For<IPersistentQueue>();
			_queue.OpenSession().Returns(_session);

			_queueFactory = Substitute.For<IOutgoingQueueFactory>();
			_queueFactory.PrepareQueue().Returns(_queue);



			_subject = new PersistentWorkQueue(_queueFactory, Substitute.For<ISleepWrapper>());
		}
Exemplo n.º 11
0
 public FileEnqueuer(string fileStorePath, string syncApi, int interval, IPersistentQueue queue) : base(interval)
 {
     _fileStorePath = fileStorePath;
     _syncApi = syncApi;
     _queue = queue;
 }
Exemplo n.º 12
0
 public void Setup()
 {
     _q = PersistentQueue.WaitFor("./queue", TimeSpan.FromSeconds(10));
 }
Exemplo n.º 13
0
 public void setup()
 {
     _q = PersistentQueue.WaitFor("./queue", TimeSpan.FromSeconds(10));
 }
 public PersistentQueueWrapper(string filename)
 {
     queue = new PersistentQueue(filename);
 }
 protected override void InitializeTarget()
 {
     // we setup thread here so that config is in place
     base.InitializeTarget();
     if (this.queuePath == null)
     {
         throw new NLog.NLogConfigurationException("no filesystem queue path provided to BatchedWebService target");
     }
     if (this.url == null)
         throw new NLog.NLogConfigurationException("no URL was provided to BatchedWebService target");
     this.webService.setUrl(this.url);
     this.queue = new PersistentQueue(this.queuePath);
     this.backgroundThread = new Thread(new ThreadStart(runThread));
     this.backgroundThread.Start();
 }
 public void EmptyQueueTest(IPersistentQueue <int> empty)
 {
     CheckEmptyBehaviour(empty);
     Assert.NotSame(empty, empty.Enqueue(1));
 }
 private static void CheckEmptyBehaviour <T>(IPersistentQueue <T> queue)
 {
     Assert.Equal(0, queue.Count);
     Assert.False(queue.GetEnumerator().MoveNext());
     Assert.Throws <InvalidOperationException>(() => queue.Dequeue());
 }
		/// <summary>
		/// Try to move messages from the incoming queue to the dispatch queue
		/// </summary>
		void TryPumpingMessages(IPersistentQueue dispatchQueue)
		{
			try
			{
				using (var incomingQueue = PersistentQueue.WaitFor(_incomingPath, TimeSpan.FromSeconds(1)))
				using (var dst = dispatchQueue.OpenSession())
				using (var src = incomingQueue.OpenSession())
				{
					byte[] data;
					while ((data = src.Dequeue()) != null)
					{
						dst.Enqueue(data);
					}
					dst.Flush();
					src.Flush();
				}
			}
			catch (TimeoutException)
			{
				Ignore();
			}
		}