How to kill a JUnit test run in Eclipse that has entered an infinte loop - eclipse

I have some Java code that I am unit testing using JUnit, running inside Eclipse (Neon). It so happens that some code under test has a bug in it, causing it to enter an infinite loop. The JUnit run then, of course, does not finish. How do I kill the test run?
The button for stopping the test run ("Stop JUnit Test Run") does not work well: the GUI seems to think that it has stopped the test run, but a look at the CPU activity (using top, for example), shows that a Java thread is still running. I can kill the thread myself by sending it a kill signal. But that seems a kludge and is inconvenient. Is there a better way, available within Eclipse itself?

Kill it from the console view, using the red button. This stops the process.
Stopping it from the junit view only asks it to stop.

You can handle such things with JUnit by specifying a time-out within
the #Test annotation. For example:
// Simple test-case which will always fail with time-out
#Test(timeout = 1000 * 60) throws Exception // 60 seconds
public void testSomething() {
for (int i = 0; i < 100; i++) { // 100 seconds
Thread.sleep(1000);
}
}
If your test method doesn't finish on time,
then JUnit will interrupt it and report a test failure.
For the example above it will be:
java.lang.Exception: test timed out after 60000 milliseconds
at java.lang.Thread.sleep(Native Method)
at my.package.Test1.testSomething(Test1.java:12)

First, try Matthew Farwell's answer. If that doesn't work then you have to go to your processes running (ctrl+shift+esc on windows, then processes tab) and select the java.exe task, then end process. In the event you ever need to kill eclipse, it's javaw.exe

Related

Spring Batch Job Stop Using jobOperator

I have Started my job using jobLauncher.run(processJob,jobParameters); and when i try stop job using another request jobOperator.stop(jobExecution.getId()); then get exeption :
org.springframework.batch.core.launch.JobExecutionNotRunningException:
JobExecution must be running so that it can be stopped
Set<JobExecution> jobExecutionsSet= jobExplorer.findRunningJobExecutions("processJob");
for (JobExecution jobExecution:jobExecutionsSet) {
System.err.println("job status : "+ jobExecution.getStatus());
if (jobExecution.getStatus()== BatchStatus.STARTED|| jobExecution.getStatus()== BatchStatus.STARTING || jobExecution.getStatus()== BatchStatus.STOPPING){
jobOperator.stop(jobExecution.getId());
System.out.println("###########Stopped#########");
}
}
when print job status always get job status : STOPPING but batch job is running
its web app, first upload some CSV file and start some operation using spring batch and during this execution if user need stop then stop request from another controller method come and try to stop running job
Please help me for stop running job
If you stop a job while it is running (typically in a STARTED state), you should not get this exception. If you have this exception, it means you have stopped your job while it is currently stopping (that is what the STOPPING status means).
jobExplorer.findRunningJobExecutions returns only running executions, so if in the next line right after this one you have a job in STOPPING status, this means the status changed right after calling jobExplorer.findRunningJobExecutions. You need to be aware that this is possible and your controller should handle this case.
When you tell spring batch to stop a job it goes into STOPPING mode. What this means is it will attempt to complete the unit of work chunk it is currently processing but then stop working. Likely what's happening is you are working on a long running task that is not finishing a unit of work (is it hung?) so it can't move from STOPPING to STOPPED.
Doing it twice rightly leads to an Exception because your job is already STOPPING by the time you did it the first time.

SBT to run Play app exits immediately when started using scala.sys.process.run?

I am writing an integration test that needs to start up several applications. One of these applications is a Play one as a SBT project called appA.
I am able to start the app on the right port using scala.sys.process as follows:
import scala.sys.process._
import org.scalatest._
class Main extends FeatureSpec with Matchers{
val app = Seq("sbt", "project appA", "run 7777").run
println(app.exitValue)
}
The spawned application however exits immediately with return value 0. No errors are displayed to the console. I just see:
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:3000
(Server started, use Ctrl+D to stop and go back to the console...)
[success] Total time: 1 s, completed Feb 27, 2014 10:26:56 PM
0
The 0 at the end of the output is from calling exitValue on the created process. exitValue blocks until the spawned process exits.
How can I run the Play application without it exiting immediately? Is there a better way to start the application?
SBT has 2 run modes - interactive and batch. If you run without any args it goes to interactive mode and does not exit. When you run it by passing commands it runs in a batch mode and exits when the last command is complete. It does not matter if your application inside SBT runs in a forked JVM or not.
Thus to "fix" it you can apply this hack: add ~ command to the end of the list of sbt commands/args:
val app = Seq("sbt", "project appA", "run 7777", "~").run
~ is used to watch source code for changes and recompile when it happens. Thus SBT will never exit unless stopped by a user or killed.
A cleaner way would be to run Play application in a Jetty container (assuming you have WAR to run) or such by calling a main class that starts up Jetty with a command like java com.example.MyMain but that requires additional setup.

