/** Returns true if this VM has acquired the right to run this TestTask */ private static DUnitRun getDUnitRun() { if (dunitRun != null) { System.out.println("BBB dunitRun not null returning"); return dunitRun; } try { SwarmBB.getBB().getSharedLock().lock(); Integer runId = (Integer) SwarmBB.getBB().getSharedMap().get(SwarmBB.RUN_ID); System.out.println("BBB runID=" + runId); if (runId != null) { dunitRun = Swarm.getDUnitRun(runId); System.out.println("BBB lookedUp RUN:" + dunitRun); } else { dunitRun = Swarm.generateNewDUnitRun(); System.out.println( "BBB GENNED UP A RUN:" + dunitRun + " mapping to id:" + dunitRun.getId()); SwarmBB.getBB().getSharedMap().put(SwarmBB.RUN_ID, dunitRun.getId()); } } catch (SQLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { SwarmBB.getBB().getSharedLock().unlock(); } return dunitRun; }
public void recordFail(String className, String methodName, long tookMs) { try { DUnitRun du = getDUnitRun(); DUnitClassInfo duci = Swarm.getOrCreateDUnitClassInfo(className); DUnitMethodInfo dumi = Swarm.getOrCreateDUnitMethodInfo(methodName, duci.getId()); Swarm.recordFailure(du, dumi, lastThrowable, tookMs); } catch (SQLException se) { se.printStackTrace(); } }
protected boolean executeOnlyIf(Connection con, String q) throws SQLException { if (q == null) return true; Statement stmt = null; try { stmt = con.createStatement(); q = q.replace("$PREFIX", getPrefix()); LOG.debug(" Executing query " + q); ResultSet rs = stmt.executeQuery(q); rs.next(); boolean res = rs.getBoolean(1); LOG.debug("Result: " + res); return res; } catch (SQLException sqe) { LOG.error(sqe.getMessage() + " from " + q); throw sqe; } finally { try { if (stmt != null) { stmt.close(); } } catch (Exception g) { } } }