protected override void BeginProcessing() { /*Type Runner = ClassResolver.ResolveAssemblyCmdClassByName(CmdClassName, Assembly.GetCallingAssembly()); if (Runner == null) { Runner = ClassResolver.ResolveAssemblyCmdClassByName(CmdClassName, Assembly.GetAssembly(typeof(CmdInterface))); } if (!typeof(CmdInterface).IsAssignableFrom(Runner)) { throw new ArgumentException("The supplied class name (argument 1) is not of type " + typeof(CmdInterface).FullName + "!"); }*/ CmdRunner PCR = new CmdRunner( NumberOfThreads, CmdClass, //(CmdInterface)Activator.CreateInstance(Runner), CmdArguments ); PCR.Start(); Thread.Sleep(WaitTime); PCR.Stop(); WriteObject(PCR.Results); }
public void DeleteEnlistment() { TestResultsHelper.OutputGVFSLogs(this); // Use cmd.exe to delete the enlistment as it properly handles tombstones and reparse points CmdRunner.DeleteDirectoryWithRetry(this.EnlistmentRoot); }
public async Task InitWithEnvVarsWithNonSleetNetConfigVerifyFeedOutput() { using (var testContext = new SleetTestContext()) { var dir = Path.Combine(testContext.Root, "sub"); var args = $"init -c none"; Directory.CreateDirectory(dir); File.WriteAllText(Path.Combine(dir, Config.FileName), @" [config] editor = code "); var envVars = new Dictionary <string, string>() { { "SLEET_FEED_TYPE", "local" }, { "SLEET_FEED_PATH", dir } }; var result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, args, envVars); result.Success.Should().BeTrue(); File.Exists(Path.Combine(dir, "sleet.settings.json")).Should().BeTrue(); } }
public void DeleteCacheDuringHydrations() { GVFSFunctionalTestEnlistment enlistment1 = this.CloneAndMountEnlistment(); Task task1 = Task.Run(() => { this.HydrateEntireRepo(enlistment1); }); while (!task1.IsCompleted) { try { CmdRunner.DeleteDirectoryWithRetry(this.localCachePath); Thread.Sleep(100); } catch (IOException) { // Hydration may have handles into the cache, so failing this delete is expected. } } task1.Exception.ShouldBeNull(); enlistment1.Status().ShouldContain("Mount status: Ready"); }
public void DeleteEnlistment() { // Use cmd.exe to delete the enlistment as it properly handles tombstones // and reparse points CmdRunner cmdRunner = new CmdRunner(); bool enlistmentExists = Directory.Exists(this.EnlistmentRoot); int retryCount = 0; while (enlistmentExists) { string output = cmdRunner.DeleteDirectory(this.EnlistmentRoot); enlistmentExists = Directory.Exists(this.EnlistmentRoot); if (enlistmentExists) { ++retryCount; Thread.Sleep(500); try { if (retryCount > 10) { retryCount = 0; throw new DeleteFolderFailedException(output); } } catch (DeleteFolderFailedException) { // Throw\catch a DeleteFolderFailedException here so that developers who are running the tests // and have a debugger attached can be alerted that something is wrong } } } }
private static void InitCmdRunner() { ConsoleAccess console = new ConsoleAccess(); CmdRunner.InitConsole(console as IConsoleWriter); CmdRunner.SetBotWorkingMode(); }
static void Main(string[] args) { string server = "localhost:8084"; string repository = SampleHelper.GenerateRepositoryWithData(server); string secondRepository = SampleHelper.GenerateEmptyRepository(server); string cmdResult = CmdRunner.ExecuteCommandWithStringResult( string.Format("cm find branch on repositories '{0}' --format={{id}}#{{name}} --nototal", repository), Environment.CurrentDirectory); ArrayList results = SampleHelper.GetListResults(cmdResult, true); List <Branch> branches = GetBranchListFromCmdResult(results); List <ReplicationResult> resultList = new List <ReplicationResult>(); foreach (Branch branch in branches) { resultList.Add(Replicate(branch, repository, secondRepository)); } Console.WriteLine(Environment.NewLine + "Replication complete"); PrintReplicationResult(resultList); Console.ReadLine(); SampleHelper.RemoveSampleRepository(repository); SampleHelper.RemoveSampleRepository(secondRepository); }
public void DeleteCacheDuringHydrations() { GVFSFunctionalTestEnlistment enlistment1 = this.CloneAndMountEnlistment(); string objectsRoot = GVFSHelpers.GetPersistedGitObjectsRoot(enlistment1.DotGVFSRoot).ShouldNotBeNull(); objectsRoot.ShouldBeADirectory(this.fileSystem); Task task1 = Task.Run(() => { this.HydrateEntireRepo(enlistment1); }); while (!task1.IsCompleted) { try { // Delete objectsRoot rather than this.localCachePath as the blob sizes database cannot be deleted while GVFS is mounted CmdRunner.DeleteDirectoryWithRetry(objectsRoot); Thread.Sleep(100); } catch (IOException) { // Hydration may have handles into the cache, so failing this delete is expected. } } task1.Exception.ShouldBeNull(); enlistment1.Status().ShouldContain("Mount status: Ready"); }
void UpdateSelector(WindowTitleBuilder builder) { string selectorInfo; string error; int cmdres = CmdRunner.ExecuteCommandWithResult( string.Format("{0} wi --machinereadable --fieldseparator={1}", DEFAULT_PLASTIC_COMMAND, FIELD_SEPARATOR), mWkPath, out selectorInfo, out error, false); if (cmdres != 0 || !string.IsNullOrEmpty(error)) { return; } string[] chunks = selectorInfo.Trim().Split( new string[] { FIELD_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries); if (chunks.Length != 3) { builder.SetSelector(string.Empty); return; } string selector = string.Format("{0}:{1}@{2}", chunks[0].ToLower(), chunks[1], chunks[2]); builder.SetSelector(selector); }
private static void FillBranchesWithRandomItems(int numBranches, string repositorySpec, bool includeThreadInfo) { int minRandomItems = 2; int maxRandomItems = 6; string threadInfo = includeThreadInfo ? string.Format("THREAD: {0} ", Thread.CurrentThread.ManagedThreadId) : string.Empty; Random r = new Random(DateTime.Now.Millisecond); for (int i = 0; i < numBranches; i++) { string branch = string.Format("br:/main/task{0}", i); CmdRunner.ExecuteCommandWithStringResult( string.Format("cm stb {0}@{1}", branch, repositorySpec), GetWorkspace()); int items = r.Next(minRandomItems, maxRandomItems); Console.WriteLine("{0}Adding {1} random items to {2}", threadInfo, items, branch); for (int j = 0; j < items; j++) { string filename = AddRandomItem(); CheckinItem(filename, "Added " + filename); } } }
public void CmdRunner_ExitCode_InBetween() { bool finalized = false; ManualResetEvent mre = new ManualResetEvent(false); CmdRunner runner = new CmdRunner(runnerFile, runnerArgs + "-delay:2", new ListStringOutputHandler()); runner.Run(false); int ret = runner.GetReturnCode(); Assert.AreEqual(CmdRunner.UNDEFINED_EXITCODE, ret, "While waiting, retCode not as expected"); Assert.IsFalse(finalized, "Finalized should NOT be true here"); runner.processFinished += delegate(object sender, EventArgs e) { mre.Set(); finalized = true; }; mre.WaitOne(2500, false); ret = runner.GetReturnCode(); Assert.That(ret, Is.Not.EqualTo(CmdRunner.UNDEFINED_EXITCODE).After(100), "After the wait, retcode not as expected."); Assert.IsTrue(finalized, "Finalized should be true here"); }
public void DeleteObjectsCacheAndCacheMappingBeforeMount() { GVFSFunctionalTestEnlistment enlistment1 = this.CloneAndMountEnlistment(); GVFSFunctionalTestEnlistment enlistment2 = this.CloneAndMountEnlistment(); enlistment1.UnmountGVFS(); string objectsRoot = GVFSHelpers.GetPersistedGitObjectsRoot(enlistment1.DotGVFSRoot).ShouldNotBeNull(); objectsRoot.ShouldBeADirectory(this.fileSystem); CmdRunner.DeleteDirectoryWithRetry(objectsRoot); string metadataPath = Path.Combine(this.localCachePath, "mapping.dat"); metadataPath.ShouldBeAFile(this.fileSystem); this.fileSystem.DeleteFile(metadataPath); enlistment1.MountGVFS(); Task task1 = Task.Run(() => this.HydrateRootFolder(enlistment1)); Task task2 = Task.Run(() => this.HydrateRootFolder(enlistment2)); task1.Wait(); task2.Wait(); task1.Exception.ShouldBeNull(); task2.Exception.ShouldBeNull(); enlistment1.Status().ShouldContain("Mount status: Ready"); enlistment2.Status().ShouldContain("Mount status: Ready"); this.AlternatesFileShouldHaveGitObjectsRoot(enlistment1); this.AlternatesFileShouldHaveGitObjectsRoot(enlistment2); }
public void DeleteCacheBeforeMount() { GVFSFunctionalTestEnlistment enlistment1 = this.CloneAndMountEnlistment(); GVFSFunctionalTestEnlistment enlistment2 = this.CloneAndMountEnlistment(); enlistment1.UnmountGVFS(); CmdRunner.DeleteDirectoryWithRetry(this.localCachePath); enlistment1.MountGVFS(); Task task1 = Task.Run(() => this.HydrateRootFolder(enlistment1)); Task task2 = Task.Run(() => this.HydrateRootFolder(enlistment2)); task1.Wait(); task2.Wait(); task1.Exception.ShouldBeNull(); task2.Exception.ShouldBeNull(); enlistment1.Status().ShouldContain("Mount status: Ready"); enlistment2.Status().ShouldContain("Mount status: Ready"); this.AlternatesFileShouldHaveGitObjectsRoot(enlistment1); this.AlternatesFileShouldHaveGitObjectsRoot(enlistment2); }
public void MountReusesLocalCacheKeyWhenGitObjectsRootDeleted() { GVFSFunctionalTestEnlistment enlistment = this.CloneAndMountEnlistment(); enlistment.UnmountGVFS(); // Find the current git objects root and ensure it's on disk string objectsRoot = GVFSHelpers.GetPersistedGitObjectsRoot(enlistment.DotGVFSRoot).ShouldNotBeNull(); objectsRoot.ShouldBeADirectory(this.fileSystem); string mappingFilePath = Path.Combine(enlistment.LocalCacheRoot, "mapping.dat"); string mappingFileContents = this.fileSystem.ReadAllText(mappingFilePath); mappingFileContents.Length.ShouldNotEqual(0, "mapping.dat should not be empty"); // Delete the git objects root folder, mount should re-create it and the mapping.dat file should not change CmdRunner.DeleteDirectoryWithRetry(objectsRoot); enlistment.MountGVFS(); GVFSHelpers.GetPersistedGitObjectsRoot(enlistment.DotGVFSRoot).ShouldEqual(objectsRoot); objectsRoot.ShouldBeADirectory(this.fileSystem); mappingFilePath.ShouldBeAFile(this.fileSystem).WithContents(mappingFileContents); this.AlternatesFileShouldHaveGitObjectsRoot(enlistment); }
public string GetLatestBranches() { string command = string.Format(FindBranchesCommand, Repository, DateFormat); string cmdResult = CmdRunner.ExecuteCommandWithStringResult(command, Environment.CurrentDirectory, false); return(string.Format("Latest branches on repository `{0}`: \r\n {1}", Repository, cmdResult)); }
private void Checkin(object sender, EventArgs e) { foreach (Change item in itemsToCommit.Items) { if (item.ChangeType == ChangeType.Added) { CmdRunner.ExecuteCommandWithStringResult( string.Format("cm add {0}", item.Name), SampleHelper.GetWorkspace()); } if (item.ChangeType == ChangeType.Deleted) { CmdRunner.ExecuteCommandWithStringResult( string.Format("cm rm {0}", item.Name), SampleHelper.GetWorkspace()); } } string result = CmdRunner.ExecuteCommandWithStringResult( string.Format("cm ci -c=\"{0}\"", textBox1.Text), SampleHelper.GetWorkspace()); MessageBox.Show(result); textBox1.Text = string.Empty; Update(sender, e); }
private void RefreshChangesetList(object sender, EventArgs e) { string cmdResult = CmdRunner.ExecuteCommandWithStringResult( "cm find changeset --nototal --format=\"{changesetid}#{date}#{comment}\"", SampleHelper.GetWorkspace()); ArrayList results = SampleHelper.GetListResults(cmdResult, true); changesetList.Items.Clear(); foreach (string item in results) { Changeset cset = new Changeset(item); cmdResult = CmdRunner.ExecuteCommandWithStringResult( string.Format("cm log {0} --csFormat=\"{{items}}\" --itemFormat=\"{{path}}#{{fullstatus}}#{{newline}}\"", cset.Id), SampleHelper.GetWorkspace()); results = SampleHelper.GetListResults(cmdResult, true); foreach (string changedItem in results) { cset.Changes.Add(new Item(changedItem)); } changesetList.Items.Add(cset); } }
public void CmdRunner_Basic_ImplicitOutput() { CmdRunner runner = new CmdRunner(runnerFile, runnerArgs); runner.Run(true); Assert.AreEqual(null, runner.outputHandler.GetOutput(), "The output from the command is not as expected."); }
private static void UpdateCommand() { int result = CmdRunner.ExecuteCommandWithResult( String.Format("cm upd {0}", Environment.CurrentDirectory), Environment.CurrentDirectory); Console.WriteLine(string.Format("The update command finished with result: " + result)); }
internal IList FilterBranches(IList branches, string initialdate) { string cmd = mCmExec + " find \"changeset where date >= '" + initialdate + "'\" --format={branch} --nototal on repository '" + mSrcServer + "'"; string cmdres = CmdRunner.ExecuteCommandWithStringResult(cmd, mWkpath); StringReader reader = new StringReader(cmdres); ArrayList filtered = new ArrayList(); // there will be many csets on some branches, only take on // branch for each string line; while ((line = reader.ReadLine()) != null) { if (line.Trim() == string.Empty) { continue; } line = line.Trim(); if (!filtered.Contains(line)) { filtered.Add(line); } } filtered.Sort(); ArrayList result = new ArrayList(); foreach (string branchname in filtered) { // find it on the original list... (it has the id list) foreach (Branch br in branches) { if (br.Name == branchname) { if (!result.Contains(br)) { result.Add(br); } break; } } } result.Sort(new BranchComparer()); return(result); }
public async Task GivenABadCommandVerifyFailure(string arguments) { using (var workingDir = new TestFolder()) { var result = await CmdRunner.RunAsync(ExeUtils.NuGetMirrorExePath, workingDir, arguments); result.Success.Should().BeFalse(); } }
private static void GenerateBranches(string repServer, int numBranches) { for (int i = 0; i < numBranches; i++) { string cmdResult = CmdRunner.ExecuteCommandWithStringResult( string.Format("cm mkbranch br:/main/task{0}", i), GetWorkspace()); } }
public void CmdRunner_ExitCode_Successful() { CmdRunner runner = new CmdRunner(runnerFile, runnerArgs, new ListStringOutputHandler()); runner.Run(true); int ret = runner.GetReturnCode(); Assert.AreEqual(1, ret, "return value for the exit code is not as expected"); }
public void CmdRunner_Basic_NullOutput() { NullOutputHandler nullHandler = new NullOutputHandler(); CmdRunner runner = new CmdRunner(runnerFile, runnerArgs, nullHandler); runner.Run(true); Assert.AreEqual(null, nullHandler.GetOutput(), "The output from the command is not as expected."); }
public async Task GivenABadCommandVerifyFailure(string arguments) { using (var testContext = new SleetTestContext()) { var result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, testContext.Root, arguments); result.Success.Should().BeFalse(); } }
private static void PrintCmBranches() { string cmdResult = CmdRunner.ExecuteCommandWithStringResult( "cm find branches on repository 'default' --nototal", Environment.CurrentDirectory); Console.WriteLine("Branches on default repository:"); PrintResult(cmdResult); Console.WriteLine(); }
public static void CheckinItem(string fileName, string comment) { string addResult = CmdRunner.ExecuteCommandWithStringResult( string.Format("cm add {0}", fileName), GetWorkspace()); string commitResult = CmdRunner.ExecuteCommandWithStringResult( string.Format("cm ci -c=\"{0}\"", comment), GetWorkspace()); }
private static void PrintCmVersion() { string cmVersion = CmdRunner.ExecuteCommandWithStringResult( "cm version", Environment.CurrentDirectory); Console.WriteLine(string.Format("The cm version is: {0}", cmVersion)); Console.WriteLine(); }
List <Branch> GetBranchesFromRepo(string repository) { string cmdResult = CmdRunner.ExecuteCommandWithStringResult( string.Format("cm find branch on repositories '{0}' --format={{id}}#{{name}} --nototal", repository), Environment.CurrentDirectory); ArrayList results = SampleHelper.GetListResults(cmdResult, true); return(GetBranchListFromCmdResult(results)); }
public async Task RunToolWithCreateConfigVerifySuccess() { using (var testContext = new SleetTestContext()) { var dir = Path.Combine(testContext.Root, "project"); Directory.CreateDirectory(dir); var dotnetExe = GetDotnetPath(); var exeFile = new FileInfo(dotnetExe); var nupkgsFolder = Path.Combine(exeFile.Directory.Parent.FullName, "artifacts", "nupkgs"); var sleetNupkg = LocalFolderUtility.GetPackagesV2(nupkgsFolder, "Sleet", NullLogger.Instance) .OrderByDescending(e => e.Nuspec.GetVersion()) .First(); var sleetVersion = sleetNupkg.Nuspec.GetVersion().ToNormalizedString(); var result = await CmdRunner.RunAsync(dotnetExe, dir, "new classlib"); result.Success.Should().BeTrue(); var projectPath = Path.Combine(dir, "project.csproj"); var pathContext = NuGetPathContext.Create(dir); var pathResolver = new FallbackPackagePathResolver(pathContext); // Delete restore assets file var toolInstallPath = Path.Combine(pathContext.UserPackageFolder, ".tools", "sleet"); Delete(new DirectoryInfo(toolInstallPath)); // Delete the tool package itself if it exists var toolPackagePath = Path.Combine(pathContext.UserPackageFolder, "sleet", sleetVersion); Delete(new DirectoryInfo(toolPackagePath)); // Add a reference to the tool var xml = XDocument.Load(projectPath); xml.Root.Add(new XElement(XName.Get("ItemGroup"), new XElement(XName.Get("DotNetCliToolReference"), new XAttribute("Include", "Sleet"), new XAttribute("Version", sleetVersion)))); xml.Save(projectPath); // Restore the tool result = await CmdRunner.RunAsync(dotnetExe, dir, $"restore --source {nupkgsFolder}"); result.Success.Should().BeTrue(); // Run the tool result = await CmdRunner.RunAsync(dotnetExe, dir, $"sleet createconfig"); result.Success.Should().BeTrue(); File.Exists(Path.Combine(dir, "sleet.json")).Should().BeTrue(); } }
private static string GetDotnetPath() { var dotnetExeRelativePath = ".cli/dotnet.exe"; if (!RuntimeEnvironmentHelper.IsWindows) { dotnetExeRelativePath = ".cli/dotnet"; } return(CmdRunner.GetPath(dotnetExeRelativePath)); }
static void Main(string[] args) { // to test GenericCmd: args = new string[] { "GenericCmd", "4", "1000", @"c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe", "-File", @"..\..\..\test.ps1" }; CmdRunner PCR; int waitTime = 10000; int numberOfThreads = 4; try { if (args.Length < 1) { args = new string[] { "DummyCmd" }; } if (args.Length < 2) { args = new string[] { args[0], numberOfThreads.ToString() }; } if (args.Length < 3) { args = new string[] { args[0], args[1], waitTime.ToString() }; } Type Runner = ClassResolver.ResolveCmdClassByName(args[0]); if (Runner == null) Console.WriteLine("NULL"); // is it a type of CmdInterface? if (!typeof(CmdInterface).IsAssignableFrom(Runner)) { throw new ArgumentException("The supplied class name (argument 1) is not of type " + typeof(CmdInterface).FullName + "!"); } if (!int.TryParse(args[1], out numberOfThreads)) { throw new ArgumentException("The supplied number of threads (argument 2) is an invalid number!"); } if (!int.TryParse(args[2], out waitTime)) { throw new ArgumentException("The supplied wait time (argument 3) is an invalid number!"); } if (args.Length < 4) { PCR = new CmdRunner( numberOfThreads, (CmdInterface)Activator.CreateInstance(Runner), null ); } else { PCR = new CmdRunner( numberOfThreads, (CmdInterface)Activator.CreateInstance(Runner), args.Skip(3).ToArray() ); } PCR.Start(); Thread.Sleep(waitTime); PCR.Stop(); foreach (KeyValuePair<int,CmdRunnerResult> kv in PCR.Results) { Console.WriteLine(kv.Key + " = " + kv.Value.FailedCommands + ", " + kv.Value.SuccessfulCommands + " = " + kv.Value.AverageExecutionTime + "ms (AVG)"); } } catch (Exception e) { Console.WriteLine("There was a serious Problem: " + e.Message); } Console.ReadKey(); }