public async Task BetweenOperation_ShouldNotCreateFilesystem()
        {
            using (var store = NewStore())
            {
                var smugglerApi = new SmugglerFilesApi();                

                var options = new SmugglerBetweenOptions<FilesConnectionStringOptions>
                {
                    From = new FilesConnectionStringOptions
                    {
                        Url = store.Url,
                        DefaultFileSystem = SourceFilesystem
                    },
                    To = new FilesConnectionStringOptions
                    {
                        Url = store.Url,
                        DefaultFileSystem = DestinationFilesystem
                    }
                };
                
                var exception = await AssertAsync.Throws<SmugglerException>(() => smugglerApi.Between(options));
                Assert.True(exception.Message.StartsWith("Smuggler does not support file system creation (file system '" + SourceFilesystem + "' on server"));

                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(SourceFilesystem);

                exception = await AssertAsync.Throws<SmugglerException>(() => smugglerApi.Between(options));
                Assert.True(exception.Message.StartsWith("Smuggler does not support file system creation (file system '" + DestinationFilesystem + "' on server"));
            }
        }
Beispiel #2
0
        public void SmugglerBetweenOperationShouldNotCreateDatabases()
        {
            using (var store = NewRemoteDocumentStore())
            {
                var smugglerApi = new SmugglerDatabaseApi();

                var options = new SmugglerBetweenOptions<RavenConnectionStringOptions>
                              {
                                    From = new RavenConnectionStringOptions
                                    {
                                        Url = store.Url, 
                                        DefaultDatabase = "DB1"
                                    },
                                    To = new RavenConnectionStringOptions
                                    {
                                        Url = store.Url, 
                                        DefaultDatabase = "DB2"
                                    }
                              };

                var aggregateException = Assert.Throws<AggregateException>(() => smugglerApi.Between(options).Wait());
                var exception = aggregateException.ExtractSingleInnerException();
                Assert.True(exception.Message.StartsWith("Smuggler does not support database creation (database 'DB1' on server"));

                store.DatabaseCommands.GlobalAdmin.EnsureDatabaseExists("DB1");

                aggregateException = Assert.Throws<AggregateException>(() => smugglerApi.Between(options).Wait());
                exception = aggregateException.ExtractSingleInnerException();
                Assert.True(exception.Message.StartsWith("Smuggler does not support database creation (database 'DB2' on server"));
            }
        }
