Пример #1
0
        private async Task ValidateSource(IAsyncFilesCommands source)
        {
            var stats = await source.GetStatisticsAsync();

            Assert.Equal(10, stats.FileCount);
            Assert.Equal(0, stats.ActiveSyncs.Count);
            Assert.Equal(0, stats.PendingSyncs.Count);

            var headers = await source.BrowseAsync();

            Assert.Equal(10, headers.Length);

            for (int i = 0; i < 10; i++)
            {
                var metadata = new Reference <RavenJObject>();
                var stream   = await source.DownloadAsync(SynchronizedFileName(i), metadata);

                Assert.Equal(stream.GetMD5Hash(), CreateUniformFileStream(i, (char)i).GetMD5Hash());
            }

            var search = await source.SearchAsync("");

            Assert.Equal(10, search.Files.Count);
            Assert.Equal(10, search.FileCount);
        }
 private async Task CreateSampleData(IAsyncFilesCommands commands, int startIndex = 1, int count = 2)
 {
     for (var i = startIndex; i < startIndex + count; i++)
     {
         await commands.UploadAsync(string.Format("file{0}.bin", i), StringToStream("Secret records / " + i));
     }
 }
Пример #3
0
        private async Task ValidateDestination(IAsyncFilesCommands destination)
        {
            var stats = await destination.GetStatisticsAsync();

            Assert.Equal(20, stats.FileCount);

            var headers = await destination.BrowseAsync();

            Assert.Equal(20, headers.Length);

            for (int i = 0; i < 10; i++)
            {
                var metadata = new Reference <RavenJObject>();
                var stream   = await destination.DownloadAsync(SynchronizedFileName(i), metadata);

                Assert.Equal(stream.GetMD5Hash(), CreateUniformFileStream(i, (char)i).GetMD5Hash());

                stream = await destination.DownloadAsync(FileName(i), metadata);

                Assert.Equal(stream.GetMD5Hash(), CreateUniformFileStream(i, (char)i).GetMD5Hash());

                var searchResult = await destination.SearchAsync("ETag:" + metadata.Value[Constants.MetadataEtagField]);

                Assert.Equal(1, searchResult.Files.Count);
                Assert.Equal(1, searchResult.FileCount);

                var config = await destination.Configuration.GetKeyAsync <RavenJObject>(ConfigurationName(i));

                Assert.Equal(string.Format("value-{0}", i), config["key"].ToString());
            }
        }
Пример #4
0
        public static SynchronizationDestination ToSynchronizationDestination(this IAsyncFilesCommands self)
        {
            var selfImpl = (IAsyncFilesCommandsImpl)self;

            var result = new SynchronizationDestination
            {
                FileSystem = self.FileSystemName,
                ServerUrl  = selfImpl.ServerUrl,
            };

            if (self.PrimaryCredentials != null)
            {
                var networkCredential = self.PrimaryCredentials.Credentials as NetworkCredential;

                if (networkCredential != null)
                {
                    result.Username = networkCredential.UserName;
                    result.Password = networkCredential.Password;
                    result.Domain   = networkCredential.Domain;
                }
                else
                {
                    throw new InvalidOperationException("Expected NetworkCredential object while get: " + self.PrimaryCredentials.Credentials);
                }

                result.ApiKey = self.PrimaryCredentials.ApiKey;
            }

            return(result);
        }
Пример #5
0
        protected void WaitForBackup(IAsyncFilesCommands filesCommands, bool checkError)
        {
            var done = SpinWait.SpinUntil(() =>
            {
                var backupStatus = AsyncHelpers.RunSync(() => filesCommands.Configuration.GetKeyAsync <BackupStatus>(BackupStatus.RavenBackupStatusDocumentKey));
                if (backupStatus == null)
                {
                    return(true);
                }

                if (backupStatus.IsRunning == false)
                {
                    if (checkError)
                    {
                        var firstOrDefault = backupStatus.Messages.FirstOrDefault(x => x.Severity == BackupStatus.BackupMessageSeverity.Error);
                        if (firstOrDefault != null)
                        {
                            Assert.True(false, string.Format("{0}\n\nDetails: {1}", firstOrDefault.Message, firstOrDefault.Details));
                        }
                    }

                    return(true);
                }
                return(false);
            }, Debugger.IsAttached ? TimeSpan.FromMinutes(120) : TimeSpan.FromMinutes(15));

            Assert.True(done);
        }
