public void Byte_overage_spills_into_consecutive_files()
 {
     using(var queueStream = new MultiFileQueueStream(_path, 4)) {
         var s1 = GetStream(1);
         var s2 = GetStream(2);
         var s3 = GetStream(3);
         var s4 = GetStream(4);
         queueStream.AppendRecord(s1, s1.Length);
         queueStream.AppendRecord(s2, s2.Length);
         queueStream.AppendRecord(s3, s3.Length);
         queueStream.AppendRecord(s4, s4.Length);
         Assert.AreEqual(5, Directory.GetFiles(_path).Length);
     }
 }
 public void Can_append_read_after_truncate()
 {
     using(var queueStream = new MultiFileQueueStream(_path, 14)) {
         var s1 = GetStream(1);
         var s2 = GetStream(2);
         queueStream.AppendRecord(s1, s1.Length);
         queueStream.AppendRecord(s2, s2.Length);
         queueStream.Truncate();
         var s3 = GetStream(3);
         queueStream.AppendRecord(s3, s3.Length);
         Assert.AreEqual(1, queueStream.UnreadCount);
         var h3 = queueStream.ReadNextRecord();
         Assert.AreEqual(0, queueStream.UnreadCount);
         Assert.AreEqual(GetValue(s3),GetValue(h3.Stream));
     }
 }
 public void Truncate_removes_files()
 {
     using(var queueStream = new MultiFileQueueStream(_path, 14)) {
         var s1 = GetStream(1);
         var s2 = GetStream(2);
         var s3 = GetStream(3);
         var s4 = GetStream(4);
         var s5 = GetStream(5);
         queueStream.AppendRecord(s1, s1.Length);
         queueStream.AppendRecord(s2, s2.Length);
         queueStream.AppendRecord(s3, s3.Length);
         queueStream.AppendRecord(s4, s4.Length);
         queueStream.AppendRecord(s5, s5.Length);
         Assert.AreEqual(3, Directory.GetFiles(_path).Length);
         queueStream.Truncate();
         Assert.AreEqual(1, Directory.GetFiles(_path).Length);
         Assert.AreEqual(0, queueStream.UnreadCount);
         Assert.AreEqual(QueueStreamRecord.Empty, queueStream.ReadNextRecord());
     }
 }
 public void Item_depletion_of_non_head_resets_file_numbering_if_all_other_files_are_empty_already()
 {
     using(var queueStream = new MultiFileQueueStream(_path, 14)) {
         var s1 = GetStream(1);
         var s2 = GetStream(2);
         var s3 = GetStream(3);
         var s4 = GetStream(4);
         var s5 = GetStream(5);
         queueStream.AppendRecord(s1, s1.Length);
         queueStream.AppendRecord(s2, s2.Length);
         queueStream.AppendRecord(s3, s3.Length);
         queueStream.AppendRecord(s4, s4.Length);
         queueStream.AppendRecord(s5, s5.Length);
         Assert.AreEqual(3, Directory.GetFiles(_path).Length);
         var h1 = queueStream.ReadNextRecord();
         var h2 = queueStream.ReadNextRecord();
         var h3 = queueStream.ReadNextRecord();
         var h4 = queueStream.ReadNextRecord();
         var h5 = queueStream.ReadNextRecord();
         Assert.IsNotNull(h5);
         queueStream.DeleteRecord(h1.Handle);
         queueStream.DeleteRecord(h2.Handle);
         queueStream.DeleteRecord(h3.Handle);
         queueStream.DeleteRecord(h5.Handle);
         var files = Directory.GetFiles(_path);
         Assert.AreEqual(2, files.Length);
         Assert.AreEqual("data_2.bin", Path.GetFileName(files[0]));
         Assert.AreEqual("data_3.bin", Path.GetFileName(files[1]));
         queueStream.DeleteRecord(h4.Handle);
         files = Directory.GetFiles(_path);
         Assert.AreEqual(1, files.Length);
         Assert.AreEqual("data_1.bin", Path.GetFileName(files[0]));
     }
 }
 public void Item_depletion_removes_read_files()
 {
     using(var queueStream = new MultiFileQueueStream(_path, 4)) {
         var s1 = GetStream(1);
         var s2 = GetStream(2);
         var s3 = GetStream(3);
         var s4 = GetStream(4);
         queueStream.AppendRecord(s1, s1.Length);
         queueStream.AppendRecord(s2, s2.Length);
         queueStream.AppendRecord(s3, s3.Length);
         queueStream.AppendRecord(s4, s4.Length);
         var h1 = queueStream.ReadNextRecord();
         var h2 = queueStream.ReadNextRecord();
         var h3 = queueStream.ReadNextRecord();
         var h4 = queueStream.ReadNextRecord();
         Assert.IsNotNull(h4);
         Assert.AreEqual(5, Directory.GetFiles(_path).Length);
         queueStream.DeleteRecord(h2.Handle);
         Assert.AreEqual(4, Directory.GetFiles(_path).Length);
         queueStream.DeleteRecord(h3.Handle);
         Assert.AreEqual(3, Directory.GetFiles(_path).Length);
         queueStream.DeleteRecord(h1.Handle);
         Assert.AreEqual(2, Directory.GetFiles(_path).Length);
         queueStream.DeleteRecord(h4.Handle);
         Assert.AreEqual(1, Directory.GetFiles(_path).Length);
     }
 }
 public void Item_depletion_of_head_does_nothing_to_file_count()
 {
     using(var queueStream = new MultiFileQueueStream(_path, 14)) {
         var s1 = GetStream(1);
         var s2 = GetStream(2);
         var s3 = GetStream(3);
         var s4 = GetStream(4);
         var s5 = GetStream(5);
         queueStream.AppendRecord(s1, s1.Length);
         queueStream.AppendRecord(s2, s2.Length);
         queueStream.AppendRecord(s3, s3.Length);
         queueStream.AppendRecord(s4, s4.Length);
         queueStream.AppendRecord(s5, s5.Length);
         Assert.AreEqual(3, Directory.GetFiles(_path).Length);
         var h1 = queueStream.ReadNextRecord();
         var h2 = queueStream.ReadNextRecord();
         var h3 = queueStream.ReadNextRecord();
         var h4 = queueStream.ReadNextRecord();
         var h5 = queueStream.ReadNextRecord();
         Assert.IsNotNull(h5);
         queueStream.DeleteRecord(h5.Handle);
         Assert.AreEqual(3, Directory.GetFiles(_path).Length);
     }
 }
 public void Creating_queue_from_chunks_reports_proper_unreadcount()
 {
     using(var queueStream = new MultiFileQueueStream(_path, 4)) {
         var s1 = GetStream(1);
         var s2 = GetStream(2);
         var s3 = GetStream(3);
         var s4 = GetStream(4);
         queueStream.AppendRecord(s1, s1.Length);
         queueStream.AppendRecord(s2, s2.Length);
         queueStream.AppendRecord(s3, s3.Length);
         queueStream.AppendRecord(s4, s4.Length);
     }
     using(var queueStream = new MultiFileQueueStream(_path, 4)) {
         Assert.AreEqual(4, queueStream.UnreadCount);
     }
 }
 public void Can_append_record_to_truncated_file()
 {
     AppendRecord(1, false);
     using(var queueStream = new MultiFileQueueStream(_path)) {
         var handle = queueStream.ReadNextRecord().Handle;
         queueStream.DeleteRecord(handle);
         var s1 = GetStream(10);
         queueStream.AppendRecord(s1, s1.Length);
         Assert.AreEqual(1, queueStream.UnreadCount);
     }
     AssertRecord(10, 0, false);
 }
 public void Can_append_record_to_existing_queue()
 {
     AppendRecord(1, false);
     var p = AppendRecord(2, true);
     using(var queueStream = new MultiFileQueueStream(_path)) {
         var stream = GetStream(10);
         queueStream.AppendRecord(stream, stream.Length);
         Assert.AreEqual(2, queueStream.UnreadCount);
     }
     AssertRecord(10, p, false);
 }
 public void Can_append_record()
 {
     using(var queueStream = new MultiFileQueueStream(_path)) {
         var stream = GetStream(10);
         queueStream.AppendRecord(stream, stream.Length);
         Assert.AreEqual(1, queueStream.UnreadCount);
     }
     AssertRecord(10, 0, false);
 }