<commit_before>package com.arjuna.qa.extension;

import org.jboss.arquillian.container.spi.Container;
import org.jboss.arquillian.container.spi.ServerKillProcessor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.logging.Logger;

public class JBossAS7ServerKillProcessor implements ServerKillProcessor {

    private static final Logger logger = Logger.getLogger(JBossAS7ServerKillProcessor.class.getName());
    private static final String CHECK_JBOSS_ALIVE_CMD = "if [ \"$(jps | grep jboss-modules.jar)\" == \"\" ]; then exit 1; fi";
    private static final String CHECK_FOR_DEFUNCT_JAVA_CMD = "if [ \"$(ps aux | grep '\\[java\\] <defunct>')\" == \"\" ]; then exit 1; fi";
    private static final String SHUTDOWN_JBOSS_CMD = "jps | grep jboss-modules.jar | awk '{ print $1 }' | xargs kill";

    private int checkPeriodMillis = 10 * 1000;
    private int numChecks = 60;

    private static int processLogId = 0;

    @Override
    public void kill(Container container) throws Exception {
        logger.info("waiting for byteman to kill the server");

        for (int i = 0; i < numChecks; i++) {

            if (jbossIsAlive()) {
                Thread.sleep(checkPeriodMillis);
                logger.info("jboss-as is still alive, sleeping for a further " + checkPeriodMillis + "ms");
            } else if (isDefunctJavaProcess()) {
                logger.info("Found a defunct java process, sleeping for a further " + checkPeriodMillis + "ms");
                dumpProcesses(container);
            } else {
                logger.info("jboss-as killed by byteman scirpt");
                dumpProcesses(container);
                return;
            }
        }

        //We've waited long enough for Byteman to kil the server and it has not yet done it.
        // Kill the server manually and fail the test
        shutdownJBoss();
        throw new RuntimeException("jboss-as was not killed by Byteman, this indicates a test failure");
    }

    private boolean jbossIsAlive() throws Exception {
        int exitCode = runShellCommand(CHECK_JBOSS_ALIVE_CMD);

        //Command will 'exit 1' if jboss is not running and 'exit 0' if it is
        return exitCode == 0;
    }

    private boolean isDefunctJavaProcess() throws Exception {
        int exitCode = runShellCommand(CHECK_FOR_DEFUNCT_JAVA_CMD);

        //Command will 'exit 1' if a defunct java process is not running and 'exit 0' if there is
        return exitCode == 0;
    }


    private void shutdownJBoss() throws Exception {
        runShellCommand(SHUTDOWN_JBOSS_CMD);

        // wait 5 * 60 second for jboss-as shutdown complete<commit_msg>[JBTM-1957] fixing XTS tests for IBM JDK<commit_after>package com.arjuna.qa.extension;

import org.jboss.arquillian.container.spi.Container;
import org.jboss.arquillian.container.spi.ServerKillProcessor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.logging.Logger;

public class JBossAS7ServerKillProcessor implements ServerKillProcessor {

    private static final Logger logger = Logger.getLogger(JBossAS7ServerKillProcessor.class.getName());
    private static final String CHECK_JBOSS_ALIVE_CMD = "if [ \"$(ps aux | grep 'jboss-module[s]')\" == \"\" ]; then exit 1; fi";
    private static final String CHECK_FOR_DEFUNCT_JAVA_CMD = "if [ \"$(ps aux | grep '\\[java\\] <defunct>')\" == \"\" ]; then exit 1; fi";
    private static final String SHUTDOWN_JBOSS_CMD = "ps axu | grep jboss-module[s] | awk '{print $2}' | xargs kill";

    private int checkPeriodMillis = 10 * 1000;
    private int numChecks = 60;

    private static int processLogId = 0;

    @Override
    public void kill(Container container) throws Exception {
        logger.info("waiting for byteman to kill the server");

        for (int i = 0; i < numChecks; i++) {

            if (jbossIsAlive()) {
                Thread.sleep(checkPeriodMillis);
                logger.info("jboss-as is still alive, sleeping for a further " + checkPeriodMillis + "ms");
            } else if (isDefunctJavaProcess()) {
                logger.info("Found a defunct java process, sleeping for a further " + checkPeriodMillis + "ms");
                dumpProcesses(container);
            } else {
                logger.info("jboss-as killed by byteman scirpt");
                dumpProcesses(container);
                return;
            }
        }

        //We've waited long enough for Byteman to kil the server and it has not yet done it.
        // Kill the server manually and fail the test
        shutdownJBoss();
        throw new RuntimeException("jboss-as was not killed by Byteman, this indicates a test failure");
    }

    private boolean jbossIsAlive() throws Exception {
        int exitCode = runShellCommand(CHECK_JBOSS_ALIVE_CMD);

        //Command will 'exit 1' if jboss is not running and 'exit 0' if it is
        return exitCode == 0;
    }
    
    private boolean isDefunctJavaProcess() throws Exception {
        int exitCode = runShellCommand(CHECK_FOR_DEFUNCT_JAVA_CMD);

        //Command will 'exit 1' if a defunct java process is not running and 'exit 0' if there is
        return exitCode == 0;
    }

    private void shutdownJBoss() throws Exception {
        runShellCommand(SHUTDOWN_JBOSS_CMD);

        // wait 5 * 60 second for jboss-as shutdown complete
{'fraction_non_alphanumeric': 0.09586806814063066, 'fraction_numerical': 0.009423704240666908, 'mean_word_length': 2.793127147766323, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5017857', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1543, 'n_words': 505}