Пример #6
0
		public static void TurnOffSynchronization(IAsyncFilesCommands source)
		{
            var destinations = source.Synchronization.GetDestinationsAsync().Result;
            foreach ( var destination in destinations )
                destination.Enabled = false;

            source.Synchronization.SetDestinationsAsync(destinations).Wait();          
		}
        public SynchronizationNotificationTests()
        {
            sourceStore = NewStore(0);
            sourceClient = sourceStore.AsyncFilesCommands;

            destinationStore = NewStore(1);
            destinationClient = destinationStore.AsyncFilesCommands;
        }
Пример #8
0
        public AbstractFilesQuery(InMemoryFilesSessionOperations theSession, IAsyncFilesCommands commands)
        {
            this.conventions      = theSession == null ? new FilesConvention() : theSession.Conventions;
            this.linqPathProvider = new LinqPathProvider(conventions);

            this.Session  = theSession;
            this.Commands = commands;
        }
Пример #9
0
        private static void ZeroTimeoutTest(IAsyncFilesCommands destinationClient, Action action)
        {
            destinationClient.Configuration.SetKeyAsync(RavenFileNameHelper.SyncLockNameForFile("test.bin"), SynchronizationConfig(DateTime.MinValue)).Wait();

            destinationClient.Configuration.SetKeyAsync(SynchronizationConstants.RavenSynchronizationLockTimeout, TimeSpan.FromSeconds(0)).Wait();

            Assert.DoesNotThrow(() => action());
        }
 private string[] FetchMd5Sums(IAsyncFilesCommands filesCommands, int filesCount = 2)
 {
     return(Enumerable.Range(1, filesCount).Select(i =>
     {
         var meta = filesCommands.GetMetadataForAsync(string.Format("file{0}.bin", i)).Result;
         return meta.Value <string>("Content-MD5");
     }).ToArray());
 }
        public SynchronizationNotificationTests()
        {
            sourceStore  = NewStore(0);
            sourceClient = sourceStore.AsyncFilesCommands;

            destinationStore  = NewStore(1);
            destinationClient = destinationStore.AsyncFilesCommands;
        }
Пример #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncFilesSession"/> class.
 /// </summary>
 public AsyncFilesSession(FilesStore filesStore,
                          IAsyncFilesCommands asyncFilesCommands,
                          FilesSessionListeners listeners,
                          Guid id)
     : base(filesStore, listeners, id)
 {
     Commands = asyncFilesCommands;
     filesStore.Changes().ForConflicts().Subscribe(this);
 }
Пример #13
0
        private static async Task ValidateSourceEtags(IAsyncFilesCommands source)
        {
            foreach (var syncResultName in (await source.Configuration.SearchAsync("Syncing/")).ConfigNames)
            {
                var syncDetails = await source.Configuration.GetKeyAsync <SynchronizationDetails>(syncResultName);

                Assert.Equal(1, syncDetails.FileETag.Restarts);                 // make sure that etags are valid after conversion from guids
            }
        }
 private string[] ComputeMd5Sums(IAsyncFilesCommands filesCommands, int filesCount = 2)
 {
     return(Enumerable.Range(1, filesCount).Select(i =>
     {
         using (var stream = filesCommands.DownloadAsync(string.Format("file{0}.bin", i)).Result)
         {
             return stream.GetMD5Hash();
         }
     }).ToArray());
 }
Пример #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncFilesSession"/> class.
 /// </summary>
 public AsyncFilesSession(FilesStore filesStore,
                          IAsyncFilesCommands asyncFilesCommands,
                          FilesSessionListeners listeners,
                          Guid id)
     : base(filesStore, listeners, id)
 {
     Commands             = asyncFilesCommands;
     conflictCacheRemoval = filesStore.Changes(this.FileSystemName)
                            .ForConflicts()
                            .Subscribe <ConflictNotification>(this.OnFileConflict);
 }
Пример #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncFilesSession"/> class.
 /// </summary>
 public AsyncFilesSession(FilesStore filesStore,
                          IAsyncFilesCommands asyncFilesCommands,
                          FilesSessionListeners listeners,
                          Guid id)
     : base(filesStore, listeners, id)
 {
     Commands             = asyncFilesCommands;
     conflictCacheRemoval = filesStore.Changes(this.FileSystemName)
                            .ForConflicts()
                            .Subscribe(new FileConflictObserver(this));
 }