py.test hangs after showing test results

I'm using py.test to run a bunch of tests. The tests seem to pass, but the process never terminates:
===== test session starts =====
platform win32 -- Python 2.7.3 -- pytest-2.3.4
collected 179 items
common/tests/test_bar.py ...............
common/tests/test_foo.py .......
....
===== 159 passed, 20 skipped in 98.58 seconds =====
<-- the prompt never gets back -->
Any ideas what can cause this and how to debug?
EDIT
#hpk42 is right - it was a non-daemon thread that never terminated.
It's likely that your tests start a thread with server loops. If that is the case, you may use thread.setDaemon(True) which marks the thread as "can be thrown away" and might help to get through the Python shutdown. Ideally, though, you should rather signal to your thread/loop that it should terminate.

Orientdb client using 100% cpu after connection has been established

When I use the following code in a servlet running in tomcat7 (also tested in tomcat6) on Ubuntu 10.10 Server (openjdk 1.6.0_20 64bit), the java process uses 100% cpu and above after the connection has been established once.
ODatabaseObjectTx db = ODatabaseObjectPool.global().acquire("remote:localhost/test", "test", "test");
db.getEntityManager().registerEntityClass(BlogPost.class);
List<BlogPost> posts = db.query(new OSQLSynchQuery<BlogPost>("select * from BlogPost order by date desc"));
db.close();
Does anyone know how to resolve this issue?
EDIT:
The issue also happens right after acquire. There is a Thread "ClientService" being spawned that causes the high load.
I took several thread dumps and it always shows the same for this thread:
"ClientService" daemon prio=10 tid=0x00007f4d88344800 nid=0x558e runnable [0x00007f4d872da000]
java.lang.Thread.State: RUNNABLE
at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:127)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1239)
at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:431)
at com.orientechnologies.orient.enterprise.channel.binary.OChannelBinaryAsynch.endResponse(OChannelBinaryAsyn
ch.java:73)
at com.orientechnologies.orient.client.remote.OStorageRemoteServiceThread.execute(OStorageRemoteServiceThread
.java:59)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:48)
When I suspend the thread in the debugger, the high load stops until I press continue.
Happens after the acquire() or the query?

How do I turn off the Scala Fast Compilation server's (FSC) timeout?

I am using a Scala compilation server. This is probably not related to my IDE IntelliJ IDEA, but I will just inform you that I start the Scala compilation server through a special run configuration in that IDE.
After some time that goes by without compiling anything, the compilation server terminates, without any message. Usually, I only notice this when I try to compile something and compilation fails. Then, I need to start the compilation server again, and of course the next compilation takes a long time, because it's once more the first compilation since starting the compilation server.
How do I turn off that timeout? I looked at the manpage for scalac, and there seems to be no option for it. I can add VM options for that run configuration.
Pass -max-idle 0 as parameter. It will work on a very (very!) recent nightly, and it should be available on Scala 2.9.0 when it comes out. However, there's no guarantee the name won't change until then.
I don't think you can. Here is a code snippet from the compilation server:
object SocketServer
{
// After 30 idle minutes, politely exit.
// Should the port file disappear, and the clients
// therefore unable to contact this server instance,
// the process will just eventually terminate by itself.
val IdleTimeout = 1800000
val BufferSize = 10240
def bufferedReader(s: Socket) = new BufferedReader(new InputStreamReader(s.getInputStream()))
def bufferedOutput(s: Socket) = new BufferedOutputStream(s.getOutputStream, BufferSize)
}
I think you should open a feature request in scala-lang.org