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();
}
Aggregations