protected static async Task <ModifyOngoingTaskResult> AddWatcherToReplicationTopology <T>( IDocumentStore store, T watcher, string[] urls = null) where T : ExternalReplicationBase { var result = await store.Maintenance.SendAsync(new PutConnectionStringOperation <RavenConnectionString>(new RavenConnectionString { Name = watcher.ConnectionStringName, Database = watcher.Database, TopologyDiscoveryUrls = urls ?? store.Urls })); Assert.NotNull(result.RaftCommandIndex); IMaintenanceOperation <ModifyOngoingTaskResult> op; if (watcher is PullReplicationAsSink pull) { op = new UpdatePullReplicationAsSinkOperation(pull); } else if (watcher is ExternalReplication ex) { op = new UpdateExternalReplicationOperation(ex); } else { throw new ArgumentException($"Unrecognized type: {watcher.GetType().FullName}"); } return(await store.Maintenance.SendAsync(op)); }
private static async Task <ModifyOngoingTaskResult> SetupReplication(IDocumentStore store, ExternalReplicationBase watcher) { var result = await store.Maintenance.SendAsync(new PutConnectionStringOperation <RavenConnectionString>(new RavenConnectionString { Name = watcher.ConnectionStringName, Database = watcher.Database, TopologyDiscoveryUrls = new[] { watcher.Url } })); Assert.NotNull(result.RaftCommandIndex); IMaintenanceOperation <ModifyOngoingTaskResult> op; switch (watcher) { case PullReplicationAsSink pull: op = new UpdatePullReplicationAsSinkOperation(pull); break; case ExternalReplication ex: op = new UpdateExternalReplicationOperation(ex); break; default: throw new ArgumentException($"Unrecognized type: {watcher.GetType().FullName}"); } return(await store.Maintenance.SendAsync(op)); }
protected static async Task <ModifyOngoingTaskResult> AddWatcherToReplicationTopology( DocumentStore store, ExternalReplication watcher) { var op = new UpdateExternalReplicationOperation(store.Database, watcher); return(await store.Admin.Server.SendAsync(op)); }
protected static async Task <ModifyOngoingTaskResult> AddWatcherToReplicationTopology( DocumentStore store, ExternalReplication watcher, string[] urls = null) { await store.Maintenance.SendAsync(new PutConnectionStringOperation <RavenConnectionString>(new RavenConnectionString { Name = watcher.ConnectionStringName, Database = watcher.Database, TopologyDiscoveryUrls = urls ?? store.Urls })); var op = new UpdateExternalReplicationOperation(watcher); return(await store.Maintenance.SendAsync(op)); }
public async Task EditExternalReplication() { using (var store1 = GetDocumentStore()) using (var store2 = GetDocumentStore()) { var delay = TimeSpan.FromSeconds(5); var externalTask = new ExternalReplication(store2.Database, "DelayedExternalReplication") { DelayReplicationFor = delay }; await AddWatcherToReplicationTopology(store1, externalTask); DateTime date; using (var s1 = store1.OpenSession()) { s1.Store(new User(), "foo/bar"); date = DateTime.UtcNow; s1.SaveChanges(); } Assert.True(WaitForDocument(store2, "foo/bar")); var elapsed = DateTime.UtcNow - date; Assert.True(elapsed >= delay, $" only {elapsed}/{delay} ticks elapsed"); delay = TimeSpan.Zero; externalTask.DelayReplicationFor = delay; var op = new UpdateExternalReplicationOperation(externalTask); await store1.Maintenance.SendAsync(op); using (var s1 = store1.OpenSession()) { s1.Store(new User(), "foo/bar"); date = DateTime.UtcNow; s1.SaveChanges(); } Assert.True(WaitForDocument(store2, "foo/bar")); var elapsedTime = DateTime.UtcNow - date; Assert.True(elapsedTime >= delay && elapsedTime < elapsed, $" only {elapsed}/{delay} ticks elapsed"); } }
private static async Task <ModifyOngoingTaskResult> SetupReplication(IDocumentStore src, IDocumentStore dst) { var csName = $"cs-to-{dst.Database}"; var result = await src.Maintenance.SendAsync(new PutConnectionStringOperation <RavenConnectionString>(new RavenConnectionString { Name = csName, Database = dst.Database, TopologyDiscoveryUrls = new[] { dst.Urls.First() } })); Assert.NotNull(result.RaftCommandIndex); var op = new UpdateExternalReplicationOperation(new ExternalReplication(dst.Database.ToLowerInvariant(), csName) { Name = $"ExternalReplicationTo{dst.Database}", Url = dst.Urls.First() }); return(await src.Maintenance.SendAsync(op)); }
public void GetExternalReplicationTaskInfo() { var watcher = new ExternalReplication("Watcher1", "Connection") { Name = "MyExternalReplication" }; using (var store = GetDocumentStore()) { var result = store.Maintenance.Send(new PutConnectionStringOperation <RavenConnectionString>(new RavenConnectionString { Name = watcher.ConnectionStringName, Database = watcher.Database, TopologyDiscoveryUrls = store.Urls })); Assert.NotNull(result.RaftCommandIndex); var replicationOperation = new UpdateExternalReplicationOperation(watcher); var replication = store.Maintenance.Send(replicationOperation); var taskId = replication.TaskId; var op = new GetOngoingTaskInfoOperation(taskId, OngoingTaskType.Replication); var replicationResult = (OngoingTaskReplication)store.Maintenance.Send(op); Assert.Equal(watcher.Database, replicationResult.DestinationDatabase); Assert.Equal(watcher.Url, replicationResult.DestinationUrl); Assert.Equal(watcher.Name, replicationResult.TaskName); op = new GetOngoingTaskInfoOperation("MyExternalReplication", OngoingTaskType.Replication); replicationResult = (OngoingTaskReplication)store.Maintenance.Send(op); Assert.Equal(watcher.Database, replicationResult.DestinationDatabase); Assert.Equal(watcher.Url, replicationResult.DestinationUrl); Assert.Equal(taskId, replicationResult.TaskId); } }