示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogExceptionStacktrace() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void shouldLogExceptionStacktrace()
        {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            Logger logger = Logger.getLogger(typeof(ProcessScope).FullName);

            using (MemoryStream @out = new MemoryStream(), )
            {
                Handler handler = new StreamHandler(@out, new SimpleFormatter());
                logger.addHandler(handler);
                try
                {
                    ProcessScope scope    = new ProcessScope();
                    object       variable = scope.get("testObject", null);
                    assertNull(variable);
                }
                finally
                {
                    handler.flush();
                    handler.close();
                    logger.removeHandler(handler);
                }
                // test for logged exception
                string message = StringHelper.NewString(@out.toByteArray(), StandardCharsets.UTF_8);
                assertTrue(message.Length > 0);
                assertTrue(message.Contains("org.camunda.bpm.engine.spring.components.scope.ProcessScope get"));
                assertTrue(message.Contains("couldn't return value from process scope! java.lang.NullPointerException"));
                assertTrue(message.Contains("at org.camunda.bpm.engine.spring.components.scope.ProcessScope.getExecutionId(ProcessScope.java:"));
                assertTrue(message.Contains("at org.camunda.bpm.engine.spring.components.scope.ProcessScope.getConversationId(ProcessScope.java:"));
                assertTrue(message.Contains("at org.camunda.bpm.engine.spring.components.scope.ProcessScope.get(ProcessScope.java:"));
                assertTrue(message.Contains("at org.camunda.bpm.engine.spring.test.components.scope.ProcessScopeTest.shouldLogExceptionStacktrace(ProcessScopeTest.java:"));
            }
        }
示例#2
0
        public TreeNode CreateVirtualEnvironment(EnvDTE.Project project, out string envName, out string envPath)
        {
            var environmentsNode = OpenSolutionExplorer().FindChildOfProject(project, Strings.Environments);

            environmentsNode.Select();

            using (var pss = new ProcessScope("python")) {
                using (var createVenv = AutomationDialog.FromDte(this, "Python.AddVirtualEnvironment")) {
                    envPath = new TextBox(createVenv.FindByAutomationId("VirtualEnvPath")).GetValue();
                    var baseInterp = new ComboBox(createVenv.FindByAutomationId("BaseInterpreter")).GetSelectedItemName();

                    envName = string.Format("{0} ({1})", envPath, baseInterp);

                    Console.WriteLine("Expecting environment named: {0}", envName);

                    // Force a wait for the view to be updated.
                    var wnd = (DialogWindowVersioningWorkaround)HwndSource.FromHwnd(
                        new IntPtr(createVenv.Element.Current.NativeWindowHandle)
                        ).RootVisual;
                    wnd.Dispatcher.Invoke(() => {
                        var view = (AddVirtualEnvironmentView)wnd.DataContext;
                        return(view.UpdateInterpreter(view.BaseInterpreter));
                    }).Wait();

                    createVenv.ClickButtonByAutomationId("Create");
                    createVenv.ClickButtonAndClose("Close", nameIsAutomationId: true);
                }

                var nowRunning = pss.WaitForNewProcess(TimeSpan.FromMinutes(1));
                if (nowRunning == null || !nowRunning.Any())
                {
                    Assert.Fail("Failed to see python process start to create virtualenv");
                }
                foreach (var p in nowRunning)
                {
                    if (p.HasExited)
                    {
                        continue;
                    }
                    try {
                        p.WaitForExit(30000);
                    } catch (Win32Exception ex) {
                        Console.WriteLine("Error waiting for process ID {0}\n{1}", p.Id, ex);
                    }
                }
            }

            try {
                return(OpenSolutionExplorer().WaitForChildOfProject(project, Strings.Environments, envName));
            } finally {
                var text = GetOutputWindowText("General");
                if (!string.IsNullOrEmpty(text))
                {
                    Console.WriteLine("** Output Window text");
                    Console.WriteLine(text);
                    Console.WriteLine("***");
                    Console.WriteLine();
                }
            }
        }
