public void Create_NoLeaseExists_LeaseCreated(
     IConcurrencyControlRepository<ElasticLease> repo,
     ElasticLease lease,
     ISystemContext ctx,
     TestIndexUtils contactIndex)
 {
     using (contactIndex)
     {
         var actual = repo.Create(lease, ctx);
         actual.Should().BeTrue();
     }
 }
コード例 #2
0
 public void TryObtainLock_NoLeaseExists_LockObtained(
     ILeaseService service,
     ISystemContext ctx,
     ElasticLease lease,
     TestIndexUtils contactIndex)
 {
     using (contactIndex)
     {
         ElasticLease winner;
         service.TryObtainLock(lease, ctx, out winner).Should().BeTrue();
         lease.ShouldBeEquivalentTo(winner);
     }
 }
コード例 #3
0
        public void GetContact_ContactExists_ContactReturned(
            TestIndexUtils contactIndex,
            IRepository<ElasticContact> repo,
            ElasticContact contact,
            ISystemContext ctx)
        {
            using (contactIndex)
            {
                repo.Save(contact, ctx);

                var res = repo.Get(contact.Id, ctx);
                res.Should().NotBeNull();
                res.Id.Should().Be(contact.Id);
            }
        }
コード例 #4
0
        public void GetContact_ContactDoesntExist_ContactNotReturned(
            TestIndexUtils contactIndex,
            IRepository<ElasticContact> repo,
            ElasticContact contact,
            ISystemContext ctx)
        {
            using (contactIndex)
            {
                // a little hacky - this is an easy way of ensuring the test index exists first.
                repo.Save(contact, ctx);

                var res = repo.Get(new Guid(), ctx);
                res.Should().BeNull();
            }
        }
        public void SaveContact_ContactDoesntExist_ContactSave(
            DataAdapterProvider provider,
            IContactFactory contactFactory,
            IContact contact,
            LeaseOwner leaseOwner,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                provider.SaveContact(contact, new ContactSaveOptions(true, leaseOwner)).Should().BeTrue();

                var actual = provider.LoadContactReadOnly(contact.Id, contactFactory);

                AssertContactsEqual(actual, contact);
            }
        }
コード例 #6
0
        public void TryLoadAndLockById_ContactExistsAndNotLockedWithNoSuccessors_ReturnsContact(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner us,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact, us, true, ctx)
                    .Should().Be(true);

                var res = contactService.TryLoadAndLock(contact.Id, us, TimeSpan.FromMinutes(1), ctx);

                res.Status.Should().Be(LockAttemptStatus.Success);
                res.LockedObject.ShouldBeEquivalentToContact(contact, l => l.Expires > DateTime.UtcNow && l.IsOwnedBy(us) && l.Version == 3);
            }
        }
コード例 #7
0
        public void SaveContact_ContactLockedbyDifferentOwner_ContactNotAdded(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner us,
            ElasticLeaseOwner them,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact, them, false, ctx)
                    .Should().Be(true);

                contactService.Save(contact, us, false, ctx)
                    .Should().Be(false);
            }
        }
コード例 #8
0
        public void DeleteContact_ContactExistsWithActiveLeaseBySameOwner_ContactDeleted(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner us,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact, us, false, ctx).Should().BeTrue();

                // deletes seem to be brutal - they don't care about locks
                contactService.Delete(contact.Id, ctx);

                contactService
                    .LoadForReadOnly(contact.Id, ctx)
                    .Should()
                    .BeNull();
            }
        }
コード例 #9
0
        public void DeleteContact_ContactExistsWithActiveLeaseByDifferentOwner_DeleteStillHonoured(
            IElasticAnalyticsContactService contactService,
            ILeaseService leaseService,
            ElasticContact contact,
            ElasticLeaseOwner us,
            ElasticLeaseOwner them,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact, them, false, ctx).Should().BeTrue();

                // deletes seem to be brutal
                contactService.Delete(contact.Id, ctx);

                contactService
                    .LoadForReadOnly(contact.Id, ctx)
                    .Should()
                    .BeNull();

                // lease is deleted so if we wanted, we can just go and create another contact with the
                // same id straight away...
                contact.Lease = null;
                contactService.Save(contact, us, false, ctx).Should().BeTrue();
            }
        }
