本文整理汇总了C#中PrepareLogRecord.WriteWithLengthPrefixAndSuffixTo方法的典型用法代码示例。如果您正苦于以下问题:C# PrepareLogRecord.WriteWithLengthPrefixAndSuffixTo方法的具体用法?C# PrepareLogRecord.WriteWithLengthPrefixAndSuffixTo怎么用?C# PrepareLogRecord.WriteWithLengthPrefixAndSuffixTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PrepareLogRecord
的用法示例。
在下文中一共展示了PrepareLogRecord.WriteWithLengthPrefixAndSuffixTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: can_read_a_record_straddling_multiple_files
public void can_read_a_record_straddling_multiple_files()
{
var writerchk = new InMemoryCheckpoint(20020);
var readerchk = new InMemoryCheckpoint("reader", 9990);
var config = new TransactionFileDatabaseConfig(PathName, "prefix.tf", 10000, writerchk, new[] {readerchk});
var recordToWrite = new PrepareLogRecord(logPosition: 0,
correlationId: _correlationId,
eventId: _eventId,
transactionPosition: 0,
transactionOffset: 0,
eventStreamId: "WorldEnding",
expectedVersion: 1234,
timeStamp: new DateTime(2012, 12, 21),
flags: PrepareFlags.None,
eventType: "type",
data: new byte[] { 1, 2, 3, 4, 5 },
metadata: new byte[] {7, 17});
var memstream = new MemoryStream();
var writer = new BinaryWriter(memstream);
recordToWrite.WriteWithLengthPrefixAndSuffixTo(writer);
var buf = memstream.GetBuffer();
using (var fs = new FileStream(config.FileNamingStrategy.GetFilenameFor(0), FileMode.CreateNew, FileAccess.Write))
{
fs.Seek(9990, SeekOrigin.Begin);
fs.Write(buf, 0, 10);
fs.Close();
}
using (var fs = new FileStream(config.FileNamingStrategy.GetFilenameFor(1), FileMode.CreateNew, FileAccess.Write))
{
fs.Seek(0, SeekOrigin.Begin);
fs.Write(buf, 10, recordToWrite.GetSizeWithLengthPrefixAndSuffix() - 10);
fs.Close();
}
var reader = new MultifileTransactionFileChaser(config, readerchk);
reader.Open();
LogRecord record;
var readRecord = reader.TryReadNext(out record);
reader.Close();
Assert.IsTrue(readRecord);
Assert.That(recordToWrite, Is.EqualTo(record));
Assert.AreEqual(9990 + recordToWrite.GetSizeWithLengthPrefixAndSuffix(), readerchk.Read());
}
示例2: try_read_returns_record_when_writerchecksum_ahead
public void try_read_returns_record_when_writerchecksum_ahead()
{
var recordToWrite = new PrepareLogRecord(logPosition: 0,
correlationId: _correlationId,
eventId: _eventId,
transactionPosition: 0,
transactionOffset: 0,
eventStreamId: "WorldEnding",
expectedVersion: 1234,
timeStamp: new DateTime(2012, 12, 21),
flags: PrepareFlags.None,
eventType: "type",
data: new byte[] { 1, 2, 3, 4, 5 },
metadata: new byte[] { 7, 17 });
using (var fs = new FileStream(GetFilePathFor("prefix.tf0"), FileMode.CreateNew, FileAccess.Write))
{
fs.SetLength(ChunkHeader.Size + ChunkFooter.Size + 10000);
var chunkHeader = new ChunkHeader(TFChunk.CurrentChunkVersion, 10000, 0, 0, false).AsByteArray();
var writer = new BinaryWriter(fs);
writer.Write(chunkHeader);
recordToWrite.WriteWithLengthPrefixAndSuffixTo(writer);
fs.Close();
}
var writerchk = new InMemoryCheckpoint(128);
var chaserchk = new InMemoryCheckpoint(Checkpoint.Chaser, 0);
var db = new TFChunkDb(new TFChunkDbConfig(PathName,
new PrefixFileNamingStrategy(PathName, "prefix.tf"),
10000,
0,
writerchk,
chaserchk,
new[] {chaserchk}));
db.OpenVerifyAndClean();
var chaser = new TFChunkChaser(db, writerchk, chaserchk);
chaser.Open();
LogRecord record;
var recordRead = chaser.TryReadNext(out record);
chaser.Close();
Assert.AreEqual(record.GetSizeWithLengthPrefixAndSuffix(), chaserchk.Read());
Assert.IsTrue(recordRead);
Assert.AreEqual(recordToWrite, record);
db.Close();
}
示例3: try_read_returns_record_when_writerchecksum_equal
public void try_read_returns_record_when_writerchecksum_equal()
{
var writerchk = new InMemoryCheckpoint(0);
var readerchk = new InMemoryCheckpoint("reader", 0);
var config = new TransactionFileDatabaseConfig(PathName, "prefix.tf", 10000, writerchk,
new List<ICheckpoint> {readerchk});
var recordToWrite = new PrepareLogRecord(logPosition: 0,
correlationId: _correlationId,
eventId: _eventId,
transactionPosition: 0,
transactionOffset: 0,
eventStreamId: "WorldEnding",
expectedVersion: 1234,
timeStamp: new DateTime(2012, 12, 21),
flags: PrepareFlags.None,
eventType: "type",
data: new byte[] { 1, 2, 3, 4, 5 },
metadata: new byte[] {7, 17});
using (var fs = new FileStream(Path.Combine(PathName, "prefix.tf0"), FileMode.CreateNew, FileAccess.Write))
{
var writer = new BinaryWriter(fs);
recordToWrite.WriteWithLengthPrefixAndSuffixTo(writer);
fs.Close();
}
writerchk.Write(recordToWrite.GetSizeWithLengthPrefixAndSuffix());
var reader = new MultifileTransactionFileChaser(config, readerchk);
reader.Open();
LogRecord record;
var readRecord = reader.TryReadNext(out record);
reader.Close();
Assert.IsTrue(readRecord);
Assert.AreEqual(record.GetSizeWithLengthPrefixAndSuffix(), readerchk.Read());
Assert.AreEqual(recordToWrite, record);
}
示例4: try_read_returns_properly_when_writer_is_written_to_while_chasing
public void try_read_returns_properly_when_writer_is_written_to_while_chasing()
{
var writerchk = new InMemoryCheckpoint(0);
var readerchk = new InMemoryCheckpoint("reader", 0);
var config = new TransactionFileDatabaseConfig(PathName, "prefix.tf", 10000, writerchk, new[] {readerchk});
var fileName = Path.Combine(PathName, "prefix.tf0");
File.Create(fileName).Close();
var reader = new MultifileTransactionFileChaser(config, readerchk);
reader.Open();
LogRecord record;
Assert.IsFalse(reader.TryReadNext(out record));
var recordToWrite = new PrepareLogRecord(logPosition: 0,
correlationId: _correlationId,
eventId: _eventId,
transactionPosition: 0,
transactionOffset: 0,
eventStreamId: "WorldEnding",
expectedVersion: 1234,
timeStamp: new DateTime(2012, 12, 21),
flags: PrepareFlags.None,
eventType: "type",
data: new byte[] { 1, 2, 3, 4, 5 },
metadata: new byte[] {7, 17});
var memstream = new MemoryStream();
var writer = new BinaryWriter(memstream);
recordToWrite.WriteWithLengthPrefixAndSuffixTo(writer);
using (var fs = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
fs.Write(memstream.ToArray(), 0, (int)memstream.Length);
fs.Flush(flushToDisk: true);
}
writerchk.Write(memstream.Length);
Assert.IsTrue(reader.TryReadNext(out record));
Assert.AreEqual(record, recordToWrite);
var recordToWrite2 = new PrepareLogRecord(logPosition: 0,
correlationId: _correlationId,
eventId: _eventId,
transactionPosition: 0,
transactionOffset: 0,
eventStreamId: "WorldEnding",
expectedVersion: 4321,
timeStamp: new DateTime(2012, 12, 21),
flags: PrepareFlags.None,
eventType: "type",
data: new byte[] { 3, 2, 1 },
metadata: new byte[] {9});
memstream.SetLength(0);
recordToWrite2.WriteWithLengthPrefixAndSuffixTo(writer);
using (var fs = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
fs.Write(memstream.ToArray(), 0, (int) memstream.Length);
fs.Flush(flushToDisk: true);
}
writerchk.Write(writerchk.Read() + memstream.Length);
Assert.IsTrue(reader.TryReadNext(out record));
Assert.AreEqual(record, recordToWrite2);
reader.Close();
}