示例#3
0
        public void DeleteVirtualEnv()
        {
            using (var app = new PythonVisualStudioApp())
                using (var procs = new ProcessScope("Microsoft.PythonTools.Analyzer"))
                    using (var dis = Init(app)) {
                        var options        = app.GetService <PythonToolsService>().GeneralOptions;
                        var oldAutoAnalyze = options.AutoAnalyzeStandardLibrary;
                        app.OnDispose(() => { options.AutoAnalyzeStandardLibrary = oldAutoAnalyze; options.Save(); });
                        options.AutoAnalyzeStandardLibrary = false;
                        options.Save();

                        var project = CreateTemporaryProject(app);

                        string   envName, envPath;
                        TreeNode env = app.CreateVirtualEnvironment(project, out envName, out envPath);

                        // Need to wait some more for the database to be loaded.
                        app.WaitForNoDialog(TimeSpan.FromSeconds(10.0));

                        for (int retries = 3; !procs.ExitNewProcesses() && retries >= 0; --retries)
                        {
                            Thread.Sleep(1000);
                            Console.WriteLine("Failed to close all analyzer processes (remaining retries {0})", retries);
                        }

                        env.Select();
                        using (var removeDeleteDlg = RemoveItemDialog.FromDte(app)) {
                            removeDeleteDlg.Delete();
                        }

                        app.WaitForNoDialog(TimeSpan.FromSeconds(5.0));

                        app.OpenSolutionExplorer().WaitForChildOfProjectRemoved(
                            project,
                            Strings.Environments,
                            envName
                            );

                        var projectHome = (string)project.Properties.Item("ProjectHome").Value;
                        envPath = Path.Combine(projectHome, envPath);
                        for (int retries = 10;
                             Directory.Exists(envPath) && retries > 0;
                             --retries)
                        {
                            Thread.Sleep(1000);
                        }
                        Assert.IsFalse(Directory.Exists(envPath), envPath);
                    }
        }
示例#4
0
        public void DeleteVEnv(PythonVisualStudioApp app)
        {
            using (var procs = new ProcessScope("Microsoft.PythonTools.Analyzer"))
                using (var dis = InitPython3(app)) {
                    var project = CreateTemporaryProject(app);

                    TreeNode env = app.CreateProjectVirtualEnvironment(project, out string envName, out string envPath);

                    // Need to wait some more for the database to be loaded.
                    app.WaitForNoDialog(TimeSpan.FromSeconds(10.0));

                    for (int retries = 3; !procs.ExitNewProcesses() && retries >= 0; --retries)
                    {
                        Thread.Sleep(1000);
                        Console.WriteLine("Failed to close all analyzer processes (remaining retries {0})", retries);
                    }

                    env.Select();
                    using (var removeDeleteDlg = RemoveItemDialog.FromDte(app)) {
                        removeDeleteDlg.Delete();
                    }

                    app.WaitForNoDialog(TimeSpan.FromSeconds(5.0));

                    app.OpenSolutionExplorer().WaitForChildOfProjectRemoved(
                        project,
                        Strings.Environments,
                        envName
                        );

                    for (int retries = 10;
                         Directory.Exists(envPath) && retries > 0;
                         --retries)
                    {
                        Thread.Sleep(1000);
                    }
                    Assert.IsFalse(Directory.Exists(envPath), envPath);
                }
        }