Beispiel #3
0
        private async Task <Etag> CopyBetweenStores(SmugglerBetweenOptions <FilesConnectionStringOptions> options, Etag lastEtag, Etag maxEtag)
        {
            var totalCount     = 0;
            var lastReport     = SystemTime.UtcNow;
            var reportInterval = TimeSpan.FromSeconds(10);

            Operations.ShowProgress("Exporting Files");

            Exception exceptionHappened = null;

            try
            {
                using (var files = await Operations.GetFiles(options.From, lastEtag, Math.Min(Options.BatchSize, int.MaxValue)))
                {
                    while (await files.MoveNextAsync())
                    {
                        var file = files.Current;

                        var tempLastEtag = file.Etag;
                        if (maxEtag != null && tempLastEtag.CompareTo(maxEtag) > 0)
                        {
                            break;
                        }

                        var downloadedFile = await Operations.DownloadFile(file);

                        await Operations.PutFiles(file, downloadedFile, file.TotalSize.Value);

                        lastEtag = tempLastEtag;

                        totalCount++;
                        if (totalCount % 1000 == 0 || SystemTime.UtcNow - lastReport > reportInterval)
                        {
                            //TODO: Show also the MB/sec and total GB exported.
                            Operations.ShowProgress("Exported {0} files. ", totalCount);
                            lastReport = SystemTime.UtcNow;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Operations.ShowProgress("Got Exception during smuggler export. Exception: {0}. ", e.Message);
                Operations.ShowProgress("Done with reading files, total: {0}, lastEtag: {1}", totalCount, lastEtag);

                exceptionHappened = new SmugglerExportException(e.Message, e)
                {
                    LastEtag = lastEtag,
                };
            }

            if (exceptionHappened != null)
            {
                throw exceptionHappened;
            }

            Operations.ShowProgress("Done with reading documents, total: {0}, lastEtag: {1}", totalCount, lastEtag);
            return(lastEtag);
        }
Beispiel #4
0
        public virtual async Task Between(SmugglerBetweenOptions <FilesConnectionStringOptions> betweenOptions)
        {
            Operations.Configure(Options);
            Operations.Initialize(Options);

            try
            {
                await DetectServerSupportedFeatures(betweenOptions.From);
                await DetectServerSupportedFeatures(betweenOptions.To);
            }
            catch (WebException e)
            {
                throw new SmugglerExportException("Failed to query server for supported features. Reason : " + e.Message)
                      {
                          LastEtag = Etag.Empty,
                      };
            }

            if (string.IsNullOrWhiteSpace(betweenOptions.IncrementalKey))
            {
                betweenOptions.IncrementalKey = Operations.CreateIncrementalKey();
            }

            var incremental = new ExportFilesDestinationKey();

            if (this.Options.Incremental)
            {
                var smugglerExportIncremental = await Operations.GetIncrementalExportKey(); // importStore.AsyncFilesCommands.Configuration.GetKeyAsync<SmugglerExportIncremental>(SmugglerExportIncremental.RavenDocumentKey);

                ExportFilesDestinationKey value;
                if (smugglerExportIncremental.Destinations.TryGetValue(betweenOptions.IncrementalKey, out value))
                {
                    incremental = value;
                }

                this.Options.StartFilesEtag = incremental.LastEtag ?? Etag.Empty;
            }

            var result = new ExportFilesResult
            {
                LastFileEtag = Options.StartFilesEtag,
            };

            // used to synchronize max returned values for put/delete operations
            var maxEtags = Operations.FetchCurrentMaxEtags();

            incremental.LastEtag = await CopyBetweenStores(result.LastFileEtag, maxEtags.LastFileEtag);

            if (this.Options.Incremental)
            {
                var smugglerExportIncremental = await Operations.GetIncrementalExportKey();

                smugglerExportIncremental.Destinations[betweenOptions.IncrementalKey] = incremental;

                await Operations.PutIncrementalExportKey(smugglerExportIncremental); // importStore.AsyncFilesCommands.Configuration.SetKeyAsync<SmugglerExportIncremental>(SmugglerExportIncremental.RavenDocumentKey, smugglerExportIncremental);
            }
        }
        public async Task BetweenOperation_BehaviorWhenServerIsDown()
        {
            string dataDirectory = null;

            try
            {
                using (var store = NewStore())
                {
                    var server = GetServer();

                    var smugglerApi = new SmugglerFilesApi();

                    var options = new SmugglerBetweenOptions<FilesConnectionStringOptions>
                    {
                        From = new FilesConnectionStringOptions
                        {
                            Url = "http://localhost:8078/",
                            DefaultFileSystem = SourceFilesystem
                        },
                        To = new FilesConnectionStringOptions
                        {
                            Url = store.Url,
                            DefaultFileSystem = DestinationFilesystem
                        }
                    };

                    await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(SourceFilesystem);
                    await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(DestinationFilesystem);

                    var e = await AssertAsync.Throws<SmugglerException>(() => smugglerApi.Between(options));
                    Assert.Contains("Smuggler encountered a connection problem:", e.Message);

                    options.From.Url = store.Url;
                    options.To.Url = "http://localhost:8078/";

                    e = await AssertAsync.Throws<SmugglerException>(() => smugglerApi.Between(options));
                    Assert.Contains("Smuggler encountered a connection problem:", e.Message);

                    server.Dispose();
                }
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(dataDirectory))
                    IOExtensions.DeleteDirectory(dataDirectory);
            }
        }
        public override async Task Between(SmugglerBetweenOptions<FilesConnectionStringOptions> betweenOptions)
        {
            if (betweenOptions.From == null)
                throw new ArgumentNullException("betweenOptions.From");

            if (betweenOptions.To == null)
                throw new ArgumentNullException("betweenOptions.To");            

            using (primaryStore = await CreateStore(betweenOptions.From))
            using (secondaryStore = await CreateStore(betweenOptions.To))
            using (documentStore = CreateDocumentStore(betweenOptions.To))
            {
                Operations = new SmugglerBetweenRemoteFilesOperations(() => primaryStore, () => secondaryStore, () => documentStore);

                await base.Between(betweenOptions);
            }              
        }
        public async Task BetweenOperation_CanDumpEmptyFileSystem()
        {
            string dataDirectory = null;

            try
            {
                using (var store = NewStore())
                {
                    var server = GetServer();
                    dataDirectory = server.Configuration.DataDirectory;

                    var smugglerApi = new SmugglerFilesApi();

                    var options = new SmugglerBetweenOptions<FilesConnectionStringOptions>
                    {
                        From = new FilesConnectionStringOptions
                        {
                            Url = store.Url,
                            DefaultFileSystem = SourceFilesystem
                        },
                        To = new FilesConnectionStringOptions
                        {
                            Url = store.Url,
                            DefaultFileSystem = DestinationFilesystem
                        }
                    };

                    await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(SourceFilesystem);
                    await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(DestinationFilesystem);

                    await smugglerApi.Between(options);

                    using (var session = store.OpenAsyncSession(DestinationFilesystem))
                    {
                        var files = await session.Commands.BrowseAsync();
                        Assert.Equal(0, files.Count());
                    }

                    server.Dispose();
                }
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(dataDirectory))
                    IOExtensions.DeleteDirectory(dataDirectory);
            }
        }
        public override Task Between(SmugglerBetweenOptions<RavenConnectionStringOptions> betweenOptions)
		{
            return SmugglerDatabaseBetweenOperation.Between(betweenOptions, Options);
		}
Beispiel #9
0
 public abstract Task Between(SmugglerBetweenOptions betweenOptions);
        public async Task BetweenOperation_OnlyActiveContentIsPreserved_MultipleDirectories()
        {
            using (var store = NewStore())
            {
                var server = GetServer();

                var smugglerApi = new SmugglerFilesApi();

                var options = new SmugglerBetweenOptions<FilesConnectionStringOptions>
                {
                    From = new FilesConnectionStringOptions
                    {
                        Url = store.Url,
                        DefaultFileSystem = SourceFilesystem
                    },
                    To = new FilesConnectionStringOptions
                    {
                        Url = store.Url,
                        DefaultFileSystem = DestinationFilesystem
                    }
                };

                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(SourceFilesystem);
                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(DestinationFilesystem);

                int total = 10;
                var files = new string[total];
                using (var session = store.OpenAsyncSession(SourceFilesystem))
                {
                    for (int i = 0; i < total; i++)
                    {
                        files[i] = i + "/test.file";
                        session.RegisterUpload(files[i], CreateRandomFileStream(100 * i + 12));
                    }

                    await session.SaveChangesAsync();
                }

                int deletedFiles = 0;
                var rnd = new Random();
                using (var session = store.OpenAsyncSession(SourceFilesystem))
                {
                    for (int i = 0; i < total; i++)
                    {
                        if (rnd.Next(2) == 0)
                        {
                            session.RegisterFileDeletion(files[i]);
                            deletedFiles++;
                        }

                    }

                    await session.SaveChangesAsync();
                }

                await smugglerApi.Between(options);

                using (var session = store.OpenAsyncSession(DestinationFilesystem))
                {
                    int activeFiles = 0;
                    for (int i = 0; i < total; i++)
                    {
                        var file = await session.LoadFileAsync(files[i]);
                        if (file != null)
                            activeFiles++;
                    }

                    Assert.Equal(total - deletedFiles, activeFiles);
                }
            }
        }
		public abstract Task Between(SmugglerBetweenOptions betweenOptions);
Beispiel #12
0
		public override Task Between(SmugglerBetweenOptions betweenOptions)
		{
			return SmugglerBetweenOperation.Between(betweenOptions, SmugglerOptions);
		}
        public async Task CanDisableVersioningDuringImport_Between()
        {
            using (var storeExport = NewStore())
            using (var storeImport = NewStore(activeBundles: "Versioning", fileSystemName: "Import", index: 1))
            {
                for (int i = 0; i < 10; i++)
                {
                    await storeExport.AsyncFilesCommands.UploadAsync("test-" + i, StringToStream("hello"));
                }

                await storeImport.AsyncFilesCommands.Configuration.SetKeyAsync(VersioningUtil.DefaultConfigurationName, new VersioningConfiguration
                {
                    Id = VersioningUtil.DefaultConfigurationName
                });

                var fileCount = (await storeExport.AsyncFilesCommands.GetStatisticsAsync()).FileCount;

                var smuggler = new SmugglerFilesApi(new SmugglerFilesOptions()
                {
                    ShouldDisableVersioningBundle = true
                });

                var options = new SmugglerBetweenOptions<FilesConnectionStringOptions>
                {
                    From = new FilesConnectionStringOptions
                    {
                        Url = storeExport.Url,
                        DefaultFileSystem = storeExport.DefaultFileSystem
                    },
                    To = new FilesConnectionStringOptions
                    {
                        Url = storeImport.Url,
                        DefaultFileSystem = storeImport.DefaultFileSystem
                    }
                };

                await smuggler.Between(options);

                var fileCountAfterImport = (await storeImport.AsyncFilesCommands.GetStatisticsAsync()).FileCount;

                Assert.Equal(fileCount, fileCountAfterImport);

                // after import versioning should be active
                await storeImport.AsyncFilesCommands.UploadAsync("with-rev", StringToStream("rev"));

                using (var session = storeImport.OpenAsyncSession())
                {
                    var revisions = await session.GetRevisionsForAsync("with-rev", 0, 10);
                    Assert.Equal(1, revisions.Length);
                }
            }
        }
		public async Task ShouldSmuggleConfigurationsInBetweenOperation()
		{
			using (var exportStore = NewStore())
			using (var importStore = NewStore(1))
			{
				for (int i = 0; i < 100; i++)
				{
					await exportStore.AsyncFilesCommands.Configuration.SetKeyAsync("items/" + i, new RavenJObject
						{
							{
								"test", "value"
							},
							{
								"test-array", new RavenJArray
								{
									"item-1", "item-2", "item-3"
								}
							}
						});
				}

				var countOfConfigurations = (await exportStore.AsyncFilesCommands.Configuration.GetKeyNamesAsync(0, 200)).Length;

				var options = new SmugglerBetweenOptions<FilesConnectionStringOptions>()
				{
					From = new FilesConnectionStringOptions()
					{
						Url = exportStore.Url,
						DefaultFileSystem = exportStore.DefaultFileSystem
					},
					To = new FilesConnectionStringOptions()
					{
						Url = importStore.Url,
						DefaultFileSystem = importStore.DefaultFileSystem
					}
				};

				var smugglerFilesApi = new SmugglerFilesApi();

				smugglerFilesApi.Options.BatchSize = 5;

				await smugglerFilesApi.Between(options);

				Assert.Equal(countOfConfigurations, (await importStore.AsyncFilesCommands.Configuration.GetKeyNamesAsync(0, 200)).Length);

				for (int i = 0; i < 100; i++)
				{
					Assert.NotNull(await importStore.AsyncFilesCommands.Configuration.GetKeyAsync<RavenJObject>("items/" + i));
				}
			}
		}
		public async Task BetweenExportShouldDisableSynchronizationDestinations()
		{
			using (var exportStore = NewStore())
			using (var importStore = NewStore(1))
			{
				await exportStore.AsyncFilesCommands.Synchronization.SetDestinationsAsync(new SynchronizationDestination()
				{
					ServerUrl = "http://sample.com",
					FileSystem = "Sample",
					Enabled = true
				});

				var options = new SmugglerBetweenOptions<FilesConnectionStringOptions>()
				{
					From = new FilesConnectionStringOptions()
					{
						Url = exportStore.Url,
						DefaultFileSystem = exportStore.DefaultFileSystem
					},
					To = new FilesConnectionStringOptions()
					{
						Url = importStore.Url,
						DefaultFileSystem = importStore.DefaultFileSystem
					}
				};

				await new SmugglerFilesApi().Between(options);

				var destinations = await importStore.AsyncFilesCommands.Synchronization.GetDestinationsAsync();

				Assert.Equal(1, destinations.Length);
				Assert.Equal("http://sample.com/fs/Sample", destinations[0].Url);
				Assert.Equal("Sample", destinations[0].FileSystem);
				Assert.False(destinations[0].Enabled);
			}
		}
        public async Task BetweenOperation_CanHandleFilesExceptionsGracefully()
        {
            using (var store = NewStore())
            {
                store.DefaultFileSystem = SourceFilesystem;

                var server = GetServer();

                var alreadyReset = false;
                var port = 8070;
                var forwarder = new ProxyServer(ref port, server.Configuration.Port)
                {
                    VetoTransfer = (totalRead, buffer) =>
                    {
                        var s = Encoding.UTF8.GetString(buffer.Array, buffer.Offset, buffer.Count);
                        if (alreadyReset == false && totalRead > 28000 && !s.Contains("200 OK"))
                        {
                            alreadyReset = true;
                            return true;
                        }
                        return false;
                    }
                };

                try
                {
                    var smugglerApi = new SmugglerFilesApi();

                    var options = new SmugglerBetweenOptions<FilesConnectionStringOptions>
                    {
                        From = new FilesConnectionStringOptions
                        {
                            Url = "http://localhost:" + port,
                            DefaultFileSystem = SourceFilesystem
                        },
                        To = new FilesConnectionStringOptions
                        {
                            Url = store.Url,
                            DefaultFileSystem = DestinationFilesystem
                        }
                    };

                    await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(SourceFilesystem);
                    await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(DestinationFilesystem);

                    ReseedRandom(100); // Force a random distribution.

                    await InitializeWithRandomFiles(store, 20, 30);


                    Etag lastEtag = Etag.InvalidEtag;
                    try
                    {
                        await smugglerApi.Between(options);
                        Assert.False(true, "Expected error to happen during this Between operation, but it didn't happen :-(");
                    }
                    catch (SmugglerExportException inner)
                    {
                        lastEtag = inner.LastEtag;
                    }

                    Assert.NotEqual(Etag.InvalidEtag, lastEtag);

                    await smugglerApi.Between(options);

                    using (var session = store.OpenAsyncSession(DestinationFilesystem))
                    {
                        var files = await session.Commands.BrowseAsync();
                        Assert.Equal(20, files.Count());
                    }
                }
                finally
                {
                    forwarder.Dispose();
                    server.Dispose();
                }
            }
        }
        public async Task BetweenOperation_ContentIsPreserved_SingleFile()
        {
            using (var store = NewStore())
            {
                var server = GetServer();

                ReseedRandom(100); // Force a random distribution.

                int fileSize = 10000;

                var smugglerApi = new SmugglerFilesApi();

                var options = new SmugglerBetweenOptions<FilesConnectionStringOptions>
                {
                    From = new FilesConnectionStringOptions
                    {
                        Url = store.Url,
                        DefaultFileSystem = SourceFilesystem
                    },
                    To = new FilesConnectionStringOptions
                    {
                        Url = store.Url,
                        DefaultFileSystem = DestinationFilesystem
                    }
                };

                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(SourceFilesystem);
                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(DestinationFilesystem);

                var fileContent = CreateRandomFileStream(fileSize);
                using (var session = store.OpenAsyncSession(SourceFilesystem))
                {
                    session.RegisterUpload("test1.file", fileContent);
                    await session.SaveChangesAsync();
                }

                await smugglerApi.Between(options);

                fileContent.Position = 0;
                using (var session = store.OpenAsyncSession(DestinationFilesystem))
                {
                    var file = session.LoadFileAsync("test1.file").Result;

                    Assert.Equal(fileSize, file.TotalSize);

                    var stream = session.DownloadAsync(file).Result;

                    Assert.Equal(fileContent.GetMD5Hash(), stream.GetMD5Hash());
                }
            }
        }
 public abstract Task Between(SmugglerBetweenOptions <RavenConnectionStringOptions> betweenOptions);
        public async Task BetweenOperation_ContentIsPreserved_MultipleDirectories()
        {
            using (var store = NewStore())
            {
                var server = GetServer();

                var smugglerApi = new SmugglerFilesApi();

                var options = new SmugglerBetweenOptions<FilesConnectionStringOptions>
                {
                    From = new FilesConnectionStringOptions
                    {
                        Url = store.Url,
                        DefaultFileSystem = SourceFilesystem
                    },
                    To = new FilesConnectionStringOptions
                    {
                        Url = store.Url,
                        DefaultFileSystem = DestinationFilesystem
                    }
                };

                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(SourceFilesystem);
                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(DestinationFilesystem);

                var files = new Stream[10];
                using (var session = store.OpenAsyncSession(SourceFilesystem))
                {
                    for (int i = 0; i < files.Length; i++)
                    {
                        files[i] = CreateRandomFileStream(100 * i + 12);
                        session.RegisterUpload(i + "/test.file", files[i]);
                    }

                    await session.SaveChangesAsync();
                }

                await smugglerApi.Between(options);

                for (int i = 0; i < files.Length; i++)
                {
                    using (var session = store.OpenAsyncSession(DestinationFilesystem))
                    {
                        var file = await session.LoadFileAsync(i + "/test.file");
                        var stream = await session.DownloadAsync(file);

                        files[i].Position = 0;
                        Assert.Equal(files[i].GetMD5Hash(), stream.GetMD5Hash());
                    }
                }
            }
        }
        public async Task BetweenOperation_CanHandleFilesExceptionsGracefully()
        {
            using (var store = NewStore())
            {
                store.DefaultFileSystem = SourceFilesystem;

                var server = GetServer();

                var alreadyReset = false;
                var forwarder = new ProxyServer(8070, server.Configuration.Port)
                {
                    VetoTransfer = (totalRead, buffer) =>
                    {
                        if (alreadyReset == false && totalRead > 28000)
                        {
                            alreadyReset = true;
                            return true;
                        }
                        return false;
                    }
                };

                var smugglerApi = new SmugglerFilesApi();

                var options = new SmugglerBetweenOptions<FilesConnectionStringOptions>
                {
                    From = new FilesConnectionStringOptions
                    {
                        Url = "http://localhost:8070",
                        DefaultFileSystem = SourceFilesystem
                    },
                    To = new FilesConnectionStringOptions
                    {
                        Url = store.Url,
                        DefaultFileSystem = DestinationFilesystem
                    }
                };

                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(SourceFilesystem);
                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(DestinationFilesystem);

                ReseedRandom(100); // Force a random distribution.

                await InitializeWithRandomFiles(store, 20, 30);


                Etag lastEtag = Etag.InvalidEtag;
                try
                {
                    await smugglerApi.Between(options);
                }
                catch (SmugglerExportException inner)
                {
                    lastEtag = inner.LastEtag;
                }

                Assert.NotEqual(Etag.InvalidEtag, lastEtag);

                await smugglerApi.Between(options);

                using (var session = store.OpenAsyncSession(DestinationFilesystem))
                {
                    var files = await session.Commands.BrowseAsync();
                    Assert.Equal(20, files.Count());
                }
            }
        }
        public async Task BetweenOperation_MetadataIsPreserved()
        {
            using (var store = NewStore())
            {
                var server = GetServer();

                var smugglerApi = new SmugglerFilesApi();

                var options = new SmugglerBetweenOptions<FilesConnectionStringOptions>
                {
                    From = new FilesConnectionStringOptions
                    {
                        Url = store.Url,
                        DefaultFileSystem = SourceFilesystem
                    },
                    To = new FilesConnectionStringOptions
                    {
                        Url = store.Url,
                        DefaultFileSystem = DestinationFilesystem
                    }
                };

                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(SourceFilesystem);
                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(DestinationFilesystem);

                FileHeader originalFile;
                using (var session = store.OpenAsyncSession(SourceFilesystem))
                {
                    session.RegisterUpload("test1.file", CreateRandomFileStream(12800));
                    await session.SaveChangesAsync();

                    // content update after a metadata change
                    originalFile = await session.LoadFileAsync("test1.file");
                    originalFile.Metadata["Test"] = new RavenJValue("Value");
                    await session.SaveChangesAsync();
                }

                await smugglerApi.Between(options);

                using (var session = store.OpenAsyncSession(DestinationFilesystem))
                {
                    var file = await session.LoadFileAsync("test1.file");

                    Assert.Equal(originalFile.CreationDate, file.CreationDate);
                    Assert.Equal(originalFile.Directory, file.Directory);
                    Assert.Equal(originalFile.Extension, file.Extension);
                    Assert.Equal(originalFile.FullPath, file.FullPath);
                    Assert.Equal(originalFile.Name, file.Name);
                    Assert.Equal(originalFile.TotalSize, file.TotalSize);
                    Assert.Equal(originalFile.UploadedSize, file.UploadedSize);
                    Assert.Equal(originalFile.LastModified, file.LastModified);

                    Assert.True(file.Metadata.ContainsKey("Test"));
                }              
            }
        }
        public override Task Between(SmugglerBetweenOptions<RavenConnectionStringOptions> betweenOptions)
		{
			throw new NotSupportedException();
		}
        public static async Task Between(SmugglerBetweenOptions<RavenConnectionStringOptions> betweenOptions, SmugglerDatabaseOptions databaseOptions)
		{
			SetDatabaseNameIfEmpty(betweenOptions.From);
			SetDatabaseNameIfEmpty(betweenOptions.To);

			using (var exportStore = CreateStore(betweenOptions.From))
			using (var importStore = CreateStore(betweenOptions.To))
			{
				SmugglerDatabaseApi.ValidateThatServerIsUpAndDatabaseExists(betweenOptions.From, exportStore);
				SmugglerDatabaseApi.ValidateThatServerIsUpAndDatabaseExists(betweenOptions.To, importStore);

				var exportBatchSize = GetBatchSize(exportStore, databaseOptions);
				var importBatchSize = GetBatchSize(importStore, databaseOptions);

				var exportStoreSupportedFeatures = await DetectServerSupportedFeatures(exportStore);
				var importStoreSupportedFeatures = await DetectServerSupportedFeatures(importStore);

				if (string.IsNullOrEmpty(betweenOptions.IncrementalKey))
				{
					betweenOptions.IncrementalKey = ((AsyncServerClient)exportStore.AsyncDatabaseCommands).Url;
				}

				var incremental = new ExportIncremental();
				if (databaseOptions.Incremental)
				{
					var jsonDocument = await importStore.AsyncDatabaseCommands.GetAsync(SmugglerExportIncremental.RavenDocumentKey);
					if (jsonDocument != null)
					{
						var smugglerExportIncremental = jsonDocument.DataAsJson.JsonDeserialization<SmugglerExportIncremental>();
						ExportIncremental value;
						if (smugglerExportIncremental.ExportIncremental.TryGetValue(betweenOptions.IncrementalKey, out value))
						{
							incremental = value;
						}

						databaseOptions.StartDocsEtag = incremental.LastDocsEtag ?? Etag.Empty;
						databaseOptions.StartAttachmentsEtag = incremental.LastAttachmentsEtag ?? Etag.Empty;
					}
				}

				if (databaseOptions.OperateOnTypes.HasFlag(ItemType.Indexes))
				{
					await ExportIndexes(exportStore, importStore, exportBatchSize);
				}
				if (databaseOptions.OperateOnTypes.HasFlag(ItemType.Transformers) && exportStoreSupportedFeatures.IsTransformersSupported && importStoreSupportedFeatures.IsTransformersSupported)
				{
					await ExportTransformers(exportStore, importStore, exportBatchSize);
				}
				if (databaseOptions.OperateOnTypes.HasFlag(ItemType.Documents))
				{
					incremental.LastDocsEtag = await ExportDocuments(exportStore, importStore, databaseOptions, exportStoreSupportedFeatures, exportBatchSize, importBatchSize);
				}
				if (databaseOptions.OperateOnTypes.HasFlag(ItemType.Attachments))
				{
					incremental.LastAttachmentsEtag = await ExportAttachments(exportStore, importStore, databaseOptions, exportBatchSize);
				}
				if (exportStoreSupportedFeatures.IsIdentitiesSmugglingSupported && importStoreSupportedFeatures.IsIdentitiesSmugglingSupported)
				{
                    await ExportIdentities(exportStore, importStore, databaseOptions.OperateOnTypes);
				}

				if (databaseOptions.Incremental)
				{
					var smugglerExportIncremental = new SmugglerExportIncremental();
					var jsonDocument = await importStore.AsyncDatabaseCommands.GetAsync(SmugglerExportIncremental.RavenDocumentKey);
					if (jsonDocument != null)
					{
						smugglerExportIncremental = jsonDocument.DataAsJson.JsonDeserialization<SmugglerExportIncremental>();
					}
					smugglerExportIncremental.ExportIncremental[betweenOptions.IncrementalKey] = incremental;
					await importStore.AsyncDatabaseCommands.PutAsync(SmugglerExportIncremental.RavenDocumentKey, null, RavenJObject.FromObject(smugglerExportIncremental), new RavenJObject());
				}
			}
		}
Beispiel #24
0
		public override Task Between(SmugglerBetweenOptions betweenOptions)
		{
			throw new NotSupportedException();
		}