Search in sources :

Example 1 with MessageConsole

use of com.centurylink.mdw.plugin.MessageConsole in project mdw-designer by CenturyLinkCloud.

the class AutomatedTestView method runTests.

public void runTests() {
    // TODO: currently mixed execution of Gherkin/Groovy scripts
    // fails to start LogMessageMonitor in Designer VM (otherwise will
    // conflict with Cucumber-JVM)
    boolean hasGherkin = false;
    for (AutomatedTestCase rtc : testSuite.getTestCases()) {
        if (rtc.isGherkin())
            hasGherkin = true;
    }
    try {
        prepForRun();
        counterData = new CounterData(testSuite.getTestCases().size());
        updateCounterPanel(0, 0, 0, true);
        monitor = null;
        if (!hasGherkin && !testSuite.isDebug())
            monitor = new LogMessageMonitor(testSuite.getProject().getDesignerProxy().getDesignerDataAccess(), testSuite.getProject().isOldNamespaces());
        String msg = designerProxy.checkForServerDbMismatch();
        if (msg != null) {
            MessageDialog.openError(getSite().getShell(), "Server DB Mismatch", msg);
            handleStop();
            return;
        }
        if (StubServer.isRunning())
            StubServer.stop();
        if (testSuite.isStubbing() && !hasGherkin && !testSuite.isDebug()) {
            StubServer.Stubber stubber = new TestStubber();
            int port = testSuite.getProject().getServerSettings().getStubServerPort();
            StubServer.start(testSuite.getProject().getDesignerProxy().getRestfulServer(), port, stubber, testSuite.getProject().isOldNamespaces());
        }
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Automated Test", testSuite.getProject());
        handleStop();
        return;
    }
    Thread background = new Thread(new Runnable() {

        public void run() {
            testCaseStatuses = new HashMap<>();
            updateProgressBar(5, false, false);
            threadPool = new ThreadPool(testSuite.getThreadCount());
            PrintStream printStream = null;
            updateProgressBar(10, false, false);
            if (monitor != null)
                monitor.start(true);
            for (AutomatedTestCase testCase : testSuite.getTestCases()) {
                if (!testSuite.isRunning())
                    continue;
                File resultDir = testCase.getResultsDir();
                try {
                    File executeLog = testCase.getOutputFile();
                    deleteFile(executeLog);
                    if (testCase.isPostman())
                        deleteFile(testCase.getItemOutputFile());
                    if (!executeLog.getParentFile().exists() && !executeLog.getParentFile().mkdirs())
                        throw new IOException("Unable to create test run directory: " + executeLog.getParentFile());
                    PrintStream log = new PrintStream(executeLog);
                    ImageDescriptor icon = MdwPlugin.getImageDescriptor("icons/auto_test.gif");
                    MessageConsole console = MessageConsole.findConsole("Tests", icon, display);
                    printStream = new PrintStream(console.newFileConsoleOutputStream(executeLog));
                    TestCaseRun testCaseRun = designerProxy.prepareTestCase(testCase, 0, resultDir, testSuite.isCreateReplaceResults(), testSuite.isVerbose(), log, monitor, testSuite.isSingleServer(), testSuite.isStubbing(), testSuite.isDebug());
                    masterRequestRunMap.put(testCaseRun.getMasterRequestId(), testCaseRun);
                    testCaseRun.setMasterRequestListener(AutomatedTestView.this);
                    threadPool.execute(testCaseRun);
                    updateTreeAndProgressBar(false);
                    try {
                        Thread.sleep(testSuite.getThreadInterval() * 1000);
                    } catch (InterruptedException ex) {
                    }
                } catch (Exception ex) {
                    PluginMessages.log(ex);
                    testCase.setErrored();
                    updateTreeAndProgressBar(true);
                    testSuite.setRunning(false);
                    if (printStream != null) {
                        ex.printStackTrace(printStream);
                        printStream.close();
                    }
                    handleStop();
                    return;
                }
            }
            while (!threadPool.isTerminated()) {
                // update the tree and the progress bar
                updateTreeAndProgressBar(false);
                if (testSuite.isFinished())
                    threadPool.shutdown();
                try {
                    Thread.sleep(2500);
                } catch (InterruptedException e) {
                }
            }
            updateTreeAndProgressBar(true);
            testSuite.setRunning(false);
            actionGroup.enableStopAction(false);
            actionGroup.enableRerunAction(true);
            File resultsFile = testSuite.getProject().getFunctionTestResultsFile();
            actionGroup.enableFormatFunctionTestResults(resultsFile != null && resultsFile.exists());
            locked = false;
            if (monitor != null && monitor.isBound())
                monitor.shutdown();
            if (printStream != null)
                printStream.close();
        }
    });
    background.start();
}
Also used : PrintStream(java.io.PrintStream) MessageConsole(com.centurylink.mdw.plugin.MessageConsole) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ThreadPool(com.centurylink.mdw.designer.testing.ThreadPool) Stubber(com.centurylink.mdw.designer.testing.StubServer.Stubber) IOException(java.io.IOException) JSONException(org.json.JSONException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) StubServer(com.centurylink.mdw.designer.testing.StubServer) LogMessageMonitor(com.centurylink.mdw.designer.testing.LogMessageMonitor) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) TestCaseRun(com.centurylink.mdw.designer.testing.TestCaseRun) File(java.io.File)

