Example #1
0
        public void should_be_able_to_read_the_transactional_writes_when_the_commit_is_present()
        {
            /*
             * create a db with a transaction where the commit is not present yet (read happened before the chaser could commit)
             * in the following case the read will return the event for the single non-transactional write
             * performing a read from the next position returned will fail as the prepares are all less than what we have asked for.
             */
            CreateDb(Rec.TransSt(0, "transaction_stream_id"),
                     Rec.Prepare(0, "transaction_stream_id"),
                     Rec.TransEnd(0, "transaction_stream_id"),
                     Rec.Prepare(1, "single_write_stream_id_1", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted),
                     Rec.Prepare(2, "single_write_stream_id_2", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted),
                     Rec.Prepare(3, "single_write_stream_id_3", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted));

            var firstRead = ReadIndex.ReadAllEventsForward(new Data.TFPos(0, 0), 10);

            Assert.AreEqual(3, firstRead.Records.Count);
            Assert.AreEqual("single_write_stream_id_1", firstRead.Records[0].Event.EventStreamId);
            Assert.AreEqual("single_write_stream_id_2", firstRead.Records[1].Event.EventStreamId);
            Assert.AreEqual("single_write_stream_id_3", firstRead.Records[2].Event.EventStreamId);

            //create the exact same db as above but now with the transaction's commit
            CreateDb(Rec.TransSt(0, "transaction_stream_id"),
                     Rec.Prepare(0, "transaction_stream_id"),
                     Rec.TransEnd(0, "transaction_stream_id"),
                     Rec.Prepare(1, "single_write_stream_id_1", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted),
                     Rec.Prepare(2, "single_write_stream_id_2", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted),
                     Rec.Prepare(3, "single_write_stream_id_3", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted),
                     Rec.Commit(0, "transaction_stream_id"));

            var transactionRead = ReadIndex.ReadAllEventsForward(firstRead.NextPos, 10);

            Assert.AreEqual(1, transactionRead.Records.Count);
            Assert.AreEqual("transaction_stream_id", transactionRead.Records[0].Event.EventStreamId);
        }
        public void should_be_able_to_read_the_transactional_writes_when_the_commit_is_present()
        {
            CreateDb(Rec.Prepare(0, "single_write_stream_id_1", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted),
                     Rec.TransSt(1, "transaction_stream_id"),
                     Rec.Prepare(1, "transaction_stream_id"),
                     Rec.TransEnd(1, "transaction_stream_id"),
                     Rec.Prepare(2, "single_write_stream_id_2", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted),
                     Rec.Prepare(3, "single_write_stream_id_3", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted),
                     Rec.Prepare(4, "single_write_stream_id_4", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted));

            var firstRead = ReadIndex.ReadAllEventsForward(new Data.TFPos(0, 0), 10);

            Assert.AreEqual(4, firstRead.Records.Count);
            Assert.AreEqual("single_write_stream_id_1", firstRead.Records[0].Event.EventStreamId);
            Assert.AreEqual("single_write_stream_id_2", firstRead.Records[1].Event.EventStreamId);
            Assert.AreEqual("single_write_stream_id_3", firstRead.Records[2].Event.EventStreamId);
            Assert.AreEqual("single_write_stream_id_4", firstRead.Records[3].Event.EventStreamId);

            CreateDb(Rec.Prepare(0, "single_write_stream_id_1", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted),
                     Rec.TransSt(1, "transaction_stream_id"),
                     Rec.Prepare(1, "transaction_stream_id"),
                     Rec.TransEnd(1, "transaction_stream_id"),
                     Rec.Prepare(2, "single_write_stream_id_2", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted),
                     Rec.Prepare(3, "single_write_stream_id_3", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted),
                     Rec.Prepare(4, "single_write_stream_id_4", prepareFlags: PrepareFlags.Data | PrepareFlags.IsCommitted),
                     Rec.Commit(1, "transaction_stream_id"));

            var transactionRead = ReadIndex.ReadAllEventsForward(firstRead.NextPos, 10);

            Assert.AreEqual(1, transactionRead.Records.Count);
            Assert.AreEqual("transaction_stream_id", transactionRead.Records[0].Event.EventStreamId);
        }
