public void ClientSideBigFileAddition(string canonical_name, string localPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare checkout directory. string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name); CleanDirectory(localDirectory); Console.WriteLine("Synced to clean state."); IActivityListener activityListener = new Mock<IActivityListener>().Object; RepoInfo repoInfo = new RepoInfo( canonical_name, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, new DateTime(1900, 01, 01), true); using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener)) { using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(repoInfo, cmis, activityListener)) using (Watcher watcher = new Watcher(localDirectory)) { synchronizedFolder.resetFailedOperationsCounter(); synchronizedFolder.Sync(); Console.WriteLine("Synced to clean state."); // Create random big file. string filename = LocalFilesystemActivityGenerator.GetNextFileName(); string remoteFilePath = (remoteFolderPath + "/" + filename).Replace("//", "/"); watcher.EnableRaisingEvents = true; LocalFilesystemActivityGenerator.CreateRandomFile(localDirectory, 1000); // 1 MB ... no that big to not load servers too much. WatcherTest.WaitWatcher((int)repoInfo.PollInterval, watcher, 1); // Sync again. Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder,delegate { try{ IDocument d = (IDocument)CreateSession(repoInfo).GetObjectByPath(remoteFilePath); if(d!=null) return true; }catch(Exception) {return false;} return false; })); Console.WriteLine("Second sync done."); // Check that file is present server-side. IDocument doc = (IDocument)CreateSession(repoInfo).GetObjectByPath(remoteFilePath); Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); // Clean. Console.WriteLine("Clean all."); Clean(localDirectory, synchronizedFolder); } } }
public void ResumeBigFile(string canonical_name, string localPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare checkout directory. string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name); string canonical_name2 = canonical_name + ".BigFile"; string localDirectory2 = Path.Combine(CMISSYNCDIR, canonical_name2); CleanDirectory(localDirectory); CleanDirectory(localDirectory2); Console.WriteLine("Synced to clean state."); string filename = "ResumeBigFile.File"; int fileSizeInMB = 10; string file = Path.Combine(localDirectory, filename); string file2 = Path.Combine(localDirectory2, filename); // Mock. IActivityListener activityListener = new Mock<IActivityListener>().Object; // Sync. RepoInfo repoInfo = new RepoInfo( canonical_name, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, DateTime.MinValue, true); repoInfo.ChunkSize = 1024 * 1024; RepoInfo repoInfo2 = new RepoInfo( canonical_name2, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, DateTime.MinValue, true); repoInfo2.ChunkSize = 1024 * 1024; using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(repoInfo, cmis, activityListener)) { synchronizedFolder.resetFailedOperationsCounter(); synchronizedFolder.Sync(); CleanAll(localDirectory); WatcherTest.WaitWatcher(); synchronizedFolder.Sync(); Console.WriteLine("Synced to clean state."); } // create file byte[] data = new byte[1024 * 1024]; new Random().NextBytes(data); using (FileStream stream = File.OpenWrite(file)) { for (int i = 0; i < fileSizeInMB; i++) { stream.Write(data, 0, data.Length); } } string remoteFilePath = (remoteFolderPath + "/" + filename).Replace("//", "/"); Console.WriteLine(String.Format("Upload big file size: {0}MB", fileSizeInMB)); for (int currentFileSizeInMB = 0, retry = 0; currentFileSizeInMB < fileSizeInMB && retry < 100; ++retry) { using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(repoInfo, cmis, activityListener)) { // disable the chunk upload //synchronizedFolder.SyncInBackground(); //System.Threading.Thread.Sleep(1000); synchronizedFolder.Sync(); } try { IDocument doc = (IDocument)CreateSession(repoInfo).GetObjectByPath(remoteFilePath); long fileSize = doc.ContentStreamLength ?? 0; Assert.IsTrue(0 == fileSize % (1024 * 1024)); currentFileSizeInMB = (int)(fileSize / 1024 / 1024); } catch (Exception) { } Console.WriteLine("Upload big file, current size: {0}MB", currentFileSizeInMB); } Console.WriteLine(String.Format("Download big file size: {0}MB", fileSizeInMB)); for (int currentFileSizeInMB = 0, retry = 0; currentFileSizeInMB < fileSizeInMB && retry < 100; ++retry) { using (CmisRepo cmis2 = new CmisRepo(repoInfo2, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder2 = new CmisRepo.SynchronizedFolder(repoInfo2, cmis2, activityListener)) { synchronizedFolder2.SyncInBackground(true); System.Threading.Thread.Sleep(1000); } string file2Tmp = file2 + ".sync"; FileInfo info = new FileInfo(file2); FileInfo infoTmp = new FileInfo(file2Tmp); if (infoTmp.Exists) { currentFileSizeInMB = (int)(infoTmp.Length / 1024 / 1024); } else if (info.Exists) { currentFileSizeInMB = (int)(info.Length / 1024 / 1024); } Console.WriteLine("Download big file, current size: {0}MB", currentFileSizeInMB); } string checksum1 = Database.Checksum(file); string checksum2 = Database.Checksum(file2); Assert.IsTrue(checksum1 == checksum2); using (CmisRepo cmis2 = new CmisRepo(repoInfo2, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder2 = new CmisRepo.SynchronizedFolder(repoInfo2, cmis2, activityListener)) { // Clean. Console.WriteLine("Clean all."); Clean(localDirectory2, synchronizedFolder2); } }
public void ClientSideDirectoryAndSmallFilesAddition(string canonical_name, string localPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare checkout directory. string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name); CleanDirectory(localDirectory); Console.WriteLine("Synced to clean state."); IActivityListener activityListener = new Mock<IActivityListener>().Object; RepoInfo repoInfo = new RepoInfo( canonical_name, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, new DateTime(1900, 01, 01), true); using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener)) { using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder( repoInfo, cmis, activityListener)) { synchronizedFolder.resetFailedOperationsCounter(); synchronizedFolder.Sync(); Console.WriteLine("Synced to clean state."); // Create directory and small files. LocalFilesystemActivityGenerator.CreateDirectoriesAndFiles(localDirectory); // Sync again. synchronizedFolder.Sync(); Console.WriteLine("Second sync done."); // Clean. Console.WriteLine("Clean all."); Clean(localDirectory, synchronizedFolder); } } }
public void SyncWhileModifyingFolders(string canonical_name, string localPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare checkout directory. string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name); CleanDirectory(localDirectory); Console.WriteLine("Synced to clean state."); // Mock. IActivityListener activityListener = new Mock<IActivityListener>().Object; // Sync. RepoInfo repoInfo = new RepoInfo( canonical_name, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, DateTime.MinValue, true); using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener)) { using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder( repoInfo, cmis, new Mock<IActivityListener>().Object)) { synchronizedFolder.resetFailedOperationsCounter(); synchronizedFolder.Sync(); Console.WriteLine("Synced to clean state."); // Sync a few times in a different thread. bool syncing = true; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += new DoWorkEventHandler( delegate(Object o, DoWorkEventArgs args) { for (int i = 0; i < 10; i++) { Console.WriteLine("Sync D" + i.ToString()); synchronizedFolder.Sync(); } } ); bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler( delegate(object o, RunWorkerCompletedEventArgs args) { syncing = false; } ); bw.RunWorkerAsync(); // Keep creating/removing a file as long as sync is going on. int count = 1000; while (syncing) { count--; if (count <= 0) { System.Threading.Thread.Sleep(1000); } //Console.WriteLine("Create/remove."); LocalFilesystemActivityGenerator.CreateDirectoriesAndFiles(localDirectory); CleanAll(localDirectory); } // Clean. Console.WriteLine("Clean all."); Clean(localDirectory, synchronizedFolder); } } }
public void SyncConcurrentHeavyFolder(string canonical_name, string localPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare checkout directory. string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name); CleanDirectory(localDirectory); Console.WriteLine("Synced to clean state."); // Mock. IActivityListener activityListener = new Mock<IActivityListener>().Object; // Sync. RepoInfo repoInfo = new RepoInfo( canonical_name, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 100, false, DateTime.MinValue, true); using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(repoInfo, cmis, activityListener)) { synchronizedFolder.resetFailedOperationsCounter(); synchronizedFolder.Sync(); CleanAll(localDirectory); WatcherTest.WaitWatcher(); synchronizedFolder.Sync(); Console.WriteLine("Synced to clean state."); // Invoke the backend synchronize for concurrent cmis.Initialize(); ISession session = CreateSession(repoInfo); IFolder folder = (IFolder)session.GetObjectByPath(remoteFolderPath); string name1 = "SyncConcurrent.1"; string path1 = Path.Combine(localDirectory, name1); string name2 = "SyncConcurrent.2"; string path2 = Path.Combine(localDirectory, name2); // create heavy folder in concurrent Console.WriteLine(" Concurrent create heavy folder"); Assert.IsFalse(Directory.Exists(path1)); IFolder folder1 = CreateFolder(folder, name1); Assert.IsTrue(WaitUntilDone(delegate { return Directory.Exists(path1); })); Assert.IsTrue(Directory.Exists(path1)); CreateHeavyFolderRemote(folder1); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate { return CheckHeavyFolder(path1); })); Assert.IsTrue(CheckHeavyFolder(path1)); // rename heavy folder in concurrent Console.WriteLine(" Concurrent rename heavy folder"); IFolder folder2 = RenameFolder(folder1, name2); Assert.IsTrue(WaitUntilDone(delegate { return CheckHeavyFolder(path2); })); Assert.IsTrue(CheckHeavyFolder(path2)); // move heavy folder in concurrent Console.WriteLine(" Concurrent move heavy folder"); folder1 = CreateFolder(folder, name1); folder2.Move(folder, folder1); Assert.IsTrue(WaitUntilDone(delegate { return CheckHeavyFolder(Path.Combine(path1, name2)); })); Assert.IsTrue(CheckHeavyFolder(Path.Combine(path1, name2))); // delete heavy folder in concurrent Console.WriteLine(" Remote delete heavy folder"); folder1.DeleteTree(true, null, true); Assert.IsTrue(WaitUntilDone(delegate { return !Directory.Exists(path1); })); Assert.IsFalse(Directory.Exists(path1)); // create and delete heavy folder in concurrent Console.WriteLine(" Remote create and delete heavy folder"); cmis.Suspend(); folder1 = CreateFolder(folder, name1); CreateHeavyFolderRemote(folder1); cmis.Resume(); folder1.DeleteTree(true, null, true); Assert.IsTrue(WaitUntilDone(delegate { return !Directory.Exists(path1); })); Assert.IsFalse(Directory.Exists(path1)); // Clean. Console.WriteLine("Clean all."); Clean(localDirectory, synchronizedFolder); } }
public void SyncEqualityHeavyFolder(string canonical_name, string localPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare checkout directory. string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name); string canonical_name2 = canonical_name + ".equality"; string localDirectory2 = Path.Combine(CMISSYNCDIR, canonical_name2); CleanDirectory(localDirectory); CleanDirectory(localDirectory2); Console.WriteLine("Synced to clean state."); // Mock. IActivityListener activityListener = new Mock<IActivityListener>().Object; // Sync. RepoInfo repoInfo = new RepoInfo( canonical_name, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, DateTime.MinValue, true); RepoInfo repoInfo2 = new RepoInfo( canonical_name2, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, DateTime.MinValue, true); using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(repoInfo, cmis, activityListener)) using (CmisRepo cmis2 = new CmisRepo(repoInfo2, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder2 = new CmisRepo.SynchronizedFolder(repoInfo2, cmis2, activityListener)) using (Watcher watcher = new Watcher(localDirectory)) using (Watcher watcher2 = new Watcher(localDirectory2)) { synchronizedFolder.resetFailedOperationsCounter(); synchronizedFolder2.resetFailedOperationsCounter(); synchronizedFolder.Sync(); synchronizedFolder2.Sync(); CleanAll(localDirectory); CleanAll(localDirectory2); WatcherTest.WaitWatcher(); synchronizedFolder.Sync(); synchronizedFolder2.Sync(); Console.WriteLine("Synced to clean state."); string oldname = "SyncEquality.Old"; string newname = "SyncEquality.New"; // test heavy folder create Console.WriteLine(" Local create heavy folder"); string oldfolder = Path.Combine(localDirectory, oldname); string oldfolder2 = Path.Combine(localDirectory2, oldname); Directory.CreateDirectory(oldfolder); CreateHeavyFolder(oldfolder); Assert.IsTrue(CheckHeavyFolder(oldfolder)); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { synchronizedFolder.Sync(); return CheckHeavyFolder(oldfolder2); }, 10)); Assert.IsTrue(CheckHeavyFolder(oldfolder2)); // test heavy folder rename Console.WriteLine(" Local rename heavy folder"); string newfolder = Path.Combine(localDirectory, newname); string newfolder2 = Path.Combine(localDirectory2, newname); Directory.Move(oldfolder, newfolder); Assert.IsTrue(CheckHeavyFolder(newfolder)); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { synchronizedFolder.Sync(); return CheckHeavyFolder(newfolder2); }, 10)); Assert.IsTrue(CheckHeavyFolder(newfolder2)); // test heavy folder move Console.WriteLine(" Local move heavy folder"); Directory.CreateDirectory(oldfolder); Directory.Move(newfolder,Path.Combine(oldfolder,newname)); newfolder = Path.Combine(oldfolder, newname); newfolder2 = Path.Combine(oldfolder2, newname); Assert.IsTrue(CheckHeavyFolder(newfolder)); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { synchronizedFolder.Sync(); return CheckHeavyFolder(newfolder2); }, 10)); Assert.IsTrue(CheckHeavyFolder(newfolder2)); // test heavy folder delete Console.WriteLine(" Local delete heavy folder"); Directory.Delete(newfolder, true); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { synchronizedFolder.Sync(); return !Directory.Exists(newfolder2); }, 10)); Assert.IsTrue(!Directory.Exists(newfolder2)); // Clean. Console.WriteLine("Clean all."); Clean(localDirectory, synchronizedFolder); Clean(localDirectory2, synchronizedFolder2); } }
public void SyncEmptyFileEquality(string canonical_name, string localPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare checkout directory. string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name); string canonical_name2 = canonical_name + ".equality"; string localDirectory2 = Path.Combine(CMISSYNCDIR, canonical_name2); CleanDirectory(localDirectory); CleanDirectory(localDirectory2); Console.WriteLine("Synced to clean state."); // Mock. IActivityListener activityListener = new Mock<IActivityListener>().Object; // Sync. RepoInfo repoInfo = new RepoInfo( canonical_name, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, DateTime.MinValue, true); RepoInfo repoInfo2 = new RepoInfo( canonical_name2, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, DateTime.MinValue, true); using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(repoInfo, cmis, activityListener)) using (CmisRepo cmis2 = new CmisRepo(repoInfo2, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder2 = new CmisRepo.SynchronizedFolder(repoInfo2, cmis2, activityListener)) using (Watcher watcher = new Watcher(localDirectory)) using (Watcher watcher2 = new Watcher(localDirectory2)) { synchronizedFolder.resetFailedOperationsCounter(); synchronizedFolder2.resetFailedOperationsCounter(); synchronizedFolder.Sync(); synchronizedFolder2.Sync(); CleanAll(localDirectory); CleanAll(localDirectory2); WatcherTest.WaitWatcher(); synchronizedFolder.Sync(); synchronizedFolder2.Sync(); Console.WriteLine("Synced to clean state."); string filename = "empty-file.bin"; string file = Path.Combine(localDirectory, filename); string file2 = Path.Combine(localDirectory2, filename); watcher.EnableRaisingEvents = true; // Writing an empty file to the first local folder using(FileStream stream = File.Create(Path.Combine(localDirectory, filename))){ stream.Close(); }; WatcherTest.WaitWatcher((int)repoInfo.PollInterval, watcher, 1); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate { return WaitUntilSyncIsDone(synchronizedFolder2, delegate{ int files = Directory.GetFiles(localDirectory).Length; int files2 = Directory.GetFiles(localDirectory2).Length; Assert.LessOrEqual(files, 1, String.Format("There are more files ({0}) as has been created in the source repo", files)); Assert.LessOrEqual(files2, 1, String.Format("There are more files ({0}) as has been created in the target repo", files)); return File.Exists(file) && File.Exists(file2); }, 1); }, 20)); } }
public void SyncEquality(string canonical_name, string localPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare checkout directory. string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name); string canonical_name2 = canonical_name + ".equality"; string localDirectory2 = Path.Combine(CMISSYNCDIR, canonical_name2); CleanDirectory(localDirectory); CleanDirectory(localDirectory2); Console.WriteLine("Synced to clean state."); // Mock. IActivityListener activityListener = new Mock<IActivityListener>().Object; // Sync. RepoInfo repoInfo = new RepoInfo( canonical_name, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, DateTime.MinValue, true); RepoInfo repoInfo2 = new RepoInfo( canonical_name2, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, DateTime.MinValue, true); using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(repoInfo, cmis, activityListener)) using (CmisRepo cmis2 = new CmisRepo(repoInfo2, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder2 = new CmisRepo.SynchronizedFolder(repoInfo2, cmis2, activityListener)) using (Watcher watcher = new Watcher(localDirectory)) using (Watcher watcher2 = new Watcher(localDirectory2)) { synchronizedFolder.resetFailedOperationsCounter(); synchronizedFolder2.resetFailedOperationsCounter(); synchronizedFolder.Sync(); synchronizedFolder2.Sync(); CleanAll(localDirectory); CleanAll(localDirectory2); WatcherTest.WaitWatcher(); synchronizedFolder.Sync(); synchronizedFolder2.Sync(); Console.WriteLine("Synced to clean state."); // create file // remote filename = /SyncEquality.File Console.WriteLine("create file test."); string filename = "SyncEquality.File"; string file = Path.Combine(localDirectory, filename); string file2 = Path.Combine(localDirectory2, filename); Assert.IsFalse(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); watcher.EnableRaisingEvents = true; int length = 1024; using (Stream stream = File.OpenWrite(file)) { byte[] content = new byte[length]; stream.Write(content, 0, content.Length); } Assert.IsTrue(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); WatcherTest.WaitWatcher((int)repoInfo2.PollInterval, watcher, 1); watcher.EnableRaisingEvents = false; watcher.RemoveAll(); synchronizedFolder.Sync(); Assert.IsTrue(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { FileInfo info = new FileInfo(file2); return info.Exists && info.Length == length; })); Assert.IsTrue(File.Exists(file)); Assert.IsTrue(File.Exists(file2)); // create folder // remote folder name = /SyncEquality.Folder Console.WriteLine("create folder test."); string foldername = "SyncEquality.Folder"; string folder = Path.Combine(localDirectory, foldername); string folder2 = Path.Combine(localDirectory2, foldername); Assert.IsFalse(Directory.Exists(folder)); Assert.IsFalse(Directory.Exists(folder2)); watcher.EnableRaisingEvents = true; Directory.CreateDirectory(folder); Assert.IsTrue(Directory.Exists(folder)); Assert.IsFalse(Directory.Exists(folder2)); WatcherTest.WaitWatcher((int)repoInfo2.PollInterval, watcher, 1); watcher.EnableRaisingEvents = false; watcher.RemoveAll(); synchronizedFolder.Sync(); Assert.IsTrue(Directory.Exists(folder)); Assert.IsFalse(Directory.Exists(folder2)); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { return Directory.Exists(folder2); })); Assert.IsTrue(Directory.Exists(folder)); Assert.IsTrue(Directory.Exists(folder2)); // move file // /SyncEquality.File -> /SyncEquality.Folder/SyncEquality.File Console.WriteLine("move file test."); string source = file; file = Path.Combine(folder, filename); file2 = Path.Combine(folder2, filename); Assert.IsFalse(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); watcher.EnableRaisingEvents = true; File.Move(source, file); Assert.IsTrue(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); WatcherTest.WaitWatcher((int)repoInfo2.PollInterval, watcher, 1); watcher.EnableRaisingEvents = false; watcher.RemoveAll(); synchronizedFolder.Sync(); Assert.IsTrue(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { return File.Exists(file2); })); Assert.IsTrue(File.Exists(file)); Assert.IsTrue(File.Exists(file2)); // move folder // create a folder as move target = /SyncEquality.Folder.2/ Console.WriteLine("move folder test."); string foldername2 = "SyncEquality.Folder.2"; folder = Path.Combine(localDirectory, foldername2); folder2 = Path.Combine(localDirectory2, foldername2); Assert.IsFalse(Directory.Exists(folder)); Assert.IsFalse(Directory.Exists(folder2)); watcher.EnableRaisingEvents = true; Directory.CreateDirectory(folder); Assert.IsTrue(Directory.Exists(folder)); Assert.IsFalse(Directory.Exists(folder2)); WatcherTest.WaitWatcher((int)repoInfo2.PollInterval, watcher, 1); watcher.EnableRaisingEvents = false; watcher.RemoveAll(); synchronizedFolder.Sync(); Assert.IsTrue(Directory.Exists(folder)); Assert.IsFalse(Directory.Exists(folder2)); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { return Directory.Exists(folder2); })); Assert.IsTrue(Directory.Exists(folder)); Assert.IsTrue(Directory.Exists(folder2)); //move to the created folder // moved folder = /SyncEquality.Folder/ // target folder = /SyncEquality.Folder.2/ // result = /SyncEquality.Folder.2/SyncEquality.Folder/ file = Path.Combine(folder, foldername, filename); file2 = Path.Combine(folder2, foldername, filename); Assert.IsFalse(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); watcher.EnableRaisingEvents = true; Directory.Move( Path.Combine(localDirectory, foldername), Path.Combine(folder, foldername)); Assert.IsTrue(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); WatcherTest.WaitWatcher((int)repoInfo2.PollInterval, watcher, 1); watcher.EnableRaisingEvents = false; watcher.RemoveAll(); synchronizedFolder.Sync(); Assert.IsTrue(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { return File.Exists(file2); })); Assert.IsTrue(File.Exists(file)); Assert.IsTrue(File.Exists(file2)); //change filecontent // remote file path = /SyncEquality.Folder.2/SyncEquality.Folder/SyncEquality.File Console.WriteLine("update file test."); int filecount = Directory.GetFiles(Path.Combine(folder, foldername)).Count(); int filecount2 = Directory.GetFiles(Path.Combine(folder2, foldername)).Count(); length = 2048; Assert.IsTrue(filecount == filecount2); Assert.IsTrue(filecount == 1); Console.WriteLine(" filecontent size = "+ length.ToString()); watcher.EnableRaisingEvents = true; using (Stream stream = File.OpenWrite(file)) { byte[] content = new byte[length]; stream.Write(content, 0, content.Length); } WatcherTest.WaitWatcher((int)repoInfo2.PollInterval, watcher, 1); watcher.EnableRaisingEvents = false; watcher.RemoveAll(); synchronizedFolder.Sync(); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { if(filecount2 == Directory.GetFiles(Path.Combine(folder2, foldername)).Count()) { FileInfo info = new FileInfo(file2); return info.Exists && info.Length == length; } else { return false; } }, 20)); Assert.AreEqual(filecount, Directory.GetFiles(Path.Combine(folder, foldername)).Count()); Assert.AreEqual(filecount2, Directory.GetFiles(Path.Combine(folder2, foldername)).Count()); Console.WriteLine(" checking file content equality"); using (Stream stream = File.OpenRead(file)) using (Stream stream2 = File.OpenRead(file2)) { Assert.IsTrue(stream.Length == stream2.Length && stream2.Length == length); byte[] content = new byte[length]; byte[] content2 = new byte[length]; stream.Read(content,0,length); stream.Read(content2,0,length); for(int i = 0; i < length; i++) Assert.AreEqual(content[i], content2[i]); } // delete file // remote file path = /SyncEquality.Folder.2/SyncEquality.Folder/SyncEquality.File Console.WriteLine("delete file test."); Assert.IsTrue(File.Exists(file)); Assert.IsTrue(File.Exists(file2)); watcher.EnableRaisingEvents = true; File.Delete(file); Assert.IsFalse(File.Exists(file)); Assert.IsTrue(File.Exists(file2)); WatcherTest.WaitWatcher((int)repoInfo2.PollInterval, watcher, 1); watcher.EnableRaisingEvents = false; watcher.RemoveAll(); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate { return WaitUntilSyncIsDone(synchronizedFolder2, delegate{ return !File.Exists(file) && !File.Exists(file2); }, 1); }, 20)); Assert.IsFalse(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); // delete folder tree // delete remote folder = /SyncEquality.Folder.2/ Console.WriteLine("delete folder tree test."); Assert.IsTrue(Directory.Exists(folder)); Assert.IsTrue(Directory.Exists(folder2)); watcher.EnableRaisingEvents = true; Directory.Delete(folder, true); Assert.IsFalse(Directory.Exists(folder)); Assert.IsTrue(Directory.Exists(folder2)); WatcherTest.WaitWatcher((int)repoInfo2.PollInterval, watcher, 1); watcher.EnableRaisingEvents = false; watcher.RemoveAll(); synchronizedFolder.Sync(); Assert.IsFalse(Directory.Exists(folder)); Assert.IsTrue(Directory.Exists(folder2)); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { return !Directory.Exists(folder2); }, 20)); Assert.IsFalse(Directory.Exists(folder)); Assert.IsFalse(Directory.Exists(folder2)); // Clean. Console.WriteLine("Clean all."); Clean(localDirectory, synchronizedFolder); Clean(localDirectory2, synchronizedFolder2); } }
public void SyncRenamedFiles(string canonical_name, string localPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare checkout directory. string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name); string canonical_name2 = canonical_name + ".equality"; string localDirectory2 = Path.Combine(CMISSYNCDIR, canonical_name2); CleanDirectory(localDirectory); CleanDirectory(localDirectory2); Console.WriteLine("Synced to clean state."); // Mock. IActivityListener activityListener = new Mock<IActivityListener>().Object; // Sync. RepoInfo repoInfo = new RepoInfo( canonical_name, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, DateTime.MinValue, true); RepoInfo repoInfo2 = new RepoInfo( canonical_name2, CMISSYNCDIR, remoteFolderPath, url, user, password, repositoryId, 5000, false, DateTime.MinValue, true); using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(repoInfo, cmis, activityListener)) using (CmisRepo cmis2 = new CmisRepo(repoInfo2, activityListener)) using (CmisRepo.SynchronizedFolder synchronizedFolder2 = new CmisRepo.SynchronizedFolder(repoInfo2, cmis2, activityListener)) using (Watcher watcher = new Watcher(localDirectory)) using (Watcher watcher2 = new Watcher(localDirectory2)) { synchronizedFolder.resetFailedOperationsCounter(); synchronizedFolder2.resetFailedOperationsCounter(); synchronizedFolder.Sync(); synchronizedFolder2.Sync(); CleanAll(localDirectory); CleanAll(localDirectory2); WatcherTest.WaitWatcher(); synchronizedFolder.Sync(); synchronizedFolder2.Sync(); Console.WriteLine("Synced to clean state."); // create file // remote filename = /SyncEquality.File Console.WriteLine("create file test."); string filename = "SyncRename.File"; string file = Path.Combine(localDirectory, filename); string file2 = Path.Combine(localDirectory2, filename); int localFilesCount = 0; int localFilesCount2 = 0; Assert.IsFalse(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); watcher.EnableRaisingEvents = true; int length = 1024; using (Stream stream = File.OpenWrite(file)) { byte[] content = new byte[length]; stream.Write(content, 0, content.Length); } Assert.IsTrue(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); WatcherTest.WaitWatcher((int)repoInfo2.PollInterval, watcher, 1); watcher.EnableRaisingEvents = false; watcher.RemoveAll(); Assert.IsTrue(File.Exists(file)); Assert.IsFalse(File.Exists(file2)); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { synchronizedFolder.Sync(); FileInfo info = new FileInfo(file2); return info.Exists && info.Length == length; }), String.Format("The new file \"{0}\"should exist and it should have got the length \"{1}\"", file2, length)); Assert.IsTrue(File.Exists(file)); Assert.IsTrue(File.Exists(file2)); localFilesCount = Directory.GetFiles(localDirectory).Length; localFilesCount2 = Directory.GetFiles(localDirectory2).Length; Assert.AreEqual(localFilesCount, localFilesCount2, String.Format("Both local folder should contain one file before renaming a file, but there are {0} and {1} files", localFilesCount, localFilesCount2)); // Only one file should exist Assert.AreEqual(1, localFilesCount2, String.Format("There should exist only one file in the local folder before renaming, but there are {0}", localFilesCount2)); string renamedfilename = "SyncRenameTarget.File"; string renamedfile = Path.Combine(localDirectory, renamedfilename); string renamedfile2 = Path.Combine(localDirectory2, renamedfilename); watcher.EnableRaisingEvents = true; File.Move(file, renamedfile); WatcherTest.WaitWatcher((int) repoInfo2.PollInterval, watcher, 1); watcher.EnableRaisingEvents = false; watcher.RemoveAll(); Assert.IsTrue(File.Exists(renamedfile)); Assert.IsTrue(!File.Exists(renamedfile2)); Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder2, delegate { synchronizedFolder.Sync(); FileInfo info = new FileInfo(renamedfile2); return info.Exists && info.Length == length; })); localFilesCount = Directory.GetFiles(localDirectory).Length; localFilesCount2 = Directory.GetFiles(localDirectory2).Length; Assert.AreEqual(localFilesCount, localFilesCount2, String.Format("Both local folder should contain one file, but there are {0} and {1} files", localFilesCount, localFilesCount2)); // Only one file should exist Assert.AreEqual(1, localFilesCount2, String.Format("There should exist only one file in the local folder, but there are {0}", localFilesCount2)); } }