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(); } }
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(); } }
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)); } }
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(); } }
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(); } }
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(); } }
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); } }
public void TryLoadAndLockByIdentity_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); var res = contactService.TryLoadAndLock(contact.Identification.Identity, owner, TimeSpan.FromMinutes(1), ctx); res.Status.Should().Be(LockAttemptStatus.NotFound); res.LockedObject.Should().BeNull(); } }
public void TryLoadAndLockById_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); var res = contactService.TryLoadAndLock(contact.Id, owner, TimeSpan.FromMinutes(1), ctx); res.Status.Should().Be(LockAttemptStatus.Success); res.LockedObject.ShouldBeEquivalentToContact(successor, l => l.Expires > DateTime.UtcNow && l.IsOwnedBy(owner) && l.Version == 3); } }