Example #3
0
 protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
 {
     return(dbCreator.Chunk(Rec.Prepare(0, "test"),
                            Rec.Commit(0, "test"),
                            Rec.Delete(2, "test"),
                            Rec.Commit(2, "test"))
            .CreateDb());
 }
 protected override DbResult CreateDb(TFChunkDbCreationHelper <TLogFormat, TStreamId> dbCreator)
 {
     return(dbCreator
            .Chunk(Rec.Prepare(0, "bla"), Rec.Prepare(0, "bla"), Rec.Commit(0, "bla"))
            .Chunk(Rec.Delete(1, "bla"), Rec.Commit(1, "bla"))
            .CompleteLastChunk()
            .CreateDb());
 }
Example #5
0
 protected override DbResult CreateDb(TFChunkDbCreationHelper <TLogFormat, TStreamId> dbCreator)
 {
     return(dbCreator.Chunk(
                Rec.Prepare(0, "existing_stream"),
                Rec.Commit(0, "existing_stream"),
                Rec.Prepare(1, "$existing_stream"),
                Rec.Commit(1, "$existing_stream")
                ).CreateDb());
 }
Example #6
0
 protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
 {
     return(dbCreator.Chunk(Rec.Prepare(0, "$$test", "0", metadata: new StreamMetadata(maxCount: 10)),
                            Rec.Prepare(0, "$$test", "1", metadata: new StreamMetadata(maxCount: 9)),
                            Rec.Prepare(0, "$$test", "2", metadata: new StreamMetadata(maxCount: 8)),
                            Rec.Prepare(0, "$$test", "3", metadata: new StreamMetadata(maxCount: 7)),
                            Rec.Prepare(0, "$$test", "4", metadata: new StreamMetadata(maxCount: 6)),
                            Rec.Commit(0, "$$test"))
            .CreateDb());
 }
Example #7
0
 protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
 {
     return(dbCreator.Chunk(Rec.Prepare(0, "$$test", "0", metadata: new StreamMetadata(10, null, null, null)),
                            Rec.Prepare(0, "$$test", "1", metadata: new StreamMetadata(9, null, null, null)),
                            Rec.Prepare(0, "$$test", "2", metadata: new StreamMetadata(8, null, null, null)),
                            Rec.Prepare(0, "$$test", "3", metadata: new StreamMetadata(7, null, null, null)),
                            Rec.Prepare(0, "$$test", "4", metadata: new StreamMetadata(6, null, null, null)),
                            Rec.Commit(0, "$$test"))
            .CreateDb());
 }
 protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
 {
     return(dbCreator.Chunk(Rec.Prepare(0, "test"),
                            Rec.Commit(0, "test"),
                            Rec.Prepare(1, "$$test", metadata: new StreamMetadata(2, null, null, null)),
                            Rec.Commit(1, "$$test"),
                            Rec.Delete(2, "test"),
                            Rec.Commit(2, "test"))
            .CreateDb());
 }
 protected override DbResult CreateDb(TFChunkDbCreationHelper <TLogFormat, TStreamId> dbCreator)
 {
     return(dbCreator
            .Chunk(Rec.Prepare(0, "$$bla", metadata: new StreamMetadata(10, null, null, null, null)),
                   Rec.Prepare(0, "$$bla", metadata: new StreamMetadata(5, null, null, null, null)),
                   Rec.Prepare(0, "$$bla", metadata: new StreamMetadata(3, null, null, null, null)),
                   Rec.Prepare(0, "$$bla", metadata: new StreamMetadata(2, null, null, null, null)),
                   Rec.Commit(0, "$$bla"))
            .CompleteLastChunk()
            .CreateDb());
 }
 protected override DbResult CreateDb(TFChunkDbCreationHelper <TLogFormat, TStreamId> dbCreator)
 {
     return(dbCreator.Chunk(Rec.Prepare(0, "test"),
                            Rec.Commit(0, "test"))
            .Chunk(Rec.Prepare(1, "test"),
                   Rec.Commit(1, "test"),
                   Rec.Prepare(2, "$$test",
                               metadata: new StreamMetadata(null, null, EventNumber.DeletedStream, true, null, null)),
                   Rec.Commit(2, "$$test"))
            .CompleteLastChunk()
            .CreateDb());
 }
