1

I'm using maven (plugin version-1.7) and Aspectj-1.8.3.

My scenario is as follow: I have an installer jar that I want to test. The installer is using another jar, my-common.jar library that wraps Apache's utility commons-exec-1.3 and use it to execute commands, the method that I wrote looks like this:

public static int execCommand(String command) throws ExecuteException, IOException, InterruptedException {
    logger.debug("About to execute command: ", command);
    CommandLine commandLine = CommandLine.parse(command);
    DefaultExecutor executor = new DefaultExecutor();
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
    ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
    executor.setWatchdog(watchdog);
    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
    executor.execute(commandLine, resultHandler);
    return 0;
}

The problem is that since my test executes another jar,I mean, the installer, and the installer jar executes another one(lets name it app.jar) and than, the installer terminates and the app.jar keeps running (first, the installer is doing the installment and preparing the environment, and than, he executes the app.jar), the app jar is not being terminated when the testing suite is done (this was my intention and how it suppose to be in production environment).

The global target is to kill all of those processes being created under the integration tests suite.

My solution: Since the process id's are exposed only to the java.lang.UNIXProcess I thought to collect all of the processes ids and then terminate them manually at the end of the tests suite.

I thought to put an Aspect like this:

static Collection<Integer> PidsToKill = new LinkedList<Integer>();

@After("!cflow(within(IntegrationTestsAspects)) && call(* java.lang.UNIXProcess.destroyProcess(int))&&args(pid)")
public void foo3(int pid) {
    PidsToKill.add(new Integer(pid));
}

That was my idea to solve the problem without redesign some parts of my code. So, to some it up, I'm looking for a way to make sure that all of the sub-processes being created under the integration tests suite are terminated.

Any solution is welcomed.

Modi
  • 2,200
  • 4
  • 23
  • 37
  • I know how to weave *rt.jar*, I have done it manually. But please be more specific. Why do you want to weave *rt.jar*? Maybe there is another way to achieve what you want. Can you show your aspects? What should the result be? And if you have a woven Java runtime, can you guarantee that it is used in production by everyone? Please elaborate on such a complex question, do not expect someone to present a full solution for free if you only write a one-liner. P.S.: Have you ever woven *rt.jar* successfully manually and know how to do it and how to use it later? – kriegaex Nov 29 '14 at 06:28

0 Answers0