Example 2 with MessageConsole

use of com.centurylink.mdw.plugin.MessageConsole in project mdw-designer by CenturyLinkCloud.

the class LogWatcher method startup.

public void startup(boolean watchProcess) {
    this.watchProcess = watchProcess;
    if (logListener != null)
        // already started
        return;
    pattern = Pattern.compile(MESSAGE_REG_EX, Pattern.DOTALL);
    processInstancePages = new HashMap<Long, ProcessInstancePage>();
    processInstances = new HashMap<Long, ProcessInstanceVO>();
    accumulated = new LinkedList<ProcessInstanceUpdater>();
    scheduleShutdown = false;
    MessageConsole console = MessageConsole.findConsole("Live View Log", icon, display);
    console.setRunnableEntity(this);
    console.setDefaultShowPref(true);
    console.setStatus(MessageConsole.STATUS_RUNNING);
    console.clearConsole();
    outputStream = console.newMessageStream();
    try {
        dataAccess = new DesignerDataAccess(process.getProject().getDesignerProxy().getDesignerDataAccess());
        logListener = new LogSubscriberSocket(dataAccess, serverSettings.getLogWatcherPort(), process.getProject().isOldNamespaces()) {

            protected void handleMessage(String message) {
                handleLogMessage(message);
            }
        };
        logListener.start(true);
        new Thread(new Runnable() {

            public void run() {
                processQueue();
            }
        }).start();
    } catch (Exception ex) {
        if (outputStream != null)
            ex.printStackTrace(new PrintStream(outputStream));
        if (logListener != null && !logListener.isClosed()) {
            logListener.shutdown();
            logListener = null;
        }
        PluginMessages.uiError(ex, "Monitor Logs", process.getProject());
    }
}
Also used : PrintStream(java.io.PrintStream) MessageConsole(com.centurylink.mdw.plugin.MessageConsole) IOException(java.io.IOException) LogSubscriberSocket(com.centurylink.mdw.designer.runtime.LogSubscriberSocket) ProcessInstancePage(com.centurylink.mdw.designer.runtime.ProcessInstancePage) DesignerDataAccess(com.centurylink.mdw.designer.DesignerDataAccess) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO)

Example 3 with MessageConsole

use of com.centurylink.mdw.plugin.MessageConsole in project mdw-designer by CenturyLinkCloud.

the class LogWatcher method shutdown.

public void shutdown() {
    if (logListener != null) {
        logListener.shutdown();
        logListener = null;
    }
    if (outputStream != null) {
        try {
            outputStream.println("...Monitoring Terminated");
            outputStream.close();
            outputStream = null;
        } catch (IOException ex) {
            PluginMessages.log(ex);
        }
    }
    MessageConsole messageConsole = MessageConsole.findConsole("Live View Log", icon, display);
    messageConsole.setStatus(MessageConsole.STATUS_TERMINATED);
}
Also used : MessageConsole(com.centurylink.mdw.plugin.MessageConsole) IOException(java.io.IOException)

Aggregations

MessageConsole (com.centurylink.mdw.plugin.MessageConsole)3 IOException (java.io.IOException)3 PrintStream (java.io.PrintStream)2 DesignerDataAccess (com.centurylink.mdw.designer.DesignerDataAccess)1 LogSubscriberSocket (com.centurylink.mdw.designer.runtime.LogSubscriberSocket)1 ProcessInstancePage (com.centurylink.mdw.designer.runtime.ProcessInstancePage)1 LogMessageMonitor (com.centurylink.mdw.designer.testing.LogMessageMonitor)1 StubServer (com.centurylink.mdw.designer.testing.StubServer)1 Stubber (com.centurylink.mdw.designer.testing.StubServer.Stubber)1 TestCaseRun (com.centurylink.mdw.designer.testing.TestCaseRun)1 ThreadPool (com.centurylink.mdw.designer.testing.ThreadPool)1 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)1 AutomatedTestCase (com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 JSONException (org.json.JSONException)1