Пример #17
0
        /// <summary>
		/// Initializes a new instance of the <see cref="AsyncFilesSession"/> class.
		/// </summary>
        public AsyncFilesSession(FilesStore filesStore,
                                 IAsyncFilesCommands asyncFilesCommands,
								 FilesSessionListeners listeners,
								 Guid id)
			: base(filesStore, listeners, id)
		{
            Commands = asyncFilesCommands;
            conflictCacheRemoval = filesStore.Changes(this.FileSystemName)
                                             .ForConflicts()
                                             .Subscribe<ConflictNotification>(this.OnFileConflict);
		}
Пример #18
0
        public static void TurnOffSynchronization(IAsyncFilesCommands source)
        {
            var destinations = source.Synchronization.GetDestinationsAsync().Result;

            foreach (var destination in destinations)
            {
                destination.Enabled = false;
            }

            source.Synchronization.SetDestinationsAsync(destinations).Wait();
        }
Пример #19
0
        public static SynchronizationReport ResolveConflictAndSynchronize(IAsyncFilesCommands sourceClient,
                                                                          IAsyncFilesCommands destinationClient,
                                                                          string fileName)
        {
            var shouldBeConflict = sourceClient.Synchronization.StartAsync(fileName, destinationClient).Result;

            Assert.NotNull(shouldBeConflict.Exception);

            destinationClient.Synchronization.ResolveConflictAsync(fileName, ConflictResolutionStrategy.RemoteVersion).Wait();
            return(sourceClient.Synchronization.StartAsync(fileName, destinationClient).Result);
        }
Пример #20
0
        public static SynchronizationReport ResolveConflictAndSynchronize(IAsyncFilesCommands sourceClient,
                                                                          IAsyncFilesCommands destinationClient,
		                                                                  string fileName)
		{
			var shouldBeConflict = sourceClient.Synchronization.StartAsync(fileName, destinationClient).Result;

			Assert.NotNull(shouldBeConflict.Exception);

			destinationClient.Synchronization.ResolveConflictAsync(fileName, ConflictResolutionStrategy.RemoteVersion).Wait();
			return sourceClient.Synchronization.StartAsync(fileName, destinationClient).Result;
		}
Пример #21
0
        private void UploadFilesSynchronously(out IAsyncFilesCommands sourceClient,
                                              out IAsyncFilesCommands destinationClient, string fileName = "test.bin")
        {
            sourceClient      = NewAsyncClient(1);
            destinationClient = NewAsyncClient(0);

            var sourceContent      = new RandomlyModifiedStream(new RandomStream(10, 1), 0.01);
            var destinationContent = new RandomlyModifiedStream(new RandomStream(10, 1), 0.01);

            destinationClient.UploadAsync(fileName, destinationContent).Wait();
            sourceClient.UploadAsync(fileName, sourceContent).Wait();
        }
Пример #22
0
        public static async Task EnsureFileSystemExistsAsync(this IAsyncFilesCommands commands)
        {
            var existingSystems = await commands.Admin.GetNamesAsync().ConfigureAwait(false);

            if (existingSystems.Any(x => x.Equals(commands.FileSystemName, StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }

            var fileSystemDocument = MultiDatabase.CreateFileSystemDocument(commands.FileSystemName);

            await commands.Admin.CreateFileSystemAsync(fileSystemDocument).ConfigureAwait(false);
        }
Пример #23
0
        protected void WaitForFile(IAsyncFilesCommands filesCommands, string fileName)
        {
            var done = SpinWait.SpinUntil(() =>
            {
                var file = filesCommands.GetMetadataForAsync(fileName).Result;
                return(file != null);
            }, TimeSpan.FromSeconds(15));

            if (!done)
            {
                throw new Exception("WaitForDocument failed");
            }
        }
Пример #24
0
        public WhatAreCommands()
        {
            IFilesStore store = null;

            #region commands_access
            IAsyncFilesCommands commands = store.AsyncFilesCommands;
            #endregion

            #region commands_different_fs
            IAsyncFilesCommands southwindCommands = store
                                                    .AsyncFilesCommands
                                                    .ForFileSystem("SouthwindFS")
                                                    .With(new NetworkCredential("user", "pass"));
            #endregion
        }
Пример #25
0
        private static IAsyncFilesCommands SetupCommandsAsync(IAsyncFilesCommands filesCommands, OpenFilesSessionOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.FileSystem))
            {
                throw new ArgumentException("Filesystem cannot be null, empty or whitespace.", "FileSystem");
            }

            filesCommands = filesCommands.ForFileSystem(options.FileSystem);
            if (options.ApiKey != null || options.Credentials != null)
            {
                filesCommands = filesCommands.With(new OperationCredentials(options.ApiKey, options.Credentials));
            }

            return(filesCommands);
        }
        private static async Task RunMetadataSynchronization(IAsyncFilesCommands sourceClient, IAsyncFilesCommands destinationClient, Action action = null)
        {
            await destinationClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("metadata-test")), new RavenJObject { { "Sample-Header", "destination" } });

            if (action != null)
            {
                action();
            }

            await sourceClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("metadata-test")), new RavenJObject { { "Sample-Header", "source" } });

            var report = await sourceClient.Synchronization.StartAsync("test", destinationClient);

            Assert.Null(report.Exception);
            Assert.Equal(SynchronizationType.MetadataUpdate, report.Type);
        }
