public async Task NotificationIsReceivedWhenConflictIsDetected() { var sourceContent = new RandomlyModifiedStream(new RandomStream(1), 0.01); var destinationContent = new RandomlyModifiedStream(sourceContent, 0.01); var sourceMetadata = new RavenJObject { { "SomeTest-metadata", "some-value" } }; var destinationMetadata = new RavenJObject { { "SomeTest-metadata", "should-be-overwritten" } }; await destinationClient.UploadAsync("abc.txt", destinationContent, destinationMetadata); await sourceClient.UploadAsync("abc.txt", sourceContent, sourceMetadata); var notificationTask = destinationStore.Changes() .ForConflicts() .OfType <ConflictNotification>() .Where(x => x.Status == ConflictStatus.Detected) .Timeout(TimeSpan.FromSeconds(5)) .Take(1) .ToTask(); await sourceClient.Synchronization.StartAsync("abc.txt", destinationClient); var conflictDetected = await notificationTask; Assert.Equal("abc.txt", conflictDetected.FileName); Assert.Equal(new Uri(sourceStore.Url).Port, new Uri(conflictDetected.SourceServerUrl).Port); }
private Task <ConflictNotification> WaitForConflictDetected(IFilesStore store, int notificationsNumber, int time) { return(store.Changes() .ForConflicts() .OfType <ConflictNotification>() .Where(x => x.Status == ConflictStatus.Detected) .Timeout(TimeSpan.FromSeconds(time)) .Take(notificationsNumber) .ToTask()); }
private async Task <Task <ConflictNotification> > WaitForConflictResolved(IFilesStore store, int notificationsNumber, int time) { var changes = store.Changes(); await changes.Task; var conflicts = changes.ForConflicts(); await conflicts.Task; return(conflicts .OfType <ConflictNotification>() .Where(x => x.Status == ConflictStatus.Resolved) .Timeout(TimeSpan.FromSeconds(time)) .Take(notificationsNumber) .ToTask()); }
public async Task NotificationReceivedWhenFileAdded() { var notificationTask = store.Changes().ForFolder("/") .Timeout(TimeSpan.FromSeconds(2)) .Take(1).ToTask(); await client.UploadAsync("abc.txt", new MemoryStream()); var fileChange = await notificationTask; Assert.Equal("/abc.txt", fileChange.File); Assert.Equal(FileChangeAction.Add, fileChange.Action); }
public async Task NotificationsAreReceivedOnSourceWhenSynchronizationsAreStartedAndFinished() { // content update await sourceClient.UploadAsync("test.bin", new MemoryStream(new byte[] { 1, 2, 3 })); var notificationTask = sourceStore.Changes().ForSynchronization() .Where(s => s.Direction == SynchronizationDirection.Outgoing) .Timeout(TimeSpan.FromSeconds(20)).Take(2).ToArray(). ToTask(); var report = await sourceClient.Synchronization.StartAsync("test.bin", destinationClient); Assert.Null(report.Exception); var synchronizationUpdates = await notificationTask; Assert.Equal(SynchronizationAction.Start, synchronizationUpdates[0].Action); Assert.Equal(FileHeader.Canonize("test.bin"), synchronizationUpdates[0].FileName); Assert.Equal(SynchronizationType.ContentUpdate, synchronizationUpdates[0].Type); Assert.Equal(SynchronizationAction.Finish, synchronizationUpdates[1].Action); Assert.Equal(FileHeader.Canonize("test.bin"), synchronizationUpdates[1].FileName); Assert.Equal(SynchronizationType.ContentUpdate, synchronizationUpdates[1].Type); // metadata update await sourceClient.UpdateMetadataAsync("test.bin", new RavenJObject { { "key", "value" } }); notificationTask = sourceStore.Changes().ForSynchronization() .Where(s => s.Direction == SynchronizationDirection.Outgoing) .Timeout(TimeSpan.FromSeconds(20)) .Take(2).ToArray() .ToTask(); report = await sourceClient.Synchronization.StartAsync("test.bin", destinationClient); Assert.Null(report.Exception); synchronizationUpdates = await notificationTask; Assert.Equal(SynchronizationAction.Start, synchronizationUpdates[0].Action); Assert.Equal(FileHeader.Canonize("test.bin"), synchronizationUpdates[0].FileName); Assert.Equal(SynchronizationType.MetadataUpdate, synchronizationUpdates[0].Type); Assert.Equal(SynchronizationAction.Finish, synchronizationUpdates[1].Action); Assert.Equal(FileHeader.Canonize("test.bin"), synchronizationUpdates[1].FileName); Assert.Equal(SynchronizationType.MetadataUpdate, synchronizationUpdates[1].Type); // rename update await sourceClient.RenameAsync("test.bin", "rename.bin"); notificationTask = sourceStore.Changes().ForSynchronization() .Where(s => s.Direction == SynchronizationDirection.Outgoing) .Timeout(TimeSpan.FromSeconds(20)) .Take(2).ToArray() .ToTask(); report = await sourceClient.Synchronization.StartAsync("test.bin", destinationClient); Assert.Null(report.Exception); synchronizationUpdates = await notificationTask; Assert.Equal(SynchronizationAction.Start, synchronizationUpdates[0].Action); Assert.Equal(FileHeader.Canonize("test.bin"), synchronizationUpdates[0].FileName); Assert.Equal(SynchronizationType.Rename, synchronizationUpdates[0].Type); Assert.Equal(SynchronizationAction.Finish, synchronizationUpdates[1].Action); Assert.Equal(FileHeader.Canonize("test.bin"), synchronizationUpdates[1].FileName); Assert.Equal(SynchronizationType.Rename, synchronizationUpdates[1].Type); // delete update await sourceClient.DeleteAsync("rename.bin"); notificationTask = sourceStore.Changes().ForSynchronization() .Where(s => s.Direction == SynchronizationDirection.Outgoing) .Timeout(TimeSpan.FromSeconds(20)) .Take(2).ToArray() .ToTask(); report = await sourceClient.Synchronization.StartAsync("rename.bin", destinationClient); Assert.Null(report.Exception); synchronizationUpdates = await notificationTask; Assert.Equal(SynchronizationAction.Start, synchronizationUpdates[0].Action); Assert.Equal(FileHeader.Canonize("rename.bin"), synchronizationUpdates[0].FileName); Assert.Equal(SynchronizationType.Delete, synchronizationUpdates[0].Type); Assert.Equal(SynchronizationAction.Finish, synchronizationUpdates[1].Action); Assert.Equal(FileHeader.Canonize("rename.bin"), synchronizationUpdates[1].FileName); Assert.Equal(SynchronizationType.Delete, synchronizationUpdates[1].Type); }
private Task<ConflictNotification> WaitForConflictDetected(IFilesStore store, int notificationsNumber, int time) { return store.Changes() .ForConflicts() .OfType<ConflictNotification>() .Where(x => x.Status == ConflictStatus.Detected) .Timeout(TimeSpan.FromSeconds(time)) .Take(notificationsNumber) .ToTask(); }
private async Task<Task<ConflictNotification>> WaitForConflictResolved(IFilesStore store, int notificationsNumber, int time) { var changes = store.Changes(); await changes.Task; var conflicts = changes.ForConflicts(); await conflicts.Task; return conflicts .OfType<ConflictNotification>() .Where(x => x.Status == ConflictStatus.Resolved) .Timeout(TimeSpan.FromSeconds(time)) .Take(notificationsNumber) .ToTask(); }
public async Task Foo() { IFilesStore store = null; { #region for_folder_2 IDisposable subscription = store .Changes() .ForFolder("/documents/books") .Subscribe(change => { switch (change.Action) { case FileChangeAction.Add: // do something break; case FileChangeAction.Delete: // do something break; } }); #endregion } { #region for_synchronization_2 IDisposable subscription = store .Changes() .ForSynchronization() .Subscribe(notification => { if (notification.Direction == SynchronizationDirection.Outgoing) { return; } switch (notification.Action) { case SynchronizationAction.Start: // do something break; case SynchronizationAction.Finish: // do something break; } }); #endregion } { #region for_conflicts_2 IDisposable subscription = store .Changes() .ForConflicts() .Subscribe(conflict => { switch (conflict.Status) { case ConflictStatus.Detected: Console.WriteLine("New conflict! File name: {0}", conflict.FileName); break; case ConflictStatus.Resolved: Console.WriteLine("Conflict resolved! File name: {0}", conflict.FileName); break; } }); #endregion } { #region for_configuration_2 IDisposable subscription = store .Changes() .ForConfiguration() .Subscribe(change => { switch (change.Action) { case ConfigurationChangeAction.Set: // do something break; case ConfigurationChangeAction.Delete: // do something break; } }); #endregion } }