Example #11
0
 protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
 {
     return(dbCreator
            .Chunk(Rec.Prepare(0, "$$bla"),
                   Rec.Prepare(0, "$$bla"),
                   Rec.Prepare(0, "$$bla"),
                   Rec.Prepare(0, "$$bla"),
                   Rec.Prepare(0, "$$bla"),
                   Rec.Commit(0, "$$bla"))
            .CompleteLastChunk()
            .CreateDb());
 }
 protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
 {
     return(dbCreator.Chunk(Rec.Prepare(0, "$$test", metadata: new StreamMetadata(tempStream: true), version: LogRecordVersion.LogRecordV0),
                            Rec.Commit(0, "$$test", version: LogRecordVersion.LogRecordV0),
                            Rec.Prepare(1, "test", version: LogRecordVersion.LogRecordV0),
                            Rec.Commit(1, "test", version: LogRecordVersion.LogRecordV0),
                            Rec.Prepare(2, "test", version: LogRecordVersion.LogRecordV0),
                            Rec.Commit(2, "test", version: LogRecordVersion.LogRecordV0),
                            Rec.Prepare(3, "$$test", metadata: new StreamMetadata(truncateBefore: int.MaxValue, tempStream: true), version: LogRecordVersion.LogRecordV0),
                            Rec.Commit(3, "$$test", version: LogRecordVersion.LogRecordV0))
            .CompleteLastChunk()
            .CreateDb());
 }
 protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
 {
     return(dbCreator.Chunk(Rec.Prepare(0, "ES1", version: _version),
                            Rec.Commit(0, "ES1", version: _version),
                            Rec.Prepare(1, "ES1", version: _version),
                            Rec.Commit(1, "ES1", version: _version))
            .CompleteLastChunk()
            .Chunk(Rec.Prepare(2, "ES2", version: _version),
                   Rec.Commit(2, "ES2", version: _version),
                   Rec.Prepare(3, "ES2", version: _version),
                   Rec.Commit(3, "ES2", version: _version))
            .CreateDb());
 }
 protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
 {
     return(dbCreator.Chunk(Rec.Prepare(0, "$$test", metadata: new StreamMetadata(tempStream: true)),
                            Rec.Commit(0, "$$test"))
            .Chunk(Rec.Prepare(1, "test"),
                   Rec.Commit(1, "test"),
                   Rec.Prepare(2, "test"),
                   Rec.Commit(2, "test"),
                   Rec.Prepare(3, "$$test", metadata: new StreamMetadata(truncateBefore: EventNumber.DeletedStream, tempStream: true)),
                   Rec.Commit(3, "$$test"))
            .CompleteLastChunk()
            .CreateDb());
 }
        protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
        {
            var version = LogRecordVersion.LogRecordV0;

            return(dbCreator.Chunk(Rec.Prepare(0, "test", version: version),
                                   Rec.Commit(0, "test", version: version))
                   .Chunk(Rec.Prepare(1, "test", version: version),
                          Rec.Commit(1, "test", version: version),
                          Rec.Prepare(2, "$$test", metadata: new StreamMetadata(null, null, int.MaxValue, true, null, null), version: version),
                          Rec.Commit(2, "$$test", version: version))
                   .Chunk(Rec.Prepare(3, "random", version: version),          // Need an incomplete chunk to ensure writer checkpoints are correct
                          Rec.Commit(3, "random", version: version))
                   .CreateDb());
        }
