Esempio n. 1
0
        public void Verify_projection_change_info_for_projection_that_changed_slot_and_signature()
        {
            //Two projection in the same slot
            var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >());

            var projections = new IProjection[] { projection1 };
            var checkpoint1 = new Checkpoint(projection1.Info.CommonName, 1, projection1.Info.Signature + "modified")
            {
                Slot = projection1.Info.SlotName + "modified"
            };

            _checkPoints.InsertMany(new[] { checkpoint1, });

            _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db);
            _slotStatusCheckerSut           = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray());
            var status = _slotStatusCheckerSut.GetProjectionChangeInfo();
            var singleProjectionStatus = status.Single();

            Assert.That((Int32)(singleProjectionStatus.ChangeType | ProjectionChangeInfo.ProjectionChangeType.SlotChange), Is.GreaterThan(0));
            Assert.That((Int32)(singleProjectionStatus.ChangeType | ProjectionChangeInfo.ProjectionChangeType.SignatureChange), Is.GreaterThan(0));

            Assert.That(singleProjectionStatus.OldSlot, Is.EqualTo(projection1.Info.SlotName + "modified"));
            Assert.That(singleProjectionStatus.ActualSlot, Is.EqualTo(projection1.Info.SlotName));
            Assert.That(singleProjectionStatus.OldSignature, Is.EqualTo(projection1.Info.Signature + "modified"));
            Assert.That(singleProjectionStatus.ActualSignature, Is.EqualTo(projection1.Info.Signature));
        }
Esempio n. 2
0
        private IProjection[] SetupTwoProjectionsError()
        {
            _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db);
            var rebuildContext = new RebuildContext(false);
            var storageFactory = new MongoStorageFactory(_db, rebuildContext);
            var writer1        = new CollectionWrapper <SampleReadModel, string>(storageFactory, new NotifyToNobody());
            var writer2        = new CollectionWrapper <SampleReadModel2, string>(storageFactory, new NotifyToNobody());

            var projection1 = new Projection(writer1);
            var projection2 = new Projection2(writer2);
            var projections = new IProjection[] { projection1, projection2 };
            var p1          = new Checkpoint(projection1.Info.CommonName, 42, projection1.Info.Signature);

            p1.Slot = projection1.Info.SlotName;
            _checkPoints.Save(p1, p1.Id);

            var p2 = new Checkpoint(projection2.Info.CommonName, 40, projection2.Info.Signature);

            p2.Slot = projection1.Info.SlotName;
            _checkPoints.Save(p2, p2.Id);

            _concurrentCheckpointTrackerSut.SetUp(projections, 1, false);
            _slotStatusCheckerSut = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray());
            return(projections);
        }
Esempio n. 3
0
        public void Verify_projection_change_info_new_projection()
        {
            var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >());
            var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >());
            //A projection in other slot
            var projection3 = new Projection3(Substitute.For <ICollectionWrapper <SampleReadModel3, String> >());

            var projections = new IProjection[] { projection1, projection2, projection3 };
            var checkpoint1 = new Checkpoint(projection1.Info.CommonName, 1, projection1.Info.Signature)
            {
                Slot = projection1.Info.SlotName
            };
            var checkpoint2 = new Checkpoint(projection2.Info.CommonName, 1, projection2.Info.Signature)
            {
                Slot = projection2.Info.SlotName
            };

            _checkPoints.InsertMany(new[] { checkpoint1, checkpoint2, });

            _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db);
            _slotStatusCheckerSut           = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray());
            var status = _slotStatusCheckerSut.GetProjectionChangeInfo();

            Assert.That(status.Count(), Is.EqualTo(3));
            var none = status.Where(s => s.ChangeType == ProjectionChangeInfo.ProjectionChangeType.None);

            Assert.That(none.Count(), Is.EqualTo(2));
            var singleChange = status.Single(s => s.ChangeType == ProjectionChangeInfo.ProjectionChangeType.NewProjection);

            Assert.That(singleChange.CommonName, Is.EqualTo(projection3.Info.CommonName));
        }
