use of com.nhnent.eat.common.CommonDefine.EmptyString in project eat by nhnent.
the class JmxCommunication method compareWithRealResponse.
@Override
public Boolean compareWithRealResponse(ScenarioUnit scenarioUnit) throws SuspendExecution, InterruptedException {
Object realValue = jmxResponseStack.pop();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(scenarioUnit.json);
JsonElement jeExpect = getValueOfVar(je, "Expectation");
String expect = jeExpect != null ? jeExpect.getAsString() : EmptyString;
return packetJsonHandler.simpleMatch(expect, realValue);
}
use of com.nhnent.eat.common.CommonDefine.EmptyString in project eat by nhnent.
the class ManagerActor method makeRequestTestPreparationMessage.
/**
* Make execute message of test preparation.
*
* @param idx index of test player
* @return generated message
*/
private Messages makeRequestTestPreparationMessage(final int idx) {
String userId = EmptyString;
int playerCount = Config.obj().getScenario().getUserId().length;
if (idx < playerCount) {
userId = Config.obj().getScenario().getUserId()[idx];
previousSnoString = userId;
} else if (idx >= playerCount) {
String tempSno = previousSnoString;
int endNumber;
Pattern p = Pattern.compile("[\\D]*[\\d]+$");
Matcher m = p.matcher(tempSno);
Boolean isEndByNumber = false;
while (m.find()) {
isEndByNumber = true;
tempSno = m.group(0);
}
if (isEndByNumber) {
String beforeSno = tempSno.replaceAll("[\\D]", "");
endNumber = Integer.parseInt(beforeSno);
int endNumberLength = Integer.toString(endNumber).length();
endNumber++;
userId = previousSnoString.substring(0, previousSnoString.length() - endNumberLength) + Integer.toString(endNumber);
previousSnoString = userId;
} else {
userId = Integer.toString(idx);
}
}
// TODO : it should changed later
// try {
// previousSno = Long.parseLong(userId);
// } catch (Exception e) {
// //it means, the userId is not Numeric.
// previousSno = playerCount;
// }
String scenarioFile;
int scenarioFileCount = Config.obj().getScenario().getScenarioFile().length;
int recursiveScenarioIdx = idx % scenarioFileCount;
scenarioFile = Config.obj().getScenario().getScenarioFile()[recursiveScenarioIdx];
return new Messages(this.ref, MessageType.PrepareTest, userId, scenarioFile, idx);
}
use of com.nhnent.eat.common.CommonDefine.EmptyString in project eat by nhnent.
the class JMXClient method setQaCommand.
public void setQaCommand(String json) throws InterruptedException, SuspendExecution, ExecutionException, IOException, MalformedObjectNameException {
String command;
String data;
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(json);
JsonElement jeCommand = getValueOfVar(je, "Command");
if (jeCommand != null) {
command = jeCommand.getAsString();
} else {
command = EmptyString;
}
JsonElement jeData = getValueOfVar(je, "Data");
if (jeData != null) {
data = jeData.toString();
} else {
data = EmptyString;
}
JMXClient.obj().connect();
mBeanProxy.sendLobbyCommand(command, data);
}
use of com.nhnent.eat.common.CommonDefine.EmptyString in project eat by nhnent.
the class RESTClient method requestRestCall.
/**
* Call REST requests
*
* @param scenarioUnit scenarioUnit which contains REST data
* @return REST response
*/
public String requestRestCall(ScenarioUnit scenarioUnit) {
String method;
String url;
String jsonBody;
String resultJson;
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(scenarioUnit.json);
JsonElement jeMethod = getValueOfVar(je, "Method");
if (jeMethod != null) {
method = jeMethod.getAsString();
} else {
method = EmptyString;
}
JsonElement jeURL = getValueOfVar(je, "Url");
if (jeURL != null) {
url = jeURL.getAsString();
} else {
url = EmptyString;
}
if (method.equals("GET")) {
resultJson = this.get(url);
logger.info("<-------RESTful Request [GET]------->");
logger.info("Url : " + url);
return resultJson;
} else if (method.equals("post")) {
JsonElement jeBody = getValueOfVar(je, "Body");
if (jeBody != null) {
jsonBody = jeBody.toString();
} else {
jsonBody = EmptyString;
}
logger.info("<-------RESTful Request [post]------->");
logger.info("Url : " + url);
logger.info("jsonBody : " + jsonBody);
resultJson = this.post(url, jsonBody);
return resultJson;
}
return null;
}
use of com.nhnent.eat.common.CommonDefine.EmptyString in project eat by nhnent.
the class ScenarioExecutor method execute.
/**
* Based on scenario list, it will perform transfer packet or receive packet, then it will report the test result.
*
* @param listScenario list of packet scenario
* @return test result(counts of succeed and failure)
*/
private ScenarioExecutionResult execute(final List<ScenarioUnit> listScenario) throws SuspendExecution {
ReportHandler reportHandler = new ReportHandler();
int succeedCount = 0;
int failureCount = 0;
List<Integer> previousLoopStartIdx = new ArrayList<>();
List<Integer> loopCountList = new ArrayList<>();
// 0 is first depth, so let's set (-1) as a default value.
int loopDepth = -1;
ScenarioExecutionResult result = new ScenarioExecutionResult();
Instant requestTime = Instant.now();
Instant responseTime;
String originalJson;
if (Config.obj().getCustomScenarioAPI().isUse()) {
ApiLoader.obj().initialize(PacketClassPool.obj(), listCommunication, runtimeVar, userId);
}
try {
for (int scenarioIdx = 0; scenarioIdx < listScenario.size(); scenarioIdx++) {
ScenarioUnit scenario = listScenario.get(scenarioIdx);
if (logger.isDebugEnabled()) {
logger.debug("Instance making for----, \n" + "pckType:" + scenario.type + ", pckName:" + scenario.name + ", \n" + "dest:" + scenario.dest + ", subId:" + scenario.subId + ", \n" + "pckJson:" + scenario.json);
}
// TODO: JMX call Old version.. have to delete
if (scenario.type.equals(ScenarioUnitType.SetCardDeck)) {
JMXClient.obj().setCardDeck(scenario.json);
logger.info("-------------------------");
logger.info("| Set Card Deck |");
logger.info("-------------------------");
logger.debug("Set Card Deck is transmitted\n.{}", scenario.json);
continue;
}
// TODO: JMX call Old version.. have to delete
if (scenario.type.equals(ScenarioUnitType.SetQaCommand)) {
JMXClient.obj().setQaCommand(scenario.json);
logger.info("-------------------------");
logger.info("| Set QA Command |");
logger.info("-------------------------");
logger.debug("Set QA Command is transmitted\n.{}", scenario.json);
continue;
}
if (scenario.loopType == LoopType.LoopStart) {
if (scenario.loopDepth != loopDepth) {
loopDepth = scenario.loopDepth;
previousLoopStartIdx.add(scenarioIdx);
loopCountList.add(scenario.loopCount);
logger.debug("Loop Start");
}
continue;
}
if (scenario.loopType == LoopType.LoopEnd) {
int currentLoopCount = loopCountList.get(loopDepth) - 1;
if (currentLoopCount < 1) {
// If loop is finished
loopCountList.remove(loopDepth);
previousLoopStartIdx.remove(loopDepth);
loopDepth--;
logger.debug("Loop End");
} else {
// If need to continue loop
loopCountList.set(loopDepth, currentLoopCount);
// To move 1 after from loop start
scenarioIdx = previousLoopStartIdx.get(scenario.loopDepth);
if (logger.isDebugEnabled())
logger.debug("LOOP CONTINUE currentLoopCount=> " + currentLoopCount + " scenarioIdx=> " + scenarioIdx);
}
continue;
}
if (scenario.type.equals(ScenarioUnitType.Sleep)) {
if (logger.isDebugEnabled())
logger.debug("Take a Sleep during {} ms", scenario.sleepPeriod);
Strand.sleep(scenario.sleepPeriod);
continue;
}
if (scenario.type.equals(ScenarioUnitType.Print)) {
logger.info("[PRINT] {}", scenario.reservedField);
continue;
}
if (scenario.type.equals(ScenarioUnitType.ExtraFunctionCall)) {
if (ApiLoader.obj().executeExtraFunction(result, userId, scenario).equals(Boolean.FALSE)) {
// If status is in Loop, exit from current Loop
if (loopDepth >= 0) {
int currentLoopCount = loopCountList.get(loopDepth) - 1;
logger.warn("Stopped by API, currentLoopCount:{}, loopDepth:{}", currentLoopCount, loopDepth);
if (currentLoopCount >= 0) {
int tmpScenarioIdx = scenarioIdx + 1;
while (true) {
ScenarioUnit tmpScenario = listScenario.get(tmpScenarioIdx);
if (tmpScenario.loopType == LoopType.LoopEnd && tmpScenario.loopDepth == loopDepth) {
scenarioIdx = tmpScenarioIdx - 1;
break;
}
tmpScenarioIdx++;
}
}
if (loopDepth > 0) {
logger.warn("End Loop by API(In-Loop level)");
} else {
logger.warn("End Loop by API(Top level)");
}
}
}
continue;
}
if (scenario.json.contains(UsingVariableDelimiter)) {
originalJson = scenario.json;
scenario.json = applyVariable(runtimeVar, scenario.json);
} else {
originalJson = EmptyString;
}
for (IBaseCommunication communication : listCommunication) {
if (// Is it REST or Netty or JMX... ?
communication.isRegisteredScenarioType(scenario.type)) {
switch(// Is it Request or Response ?
scenario.communicationMethod) {
case CommunicationMethod.Request:
requestTime = Instant.now();
communication.execute(scenario);
break;
case CommunicationMethod.Response:
Boolean isSucceed = communication.compareWithRealResponse(scenario);
if (isSucceed) {
if (scenario.type.equals(ScenarioUnitType.Response)) {
responseTime = Instant.now();
result.listResponseTime.add(Duration.between(requestTime, responseTime));
}
succeedCount++;
} else
failureCount++;
break;
default:
logger.error("Receive invalid packet type : " + scenario.type);
break;
}
}
}
// set it to original JSon string
if (!originalJson.equals(EmptyString)) {
scenario.json = originalJson;
}
}
StatisticsResult statisticsResult = null;
result.succeedCount += succeedCount;
result.failureCount += failureCount;
reportHandler.writeLogForFinalResult(result.succeedCount, result.failureCount);
statisticsResult = reportHandler.writeLogForStatisticsResult(result.listResponseTime);
result.statisticsResult = statisticsResult;
} catch (Exception e) {
logger.error(ExceptionUtils.getStackTrace(e));
}
return result;
}
Aggregations