Example #16
0
 protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
 {
     return(dbCreator
            .Chunk(Rec.Prepare(0, "$$bla", metadata: new StreamMetadata(null, TimeSpan.FromMinutes(1), null, null, null)),
                   Rec.Commit(0, "$$bla"),
                   Rec.Prepare(1, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(25)),
                   Rec.Commit(1, "bla"),
                   Rec.Prepare(2, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(20)),
                   Rec.Prepare(2, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(10)),
                   Rec.Prepare(2, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(5)),
                   Rec.Prepare(2, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(3)),
                   Rec.Commit(2, "bla"))
            .CompleteLastChunk()
            .CreateDb());
 }
Example #17
0
 protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
 {
     return(dbCreator.Chunk(Rec.Prepare(0, _deletedMetaStream, metadata: new StreamMetadata(tempStream: true), version: LogRecordVersion.LogRecordV0),
                            Rec.Commit(0, _deletedMetaStream, version: LogRecordVersion.LogRecordV0),
                            Rec.Prepare(1, _keptStream, version: LogRecordVersion.LogRecordV1),
                            Rec.Commit(1, _keptStream, version: LogRecordVersion.LogRecordV1),
                            Rec.Prepare(2, _keptStream, version: LogRecordVersion.LogRecordV0),
                            Rec.Commit(2, _keptStream, version: LogRecordVersion.LogRecordV0),
                            Rec.Prepare(3, _deletedStream, version: LogRecordVersion.LogRecordV1),
                            Rec.Commit(3, _deletedStream, version: LogRecordVersion.LogRecordV0),
                            Rec.Prepare(4, _deletedStream, version: LogRecordVersion.LogRecordV0),
                            Rec.Commit(4, _deletedStream, version: LogRecordVersion.LogRecordV1),
                            Rec.Prepare(5, _keptStream, version: LogRecordVersion.LogRecordV1),
                            Rec.Commit(5, _keptStream, version: LogRecordVersion.LogRecordV1),
                            Rec.Prepare(6, _deletedMetaStream, metadata: new StreamMetadata(truncateBefore: EventNumber.DeletedStream, tempStream: true), version: LogRecordVersion.LogRecordV1),
                            Rec.Commit(6, _deletedMetaStream, version: LogRecordVersion.LogRecordV0))
            .CompleteLastChunk()
            .CreateDb());
 }
Example #18
0
 protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
 {
     return(dbCreator
            .Chunk(Rec.Prepare(0, "$$bla", metadata: new StreamMetadata(3, null, null, null)),
                   Rec.Commit(0, "$$bla"),
                   Rec.Prepare(1, "bla"),
                   Rec.Commit(1, "bla"),
                   Rec.Prepare(2, "bla"),
                   Rec.Prepare(2, "bla"),
                   Rec.Prepare(2, "bla"),
                   Rec.Prepare(2, "bla"),
                   Rec.Prepare(2, "bla"),
                   Rec.Commit(2, "bla"),
                   Rec.Prepare(3, "bla"),
                   Rec.Prepare(3, "bla"),
                   Rec.Prepare(3, "bla"),
                   Rec.Prepare(3, "bla"),
                   Rec.Commit(3, "bla"))
            .CompleteLastChunk()
            .CreateDb());
 }