Пример #27
0
        private static async Task ValidateDestinationEtags(IAsyncFilesCommands destination, Guid sourceServeId)
        {
            var lastSynchronizedEtag = (await destination.Synchronization.GetLastSynchronizationFromAsync(sourceServeId)).LastSourceFileEtag;

            Assert.Equal(1, lastSynchronizedEtag.Restarts);             // make sure that etags are valid after conversion from guids

            var sourceInfo = await destination.Configuration.GetKeyAsync <SourceSynchronizationInformation>(SynchronizationConstants.RavenSynchronizationSourcesBasePath + "/" + sourceServeId);

            Assert.Equal(1, sourceInfo.LastSourceFileEtag.Restarts);             // make sure that etags are valid after conversion from guids

            foreach (var syncResultName in (await destination.Configuration.SearchAsync("SyncResult/")).ConfigNames)
            {
                var syncResult = await destination.Configuration.GetKeyAsync <SynchronizationReport>(syncResultName);

                Assert.Equal(1, syncResult.FileETag.Restarts);                 // make sure that etags are valid after conversion from guids
            }
        }
Пример #28
0
        public static async Task EnsureFileSystemExistsAsync(this IAsyncFilesCommands commands)
        {
            var existingSystems = await commands.Admin.GetNamesAsync().ConfigureAwait(false);

            if (existingSystems.Any(x => x.Equals(commands.FileSystemName, StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }

            await commands.Admin.CreateFileSystemAsync(new FileSystemDocument
            {
                Id       = "Raven/FileSystem/" + commands.FileSystemName,
                Settings =
                {
                    { Constants.FileSystem.DataDirectory, Path.Combine("FileSystems", commands.FileSystemName) }
                }
            }).ConfigureAwait(false);
        }
Пример #29
0
        public static async Task EnsureFileSystemExistsAsync(this IAsyncFilesCommands commands)
        {
            var existingSystems = await commands.Admin.GetNamesAsync();

            if (existingSystems.Any(x => x.Equals(commands.FileSystem, StringComparison.InvariantCultureIgnoreCase)))
            {
                return;
            }

            await commands.Admin.CreateFileSystemAsync(new FileSystemDocument
            {
                Id       = "Raven/FileSystem/" + commands.FileSystem,
                Settings =
                {
                    { "Raven/FileSystem/DataDir", Path.Combine("FileSystems", commands.FileSystem) }
                }
            });
        }
        private static async Task RunDeleteSynchronization(IAsyncFilesCommands sourceClient, IAsyncFilesCommands destinationClient, Action action = null)
        {
            await destinationClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("delete-test")));

            if (action != null)
            {
                action();
            }

            await sourceClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("delete-test")));

            await sourceClient.DeleteAsync("test");

            var report = await sourceClient.Synchronization.StartAsync("test", destinationClient);

            Assert.Null(report.Exception);
            Assert.Equal(SynchronizationType.Delete, report.Type);
        }
        private static async Task <string> RunContentSynchronization(IAsyncFilesCommands sourceClient, IAsyncFilesCommands destinationClient, Action action = null)
        {
            await destinationClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("destination")));

            if (action != null)
            {
                action();
            }

            await sourceClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("source")));

            var report = await sourceClient.Synchronization.StartAsync("test", destinationClient);

            Assert.Null(report.Exception);
            Assert.Equal(SynchronizationType.ContentUpdate, report.Type);

            var stream = await destinationClient.DownloadAsync("test");

            return(StreamToString(stream));
        }
        private static async Task <string> ExecuteRawSynchronizationRequest(IAsyncFilesCommands sourceClient, IAsyncFilesCommands destinationClient, Action action = null)
        {
            await destinationClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("destination")));

            if (action != null)
            {
                action();
            }

            await sourceClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("source")));

            var sourceStream = new MemoryStream();

            (await sourceClient.DownloadAsync("test")).CopyTo(sourceStream);

            var metadata = await sourceClient.GetMetadataForAsync("test");

            var request = new SynchronizationMultipartRequest(destinationClient.Synchronization, new ServerInfo()
            {
                FileSystemUrl = sourceClient.UrlFor(),
                Id            = sourceClient.GetServerIdAsync().Result
            }, "test", metadata, sourceStream, new[]
            {
                new RdcNeed()
                {
                    BlockLength = 6,
                    BlockType   = RdcNeedType.Source,
                    FileOffset  = 0
                }
            });

            var synchronizationReport = await request.PushChangesAsync(CancellationToken.None);

            Assert.Null(synchronizationReport.Exception);

            var stream = await destinationClient.DownloadAsync("test");

            return(StreamToString(stream));
        }