Esempio n. 4
0
        public void Verify_projection_change_info_all_ok()
        {
            //Two projection in the same slot
            var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >());
            var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >());
            //A projection in other slot
            var projection3 = new Projection3(Substitute.For <ICollectionWrapper <SampleReadModel3, String> >());

            var projections = new IProjection[] { projection1, projection2, projection3 };
            var checkpoint1 = new Checkpoint(projection1.Info.CommonName, 1, projection1.Info.Signature)
            {
                Slot = projection1.Info.SlotName
            };
            var checkpoint2 = new Checkpoint(projection2.Info.CommonName, 1, projection2.Info.Signature)
            {
                Slot = projection2.Info.SlotName
            };
            var checkpoint3 = new Checkpoint(projection3.Info.CommonName, 1, projection3.Info.Signature)
            {
                Slot = projection3.Info.SlotName
            };

            _checkPoints.InsertMany(new[] { checkpoint1, checkpoint2, checkpoint3 });

            _slotStatusCheckerSut = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray());
            var status = _slotStatusCheckerSut.GetProjectionChangeInfo();

            Assert.That(status.Count(), Is.EqualTo(3));
            Assert.That(status.All(s => s.ChangeType == ProjectionChangeInfo.ProjectionChangeType.None));
        }
Esempio n. 5
0
        public void Verify_slot_status_new_projection()
        {
            //Two projection in the same slot
            var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >());
            var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >());
            //A projection in other slot
            var projection3 = new Projection3(Substitute.For <ICollectionWrapper <SampleReadModel3, String> >());

            var projections = new IProjection[] { projection1, projection2, projection3 };
            var checkpoint1 = new Checkpoint(projection1.Info.CommonName, 1, projection1.Info.Signature);
            var checkpoint2 = new Checkpoint(projection2.Info.CommonName, 1, projection2.Info.Signature);

            checkpoint1.Current = checkpoint1.Value;
            checkpoint2.Current = checkpoint2.Value;

            _checkPoints.InsertMany(new[] { checkpoint1, checkpoint2, });

            _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db, 60);
            _slotStatusCheckerSut           = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray());
            var status = _slotStatusCheckerSut.GetSlotsStatus();

            Assert.That(status.NewSlots, Is.EquivalentTo(new[] { projection3.Info.SlotName }));

            Assert.That(status.SlotsThatNeedsRebuild, Has.Count.EqualTo(0));
        }
Esempio n. 6
0
        public void updateSlotAndSetCheckpoint_should_create_record_in_database()
        {
            Assert.Inconclusive("Probably this is not correct, it is better to setup the tracker and then set values");
            var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >());
            var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >());
            var projections = new IProjection[] { projection1, projection2 };

            _sut = new ConcurrentCheckpointTracker(_db);
            _sut.UpdateSlotAndSetCheckpoint(projection1.GetSlotName(), projections.Select(p => p.GetCommonName()), 2);
            var checkpoints = _checkPoints.FindAll().ToEnumerable().Where(c => c.Id != "VERSION").ToList();

            Assert.That(checkpoints, Has.Count.EqualTo(2));
            Assert.That(checkpoints.All(c => c.Value == 2));
        }
Esempio n. 7
0
        public void Verify_slot_status_all_ok_with_no_checkpoints()
        {
            //Two projection in the same slot
            var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >());
            var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >());
            //A projection in other slot
            var projection3 = new Projection3(Substitute.For <ICollectionWrapper <SampleReadModel3, String> >());

            var projections = new IProjection[] { projection1, projection2, projection3 };

            _slotStatusCheckerSut = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray());
            var status = _slotStatusCheckerSut.GetSlotsStatus();

            Assert.That(status.AllSlots, Has.Count.EqualTo(2));
        }
