public async Task WillUseDefaultNetworkCredentialsWhenServerRequiresAuthentication()
        {
            var server = CreateRavenDbServer(Ports[0], fileSystemName: "WillUseDefaultCredentials", enableAuthentication: true); // enable authentication

            using (var client = new RavenFileSystemClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "WillUseDefaultCredentials"))
            {
                await client.Admin.CreateFileSystemAsync(new DatabaseDocument()
                {
                    Id = "Raven/FileSystem/" + client.FileSystemName,
                    Settings =
                    {
                        {"Raven/FileSystem/DataDir", Path.Combine("~", Path.Combine("FileSystems", client.FileSystemName))}
                    }
                });

                await client.UploadAsync("a", new NameValueCollection(), new MemoryStream(new byte[] {1, 2}));

                var ms = new MemoryStream();
                await client.DownloadAsync("a", ms);

                var array = ms.ToArray();
                Assert.Equal(1, array[0]);
                Assert.Equal(2, array[1]);
            }
        }
Пример #2
0
        public async Task WillUseDefaultNetworkCredentialsWhenServerRequiresAuthentication()
        {
            var server = CreateRavenDbServer(Ports[0], fileSystemName: "WillUseDefaultCredentials", enableAuthentication: true); // enable authentication

            using (var client = new RavenFileSystemClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "WillUseDefaultCredentials"))
            {
                await client.Admin.CreateFileSystemAsync(new DatabaseDocument()
                {
                    Id       = "Raven/FileSystem/" + client.FileSystemName,
                    Settings =
                    {
                        { "Raven/FileSystem/DataDir", Path.Combine("FileSystems", client.FileSystemName) }
                    }
                });

                await client.UploadAsync("a", new MemoryStream(new byte[] { 1, 2 }));

                var ms = new MemoryStream();
                await client.DownloadAsync("a", ms);

                var array = ms.ToArray();
                Assert.Equal(1, array[0]);
                Assert.Equal(2, array[1]);
            }
        }