Пример #33
0
        private static void WaitForFileDelete(IAsyncFilesCommands client, string fileName)
        {
            var result = SpinWait.SpinUntil(() =>
            {
                try
                {
                    var file = AsyncHelpers.RunSync(() => client.DownloadAsync(fileName));
                    return(file == null);
                }
                catch (FileNotFoundException)
                {
                    return(true);
                }
            }, TimeSpan.FromSeconds(30));

            if (result)
            {
                return;
            }

            throw new TimeoutException("Could retrieve file " + fileName + " while it was supposed to be deleted");
        }
Пример #34
0
        private new static void WaitForFile(IAsyncFilesCommands client, string fileName)
        {
            var result = SpinWait.SpinUntil(() =>
            {
                try
                {
                    var file = AsyncHelpers.RunSync(() => client.DownloadAsync(fileName));
                    return(file != null);
                }
                catch (FileNotFoundException)
                {
                    return(false);
                }
            }, TimeSpan.FromSeconds(30));

            if (result)
            {
                return;
            }

            throw new TimeoutException("Could not download file " + fileName);
        }
		private static async Task<string> ExecuteRawSynchronizationRequest(IAsyncFilesCommands sourceClient, IAsyncFilesCommands destinationClient, Action action = null)
		{
			await destinationClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("destination")));

			if (action != null)
				action();

			await sourceClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("source")));

			var sourceStream = new MemoryStream();

			(await sourceClient.DownloadAsync("test")).CopyTo(sourceStream);

			var metadata = await sourceClient.GetMetadataForAsync("test");

			var request = new SynchronizationMultipartRequest(destinationClient.Synchronization, new ServerInfo()
			{
				FileSystemUrl = sourceClient.UrlFor(),
				Id = sourceClient.GetServerIdAsync().Result
			}, "test", metadata, sourceStream, new[]
			{
				new RdcNeed()
				{
					BlockLength = 6,
					BlockType = RdcNeedType.Source,
					FileOffset = 0
				}
			});

			var synchronizationReport = await request.PushChangesAsync(CancellationToken.None);

			Assert.Null(synchronizationReport.Exception);

			var stream = await destinationClient.DownloadAsync("test");

			return StreamToString(stream);
		}
Пример #36
0
        private static IAsyncFilesCommands SetupCommandsAsync(IAsyncFilesCommands filesCommands, OpenFilesSessionOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.FileSystem))
                throw new ArgumentException("Filesystem cannot be null, empty or whitespace.", "FileSystem");

            filesCommands = filesCommands.ForFileSystem(options.FileSystem);
	        if (options.ApiKey != null || options.Credentials != null)
		        filesCommands = filesCommands.With(new OperationCredentials(options.ApiKey, options.Credentials));
            
            return filesCommands;
        }
		private string[] FetchMd5Sums(IAsyncFilesCommands filesCommands, int filesCount = 2)
		{
			return Enumerable.Range(1, filesCount).Select(i =>
			{
				var meta = filesCommands.GetMetadataForAsync(string.Format("file{0}.bin", i)).Result;
				return meta.Value<string>("Content-MD5");
			}).ToArray();
		}