コード例 #10
0
        public void DeleteContact_ContactExistsWithNoLease_ContactDeleted(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner us,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService
                    .Save(contact, us, true, ctx)
                    .Should().BeTrue();

                contactService.Delete(contact.Id, ctx);

                contactService
                    .LoadForReadOnly(contact.Id, ctx)
                    .Should()
                    .BeNull();
            }
        }
コード例 #11
0
        public void DeleteContact_ContactExistsWithExpiredLeaseByDifferentOwner_ContactDeleted(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner them,
            ISystemContext ctx,
            IDateTimeController dateTime,
            TestIndexUtils contactIndex) 
        {
            using (contactIndex)
            {
                // arrange contact with expired lease from another owner...
                var timeTraveller = (DateTimeTimeTraveller)dateTime;

                using (timeTraveller.NewJourney(-24))
                {
                    contactService.Save(contact, them, false, ctx).Should().BeTrue();
                }

                // deletes don't have an owner, at this level at least.
                contactService.Delete(contact.Id, ctx);

                contactService
                    .LoadForReadOnly(contact.Id, ctx)
                    .Should()
                    .BeNull();
            }
        }
コード例 #12
0
        public void LoadForReadOnlyById_ContactExistsNotLocked_ContactReturned(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner them,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact, them, true, ctx)
                    .Should().Be(true);

                contactService.LoadForReadOnly(contact.Id, ctx)
                    .ShouldBeEquivalentToContact(contact, l => l == null);
            }
        }
コード例 #13
0
        public void TryExtendLock_ContactExistsLockedByDifferentOwner_NotExtended(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner them,
            ElasticLeaseOwner us,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                // lock by a different owner
                contactService.Save(contact, them, false, ctx)
                    .Should().Be(true);

                // extend it
                contact.Lease = new ElasticLease(contact.Id, DateTime.UtcNow, us); // specify the lease we want
                var res = contactService.TryExtendLock(contact, TimeSpan.FromHours(1), ctx);

                res.Should().BeFalse();
                contact.Lease.IsOwnedBy(us); // currently Andes does not update the lease reference in this scenario
            }
        }
コード例 #14
0
         public void ObsoleteContact_ContactExistsAndLockedByDifferentOwner_ReturnsFalse(
            IElasticAnalyticsContactService contactService,
            IRepository<ElasticContact> contactRepo,
            ElasticContact contact,
            Guid successor,
            ElasticLeaseOwner us,
            ElasticLeaseOwner them,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
         {
             using (contactIndex)
             {
                 // contact exists and currently locked.
                 contactService
                     .Save(contact, them, false, ctx)
                     .Should()
                     .Be(true);

                 contactService.Obsolete(contact.Id, successor, us, ctx).Should().BeFalse();
             }
         }
コード例 #15
0
 public void ReleaseContact_ContactDoesntExist_NothingHappens(
     IElasticAnalyticsContactService contactService,
     ElasticContact contact,
     ElasticLeaseOwner us,
     ISystemContext ctx,
     TestIndexUtils contactIndex)
 {
     using (contactIndex)
     {
         AssertionExtensions.ShouldNotThrow(() => 
             contactService.Release(contact.Id, us, ctx));
     }
 }
コード例 #16
0
 public void DeleteContact_ContactDoesntExist_ReturnsSuccessfully(
     IElasticAnalyticsContactService contactService,
     ILeaseService leaseService,
     ElasticContact contact,
     ElasticLeaseOwner us,
     ElasticLeaseOwner them,
     ISystemContext ctx,
     TestIndexUtils contactIndex) 
 {
     using (contactIndex)
     {
         AssertionExtensions.ShouldNotThrow(() => 
             contactService.Delete(contact.Id, ctx));
     }
 }
コード例 #17
0
 public void ObsoleteContact_ContactDoesntExist_NothingHappens(
     IElasticAnalyticsContactService contactService,
     ElasticContact contact,
     Guid successor,
     ElasticLeaseOwner owner,
     ISystemContext ctx,
     TestIndexUtils contactIndex)
 {
     using (contactIndex)
     {
         AssertionExtensions.ShouldNotThrow(() => contactService.Obsolete(contact.Id, successor, owner, ctx));
     }
 }
コード例 #18
0
        public void SaveContact_ContactDoesntExistShouldNotBeReleased_ContactCreatedWithLock(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner us,
            ElasticLeaseOwner them,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact, them, false, ctx)
                    .Should().Be(true);

                var res = contactService.TryLoadAndLock(contact.Id, us, TimeSpan.FromMinutes(1), ctx);

                res.Status.Should().Be(LockAttemptStatus.AlreadyLocked);
                res.LockedObject.ShouldBeEquivalentToContact(contact);

                contactService.LoadForReadOnly(contact.Identification.Identity, ctx)
                    .ShouldBeEquivalentToContact(contact, l => l == null);
            }
        }
