users@glassfish.java.net

Re: JSR 352: Batch Job 'unit testing' - TimerTask triggers ...

From: <forums_at_java.net>
Date: Thu, 27 Jun 2013 02:10:48 -0500 (CDT)

Reached an initial solution - details below in case anyone else finds
themselves travelling this path :) CAUSES: 1. First a dumb error on my part.
In this situation, I did want a blocking wait and was thinking Timer.schedule
was a blocking call like Thread.sleep() ! 2. JobOperator.getJobExecution()
was throwing the security exception . Probably a combination of timing/early
termination of the test class. CURRENT SOLUTION: Switched to Thread.sleep()
(not sure if this is a right approach) and polling
JobExecution.getBatchStatus()). public abstract class BatchJobUtil { public
static boolean isBatchJobRunning(JobExecution je) { BatchStatus batchStatus =
je.getBatchStatus(); // Not sure what STOPPED means vs COMPLETED return
!((batchStatus == BatchStatus.COMPLETED) || (batchStatus ==
BatchStatus.STOPPED) || (batchStatus == BatchStatus.FAILED) || (batchStatus
== BatchStatus.ABANDONED)); } public static final void
waitForBatchJobToFinish(JobExecution je, long sleepTimeMillis) { while
(isBatchJobRunning(je)) { try { Thread.sleep(sleepTimeMillis); } catch
(InterruptedException e) { e.printStackTrace(); break; } } } } ISSUES: With
an Embedded Glassfish / Arquillian an intermittent, non-fatal RAR7093 : Error
while cleaning up ManagedConnection (see
https://java.net/jira/browse/GLASSFISH-20329) Arquillian test using a Remote
Glassfish / Arquillian, no obvious errors so far.

--
[Message sent by forum member 'jimnicolson']
View Post: http://forums.java.net/node/897482