Пример #38
0
		private static async Task ValidateDestinationEtags(IAsyncFilesCommands destination, Guid sourceServeId)
		{
			var lastSynchronizedEtag = (await destination.Synchronization.GetLastSynchronizationFromAsync(sourceServeId)).LastSourceFileEtag;

			Assert.Equal(1, lastSynchronizedEtag.Restarts); // make sure that etags are valid after conversion from guids

			var sourceInfo = await destination.Configuration.GetKeyAsync<SourceSynchronizationInformation>(SynchronizationConstants.RavenSynchronizationSourcesBasePath + "/" + sourceServeId);

			Assert.Equal(1, sourceInfo.LastSourceFileEtag.Restarts); // make sure that etags are valid after conversion from guids

			foreach (var syncResultName in (await destination.Configuration.SearchAsync("SyncResult/")).ConfigNames)
			{
				var syncResult = await destination.Configuration.GetKeyAsync<SynchronizationReport>(syncResultName);

				Assert.Equal(1, syncResult.FileETag.Restarts); // make sure that etags are valid after conversion from guids
			}
		}
Пример #39
0
        public static void TurnOnSynchronization(IAsyncFilesCommands source, params IAsyncFilesCommands[] destinations)
		{
            source.Synchronization.SetDestinationsAsync(destinations.Select(x => x.ToSynchronizationDestination()).ToArray()).Wait();
		}
		private static async Task<string> RunContentSynchronization(IAsyncFilesCommands sourceClient, IAsyncFilesCommands destinationClient, Action action = null)
		{
			await destinationClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("destination")));

			if (action != null)
				action();

			await sourceClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("source")));

			var report = await sourceClient.Synchronization.StartAsync("test", destinationClient);

			Assert.Null(report.Exception);
			Assert.Equal(SynchronizationType.ContentUpdate, report.Type);

			var stream = await destinationClient.DownloadAsync("test");

			return StreamToString(stream);
		}
Пример #41
0
		private static async Task ValidateSourceEtags(IAsyncFilesCommands source)
		{
			foreach (var syncResultName in (await source.Configuration.SearchAsync("Syncing/")).ConfigNames)
			{
				var syncDetails = await source.Configuration.GetKeyAsync<SynchronizationDetails>(syncResultName);

				Assert.Equal(1, syncDetails.FileETag.Restarts); // make sure that etags are valid after conversion from guids
			}
		}
		private static async Task RunDeleteSynchronization(IAsyncFilesCommands sourceClient, IAsyncFilesCommands destinationClient, Action action = null)
		{
			await destinationClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("delete-test")));

			if (action != null)
				action();

			await sourceClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("delete-test")));
			await sourceClient.DeleteAsync("test");

			var report = await sourceClient.Synchronization.StartAsync("test", destinationClient);

			Assert.Null(report.Exception);
			Assert.Equal(SynchronizationType.Delete, report.Type);
		}
		private static async Task RunMetadataSynchronization(IAsyncFilesCommands sourceClient, IAsyncFilesCommands destinationClient, Action action = null)
		{
			await destinationClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("metadata-test")), new RavenJObject { { "Sample-Header", "destination" } });

			if (action != null)
				action();

			await sourceClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("metadata-test")), new RavenJObject { { "Sample-Header", "source" } });

			var report = await sourceClient.Synchronization.StartAsync("test", destinationClient);

			Assert.Null(report.Exception);
			Assert.Equal(SynchronizationType.MetadataUpdate, report.Type);
		}
Пример #44
0
        private void UploadFilesSynchronously(out IAsyncFilesCommands sourceClient,
                                              out IAsyncFilesCommands destinationClient, string fileName = "test.bin")
		{
			sourceClient = NewAsyncClient(1);
			destinationClient = NewAsyncClient(0);

			var sourceContent = new RandomlyModifiedStream(new RandomStream(10, 1), 0.01);
			var destinationContent = new RandomlyModifiedStream(new RandomStream(10, 1), 0.01);

			destinationClient.UploadAsync(fileName, destinationContent).Wait();
			sourceClient.UploadAsync(fileName, sourceContent).Wait();
		}