示例#5
0
        private static void LaunchAndVerifyNoDebug(
            VisualStudioApp app,
            int port,
            string textInResponse
            )
        {
            bool   prevNormal = true, prevAbnormal = true;
            string text;
            int    retries;

            try {
                using (var processes = new ProcessScope("python")) {
                    EndToEndLog("Transitioning to UI thread to build");
                    app.ServiceProvider.GetUIThread().Invoke(() => {
                        EndToEndLog("Building");
                        app.Dte.Solution.SolutionBuild.Build(true);
                        EndToEndLog("Build output: {0}", app.GetOutputWindowText("Build"));
                        EndToEndLog("Updating settings");
                        prevNormal   = app.GetService <PythonToolsService>().DebuggerOptions.WaitOnNormalExit;
                        prevAbnormal = app.GetService <PythonToolsService>().DebuggerOptions.WaitOnAbnormalExit;
                        app.GetService <PythonToolsService>().DebuggerOptions.WaitOnNormalExit   = false;
                        app.GetService <PythonToolsService>().DebuggerOptions.WaitOnAbnormalExit = false;

                        EndToEndLog("Starting running");
                        app.Dte.Solution.SolutionBuild.Run();
                        EndToEndLog("Running");
                    });

                    var newProcesses = processes.WaitForNewProcess(TimeSpan.FromSeconds(30)).ToList();
                    Assert.IsTrue(newProcesses.Any(), "Did not find new Python process");
                    EndToEndLog("Found new processes with IDs {0}", string.Join(", ", newProcesses.Select(p => p.Id.ToString())));

                    for (retries = 100;
                         retries > 0 &&
                         !IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Any(p => p.Port == port);
                         --retries)
                    {
                        Thread.Sleep(300);
                    }
                    EndToEndLog("Active at http://localhost:{0}/", port);

                    text = WebDownloadUtility.GetString(new Uri(string.Format("http://localhost:{0}/", port)));
                }
            } finally {
                app.ServiceProvider.GetUIThread().Invoke(() => {
                    app.GetService <PythonToolsService>().DebuggerOptions.WaitOnNormalExit   = prevNormal;
                    app.GetService <PythonToolsService>().DebuggerOptions.WaitOnAbnormalExit = prevAbnormal;
                });
            }

            EndToEndLog("Response from http://localhost:{0}/", port);
            EndToEndLog(text);
            Assert.IsTrue(text.Contains(textInResponse), text);

            for (retries = 20;
                 retries > 0 && !IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().All(p => p.Port != port);
                 --retries)
            {
                Thread.Sleep(500);
            }
            if (retries > 0)
            {
                EndToEndLog("Process ended");
            }
            else
            {
                EndToEndLog("Timed out waiting for process to exit");
            }
        }
示例#6
0
        public TreeNode CreateVirtualEnvironment(EnvDTE.Project project, out string envName, out string envPath) {
            var environmentsNode = OpenSolutionExplorer().FindChildOfProject(
                project,
                SR.GetString(SR.Environments)
            );
            environmentsNode.Select();

            using (var pss = new ProcessScope("python")) {
                using (var createVenv = AutomationDialog.FromDte(this, "Python.AddVirtualEnvironment")) {
                    envPath = new TextBox(createVenv.FindByAutomationId("VirtualEnvPath")).GetValue();
                    var baseInterp = new ComboBox(createVenv.FindByAutomationId("BaseInterpreter")).GetSelectedItemName();

                    envName = string.Format("{0} ({1})", envPath, baseInterp);

                    Console.WriteLine("Expecting environment named: {0}", envName);

                    // Force a wait for the view to be updated.
                    var wnd = (DialogWindowVersioningWorkaround)HwndSource.FromHwnd(
                        new IntPtr(createVenv.Element.Current.NativeWindowHandle)
                    ).RootVisual;
                    wnd.Dispatcher.Invoke(() => {
                        var view = (AddVirtualEnvironmentView)wnd.DataContext;
                        return view.UpdateInterpreter(view.BaseInterpreter);
                    }).Wait();

                    createVenv.ClickButtonByAutomationId("Create");
                    createVenv.ClickButtonAndClose("Close", nameIsAutomationId: true);
                }

                var nowRunning = pss.WaitForNewProcess(TimeSpan.FromMinutes(1));
                if (nowRunning == null || !nowRunning.Any()) {
                    Assert.Fail("Failed to see python process start to create virtualenv");
                }
                foreach (var p in nowRunning) {
                    if (p.HasExited) {
                        continue;
                    }
                    try {
                        p.WaitForExit(30000);
                    } catch (Win32Exception ex) {
                        Console.WriteLine("Error waiting for process ID {0}\n{1}", p.Id, ex);
                    }
                }
            }

            try {
                return OpenSolutionExplorer().WaitForChildOfProject(
                    project,
                    SR.GetString(SR.Environments),
                    envName
                );
            } finally {
                var text = GetOutputWindowText("General");
                if (!string.IsNullOrEmpty(text)) {
                    Console.WriteLine("** Output Window text");
                    Console.WriteLine(text);
                    Console.WriteLine("***");
                    Console.WriteLine();
                }
            }
        }