Esempio n. 8
0
        public void Verify_status_for_slot_that_needs_to_be_rebuilded()
        {
            //Two projection in the same slot
            var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >());

            var projections = new IProjection[] { projection1 };
            var checkpoint1 = new Checkpoint(projection1.Info.CommonName, 1, projection1.Info.Signature + "modified");

            _checkPoints.InsertMany(new[] { checkpoint1, });

            _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db);
            _slotStatusCheckerSut           = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray());
            var status = _slotStatusCheckerSut.GetSlotsStatus();

            Assert.That(status.SlotsThatNeedsRebuild, Has.Count.EqualTo(1));
        }
Esempio n. 9
0
        public void Verify_slot_status_new_projection_when_db_empty()
        {
            //Two projection in the same slot
            var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >());
            var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >());
            //A projection in other slot
            var projection3 = new Projection3(Substitute.For <ICollectionWrapper <SampleReadModel3, String> >());

            var projections = new IProjection[] { projection1, projection2, projection3 };

            _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db);
            _slotStatusCheckerSut           = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray());
            var status = _slotStatusCheckerSut.GetSlotsStatus();

            Assert.That(status.NewSlots, Has.Count.EqualTo(0));

            Assert.That(status.SlotsThatNeedsRebuild, Has.Count.EqualTo(0));
        }
Esempio n. 10
0
        public void Verify_slot_status_for_interrupted_rebuilds()
        {
            //TSingle projection
            var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >());

            var projections = new IProjection[] { projection1 };
            var checkpoint  = new Checkpoint(projection1.Info.CommonName, 1, projection1.Info.Signature);

            checkpoint.Value   = 32;
            checkpoint.Current = null;
            _checkPoints.InsertMany(new[] { checkpoint });

            _slotStatusCheckerSut = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray());
            var status = _slotStatusCheckerSut.GetSlotsStatus();

            Assert.That(status.AllSlots, Has.Count.EqualTo(1));
            Assert.That(status.SlotsThatNeedsRebuild, Is.EquivalentTo(new[] { projection1.Info.SlotName }));
        }
Esempio n. 11
0
        /// <summary>
        /// If a rebuild starts then stops, we have a particular situation where signature is ok, current is null
        /// and if the slot is not marked as to rebuild, the engine will simply restart the slot redispatching everything.
        /// </summary>
        private void SetupOneProjectionWithCurrentNull()
        {
            _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db, 60);
            var rebuildContext = new RebuildContext(false);
            var storageFactory = new MongoStorageFactory(_db, rebuildContext);
            var writer1        = new CollectionWrapper <SampleReadModel, string>(storageFactory, new NotifyToNobody());

            var projection1 = new Projection(writer1);
            var projections = new IProjection[] { projection1 };
            var p1          = new Checkpoint(projection1.Info.CommonName, 42, projection1.Info.Signature);

            p1.Slot    = projection1.Info.SlotName;
            p1.Value   = 42;
            p1.Current = null;
            _checkPoints.Save(p1, p1.Id);

            _concurrentCheckpointTrackerSut.SetUp(projections, 1, false);
            _slotStatusCheckerSut = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray());
        }
Esempio n. 12
0
        public void Verify_new_projection_when_zero_events_dispatched()
        {
            //Two projection in the same slot
            var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >());
            var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >());
            //A projection in other slot
            var projection3 = new Projection3(Substitute.For <ICollectionWrapper <SampleReadModel3, String> >());

            var projections = new IProjection[] { projection1, projection2, projection3 };
            var checkpoint1 = new Checkpoint(projection1.Info.CommonName, 1, projection1.Info.Signature);
            var checkpoint2 = new Checkpoint(projection2.Info.CommonName, 1, projection2.Info.Signature);
            var checkpoint3 = new Checkpoint(projection3.Info.CommonName, 0, projection3.Info.Signature);

            _checkPoints.InsertMany(new[] { checkpoint1, checkpoint2, checkpoint3 });

            _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db);
            _slotStatusCheckerSut           = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray());
            var status = _slotStatusCheckerSut.GetSlotsStatus();

            Assert.That(status.NewSlots, Is.EquivalentTo(new[] { projection3.Info.SlotName }));
        }