public async Task ConflictListeners_RemoteVersion() { var filename = FileHeader.Canonize("test1.file"); int firstStreamSize = 130; int secondStreamSize = 128; var store = this.NewStore(1); var anotherStore = this.NewStore(2); var conflictsListener = new TakeNewestConflictsListener(); anotherStore.Listeners.RegisterListener(conflictsListener); using (var sessionDestination1 = store.OpenAsyncSession()) using (var sessionDestination2 = anotherStore.OpenAsyncSession()) { sessionDestination2.RegisterUpload(filename, CreateUniformFileStream(firstStreamSize)); await sessionDestination2.SaveChangesAsync(); await sessionDestination1.Commands.Synchronization.SynchronizeAsync(); sessionDestination1.RegisterUpload(filename, CreateUniformFileStream(secondStreamSize)); await sessionDestination1.SaveChangesAsync(); var file = await sessionDestination1.LoadFileAsync(filename); var file2 = await sessionDestination2.LoadFileAsync(filename); Assert.Equal(secondStreamSize, file.TotalSize); Assert.Equal(firstStreamSize, file2.TotalSize); 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(); //We need to sync again after conflict resolution because strategy was to resolve with remote await sessionDestination1.Commands.Synchronization.SynchronizeAsync(); await notificationTask; Assert.Equal(1, conflictsListener.DetectedCount); Assert.Equal(1, conflictsListener.ResolvedCount); file = await sessionDestination1.LoadFileAsync(filename); file2 = await sessionDestination2.LoadFileAsync(filename); Assert.Equal(secondStreamSize, file.TotalSize); Assert.Equal(secondStreamSize, file2.TotalSize); } }
public async Task ConflictListeners_RemoteVersion() { var filename = FileHeader.Canonize("test1.file"); int firstStreamSize = 130; int secondStreamSize = 128; var store = this.NewStore(1); var anotherStore = this.NewStore(2); var conflictsListener = new TakeNewestConflictsListener(); anotherStore.Listeners.RegisterListener(conflictsListener); using (var sessionDestination1 = store.OpenAsyncSession()) using (var sessionDestination2 = anotherStore.OpenAsyncSession()) { sessionDestination2.RegisterUpload(filename, CreateUniformFileStream(firstStreamSize)); await sessionDestination2.SaveChangesAsync(); sessionDestination1.RegisterUpload(filename, CreateUniformFileStream(secondStreamSize)); await sessionDestination1.SaveChangesAsync(); var notificationTask = await WaitForConflictResolved(anotherStore, 1, 30); var syncDestinations = new SynchronizationDestination[] { sessionDestination2.Commands.ToSynchronizationDestination() }; await sessionDestination1.Commands.Synchronization.SetDestinationsAsync(syncDestinations); var syncResult = await sessionDestination1.Commands.Synchronization.StartAsync(); Assert.Equal(string.Format("File {0} is conflicted", filename), syncResult[0].Reports.ToList()[0].Exception.Message); // conflict should be resolved by the registered listener Assert.True(SpinWait.SpinUntil(() => conflictsListener.DetectedCount == 1 && conflictsListener.ResolvedCount == 1, TimeSpan.FromMinutes(1)), string.Format("DetectedCount: {0}, ResolvedCount: {1}", conflictsListener.DetectedCount, conflictsListener.ResolvedCount)); // We need to sync again after conflict resolution because the strategy was to resolve with remote await sessionDestination1.Commands.Synchronization.StartAsync(); await notificationTask; Assert.Equal(1, conflictsListener.DetectedCount); Assert.Equal(1, conflictsListener.ResolvedCount); var file = await sessionDestination1.LoadFileAsync(filename); var file2 = await sessionDestination2.LoadFileAsync(filename); Assert.Equal(secondStreamSize, file.TotalSize); Assert.Equal(secondStreamSize, file2.TotalSize); } }
public async void ConflictListeners_RemoteVersion() { var store = (FilesStore)filesStore; var conflictsListener = new TakeNewestConflictsListener(); anotherStore.Listeners.RegisterListener(conflictsListener); 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 file = await sessionDestination1.LoadFileAsync("test1.file"); var file2 = await sessionDestination2.LoadFileAsync("test1.file"); Assert.Equal(128, file.TotalSize); Assert.Equal(130, file2.TotalSize); var syncDestinatios = new SynchronizationDestination[] { sessionDestination2.Commands.ToSynchronizationDestination() }; await sessionDestination1.Commands.Synchronization.SetDestinationsAsync(syncDestinatios); await sessionDestination1.Commands.Synchronization.SynchronizeAsync(); Assert.Equal(1, conflictsListener.DetectedCount); //We need to sync again after conflict resolution because strategy was to resolve with remote await sessionDestination1.Commands.Synchronization.SynchronizeAsync(); Assert.Equal(1, conflictsListener.ResolvedCount); file = await sessionDestination1.LoadFileAsync("test1.file"); file2 = await sessionDestination2.LoadFileAsync("test1.file"); Assert.Equal(128, file.TotalSize); Assert.Equal(128, file2.TotalSize); } }
public async Task ConflictListeners_RemoteVersion() { var filename = FileHeader.Canonize("test1.file"); int firstStreamSize = 130; int secondStreamSize = 128; var store = this.NewStore(1); var anotherStore = this.NewStore(2); var conflictsListener = new TakeNewestConflictsListener(); anotherStore.Listeners.RegisterListener(conflictsListener); using (var sessionDestination1 = store.OpenAsyncSession()) using (var sessionDestination2 = anotherStore.OpenAsyncSession()) { sessionDestination2.RegisterUpload(filename, CreateUniformFileStream(firstStreamSize)); await sessionDestination2.SaveChangesAsync(); await sessionDestination1.Commands.Synchronization.StartAsync(); sessionDestination1.RegisterUpload(filename, CreateUniformFileStream(secondStreamSize)); await sessionDestination1.SaveChangesAsync(); var file = await sessionDestination1.LoadFileAsync(filename); var file2 = await sessionDestination2.LoadFileAsync(filename); Assert.Equal(secondStreamSize, file.TotalSize); Assert.Equal(firstStreamSize, file2.TotalSize); var notificationTask = await WaitForConflictResolved(anotherStore, 1, 10); var syncDestinations = new SynchronizationDestination[] { sessionDestination2.Commands.ToSynchronizationDestination() }; await sessionDestination1.Commands.Synchronization.SetDestinationsAsync(syncDestinations); await sessionDestination1.Commands.Synchronization.StartAsync(); //We need to sync again after conflict resolution because strategy was to resolve with remote await sessionDestination1.Commands.Synchronization.StartAsync(); await notificationTask; Assert.Equal(1, conflictsListener.DetectedCount); Assert.Equal(1, conflictsListener.ResolvedCount); file = await sessionDestination1.LoadFileAsync(filename); file2 = await sessionDestination2.LoadFileAsync(filename); Assert.Equal(secondStreamSize, file.TotalSize); Assert.Equal(secondStreamSize, file2.TotalSize); } }
public async Task ConflictListeners_RemoteVersion() { var filename = FileHeader.Canonize("test1.file"); int firstStreamSize = 130; int secondStreamSize = 128; var store = this.NewStore(1); var anotherStore = this.NewStore(2); var conflictsListener = new TakeNewestConflictsListener(); anotherStore.Listeners.RegisterListener(conflictsListener); using (var sessionDestination1 = store.OpenAsyncSession()) using (var sessionDestination2 = anotherStore.OpenAsyncSession()) { sessionDestination2.RegisterUpload(filename, CreateUniformFileStream(firstStreamSize)); await sessionDestination2.SaveChangesAsync(); sessionDestination1.RegisterUpload(filename, CreateUniformFileStream(secondStreamSize)); await sessionDestination1.SaveChangesAsync(); var notificationTask = await WaitForConflictResolved(anotherStore, 1, 30); var syncDestinations = new SynchronizationDestination[] { sessionDestination2.Commands.ToSynchronizationDestination() }; await sessionDestination1.Commands.Synchronization.SetDestinationsAsync(syncDestinations); var syncResult = await sessionDestination1.Commands.Synchronization.StartAsync(); Assert.Equal(string.Format("File {0} is conflicted", filename), syncResult[0].Reports.ToList()[0].Exception.Message); // conflict should be resolved by the registered listener Assert.True(SpinWait.SpinUntil(() => conflictsListener.DetectedCount == 1 && conflictsListener.ResolvedCount == 1, TimeSpan.FromMinutes(1)), string.Format("DetectedCount: {0}, ResolvedCount: {1}", conflictsListener.DetectedCount, conflictsListener.ResolvedCount)); // We need to sync again after conflict resolution because the strategy was to resolve with remote await sessionDestination1.Commands.Synchronization.StartAsync(); await notificationTask; Assert.Equal(1, conflictsListener.DetectedCount); Assert.Equal(1, conflictsListener.ResolvedCount); var file = await sessionDestination1.LoadFileAsync(filename); var file2 = await sessionDestination2.LoadFileAsync(filename); Assert.Equal(secondStreamSize, file.TotalSize); Assert.Equal(secondStreamSize, file2.TotalSize); } }