public static CreateRandomFile ( string path, int maxSizeInKb ) : void | ||
path | string | |
maxSizeInKb | int | |
return | void |
public void Real(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Create temporary folder for configuration and data files. string tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); string configurationFolder = Path.Combine(tempFolder, "configuration"); Directory.CreateDirectory(tempFolder); Directory.CreateDirectory(configurationFolder); // Create XML config file. string customConfigPath = Path.Combine(configurationFolder, "config.xml"); string logPath = Path.Combine(configurationFolder, "debug_log.txt"); string localDataPath = Path.Combine(tempFolder, "data"); string customConfig = File.ReadAllText(@"../../config.xml"); // Replace variables in template customConfig.Replace("{LOG}", logPath); customConfig.Replace("{LOCAL_FOLDER}", localDataPath); customConfig.Replace("{REMOTE_FOLDER}", remoteFolderPath); customConfig.Replace("{URL}", url); customConfig.Replace("{USER}", user); customConfig.Replace("{PASSWORD}", password); customConfig.Replace("{REPOSITORY}", repositoryId); File.WriteAllText(customConfigPath, customConfig); Process process = Process.Start(CONSOLE_EXE, "-p -c " + customConfigPath); if (null == process) { Assert.Fail("Could not start process, maybe an existing process has been reused?"); } process.OutputDataReceived += (s, e) => Console.WriteLine(e.Data); process.ErrorDataReceived += (s, e) => Console.WriteLine(e.Data); //Clean(canonicalName, localPath, remoteFolderPath, url, user, password, repositoryId); // TODO clean the remote folder and delete/create local folder // Create random small file. string filename = LocalFilesystemActivityGenerator.GetNextFileName(); string remoteFilePath = (remoteFolderPath + "/" + filename).Replace("//", "/"); LocalFilesystemActivityGenerator.CreateRandomFile(localDataPath, 3); Thread.Sleep(10 * 1000); // Wait for 10 seconds so that sync gets a chance to sync things. // Check that file is present server-side. IDocument doc = (IDocument)CreateSession(url, user, password, repositoryId).GetObjectByPath(remoteFilePath, true); Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); // Exit the process to avoid any possible interference with subsequent tests. process.Kill(); }
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, ".", remoteFolderPath, url, user, password, repositoryId, 5000); using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener)) { using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder( repoInfo, activityListener, cmis)) { synchronizedFolder.Sync(); Console.WriteLine("Synced to clean state."); // Create random big file. LocalFilesystemActivityGenerator.CreateRandomFile(localDirectory, 1000); // 1 MB ... no that big to not load servers too much. // Sync again. synchronizedFolder.Sync(); Console.WriteLine("Second sync done."); // Check that file is present server-side. // TODO // Clean. Console.WriteLine("Clean all."); Clean(localDirectory, synchronizedFolder); } } }
public void ClientSideSmallFileAddition(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); // Mock. ActivityListener activityListener = new Mock <ActivityListener>().Object; // Sync. RepoInfo repoInfo = new RepoInfo( canonical_name, ".", remoteFolderPath, url, user, password, repositoryId, 5000); CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder( repoInfo, activityListener, new CmisRepo(repoInfo, activityListener) ); synchronizedFolder.Sync(); Console.WriteLine("Synced to clean state."); // Create random small file. LocalFilesystemActivityGenerator.CreateRandomFile(localDirectory, 3); // Sync again. synchronizedFolder.Sync(); Console.WriteLine("Second sync done."); // Check that file is present server-side. // TODO // Clean. Clean(localDirectory, synchronizedFolder); }
public void SyncWhileModifyingFiles(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); using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener)) { using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder( repoInfo, activityListener, cmis)) { 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 F" + 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. while (syncing) { //Console.WriteLine("Create/remove " + LocalFilesystemActivityGenerator.id); LocalFilesystemActivityGenerator.CreateRandomFile(localDirectory, 3); CleanAll(localDirectory); } // Clean. Console.WriteLine("Clean all."); Clean(localDirectory, synchronizedFolder); } } }
public void SyncWhileModifyingFile(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); // Mock. ActivityListener activityListener = new Mock <ActivityListener>().Object; // Sync. RepoInfo repoInfo = new RepoInfo( canonical_name, ".", remoteFolderPath, url, user, password, repositoryId, 5000); CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder( repoInfo, activityListener, new CmisRepo(repoInfo, activityListener) ); 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) { // Clean. CleanDirectory(Path.Combine(CMISSYNCDIR, canonical_name)); // Mock. ActivityListener activityListener2 = new Mock <ActivityListener>().Object; // Sync. RepoInfo repoInfo2 = new RepoInfo( canonical_name, ".", remoteFolderPath, url, user, password, repositoryId, 5000); CmisRepo.SynchronizedFolder synchronizedFolder2 = new CmisRepo.SynchronizedFolder( repoInfo, activityListener, new CmisRepo(repoInfo, activityListener) ); for (int i = 0; i < 10; i++) { Console.WriteLine("Sync."); synchronizedFolder2.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. while (syncing) { Console.WriteLine("Create/remove."); LocalFilesystemActivityGenerator.CreateRandomFile(localDirectory, 3); DirectoryInfo localDirectoryInfo = new DirectoryInfo(localDirectory); foreach (FileInfo file in localDirectoryInfo.GetFiles()) { try { file.Delete(); } catch (IOException e) { Console.WriteLine("Exception on testing side, ignoring"); } } } // Clean. Clean(localDirectory, synchronizedFolder); }