Пример #3
0
		static void SimpleTest(RavenFileSystemClient fs)
		{
			var ms = new MemoryStream();
			var streamWriter = new StreamWriter(ms);
			var expected = new string('a', 1024);
			streamWriter.Write(expected);
			streamWriter.Flush();
			ms.Position = 0;
			fs.UploadAsync("abc.txt", ms).Wait();

			var ms2 = new MemoryStream();
			fs.DownloadAsync("abc.txt", ms2).Wait();

			ms2.Position = 0;

			var actual = new StreamReader(ms2).ReadToEnd();
			Console.WriteLine(actual.Length);
		}
		public void Should_synchronize_to_all_destinations()
		{
			StartServerInstance(AddtitionalServerInstancePortNumber);

			var sourceContent = SyncTestUtils.PrepareSourceStream(10000);
			sourceContent.Position = 0;

			var sourceClient = NewClient(0);

			var destination1Client = NewClient(1);
			var destination2Client = new RavenFileSystemClient(ServerAddress(AddtitionalServerInstancePortNumber));

			var destination1Content = new RandomlyModifiedStream(sourceContent, 0.01);
			sourceContent.Position = 0;
			var destination2Content = new RandomlyModifiedStream(sourceContent, 0.01);
			sourceContent.Position = 0;

			destination1Client.UploadAsync("test.bin", destination1Content).Wait();
			destination2Client.UploadAsync("test.bin", destination2Content).Wait();

			sourceContent.Position = 0;
			sourceClient.UploadAsync("test.bin", sourceContent).Wait();
			sourceContent.Position = 0;

			sourceClient.Config.SetConfig(SynchronizationConstants.RavenSynchronizationDestinations, new NameValueCollection
				                                                                                         {
					                                                                                         {
						                                                                                         "url",
						                                                                                         destination1Client
						                                                                                         .ServerUrl
					                                                                                         },
					                                                                                         {
						                                                                                         "url",
						                                                                                         destination2Client
						                                                                                         .ServerUrl
					                                                                                         }
				                                                                                         }).Wait();

			var destinationSyncResults = sourceClient.Synchronization.SynchronizeDestinationsAsync().Result;

			// we expect conflicts after first attempt of synchronization
			Assert.Equal(2, destinationSyncResults.Length);
			Assert.Equal("File test.bin is conflicted", destinationSyncResults[0].Reports.ToArray()[0].Exception.Message);
			Assert.Equal("File test.bin is conflicted", destinationSyncResults[1].Reports.ToArray()[0].Exception.Message);

			destination1Client.Synchronization.ResolveConflictAsync("test.bin", ConflictResolutionStrategy.RemoteVersion).Wait();
			destination2Client.Synchronization.ResolveConflictAsync("test.bin", ConflictResolutionStrategy.RemoteVersion).Wait();

			destinationSyncResults = sourceClient.Synchronization.SynchronizeDestinationsAsync().Result;

			// check if reports match
			Assert.Equal(2, destinationSyncResults.Length);
			var result1 = destinationSyncResults[0].Reports.ToArray()[0];
			Assert.Equal(sourceContent.Length, result1.BytesCopied + result1.BytesTransfered);

			var result2 = destinationSyncResults[1].Reports.ToArray()[0];
			Assert.Equal(sourceContent.Length, result2.BytesCopied + result2.BytesTransfered);

			// check content of files
			string destination1Md5;
			using (var resultFileContent = new MemoryStream())
			{
				destination1Client.DownloadAsync("test.bin", resultFileContent).Wait();
				resultFileContent.Position = 0;
				destination1Md5 = resultFileContent.GetMD5Hash();
			}

			string destination2Md5;
			using (var resultFileContent = new MemoryStream())
			{
				destination2Client.DownloadAsync("test.bin", resultFileContent).Wait();
				resultFileContent.Position = 0;
				destination2Md5 = resultFileContent.GetMD5Hash();
			}

			sourceContent.Position = 0;
			var sourceMd5 = sourceContent.GetMD5Hash();

			Assert.Equal(sourceMd5, destination1Md5);
			Assert.Equal(sourceMd5, destination2Md5);
			Assert.Equal(destination1Md5, destination2Md5);
		}
		public async Task File_content_change_should_be_propagated()
		{
			StartServerInstance(AddtitionalServerInstancePortNumber);

			var buffer = new byte[1024*1024*2]; // 2 MB
			new Random().NextBytes(buffer);

			var content = new MemoryStream(buffer);
			var changedContent = new RandomlyModifiedStream(content, 0.02);

			var server1 = NewClient(0);
			var server2 = NewClient(1);
			var server3 = new RavenFileSystemClient(ServerAddress(AddtitionalServerInstancePortNumber));

			content.Position = 0;
			server1.UploadAsync("test.bin", new NameValueCollection {{"test", "value"}}, content).Wait();

			SyncTestUtils.TurnOnSynchronization(server1, server2);

			Assert.Null(server1.Synchronization.SynchronizeDestinationsAsync().Result[0].Exception);

			SyncTestUtils.TurnOnSynchronization(server2, server3);

			Assert.Null(server2.Synchronization.SynchronizeDestinationsAsync().Result[0].Exception);

			SyncTestUtils.TurnOffSynchronization(server1);

			content.Position = 0;
			server1.UploadAsync("test.bin", changedContent).Wait();

			SyncTestUtils.TurnOnSynchronization(server1, server2);

			var secondServer1Synchronization = await server1.Synchronization.SynchronizeDestinationsAsync();
			Assert.Null(secondServer1Synchronization[0].Exception);
			Assert.Equal(SynchronizationType.ContentUpdate, secondServer1Synchronization[0].Reports.ToArray()[0].Type);

			var secondServer2Synchronization = await server2.Synchronization.SynchronizeDestinationsAsync();
			Assert.Null(secondServer2Synchronization[0].Exception);
			Assert.Equal(SynchronizationType.ContentUpdate, secondServer2Synchronization[0].Reports.ToArray()[0].Type);

			// On all servers should have the same content of the file
			string server1Md5;
			using (var resultFileContent = new MemoryStream())
			{
				server1.DownloadAsync("test.bin", resultFileContent).Wait();
				resultFileContent.Position = 0;
				server1Md5 = resultFileContent.GetMD5Hash();
			}

			string server2Md5;
			using (var resultFileContent = new MemoryStream())
			{
				server2.DownloadAsync("test.bin", resultFileContent).Wait();
				resultFileContent.Position = 0;
				server2Md5 = resultFileContent.GetMD5Hash();
			}

			string server3Md5;
			using (var resultFileContent = new MemoryStream())
			{
				server3.DownloadAsync("test.bin", resultFileContent).Wait();
				resultFileContent.Position = 0;
				server3Md5 = resultFileContent.GetMD5Hash();
			}

			Assert.Equal(server1Md5, server2Md5);
			Assert.Equal(server2Md5, server3Md5);
		}
Пример #6
0
		static void DownloadFiles(RavenFileSystemClient client)
		{
			var files = Directory.GetFiles(@"C:\@DemoData");

			Console.WriteLine("Downloading {0} files", files.Length);

			foreach (var f in files)
			{
				Console.WriteLine();

				var filename = Path.GetFileName(f);

				try
				{
					var sw = new Stopwatch();
					sw.Start();

					var stream = File.Create(Path.Combine(@"C:\@DemoFiles", filename));

					Console.WriteLine("** Downloading: {0}", filename);
					client.DownloadAsync(filename, stream).Wait();

					stream.Close();
					stream.Dispose();

					sw.Stop();
					Console.WriteLine("** Done: {0}: Seconds {1}", filename,
									  (sw.ElapsedMilliseconds / 1000));
				}
				catch (Exception ex)
				{
					Console.WriteLine(ex.InnerException);
				}
			}
		}