Пример #45
0
        private static void ZeroTimeoutTest(IAsyncFilesCommands destinationClient, Action action)
		{
			destinationClient.Configuration.SetKeyAsync(RavenFileNameHelper.SyncLockNameForFile("test.bin"), SynchronizationConfig(DateTime.MinValue)).Wait();

            destinationClient.Configuration.SetKeyAsync(SynchronizationConstants.RavenSynchronizationLockTimeout, TimeSpan.FromSeconds(0) ).Wait();

			Assert.DoesNotThrow(() => action());
		}
Пример #46
0
		private async Task ValidateSource(IAsyncFilesCommands source)
		{
			var stats = await source.GetStatisticsAsync();

			Assert.Equal(10, stats.FileCount);
			Assert.Equal(0, stats.ActiveSyncs.Count);
			Assert.Equal(0, stats.PendingSyncs.Count);

			var headers = await source.BrowseAsync();
			Assert.Equal(10, headers.Length);

			for (int i = 0; i < 10; i++)
			{
				var metadata = new Reference<RavenJObject>();
				var stream = await source.DownloadAsync(SynchronizedFileName(i), metadata);

				Assert.Equal(stream.GetMD5Hash(), CreateUniformFileStream(i, (char) i).GetMD5Hash());
			}

			var search = await source.SearchAsync("");
			Assert.Equal(10, search.Files.Count);
			Assert.Equal(10, search.FileCount);
		}
Пример #47
0
		private async Task ValidateDestination(IAsyncFilesCommands destination)
		{
			var stats = await destination.GetStatisticsAsync();

			Assert.Equal(20, stats.FileCount);

			var headers = await destination.BrowseAsync();
			Assert.Equal(20, headers.Length);

			for (int i = 0; i < 10; i++)
			{
				var metadata = new Reference<RavenJObject>();
				var stream = await destination.DownloadAsync(SynchronizedFileName(i), metadata);

				Assert.Equal(stream.GetMD5Hash(), CreateUniformFileStream(i, (char) i).GetMD5Hash());

				stream = await destination.DownloadAsync(FileName(i), metadata);

				Assert.Equal(stream.GetMD5Hash(), CreateUniformFileStream(i, (char) i).GetMD5Hash());

				var searchResult = await destination.SearchAsync("ETag:" + metadata.Value[Constants.MetadataEtagField]);

				Assert.Equal(1, searchResult.Files.Count);
				Assert.Equal(1, searchResult.FileCount);

				var config = await destination.Configuration.GetKeyAsync<RavenJObject>(ConfigurationName(i));

				Assert.Equal(string.Format("value-{0}", i), config["key"].ToString());
			}
		}
		private string[] ComputeMd5Sums(IAsyncFilesCommands filesCommands, int filesCount = 2)
		{
			return Enumerable.Range(1, filesCount).Select(i =>
			{
				using (var stream = filesCommands.DownloadAsync(string.Format("file{0}.bin", i)).Result)
				{
					return stream.GetMD5Hash();
				}
			}).ToArray();
		}
Пример #49
0
        protected void WaitForBackup(IAsyncFilesCommands filesCommands, bool checkError)
        {
            var done = SpinWait.SpinUntil(() =>
            {
                var backupStatus = filesCommands.Configuration.GetKeyAsync<BackupStatus>(BackupStatus.RavenBackupStatusDocumentKey).ResultUnwrap();
                if (backupStatus == null)
                    return true;

                if (backupStatus.IsRunning == false)
                {
                    if (checkError)
                    {
                        var firstOrDefault =
                            backupStatus.Messages.FirstOrDefault(x => x.Severity == BackupStatus.BackupMessageSeverity.Error);
                        if (firstOrDefault != null)
                            Assert.True(false, string.Format("{0}\n\nDetails: {1}", firstOrDefault.Message, firstOrDefault.Details));
                    }

                    return true;
                }
                return false;
            }, Debugger.IsAttached ? TimeSpan.FromMinutes(120) : TimeSpan.FromMinutes(15));
            
            Assert.True(done);
        }
		private async Task CreateSampleData(IAsyncFilesCommands commands, int startIndex = 1, int count = 2)
		{
			for (var i = startIndex; i < startIndex + count; i++)
			{
				await commands.UploadAsync(string.Format("file{0}.bin", i), StringToStream("Secret records / " + i));
			}
		}