private void DocumentConflictResolveTest(StraightforwardConflictResolution docConflictResolution) { using (var master = GetDocumentStore()) using (var slave = GetDocumentStore()) { SetupReplication(master, destinations: slave); using (var session = slave.OpenSession()) { session.Store(new ReplicationConfig() { DocumentConflictResolution = docConflictResolution }, Constants.RavenReplicationConfig); session.Store(new User() { Name = "local" }, "users/1"); session.SaveChanges(); } using (var session = master.OpenSession()) { session.Store(new User() { Name = "remote" }, "users/1"); session.Store(new { Foo = "marker" }, "marker"); session.SaveChanges(); } var marker = WaitForDocument(slave, "marker"); Assert.NotNull(marker); using (var session = slave.OpenSession()) { User item = null; Assert.DoesNotThrow(() => { item = session.Load<User>("users/1"); }); Assert.Equal(docConflictResolution == StraightforwardConflictResolution.ResolveToLocal ? "local" : "remote", item.Name); } } }
private void DocumentConflictResolveTest(StraightforwardConflictResolution docConflictResolution) { var master = CreateStore(); var slave = CreateStore(); SetupReplication(master.DatabaseCommands, slave); using (var session = slave.OpenSession()) { session.Store(new ReplicationConfig() { DocumentConflictResolution = docConflictResolution }, Constants.RavenReplicationConfig); session.Store(new Item() { Name = "local" }, "items/1"); session.SaveChanges(); } using (var session = master.OpenSession()) { session.Store(new Item() { Name = "remote" }, "items/1"); session.Store(new { Foo = "marker" }, "marker"); session.SaveChanges(); } WaitForReplication(slave, "marker"); using (var session = slave.OpenSession()) { Item item = null; Assert.DoesNotThrow(() => { item = session.Load<Item>("items/1"); }); Assert.Equal(docConflictResolution == StraightforwardConflictResolution.ResolveToLocal ? "local" : "remote", item.Name); } }
private void AttachmentConflictResolveTest(StraightforwardConflictResolution attachmentConflictResolution) { using (var master = GetDocumentStore()) using (var slave = GetDocumentStore()) { SetupReplication(master, destinations: slave); using (var session = slave.OpenSession()) { session.Store(new ReplicationConfig() { AttachmentConflictResolution = attachmentConflictResolution }, Constants.RavenReplicationConfig); session.SaveChanges(); } var local = new byte[] {1, 2, 3, 4}; var remote = new byte[] {3, 2, 1}; slave.DatabaseCommands.PutAttachment("attach/1", null, new MemoryStream(local), new RavenJObject()); master.DatabaseCommands.PutAttachment("attach/1", null, new MemoryStream(remote), new RavenJObject()); master.DatabaseCommands.PutAttachment("marker", null, new MemoryStream(), new RavenJObject()); WaitForAttachment(slave, "marker"); Attachment attachment = null; Assert.DoesNotThrow(() => { attachment = slave.DatabaseCommands.GetAttachment("attach/1"); }); switch (attachmentConflictResolution) { case StraightforwardConflictResolution.ResolveToLocal: Assert.Equal(local, attachment.Data().ReadData()); break; case StraightforwardConflictResolution.ResolveToRemote: Assert.Equal(remote, attachment.Data().ReadData()); break; default: throw new ArgumentOutOfRangeException("attachmentConflictResolution"); } } }
private void DocumentConflictResolveTest(StraightforwardConflictResolution docConflictResolution) { using (var master = GetDocumentStore()) using (var slave = GetDocumentStore()) { SetupReplication(master, destinations: slave); using (var session = slave.OpenSession()) { session.Store(new ReplicationConfig() { DocumentConflictResolution = docConflictResolution }, Constants.RavenReplicationConfig); session.Store(new User() { Name = "local" }, "users/1"); session.SaveChanges(); } using (var session = master.OpenSession()) { session.Store(new User() { Name = "remote" }, "users/1"); session.Store(new { Foo = "marker" }, "marker"); session.SaveChanges(); } var marker = WaitForDocument(slave, "marker"); Assert.NotNull(marker); using (var session = slave.OpenSession()) { User item = null; Assert.DoesNotThrow(() => { item = session.Load <User>("users/1"); }); switch (docConflictResolution) { case StraightforwardConflictResolution.ResolveToLocal: Assert.Equal("local", item.Name); break; case StraightforwardConflictResolution.ResolveToRemote: Assert.Equal("remote", item.Name); break; default: throw new ArgumentOutOfRangeException("docConflictResolution"); } } } }
protected static async Task SetReplicationConflictResolutionAsync(DocumentStore store, StraightforwardConflictResolution conflictResolution) { await UpdateConflictResolver(store, null, conflictResolution == StraightforwardConflictResolution.ResolveToLatest); }
private void DocumentConflictResolveTest(StraightforwardConflictResolution docConflictResolution) { using (var master = GetDocumentStore()) using (var slave = GetDocumentStore()) { SetupReplication(master, destinations: slave); using (var session = slave.OpenSession()) { session.Store(new ReplicationConfig() { DocumentConflictResolution = docConflictResolution }, Constants.RavenReplicationConfig); session.Store(new User() { Name = "local" }, "users/1"); session.SaveChanges(); } using (var session = master.OpenSession()) { session.Store(new User() { Name = "remote" }, "users/1"); session.Store(new { Foo = "marker" }, "marker"); session.SaveChanges(); } var marker = WaitForDocument(slave, "marker"); Assert.NotNull(marker); using (var session = slave.OpenSession()) { User item = session.Load<User>("users/1"); switch (docConflictResolution) { case StraightforwardConflictResolution.ResolveToLocal: Assert.Equal("local", item.Name); break; case StraightforwardConflictResolution.ResolveToRemote: Assert.Equal("remote", item.Name); break; default: throw new ArgumentOutOfRangeException("docConflictResolution"); } } } }
private void ResolveConflictsCore(StraightforwardConflictResolution resolution, Func <IDocumentStore, string, bool> assertFunc, bool deleteLocal = false, bool deleteRemote = false) { using (var remote = CreateStore(useFiddler: true)) using (var local = CreateStore(useFiddler: true)) { TellFirstInstanceToReplicateToSecondInstance(); string id; using (var session = local.OpenSession()) { var company = new Company { Name = "Local" }; session.Store(company); session.SaveChanges(); id = session.Advanced.GetDocumentId(company); } if (deleteLocal) { using (var session = local.OpenSession()) { session.Delete(id); session.SaveChanges(); } } string remoteId; using (var session = remote.OpenSession()) { var company = new Company { Name = "Remote" }; session.Store(company); session.SaveChanges(); remoteId = session.Advanced.GetDocumentId(company); } if (deleteRemote) { using (var session = remote.OpenSession()) { session.Delete(remoteId); session.SaveChanges(); } } Assert.True(WaitForConflictDocumentsToAppear(local, id, local.DefaultDatabase), "Waited too long for conflict to be created, giving up."); using (var session = local.OpenSession()) { session.Store(new ReplicationConfig() { DocumentConflictResolution = resolution }, Constants.RavenReplicationConfig); session.SaveChanges(); } //Making sure the conflict index is up and running using (var session = local.OpenSession()) { var res = session.Query <dynamic>(Constants.ConflictDocumentsIndex).Count(); } var requestFactory = new HttpJsonRequestFactory(10); var request = requestFactory.CreateHttpJsonRequest( new CreateHttpJsonRequestParams(null, local.Url.ForDatabase(local.DefaultDatabase) + "/replication/forceConflictResolution" , HttpMethod.Get, local.DatabaseCommands.PrimaryCredentials, local.Conventions)); //Sometimes the conflict index doesn't index fast enough and we would fail if not waiting for indexes WaitForIndexing(local); request.ExecuteRequest(); var disapear = WaitForConflictDocumentsToDisappear(local, id, local.DefaultDatabase); Assert.True(disapear, $"Waited 15 seconds for conflict to be resolved but there is still a conflict for {id}"); Assert.True(assertFunc(local, id), "Conflict was resolved but the expected value is wrong"); } }
private static void ResolveAllConflictsAndWaitForOperationToComplete(DocumentStore store, StraightforwardConflictResolution resolution) { var request = store.JsonRequestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(null, store.Url.ForDatabase(store.DefaultDatabase) + "/studio-tasks/replication/conflicts/resolve?resolution=" + resolution, HttpMethod.Post, store.DatabaseCommands.PrimaryCredentials, store.Conventions)); var response = request.ReadResponseJson(); var operationId = response.Value <long>("OperationId"); var client = (AsyncServerClient)store.AsyncDatabaseCommands; var operation = new Operation(client, operationId); operation.WaitForCompletion(); WaitForIndexing(store); }