Search in sources :

Example 1 with ScenarioExecutor

use of com.nhnent.eat.handler.ScenarioExecutor 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;
}
Also used : ScenarioUnit(com.nhnent.eat.entity.ScenarioUnit) Messages(com.nhnent.eat.entity.Messages) ScenarioExecutor(com.nhnent.eat.handler.ScenarioExecutor) ArrayList(java.util.ArrayList) RestCommunication(com.nhnent.eat.communication.communicator.RestCommunication) Date(java.util.Date) NettyCommunication(com.nhnent.eat.communication.communicator.NettyCommunication) JmxCommunication(com.nhnent.eat.communication.communicator.JmxCommunication) ScenarioExecutionResult(com.nhnent.eat.entity.ScenarioExecutionResult) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with ScenarioExecutor

use of com.nhnent.eat.handler.ScenarioExecutor in project eat by nhnent.

the class ScenarioExecutorTest method execute.

@Test
public void execute() throws Exception {
    ScenarioExecutor scenExec = new ScenarioExecutor("test");
    List<ScenarioUnit> listScenPck;
    ScenarioLoader scenLoader = new ScenarioLoader();
    String scenPath = Config.obj().getScenario().getScenarioPath();
    String scenFile = scenPath + "\\chat_test.scn";
    System.out.println(scenPath);
    listScenPck = scenLoader.loadScenario(scenFile, "");
    scenExec.runScenario(listScenPck);
    listScenPck.clear();
}
Also used : ScenarioUnit(com.nhnent.eat.entity.ScenarioUnit) ScenarioExecutor(com.nhnent.eat.handler.ScenarioExecutor) ScenarioLoader(com.nhnent.eat.handler.ScenarioLoader) Test(org.junit.Test)

Aggregations

ScenarioUnit (com.nhnent.eat.entity.ScenarioUnit)2 ScenarioExecutor (com.nhnent.eat.handler.ScenarioExecutor)2 JmxCommunication (com.nhnent.eat.communication.communicator.JmxCommunication)1 NettyCommunication (com.nhnent.eat.communication.communicator.NettyCommunication)1 RestCommunication (com.nhnent.eat.communication.communicator.RestCommunication)1 Messages (com.nhnent.eat.entity.Messages)1 ScenarioExecutionResult (com.nhnent.eat.entity.ScenarioExecutionResult)1 ScenarioLoader (com.nhnent.eat.handler.ScenarioLoader)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1