コード例 #19
0
        public void SaveContact_ContactDoesntExistShouldBeReleased_ContactCreatedLockFree(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner them,
            ElasticLeaseOwner us,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact, them, true, ctx)
                    .Should().Be(true);

                var res = contactService.TryLoadAndLock(contact.Id, us, TimeSpan.FromMinutes(1), ctx);

                res.Status.Should().Be(LockAttemptStatus.Success);
                res.LockedObject.ShouldBeEquivalentToContact(contact, l => l.Expires > DateTime.UtcNow && l.IsOwnedBy(us) && l.Version == 3);

                contactService.LoadForReadOnly(contact.Identification.Identity, ctx)
                    .ShouldBeEquivalentToContact(contact);
            }
        }
コード例 #20
0
        public void LoadForReadOnlyByIdentity_ContactObsolete_NullReturned(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticContact successor,
            ElasticLeaseOwner owner,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact, owner, true, ctx)
                    .Should().Be(true);

                contactService.Obsolete(contact.Id, successor.Id, owner, ctx);
                contactService.Save(successor, owner, true, ctx);

                contactService.LoadForReadOnly(contact.Identification.Identity, ctx)
                    .Should().BeNull();
            }
        }
コード例 #21
0
        public void LoadForReadOnlyByIdentity_ContactExistsLockedByDifferentOwner_ContactReturned(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner them,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact, them, false, ctx)
                    .Should().Be(true);

                contact.Lease = null;
                contactService.LoadForReadOnly(contact.Identification.Identity, ctx)
                    .ShouldBeEquivalentToContact(contact);
            }
        }
コード例 #22
0
        public void LoadForReadOnlyById_ContactObsolete_SuccessorReturned(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticContact successor,
            ElasticLeaseOwner owner,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact, owner, true, ctx)
                    .Should().Be(true);

                contactService.Obsolete(contact.Id, successor.Id, owner, ctx);
                contactService.Save(successor, owner, true, ctx);

                contactService.LoadForReadOnly(contact.Id, ctx)
                    .ShouldBeEquivalentToContact(successor, l => l == null);
            }
        }
コード例 #23
0
        public void ObsoleteContact_ContactExistsWithSuccessorNotLocked_ContactObsoleted(
            IElasticAnalyticsContactService contactService,
            IRepository<ElasticContact> contactRepo,
            ElasticContact contact,
            Guid successor,
            ElasticLeaseOwner us,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            // andes doesn't care if a contact has successors or not apart from when loading a contact.
            using (contactIndex)
            {
                contact.Successor = Guid.NewGuid();
                contactService.Save(contact, us, true, ctx).Should().BeTrue();

                contactService.Obsolete(contact.Id, successor, us, ctx).Should().BeTrue(); 
                var obsoletedContact = contactRepo.Get(contact.Id, ctx);

                obsoletedContact.Id.Should().Be(contact.Id);
                obsoletedContact.Successor.Should().Be(successor);
                obsoletedContact.Should().BeObsolete();
            }
        }
コード例 #24
0
        public void SaveContact_ContactExistsWithIdentityNotLocked_ContactUpdated(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner us,
            ElasticLeaseOwner them,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contact.Identification.IdentityLevel.Should().Be(IdentificationLevel.Known);

                contactService.Save(contact, them, true, ctx)
                    .Should().Be(true);

                //contact.SystemInfo.VisitCount = 999; // make a change

                contactService.Save(contact, us, false, ctx)
                    .Should().Be(true);

                // Assert
                var res = contactService.TryLoadAndLock(contact.Id, us, TimeSpan.FromMinutes(1), ctx);
                res.Status.Should().Be(LockAttemptStatus.Success);
                res.LockedObject.ShouldBeEquivalentToContact(contact, l => l.Expires > DateTime.UtcNow && l.IsOwnedBy(us) && l.Version == 4);

                contactService.LoadForReadOnly(contact.Identification.Identity, ctx)
                    .ShouldBeEquivalentToContact(contact, l => l == null);
            }
        }
