public void creates_new_root_partition_on_first_epoch() { var reader = new FakeReader(withoutRecords: true); var writer = new FakeWriter(); IPartitionManager partitionManager = new PartitionManager(reader, writer, new LogV3RecordFactory()); partitionManager.Initialize(); Assert.Collection(writer.WrittenRecords, r => { Assert.Equal(LogRecordType.PartitionType, r.RecordType); Assert.IsType <PartitionTypeLogRecord>(r); Assert.Equal("Root", ((PartitionTypeLogRecord)r).Record.StringPayload); Assert.Equal(partitionManager.RootTypeId, ((PartitionTypeLogRecord)r).Record.Header.RecordId); Assert.Equal(Guid.Empty, ((PartitionTypeLogRecord)r).Record.SubHeader.PartitionId); }, r => { Assert.Equal(LogRecordType.Partition, r.RecordType); Assert.IsType <PartitionLogRecord>(r); Assert.Equal("Root", ((PartitionLogRecord)r).Record.StringPayload); Assert.Equal(partitionManager.RootId, ((PartitionLogRecord)r).Record.Header.RecordId); Assert.Equal(partitionManager.RootTypeId, ((PartitionLogRecord)r).Record.SubHeader.PartitionTypeId); Assert.Equal(Guid.Empty, ((PartitionLogRecord)r).Record.SubHeader.ParentPartitionId); }); Assert.True(writer.IsFlushed); }
public void reads_root_partition_only_once() { var reader = new FakeReader(); var writer = new FakeWriter(); IPartitionManager partitionManager = new PartitionManager(reader, writer, new LogV3RecordFactory()); partitionManager.Initialize(); partitionManager.Initialize(); Assert.Empty(writer.WrittenRecords); Assert.Equal(2, reader.ReadCount); }
public void reads_root_partition_once_initialized() { var rootPartitionId = Guid.NewGuid(); var rootPartitionTypeId = Guid.NewGuid(); var reader = new FakeReader(rootPartitionId, rootPartitionTypeId); var writer = new FakeWriter(); IPartitionManager partitionManager = new PartitionManager(reader, writer, new LogV3RecordFactory()); partitionManager.Initialize(); Assert.Empty(writer.WrittenRecords); Assert.Equal(rootPartitionId, partitionManager.RootId); Assert.Equal(rootPartitionTypeId, partitionManager.RootTypeId); }
public void creates_root_partition_in_case_it_partially_failed_previously() { var rootPartitionTypeId = Guid.NewGuid(); var reader = new FakeReader(rootPartitionId: null, rootPartitionTypeId); var writer = new FakeWriter(); IPartitionManager partitionManager = new PartitionManager(reader, writer, new LogV3RecordFactory()); partitionManager.Initialize(); Assert.True(partitionManager.RootId.HasValue); Assert.Equal(rootPartitionTypeId, partitionManager.RootTypeId); Assert.Collection(writer.WrittenRecords, r => { Assert.Equal(LogRecordType.Partition, r.RecordType); Assert.IsType <PartitionLogRecord>(r); Assert.Equal("Root", ((PartitionLogRecord)r).Record.StringPayload); Assert.Equal(partitionManager.RootId, ((PartitionLogRecord)r).Record.Header.RecordId); Assert.Equal(partitionManager.RootTypeId, ((PartitionLogRecord)r).Record.SubHeader.PartitionTypeId); Assert.Equal(Guid.Empty, ((PartitionLogRecord)r).Record.SubHeader.ParentPartitionId); }); }