public void when_queue_not_init()
        {
            var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            var result = new StatelessFileQueueReader(path, "test").TryGetMessage();

            Assert.AreEqual(GetEnvelopeResultState.Exception, result.State);
        }
 private static StatelessFileQueueReader InitQueue(string name)
 {
     var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
     var queue = new StatelessFileQueueReader(path, name);
     queue.InitIfNeeded();
     using (var sw = new StreamWriter(Path.Combine(path, "0.dat"), false))
         sw.Write("test queue");
     return queue;
 }
        public void when_directory_empty()
        {
            var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            var queue = new StatelessFileQueueReader(path, "test");
            queue.InitIfNeeded();
            var result = queue.TryGetMessage();

            Assert.AreEqual(GetEnvelopeResultState.Empty, result.State);
        }
Ejemplo n.º 4
0
        public static FileQueueReader CreateInbox(this FileStorageConfig cfg, string name, Func<uint, TimeSpan> decay = null)
        {
            var reader = new StatelessFileQueueReader(Path.Combine(cfg.FullPath, name), name);

            var waiter = decay ?? DecayEvil.BuildExponentialDecay(250);
            var inbox = new FileQueueReader(new[]{reader, }, waiter);
            inbox.Init();
            return inbox;
        }
        public void when_init_of_needed()
        {
            var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            var queue = new StatelessFileQueueReader(path, "test");

            var inbox = new FileQueueReader(new[] { queue }, x => new TimeSpan(x));

            Assert.IsFalse(Directory.Exists(path));
            inbox.InitIfNeeded();
            Assert.IsTrue(Directory.Exists(path));
        }
        public void when_ack_message()
        {
            var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            var queue = new StatelessFileQueueReader(path, "test");
            queue.InitIfNeeded();
            using (var sw = new StreamWriter(Path.Combine(path, "0.dat"), false))
                sw.Write("test message");
            var result = queue.TryGetMessage();

            Assert.IsTrue(File.Exists(Path.Combine(path, "0.dat")));
            queue.AckMessage(result.Message);
            Assert.IsFalse(File.Exists(Path.Combine(path, "0.dat")));
        }
        public void when_file_not_success()
        {
            var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            var queue = new StatelessFileQueueReader(path, "test");
            queue.InitIfNeeded();
            using (var sw = new StreamWriter(Path.Combine(path, "0.dat"), false))
                sw.Write("test message");

            using (var stream = new FileStream(Path.Combine(path, "0.dat"), FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
            {
                var result = queue.TryGetMessage();

                Assert.AreEqual(GetEnvelopeResultState.Retry, result.State);
            }
        }
 public void when_ack_null_message()
 {
     var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
     var queue = new StatelessFileQueueReader(path, "test");
     queue.AckMessage(null);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FilePartitionInbox"/> class.
 /// </summary>
 /// <param name="readers">Multiple file queue readers.</param>
 /// <param name="waiter">The waiter function (to slow down polling if there are no messages).</param>
 public FilePartitionInbox(StatelessFileQueueReader[] readers, Func<uint, TimeSpan> waiter)
 {
     _readers = readers;
     _waiter = waiter;
 }