📄 staxtestcaseactionfactory.java
字号:
{ if (!activeTestcaseMap.containsKey(testcaseName)) { STAXActiveTestcase activeTest = new STAXActiveTestcase(testcaseName, new STAXTimestamp()); activeTestcaseMap.put(testcaseName, activeTest); // Start the testcase theTest.start(job); } } // Update Testcase status theTest.updateStatus(status, message, job); return new STAFResult(STAFResult.Ok); } private STAFResult handleStartRequest( STAFServiceInterfaceLevel30.RequestInfo info, STAX staxService) { // Verify the requesting machine/user has at least trust level 3 STAFResult trustResult = STAFUtil.validateTrust( 3, staxService.getServiceName(), "START", staxService.getLocalMachineName(), info); if (trustResult.rc != STAFResult.Ok) return trustResult; // Parse the result STAFCommandParseResult parseResult= fStartParser.parse(info.request); if (parseResult.rc != STAFResult.Ok) { return new STAFResult(STAFResult.InvalidRequestString, parseResult.errorBuffer); } // Resolve the value specified for JOB and get its integer value STAFResult res = STAFUtil.resolveRequestVarAndCheckInt( "JOB", parseResult.optionValue("JOB"), staxService.getSTAFHandle(), info.requestNumber); if (res.rc != 0) return res; Integer jobID = new Integer(res.result); // Verify that the JOB ID is a currently active job STAXJob job = null; job = (STAXJob)staxService.getJobMap().get(jobID); if (job == null) { return new STAFResult( STAFResult.DoesNotExist, "Job " + jobID + " is not currently running."); } // Resolve the value specified for Testcase name res = STAFUtil.resolveRequestVar( parseResult.optionValue("TESTCASE"), staxService.getSTAFHandle(), info.requestNumber); if (res.rc != 0) return res; String testcaseName = res.result; String key = new String(""); if (parseResult.optionTimes("KEY") > 0) { // Resolve the value specified for the key if needed res = STAFUtil.resolveRequestVar( parseResult.optionValue("KEY"), staxService.getSTAFHandle(), info.requestNumber); if (res.rc != 0) return res; key = res.result; } // Check if the testcase[:key] is in the activeTestcaseMap. If not, // add it to the activeTestcaseMap, storing its start timestamp. String testcaseKey = testcaseName; if (!key.equals("")) { testcaseKey = testcaseName + ":" + key; } HashMap activeTestcaseMap = (HashMap)job.getData("activeTestcaseMap"); synchronized (activeTestcaseMap) { if (activeTestcaseMap.containsKey(testcaseKey)) { return new STAFResult(STAFResult.AlreadyExists, testcaseKey); } STAXActiveTestcase activeTest = new STAXActiveTestcase(testcaseName, new STAXTimestamp()); activeTestcaseMap.put(testcaseKey, activeTest); } // Check if the testcase name is already in the testcaseMap. // If not, add it to the testcaseMap. If the testcase already // exists, set its mode to strict if its not already strict. TreeMap testcaseMap = (TreeMap)job.getData("testcaseMap"); STAXTestcase theTest; synchronized (testcaseMap) { theTest = (STAXTestcase)testcaseMap.get(testcaseName); if (theTest == null) { theTest = new STAXTestcase(testcaseName, STAXTestcase.STRICT_MODE); testcaseMap.put(testcaseName, theTest); } else if (theTest.getMode() != STAXTestcase.STRICT_MODE) { theTest.setMode(STAXTestcase.STRICT_MODE); } } // Start the testcase theTest.start(job); return new STAFResult(STAFResult.Ok); } private STAFResult handleStopRequest( STAFServiceInterfaceLevel30.RequestInfo info, STAX staxService) { // Verify the requesting machine/user has at least trust level 3 STAFResult trustResult = STAFUtil.validateTrust( 3, staxService.getServiceName(), "STOP", staxService.getLocalMachineName(), info); if (trustResult.rc != STAFResult.Ok) return trustResult; // Parse the request STAFCommandParseResult parseResult= fStopParser.parse(info.request); if (parseResult.rc != STAFResult.Ok) { return new STAFResult(STAFResult.InvalidRequestString, parseResult.errorBuffer); } // Resolve the value specified for JOB and get its integer value STAFResult res = STAFUtil.resolveRequestVarAndCheckInt( "JOB", parseResult.optionValue("JOB"), staxService.getSTAFHandle(), info.requestNumber); if (res.rc != 0) return res; Integer jobID = new Integer(res.result); // Verify that the JOB ID is a currently active job STAXJob job = null; job = (STAXJob)staxService.getJobMap().get(jobID); if (job == null) { return new STAFResult( STAFResult.DoesNotExist, "Job " + jobID + " is not currently running."); } // Resolve the value specified for Testcase name res = STAFUtil.resolveRequestVar( parseResult.optionValue("TESTCASE"), staxService.getSTAFHandle(), info.requestNumber); if (res.rc != 0) return res; String testcaseName = res.result; String key = new String(""); if (parseResult.optionTimes("KEY") > 0) { // Resolve the value specified for the key if needed res = STAFUtil.resolveRequestVar( parseResult.optionValue("KEY"), staxService.getSTAFHandle(), info.requestNumber); if (res.rc != 0) return res; key = res.result; } // Check if the testcase:[key] is in the activeTestcaseMap. If so, // get its start timestamp and remove it from the activeTestcaseMap. // If not, return a DoesNotExist error. String testcaseKey = testcaseName; if (!key.equals("")) { testcaseKey = testcaseName + ":" + key; } STAXTimestamp startTimestamp; HashMap activeTestcaseMap = (HashMap)job.getData("activeTestcaseMap"); synchronized (activeTestcaseMap) { if (activeTestcaseMap.containsKey(testcaseKey)) { STAXActiveTestcase activeTest = (STAXActiveTestcase)activeTestcaseMap.get(testcaseKey); startTimestamp = activeTest.getStartTime(); activeTestcaseMap.remove(testcaseKey); } else { return new STAFResult(STAFResult.DoesNotExist, testcaseKey); } } // Stop the Testcase TreeMap testcaseMap = (TreeMap)job.getData("testcaseMap"); STAXTestcase theTest; synchronized (testcaseMap) { theTest = (STAXTestcase)testcaseMap.get(testcaseName); } if (theTest == null) { return new STAFResult(STAFResult.DoesNotExist, testcaseName); } theTest.stop(job, startTimestamp); return new STAFResult(STAFResult.Ok); } public String getHelpInfo(String lineSep) { return "START JOB <Job ID> TESTCASE <Testcase name> [KEY <Key>]" + lineSep + lineSep + "STOP JOB <Job ID> TESTCASE <Testcase name> [KEY <Key>]" + lineSep + lineSep + "UPDATE JOB <Job ID> TESTCASE <Testcase name> " + "STATUS <Status>" + lineSep + " [MESSAGE <Message text>] [FORCE]"; } private STAFCommandParser fUpdateParser = new STAFCommandParser(); private STAFCommandParser fStartParser = new STAFCommandParser(); private STAFCommandParser fStopParser = new STAFCommandParser(); private STAFMapClassDefinition fTestcaseInfoMapClass; private STAFMapClassDefinition fQueryTestcaseMapClass; // STAXActiveTestcase class is the value stored in the activeTestcaseMap class STAXActiveTestcase { STAXActiveTestcase(String name, STAXTimestamp startTime) { fName = name; fStartTime = startTime; } String getName() { return fName; } STAXTimestamp getStartTime() { return fStartTime; } private String fName; private STAXTimestamp fStartTime; } // end class STAXActiveTestcase}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -