use of com.nhnent.eat.communication.communicator.IBaseCommunication in project eat by nhnent.
the class BaseCustomAPI method sendPacketToServer.
public void sendPacketToServer(String packetType, String packageName, String packetName, String jsonContents) {
byte[] sendPacket = null;
try {
sendPacket = StreamPacket.obj().jsonToPacket(userId, packetType, packageName, packetName, jsonContents);
for (IBaseCommunication communication : listCommunication) {
if (communication.isRegisteredScenarioType(ScenarioUnitType.Request)) {
communication.transferPacket(sendPacket);
break;
}
}
} catch (Exception e) {
logger.error(ExceptionUtils.getStackTrace(e));
}
if (Config.obj().getDisplay().isDisplayTransferredPacket()) {
if (Config.obj().getDisplay().isDisplayTransferredPacketJson()) {
byte[] bodyPacket = StreamPacket.obj().getBodyPacket(userId, sendPacket);
logger.info("[userId:{}][Transfer Packet][{}]\n{}", userInfo.get(), packetName, decodePacket(packetName, bodyPacket));
} else {
logger.info("[userId:{}][Transfer Packet][{}]", userInfo.get(), packetName);
}
}
}
use of com.nhnent.eat.communication.communicator.IBaseCommunication in project eat by nhnent.
the class BaseCustomAPI method recvBodyPacket.
public Pair<String, byte[]> recvBodyPacket() throws SuspendExecution, InterruptedException {
Pair<String, byte[]> recvPacket = null;
for (IBaseCommunication communication : listCommunication) {
if (communication.isRegisteredScenarioType(ScenarioUnitType.Response)) {
recvPacket = communication.readPacket();
break;
}
}
responseTime = Instant.now();
scenarioResult.listResponseTime.add(Duration.between(requestTime, responseTime));
scenarioResult.succeedCount++;
requestTime = Instant.now();
if (Config.obj().getDisplay().isDisplayTransferredPacket()) {
if (Config.obj().getDisplay().isDisplayTransferredPacketJson()) {
logger.info("[userId:{}][Received packet][{}] \n{}", userInfo.get(), recvPacket.getKey(), decodePacket(recvPacket.getKey(), recvPacket.getValue()));
} else {
logger.info("[userId:{}][Received packet][{}]", userInfo.get(), recvPacket.getKey());
}
}
return recvPacket;
}
use of com.nhnent.eat.communication.communicator.IBaseCommunication 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