1

We have testing java application.
This application performs different types of testing. On one step it starts Silk Test.
This application writes a lot of traces using System.out.println.
We redirect this traces to file app.trace in our cmd file.
Something like:

java com.test.app > app.trace

When this testing application stops it is not possible to remove app.trace file because it is locked by Silk Test Open Agent.
I do not understand how this application can lock our trace file.
We do not start this application directly from our code.
We use Silk4J lib to start Silk Test.
As far as I know this library connects to Silk Test windows service which starts Silk Test Open Agent.
Does anyone can explain me - why and how Silk Test Open Agent locks our trace file?

Volodymyr Bezuglyy
  • 16,295
  • 33
  • 103
  • 133
  • I've done a quick test and I could not reproduce that behavior. Are you sure the java process that wrote the files is shut down after testing (check with Process Manager)? Did you verify that it is really the SilkTest Agent that has locked the files? – tehlexx Mar 08 '12 at 06:43
  • Yes - java process is shutdown. And yes - SilkTest Agent loks the file. I checked it via Process Explorer. I willreturn to this problem tomorrow. If I find something new - I will update my question. – Volodymyr Bezuglyy Mar 08 '12 at 09:47

2 Answers2

1

The cause of this is because Open Agent does not close down when the test finishes. I just kill Open Agent when my suite is done.

public class ProcessKill {

public void killOpenAgent ()    {
    kill ("openAgent.exe");
}

public void kill (String processName)   {
    String command = "cmd /c taskkill";
    String parameter = " /F /IM " + processName;
    System.out.println("Killing process: " + processName);

    try {
        Runtime.getRuntime().exec(command + parameter);
    } catch (IOException e) {
        e.printStackTrace();
    }       
}
}

I am using TestNG to control my tests, so I just call this from the @AfterSuite method to always make sure that Open Agent is killed after each run. This also helps to release the licence.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

The reason is that child processes inherit the open files of their parents, in this case the redirected output stream to the file. This makes sense, as is allows you to also capture the output of those child processes.

However, otherwise than David Genrich suggested in his answer, I would not forcefully kill the agent as it may then fail to release some resources and clean up properly. This might lead to follow-up problems.

I suggest separately starting the OpenAgent before you run your tests so it's not a child process of the test runner.

tehlexx
  • 2,821
  • 16
  • 29