コード例 #25
0
        public void ObsoleteContact_ContactExistsAndLockedBySameOwner_ContactObsoleted(
            IElasticAnalyticsContactService contactService,
            IRepository<ElasticContact> contactRepo,
            ElasticContact contact,
            Guid successor,
            ElasticLeaseOwner us,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact, us, false, ctx).Should().BeTrue();

                contactService.Obsolete(contact.Id, successor, us, ctx).Should().BeTrue();

                var obsoletedContact = contactRepo.Get(contact.Id, ctx);

                obsoletedContact.Id.Should().Be(contact.Id);
                obsoletedContact.Successor.Should().Be(successor);
                obsoletedContact.Should().BeObsolete();
            }
        }
コード例 #26
0
        public void SaveContact_ContactExistsWithIdentityAndIdentityInUse_ThrowsException(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact1,
            ElasticContact contact2,
            ElasticLeaseOwner owner,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact1, owner, true, ctx).Should().Be(true);

                // set the identity to be the same
                contact2.Identification.SetIdentity(
                    contact1.Identification.Identity,
                    contact1.Identification.IdentityLevel);

                AssertionExtensions.ShouldThrow<InvalidOperationException>(
                    () => contactService.Save(contact2, owner, true, ctx));
            }
        }
コード例 #27
0
        public void ObsoleteContact_ContactExistsAndExpiredLockedByDifferentOwner_ContactObsoleted(
            IElasticAnalyticsContactService contactService,
            IRepository<ElasticContact> contactRepo,
            ElasticContact contact,
            Guid successor,
            ElasticLeaseOwner us,
            ElasticLeaseOwner them,
            ISystemContext ctx,
            IDateTimeController dateTime,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                // arrange contact with expired lease from another owner...
                var timeTraveller = (DateTimeTimeTraveller)dateTime;

                using (timeTraveller.NewJourney(-24))
                {
                    contactService.Save(contact, them, false, ctx).Should().BeTrue();
                }

                contactService.Obsolete(contact.Id, successor, us, ctx).Should().BeTrue();

                var obsoletedContact = contactRepo.Get(contact.Id, ctx);

                obsoletedContact.Id.Should().Be(contact.Id);
                obsoletedContact.Successor.Should().Be(successor);
                obsoletedContact.Should().BeObsolete();
            }
        }
コード例 #28
0
 public void SaveContact_ContactExistsWithIdentityAndContactSaveFailed_ExistingIdentityRestored(
     IElasticAnalyticsContactService contactService,
     ElasticContact contact,
     ElasticLeaseOwner owner,
     ISystemContext ctx,
     TestIndexUtils contactIndex)
 {
     // ? how would a save contact fail, but first an identity save succeeds? (i.e. ES isn't down)
 }
コード例 #29
0
        public void ReleaseContact_NoLockExistsForContact_ContactReleased(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner us,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                // contact exists, no lock
                contactService.Save(contact, us, true, ctx).Should().BeTrue();

                // release
                contactService.Release(contact.Id, us, ctx);

                // should be able to lock it again
                contactService.TryLoadAndLock(contact.Id, us, TimeSpan.FromHours(1), ctx)
                    .Status.Should()
                    .Be(LockAttemptStatus.Success);
            }
        }
コード例 #30
0
        public void TryExtendLock_ContactExistsLockedBySameOwner_LeaseExtended(
            IElasticAnalyticsContactService contactService,
            ElasticContact contact,
            ElasticLeaseOwner us,
            ISystemContext ctx,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                contactService.Save(contact, us, false, ctx)
                    .Should().Be(true);

                var res = contactService.TryExtendLock(contact, TimeSpan.FromHours(1), ctx);

                res.Should().BeTrue();
                contact.Lease.IsOwnedBy(us);
            }
        }