Пример #1
0
 public void Can_append_record()
 {
     var queueStream = new SingleFileQueueStream(_stream);
     using(var stream = new MemoryStream()) {
         stream.Write(BitConverter.GetBytes(10));
         stream.Seek(0, SeekOrigin.Begin);
         queueStream.AppendRecord(stream, stream.Length);
         AssertRecord(10, 0, false);
         Assert.AreEqual(1, queueStream.UnreadCount);
     }
 }
Пример #2
0
 public void Can_append_record_to_existing_queue()
 {
     AppendRecord(1, false);
     AppendRecord(2, true);
     var queueStream = new SingleFileQueueStream(_stream);
     using(var stream = new MemoryStream()) {
         stream.Write(BitConverter.GetBytes(10));
         stream.Seek(0, SeekOrigin.Begin);
         var position = _stream.Length;
         queueStream.AppendRecord(stream, stream.Length);
         AssertRecord(10, position, false);
         Assert.AreEqual(2, queueStream.UnreadCount);
     }
 }
Пример #3
0
 public void Corrupt_record_does_not_stop_further_appending_dequeueing()
 {
     var v1 = "asdsdasdasdasdasd";
     var v2 = "asdasdsadasdwwdsdw";
     AppendRecord(v1, false);
     for(byte i = 0; i < 6; i++) {
         _stream.WriteByte(i);
     }
     var position = _stream.Position;
     var queueStream = new SingleFileQueueStream(_stream);
     Assert.AreEqual(1, queueStream.UnreadCount);
     using(var stream = new MemoryStream()) {
         stream.Write(Encoding.UTF8.GetBytes(v2));
         stream.Seek(0, SeekOrigin.Begin);
         queueStream.AppendRecord(stream, stream.Length);
         AssertRecord(v2, position, false);
         Assert.AreEqual(2, queueStream.UnreadCount);
     }
     Assert.AreEqual(v1, GetStringValue(queueStream.ReadNextRecord().Stream));
     Assert.AreEqual(v2, GetStringValue(queueStream.ReadNextRecord().Stream));
 }
Пример #4
0
 public void Can_append_record_to_truncated_file()
 {
     AppendRecord(1, false);
     var queueStream = new SingleFileQueueStream(_stream);
     var handle = queueStream.ReadNextRecord().Handle;
     queueStream.DeleteRecord(handle);
     using(var stream = new MemoryStream()) {
         stream.Write(BitConverter.GetBytes(10));
         stream.Seek(0, SeekOrigin.Begin);
         queueStream.AppendRecord(stream, stream.Length);
         AssertRecord(10, 0, false);
         Assert.AreEqual(1, queueStream.UnreadCount);
     }
 }