use of com.nhnent.eat.communication.communicator.RestCommunication in project eat by nhnent.
the class TesterActor method doRun.
/**
* doRun of Actor. It performs requests on Actor Mailbox.
*/
@Override
protected Void doRun() throws InterruptedException, SuspendExecution {
TesterActor.globalVariable.set(new HashMap<>());
List<ScenarioUnit> listScenarioPacket = new ArrayList<>();
while (true) {
Object o = receive();
logger.debug("Received testing execute (" + this.ref().toString() + ")");
if (o instanceof Messages) {
Messages m = (Messages) o;
// Handle execute of test preparation
if (m.type == MessageType.PrepareTest) {
userInfo.set(m.userId);
actorIndex = m.actorIndex;
String playerId = String.format("Player_%06d", actorIndex + 1);
MDC.put("playerId", playerId);
MDC.put("strand", Strand.currentStrand().getName());
String logfileName;
if (Config.obj().getCommon().isLoggingOnSameFile()) {
logfileName = String.format("%s", playerId);
} else {
Date now = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String format = formatter.format(now);
logfileName = String.format("%s_%s", format, playerId);
}
MDC.put("logfileName", logfileName);
logger.debug("Load Scenario [" + m.scenarioFile + "]");
listScenarioPacket.addAll(loadScenario(m.scenarioFile, m.userId));
Messages finishMessage = new Messages(this.ref, MessageType.TestPrepared);
m.sender.send(finishMessage);
}
// Handle execute of test start
if (m.type == MessageType.TestStart) {
ScenarioExecutor scenarioExecutor = new ScenarioExecutor(userId);
StreamPacket.obj().initialize(userId);
scenarioExecutor.addCommunication(new RestCommunication());
scenarioExecutor.addCommunication(new JmxCommunication());
scenarioExecutor.addCommunication(new NettyCommunication(userId, actorIndex));
ScenarioExecutionResult result = scenarioExecutor.runScenario(listScenarioPacket);
listScenarioPacket.clear();
Messages finishMessage = new Messages(this.ref, MessageType.TestFinished);
finishMessage.userId = userId;
finishMessage.scenarioExecutionResult = result;
m.sender.send(finishMessage);
break;
}
} else {
Strand.sleep(1);
}
}
logger.info("Test is finished");
MDC.remove("playerId");
MDC.remove("strand");
MDC.remove("logfileName");
return null;
}
Aggregations