001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.test.stress;
018:
019: import java.util.List;
020:
021: import edu.iu.uis.eden.EdenConstants;
022: import edu.iu.uis.eden.clientapp.WorkflowDocument;
023: import edu.iu.uis.eden.clientapp.WorkflowInfo;
024: import edu.iu.uis.eden.clientapp.vo.ActionRequestVO;
025: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
026: import edu.iu.uis.eden.clientapp.vo.UserIdVO;
027: import edu.iu.uis.eden.clientapp.vo.WorkflowGroupIdVO;
028: import edu.iu.uis.eden.clientapp.vo.WorkgroupVO;
029:
030: public class StressTestUtils {
031:
032: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
033: .getLogger(StressTestUtils.class);
034:
035: public static Object getRandomListObject(List list) {
036: return list.get((int) Math.round(Math.random()
037: * (list.size() - 1)));
038: }
039:
040: public static void handleRequests(Long documentId,
041: ActionRequestVO[] requests) throws Exception {
042: if (requests != null && requests.length > 0) {
043: for (int index = 0; index < requests.length; index++) {
044: long t1 = System.currentTimeMillis();
045: ActionRequestVO request = requests[index];
046: if (request.isActivated()) {
047: long t2 = System.currentTimeMillis();
048: UserIdVO userId = determineUser(request);
049: long t3 = System.currentTimeMillis();
050: TestInfo.addUser(userId);
051: WorkflowDocument document = new WorkflowDocument(
052: userId, documentId);
053: long t4 = System.currentTimeMillis();
054: TestInfo.markCallToServer();
055: if (request.getActionRequested().equals(
056: EdenConstants.ACTION_REQUEST_COMPLETE_REQ)) {
057: BasicTest.LOG
058: .info("Completing request from stress test "
059: + documentId);
060: document
061: .complete("Completing request from stress test.");
062: TestInfo.markCallToServer();
063: TestInfo.markDocumentApprovals();
064: } else if (request.getActionRequested().equals(
065: EdenConstants.ACTION_REQUEST_APPROVE_REQ)) {
066: BasicTest.LOG
067: .info("Approving request from stress test "
068: + documentId);
069: document
070: .approve("Approving request from stress test.");
071: TestInfo.markCallToServer();
072: TestInfo.markDocumentApprovals();
073: } else if (request
074: .getActionRequested()
075: .equals(
076: EdenConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ)) {
077: BasicTest.LOG
078: .info("Acknowledging request from stress test "
079: + documentId);
080: document
081: .acknowledge("Acknowledging request from stress test.");
082: TestInfo.markCallToServer();
083: TestInfo.markDocumentAcks();
084: } else if (request.getActionRequested().equals(
085: EdenConstants.ACTION_REQUEST_FYI_REQ)) {
086: BasicTest.LOG
087: .info("FYI request from stress test "
088: + documentId);
089: document.fyi();
090: TestInfo.markCallToServer();
091: TestInfo.markDocumentFYIs();
092: } else {
093: String message = "Illegal action request ("
094: + request.getActionRequested()
095: + ") for request "
096: + request.getActionRequestId();
097: BasicTest.LOG.error(message);
098: throw new Exception(message);
099: }
100: long t5 = System.currentTimeMillis();
101: LOG.info("Time to determine user: " + (t3 - t2));
102: LOG.info("Time to load document for user: "
103: + (t4 - t3));
104: LOG.info("Time to take action on document : "
105: + (t5 - t4));
106: }
107: long t6 = System.currentTimeMillis();
108: LOG.info("Time to handle single action request: "
109: + (t6 - t1));
110: }
111: }
112: }
113:
114: public static UserIdVO determineUser(ActionRequestVO request)
115: throws Exception {
116: LOG.info("Determining user for request "
117: + request.getActionRequestId() + ", userVO="
118: + request.getUserVO() + ", workgroupId="
119: + request.getWorkgroupId());
120: if (request.getUserVO() != null) {
121: return new NetworkIdVO(request.getUserVO().getNetworkId());
122: } else if (request.getWorkgroupId() != null) {
123: WorkgroupVO workgroup = new WorkflowInfo()
124: .getWorkgroup(new WorkflowGroupIdVO(request
125: .getWorkgroupId()));
126: TestInfo.markCallToServer();
127: int userIndex = (int) Math.round(Math.random()
128: * (workgroup.getMembers().length - 1));
129: return new NetworkIdVO(workgroup.getMembers()[userIndex]
130: .getNetworkId());
131: }
132: String message = "Could not determine user for action request: "
133: + request.getActionRequestId();
134: LOG.error(message);
135: throw new Exception(message);
136: }
137:
138: }
|