public async void Should_mark_file_to_be_resolved_using_current_strategy() { var differenceChunk = new MemoryStream(); var sw = new StreamWriter(differenceChunk); sw.Write("Coconut is Stupid"); sw.Flush(); var sourceContent = SyncTestUtils.PrepareSourceStream(10); sourceContent.Position = 0; var destinationContent = new CombinedStream(differenceChunk, sourceContent); var destinationClient = NewAsyncClient(0); var sourceClient = NewAsyncClient(1); var sourceMetadata = new RavenJObject { { "SomeTest-metadata", "some-value" } }; var destinationMetadata = new RavenJObject { { "SomeTest-metadata", "shouldnt-be-overwritten" } }; await destinationClient.UploadAsync("test.txt", destinationContent, destinationMetadata); sourceContent.Position = 0; await sourceClient.UploadAsync("test.txt", sourceContent, sourceMetadata); var shouldBeConflict = sourceClient.Synchronization.StartAsync("test.txt", destinationClient).Result; Assert.Equal(string.Format("File {0} is conflicted", FileHeader.Canonize("test.txt")), shouldBeConflict.Exception.Message); await destinationClient.Synchronization.ResolveConflictAsync("test.txt", ConflictResolutionStrategy.CurrentVersion); var result = await destinationClient.Synchronization.StartAsync("test.txt", sourceClient); Assert.Equal(destinationContent.Length, result.BytesCopied + result.BytesTransfered); // check if conflict resolution has been properly set on the source string resultMd5; using (var resultFileContent = await sourceClient.DownloadAsync("test.txt")) { var metadata = await sourceClient.GetMetadataForAsync("test.txt"); Assert.Equal("shouldnt-be-overwritten", metadata.Value <string>("SomeTest-Metadata")); resultMd5 = resultFileContent.GetMD5Hash(); } destinationContent.Position = 0; var destinationMd5 = destinationContent.GetMD5Hash(); sourceContent.Position = 0; Assert.True(resultMd5 == destinationMd5); }
public async Task Synchronize_file_with_appended_data(int size) { var differenceChunk = new MemoryStream(); var sw = new StreamWriter(differenceChunk); sw.Write("Coconut is Stupid"); sw.Flush(); var sourceContent = new CombinedStream(SyncTestUtils.PrepareSourceStream(size), differenceChunk) {Position = 0}; var destinationContent = SyncTestUtils.PrepareSourceStream(size); destinationContent.Position = 0; var sourceClient = NewAsyncClient(0); var destinationClient = NewAsyncClient(1); await destinationClient.UploadAsync("test.txt", destinationContent); sourceContent.Position = 0; await sourceClient.UploadAsync("test.txt", sourceContent); var result = SyncTestUtils.ResolveConflictAndSynchronize(sourceClient, destinationClient, "test.txt"); Assert.Equal(sourceContent.Length, result.BytesCopied + result.BytesTransfered); string resultMd5; using (var resultFileContent = await destinationClient.DownloadAsync("test.txt")) { resultMd5 = resultFileContent.GetMD5Hash(); } sourceContent.Position = 0; var sourceMd5 = sourceContent.GetMD5Hash(); Assert.True(resultMd5 == sourceMd5); }
public async void Should_reuse_pages_when_data_appended(int numberOfPages) { string filename = FileHeader.Canonize("test"); var file = SyncTestUtils.PreparePagesStream(numberOfPages); var sourceContent = new CombinedStream(file, SyncTestUtils.PreparePagesStream(numberOfPages)); // add new pages at the end var destinationContent = file; sourceContent.Position = 0; await source.UploadAsync(filename, sourceContent); destinationContent.Position = 0; await destination.UploadAsync(filename, destinationContent); var contentUpdate = new ContentUpdateWorkItem(filename, "http://localhost:12345", sourceRfs.Storage, sourceRfs.SigGenerator); // force to upload entire file, we just want to check which pages will be reused await contentUpdate.UploadToAsync(destination.Synchronization); await destination.Synchronization.ResolveConflictAsync(filename, ConflictResolutionStrategy.RemoteVersion); await contentUpdate.UploadToAsync(destination.Synchronization); FileAndPagesInformation fileAndPages = null; destinationRfs.Storage.Batch(accessor => fileAndPages = accessor.GetFile(filename, 0, 2 * numberOfPages)); Assert.Equal(2 * numberOfPages, fileAndPages.Pages.Count); for (var i = 0; i < numberOfPages; i++) { Assert.Equal(i + 1, fileAndPages.Pages[i].Id); // if page ids are in the original order it means that they were used the existing pages } sourceContent.Position = 0; Assert.Equal(sourceContent.GetMD5Hash(), destination.GetMetadataForAsync(filename).Result["Content-MD5"]); }