Example #19
0
 protected override DbResult CreateDb(TFChunkDbCreationHelper <TLogFormat, TStreamId> dbCreator)
 {
     return(dbCreator
            .Chunk(Rec.Prepare(0, "$$bla", metadata: new StreamMetadata(truncateBefore: 7)),
                   Rec.Commit(0, "$$bla"),
                   Rec.Prepare(1, "bla"),               // event 0
                   Rec.Commit(1, "bla"),
                   Rec.Prepare(2, "bla"),               // event 1
                   Rec.Prepare(2, "bla"),               // event 2
                   Rec.Prepare(2, "bla"),               // event 3
                   Rec.Prepare(2, "bla"),               // event 4
                   Rec.Prepare(2, "bla"),               // event 5
                   Rec.Commit(2, "bla"),
                   Rec.Prepare(3, "bla"),               // event 6
                   Rec.Prepare(3, "bla"),               // event 7
                   Rec.Prepare(3, "bla"),               // event 8
                   Rec.Prepare(3, "bla"),               // event 9
                   Rec.Commit(3, "bla"))
            .CompleteLastChunk()
            .CreateDb());
 }
 protected override DbResult CreateDb(TFChunkDbCreationHelper <TLogFormat, TStreamId> dbCreator)
 {
     return(dbCreator
            .Chunk(Rec.Prepare(0, "$$bla", metadata: new StreamMetadata(maxCount: 3)),
                   Rec.Commit(0, "$$bla"),
                   Rec.Prepare(1, "bla"),
                   Rec.Commit(1, "bla"),
                   Rec.Prepare(2, "bla"),
                   Rec.Prepare(2, "bla"),
                   Rec.Prepare(2, "bla"),
                   Rec.Prepare(2, "bla"),
                   Rec.Prepare(2, "bla"),
                   Rec.Commit(2, "bla"),
                   Rec.Prepare(3, "bla"),
                   Rec.Prepare(3, "bla"),
                   Rec.Prepare(3, "bla"),
                   Rec.Prepare(3, "bla"),
                   Rec.Commit(3, "bla"))
            .CompleteLastChunk()
            .CreateDb());
 }
Example #21
0
 protected override DbResult CreateDb(TFChunkDbCreationHelper dbCreator)
 {
     return(dbCreator
            .Chunk(Rec.Prepare(0, "bla"),
                   Rec.Commit(0, "bla"),
                   Rec.TransSt(1, "bla"),
                   Rec.Prepare(1, "bla"),
                   Rec.Prepare(1, "bla"),
                   Rec.Prepare(1, "bla"),
                   Rec.Prepare(1, "bla"))
            .Chunk(Rec.Prepare(1, "bla"),
                   Rec.Prepare(1, "bla"),
                   Rec.Prepare(1, "bla"),
                   Rec.Prepare(1, "bla"),
                   Rec.Prepare(1, "bla"),
                   Rec.TransEnd(1, "bla"),
                   Rec.Commit(1, "bla"))
            .Chunk(Rec.Delete(2, "bla"),
                   Rec.Commit(2, "bla"))
            .CompleteLastChunk()
            .CreateDb());
 }
Example #22
0
 protected override DbResult CreateDb(TFChunkDbCreationHelper <TLogFormat, TStreamId> dbCreator)
 {
     return(dbCreator
            .Chunk(
                Rec.Prepare(0, "$$bla",
                            metadata: new StreamMetadata(3, TimeSpan.FromMinutes(50), null, null, null)),
                Rec.Commit(0, "$$bla"),
                Rec.Prepare(3, "bla"),
                Rec.Commit(3, "bla"),
                Rec.Prepare(1, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(100)),
                Rec.Prepare(1, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(90)),
                Rec.Prepare(1, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(60)),
                Rec.Prepare(1, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(40)),
                Rec.Prepare(1, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(30)),
                Rec.Commit(1, "bla"),
                Rec.Prepare(2, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(20)),
                Rec.Prepare(2, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(3)),
                Rec.Prepare(2, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(2)),
                Rec.Prepare(2, "bla", timestamp: DateTime.UtcNow - TimeSpan.FromMinutes(1)),
                Rec.Commit(2, "bla"))
            .CompleteLastChunk()
            .CreateDb());
 }