public async void MultipleConflictListeners_MultipleResolutionListeners() { var store = (FilesStore)filesStore; var conflictsListener = new TakeLocalConflictListener(); var noOpListener = new NoOpConflictListener(); anotherStore.Listeners.RegisterListener(conflictsListener); anotherStore.Listeners.RegisterListener(noOpListener); using (var sessionDestination1 = filesStore.OpenAsyncSession()) using (var sessionDestination2 = anotherStore.OpenAsyncSession()) { sessionDestination2.RegisterUpload("test1.file", CreateUniformFileStream(130)); await sessionDestination2.SaveChangesAsync(); sessionDestination1.RegisterUpload("test1.file", CreateUniformFileStream(128)); await sessionDestination1.SaveChangesAsync(); var syncDestinatios = new SynchronizationDestination[] { sessionDestination2.Commands.ToSynchronizationDestination() }; await sessionDestination1.Commands.Synchronization.SetDestinationsAsync(syncDestinatios); await sessionDestination1.Commands.Synchronization.SynchronizeAsync(); Thread.Sleep(250); Assert.Equal(1, conflictsListener.DetectedCount); Assert.Equal(1, conflictsListener.ResolvedCount); Assert.Equal(1, noOpListener.DetectedCount); Assert.Equal(1, noOpListener.ResolvedCount); } }
public async Task MultipleConflictListeners_ConflictNotResolved() { var store = this.NewStore(1); var anotherStore = this.NewStore(2); var takeLocalConflictListener = new TakeLocalConflictListener(); var noOpListener = new NoOpConflictListener(); anotherStore.Listeners.RegisterListener(noOpListener); anotherStore.Listeners.RegisterListener(takeLocalConflictListener); using (var sessionDestination1 = store.OpenAsyncSession()) using (var sessionDestination2 = anotherStore.OpenAsyncSession()) { sessionDestination2.RegisterUpload("test1.file", CreateUniformFileStream(130)); await sessionDestination2.SaveChangesAsync(); sessionDestination1.RegisterUpload("test1.file", CreateUniformFileStream(128)); await sessionDestination1.SaveChangesAsync(); var notificationTask = WaitForConflictDetected(anotherStore, 1, 10); var syncDestinatios = new SynchronizationDestination[] { sessionDestination2.Commands.ToSynchronizationDestination() }; await sessionDestination1.Commands.Synchronization.SetDestinationsAsync(syncDestinatios); await sessionDestination1.Commands.Synchronization.SynchronizeAsync(); await notificationTask; Assert.Equal(1, noOpListener.DetectedCount); Assert.Equal(1, takeLocalConflictListener.DetectedCount); Assert.Equal(0, takeLocalConflictListener.ResolvedCount + noOpListener.ResolvedCount); // try to change content of file in destination2 sessionDestination2.RegisterUpload("test1.file", CreateUniformFileStream(140)); // Assert an exception is thrown because the conflict is still there var aggregateException = Assert.Throws <AggregateException>(() => sessionDestination2.SaveChangesAsync().Wait()); Assert.IsType <NotSupportedException>(aggregateException.InnerException); // try to change content of file in destination2 sessionDestination2.RegisterRename("test1.file", "test2.file"); // Assert an exception is thrown because the conflict is still there aggregateException = Assert.Throws <AggregateException>(() => sessionDestination2.SaveChangesAsync().Wait()); Assert.IsType <NotSupportedException>(aggregateException.InnerException); } }
public async Task ConflictListeners_LocalVersion() { var store = this.NewStore(1); var anotherStore = this.NewStore(2); var conflictsListener = new TakeLocalConflictListener(); anotherStore.Listeners.RegisterListener(conflictsListener); using (var sessionDestination1 = store.OpenAsyncSession()) using (var sessionDestination2 = anotherStore.OpenAsyncSession()) { sessionDestination1.RegisterUpload("test1.file", CreateUniformFileStream(128)); await sessionDestination1.SaveChangesAsync(); sessionDestination2.RegisterUpload("test1.file", CreateUniformFileStream(130)); await sessionDestination2.SaveChangesAsync(); var notificationTask = await WaitForConflictResolved(anotherStore, 1, 10); var syncDestinations = new SynchronizationDestination[] { sessionDestination2.Commands.ToSynchronizationDestination() }; await sessionDestination1.Commands.Synchronization.SetDestinationsAsync(syncDestinations); await sessionDestination1.Commands.Synchronization.SynchronizeAsync(); await notificationTask; Assert.Equal(1, conflictsListener.DetectedCount); Assert.Equal(1, conflictsListener.ResolvedCount); var file = await sessionDestination1.LoadFileAsync("test1.file"); var file2 = await sessionDestination2.LoadFileAsync("test1.file"); Assert.Equal(128, file.TotalSize); Assert.Equal(130, file2.TotalSize); } }
public async Task MultipleConflictListeners_OnlyOneWithShortCircuitResolution() { var store = this.NewStore(1); var anotherStore = this.NewStore(2); var conflictsListener = new TakeLocalConflictListener(); var noOpListener = new NoOpConflictListener(); anotherStore.Listeners.RegisterListener(conflictsListener); anotherStore.Listeners.RegisterListener(noOpListener); using (var sessionDestination1 = store.OpenAsyncSession()) using (var sessionDestination2 = anotherStore.OpenAsyncSession()) { sessionDestination2.RegisterUpload("test1.file", CreateUniformFileStream(130)); await sessionDestination2.SaveChangesAsync(); sessionDestination1.RegisterUpload("test1.file", CreateUniformFileStream(128)); await sessionDestination1.SaveChangesAsync(); var notificationTask = await WaitForConflictResolved(anotherStore, 1, 5); var syncDestinatios = new SynchronizationDestination[] { sessionDestination2.Commands.ToSynchronizationDestination() }; await sessionDestination1.Commands.Synchronization.SetDestinationsAsync(syncDestinatios); await sessionDestination1.Commands.Synchronization.SynchronizeAsync(); await notificationTask; Assert.Equal(1, conflictsListener.DetectedCount); Assert.Equal(1, conflictsListener.ResolvedCount); Assert.Equal(0, noOpListener.DetectedCount); Assert.Equal(1, noOpListener.ResolvedCount); } }
public async Task MultipleConflictListeners_ConflictNotResolved() { var store = this.NewStore(1); var anotherStore = this.NewStore(2); var takeLocalConflictListener = new TakeLocalConflictListener(); var noOpListener = new NoOpConflictListener(); anotherStore.Listeners.RegisterListener(noOpListener); anotherStore.Listeners.RegisterListener(takeLocalConflictListener); using (var sessionDestination1 = store.OpenAsyncSession()) using (var sessionDestination2 = anotherStore.OpenAsyncSession()) { sessionDestination2.RegisterUpload("test1.file", CreateUniformFileStream(130)); await sessionDestination2.SaveChangesAsync(); sessionDestination1.RegisterUpload("test1.file", CreateUniformFileStream(128)); await sessionDestination1.SaveChangesAsync(); var notificationTask = WaitForConflictDetected(anotherStore, 1, 10); var syncDestinatios = new SynchronizationDestination[] { sessionDestination2.Commands.ToSynchronizationDestination() }; await sessionDestination1.Commands.Synchronization.SetDestinationsAsync(syncDestinatios); await sessionDestination1.Commands.Synchronization.StartAsync(); await notificationTask; Assert.Equal(1, noOpListener.DetectedCount); Assert.Equal(1, takeLocalConflictListener.DetectedCount); Assert.Equal(0, takeLocalConflictListener.ResolvedCount + noOpListener.ResolvedCount); // try to change content of file in destination2 sessionDestination2.RegisterUpload("test1.file", CreateUniformFileStream(140)); // Assert an exception is thrown because the conflict is still there var aggregateException = Assert.Throws<AggregateException>(() => sessionDestination2.SaveChangesAsync().Wait()); Assert.IsType<NotSupportedException>(aggregateException.InnerException); // try to change content of file in destination2 sessionDestination2.RegisterRename("test1.file", "test2.file"); // Assert an exception is thrown because the conflict is still there aggregateException = Assert.Throws<AggregateException>(() => sessionDestination2.SaveChangesAsync().Wait()); Assert.IsType<NotSupportedException>(aggregateException.InnerException); } }
public async Task MultipleConflictListeners_MultipleResolutionListeners() { var store = this.NewStore(1); var anotherStore = this.NewStore(2); var conflictsListener = new TakeLocalConflictListener(); var noOpListener = new NoOpConflictListener(); anotherStore.Listeners.RegisterListener(noOpListener); anotherStore.Listeners.RegisterListener(conflictsListener); using (var sessionDestination1 = store.OpenAsyncSession()) using (var sessionDestination2 = anotherStore.OpenAsyncSession()) { sessionDestination2.RegisterUpload("test1.file", CreateUniformFileStream(130)); await sessionDestination2.SaveChangesAsync(); sessionDestination1.RegisterUpload("test1.file", CreateUniformFileStream(128)); await sessionDestination1.SaveChangesAsync(); var notificationTask = await WaitForConflictResolved(anotherStore, 1, 5); var syncDestinatios = new SynchronizationDestination[] { sessionDestination2.Commands.ToSynchronizationDestination() }; await sessionDestination1.Commands.Synchronization.SetDestinationsAsync(syncDestinatios); await sessionDestination1.Commands.Synchronization.StartAsync(); await notificationTask; Assert.Equal(1, conflictsListener.DetectedCount); Assert.Equal(1, conflictsListener.ResolvedCount); Assert.Equal(1, noOpListener.DetectedCount); Assert.Equal(1, noOpListener.ResolvedCount); } }