Search in sources :

Example 1 with LoadTestLogMonitor

use of com.centurylink.mdw.designer.testing.LoadTestLogMonitor in project mdw-designer by CenturyLinkCloud.

the class AutomatedTestView method runLoadTests.

public void runLoadTests() {
    int totalRunCount = 0;
    for (AutomatedTestCase testCase : testSuite.getTestCases()) totalRunCount += testCase.getRunCount();
    testSuite.setRunCount(totalRunCount);
    try {
        prepForRun();
        counterData = new CounterData(testSuite.getRunCount());
        updateCounterPanel(0, 0, 0, true);
        monitorObj = new LoadTestLogMonitor(testSuite.getProject().getDesignerProxy().getDesignerDataAccess(), masterRequestRunMap, null);
        String msg = designerProxy.checkForServerDbMismatch();
        if (msg != null) {
            MessageDialog.openError(getSite().getShell(), "Server DB Mismatch", msg);
            handleStop();
            return;
        }
        if (testSuite.isStubbing()) {
            StubServer.Stubber stubber = new TestStubber();
            if (StubServer.isRunning())
                StubServer.stop();
            int port = testSuite.getProject().getServerSettings().getStubServerPort();
            StubServer.start(testSuite.getProject().getDesignerProxy().getRestfulServer(), port, stubber, testSuite.getProject().isOldNamespaces());
        }
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Load 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());
            long startTime = System.currentTimeMillis();
            int totalPrepared = 0;
            int totalCompleted = 0;
            try {
                startTime = System.currentTimeMillis();
                monitorObj.start(true);
                for (AutomatedTestCase testCase : testSuite.getTestCases()) {
                    File resultDir = testCase.getResultsDir();
                    File executeLog = new File(resultDir.getPath() + "/execute.log");
                    int ct = testCase.getRunCount();
                    for (int k = 0; k < ct; k++) {
                        deleteFile(executeLog);
                        if (!executeLog.getParentFile().exists() && !executeLog.getParentFile().mkdirs())
                            throw new IOException("Unable to create test run directory: " + executeLog.getParentFile());
                        PrintStream log = new PrintStream(executeLog);
                        TestCaseRun testCaseRun = designerProxy.prepareTestCase(testCase, k, resultDir, false, testSuite.isVerbose(), log, monitorObj, testSuite.isSingleServer(), testSuite.isStubbing(), false);
                        totalPrepared++;
                        testCase.getTestCase().setNumberPrepared(totalPrepared);
                        masterRequestRunMap.put(testCaseRun.getMasterRequestId(), testCaseRun);
                        threadPool.execute(testCaseRun);
                        updateTreeAndProgressBar(false);
                        try {
                            Thread.sleep(testSuite.getThreadInterval() * 1000);
                        } catch (InterruptedException ex) {
                        }
                    }
                }
                updateProgressBar(10, false, false);
                // server's commonThreadPool
                while (!threadPool.isTerminated()) {
                    // update the tree and the progress bar
                    updateTreeAndProgressBar(false);
                    if (testSuite.isFinished())
                        threadPool.shutdown();
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
                testSuite.setRunning(false);
                actionGroup.enableStopAction(false);
                actionGroup.enableRerunAction(true);
                File resultsFile = testSuite.getProject().getLoadTestResultsFile();
                actionGroup.enableFormatLoadTestResults(resultsFile != null && resultsFile.exists());
            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                if (monitorObj != null)
                    monitorObj.shutdown();
                locked = false;
            }
            try {
                generateLoadTestReport(totalPrepared, totalCompleted, monitorObj, startTime, testSuite.getResultsDir().toString());
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
    });
    background.start();
}
Also used : PrintStream(java.io.PrintStream) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ThreadPool(com.centurylink.mdw.designer.testing.ThreadPool) FileNotFoundException(java.io.FileNotFoundException) 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) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) TestCaseRun(com.centurylink.mdw.designer.testing.TestCaseRun) LoadTestLogMonitor(com.centurylink.mdw.designer.testing.LoadTestLogMonitor) File(java.io.File)

Aggregations

LoadTestLogMonitor (com.centurylink.mdw.designer.testing.LoadTestLogMonitor)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 AutomatedTestCase (com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 JSONException (org.json.JSONException)1