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)); } }
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 ReleaseContact_CurrentLockByDifferentOwner_ReturnsFalse( IElasticAnalyticsContactService contactService, IRepository<ElasticContact> contactRepo, ElasticContact contact, ElasticLeaseOwner us, ElasticLeaseOwner them, ISystemContext ctx, IDateTimeController dateTime, TestIndexUtils contactIndex) { using (contactIndex) { // contact exists and locked contactService.Save(contact, them, false, ctx).Should().BeTrue(); // release contactService.Release(contact.Id, us, ctx).Should().BeFalse(); // shouldn't be able to lock it again -- ?? contactService.TryLoadAndLock(contact.Id, us, TimeSpan.FromHours(1), ctx) .Status.Should() .Be(LockAttemptStatus.AlreadyLocked); } }
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); } }
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 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(); } }
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(); } }
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); } }
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 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); } }
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 TryLoadAndLockByIdentity_ContactExistsAlreadyLockedByDifferentOwner_NotLoaded( IElasticAnalyticsContactService contactService, ElasticLeaseOwner us, ElasticLeaseOwner them, ElasticContact eContact, ISystemContext ctx, TestIndexUtils contactIndex) { using (contactIndex) { contactService.Save(eContact, them, false, ctx).Should().BeTrue(); var res = contactService.TryLoadAndLock(eContact.Identification.Identity, us, TimeSpan.FromMinutes(1), ctx); res.LockedObject.Id.Should().Be(eContact.Id); res.Status.Should().Be(LockAttemptStatus.AlreadyLocked); } }
public void TryLoadAndLockByIdentity_ContactExistsAlreadyLockedBySameOwner_ReturnsContact( IElasticAnalyticsContactService contactService, ElasticLeaseOwner us, ElasticContact eContact, ISystemContext ctx, TestIndexUtils contactIndex) { using (contactIndex) { contactService.Save(eContact, us, false, ctx).Should().BeTrue(); var res = contactService.TryLoadAndLock(eContact.Identification.Identity, us, TimeSpan.FromMinutes(1), ctx); eContact.Lease.IncrementVersion(); res.LockedObject.ShouldBeEquivalentToContact(eContact); res.Status.Should().Be(LockAttemptStatus.Success); } }
public void TryLoadAndLockByIdentity_ContactExistsWithSuccessor_ContactReturned( TestIndexUtils contactIndex, IElasticAnalyticsContactService contactService, ElasticContact firstContact, ElasticContact secondContact, ElasticLeaseOwner us, ISystemContext ctx) { using (contactIndex) { firstContact.Successor = secondContact.Id; contactService.Save(firstContact, us, true, ctx); contactService.Save(secondContact, us, true, ctx); var res = contactService.TryLoadAndLock(firstContact.Identification.Identity, us, TimeSpan.FromMinutes(1), ctx); res.Status.Should().Be(LockAttemptStatus.Success); res.LockedObject.ShouldBeEquivalentToContact(secondContact, l => l.Expires > DateTime.UtcNow && l.IsOwnedBy(us) && l.Version == 3); } }
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); } }
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); } }
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 } }
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 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(); } }
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); } }
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(); } }
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); } }
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 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); } }
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 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); } }
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); } }
public void ReleaseContact_ExpiredLockExistsForDifferentOwner_NothingHappens( IElasticAnalyticsContactService contactService, ElasticContact contact, ElasticLeaseOwner us, ElasticLeaseOwner them, ISystemContext ctx, IDateTimeController dateTime, TestIndexUtils contactIndex) { using (contactIndex) { // contact exists, lock expired var timeTraveller = (DateTimeTimeTraveller)dateTime; using (timeTraveller.NewJourney(-24)) { contactService.Save(contact, them, false, 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); } }