@Override public void waitChild(int id) { JqmClient c = getJqmClient(); Query q = Query.create().setQueryHistoryInstances(false).setQueryLiveInstances(true).setJobInstanceId(id); while (!c.getJobs(q).isEmpty()) { try { Thread.sleep(1000); handleInstructions(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } } }
@Override public void waitChild(int id) { JqmClient c = getJqmClient(); Query q = Query.create().setQueryHistoryInstances(false).setQueryLiveInstances(true).setJobInstanceId(id); while (!c.getJobs(q).isEmpty()) { try { Thread.sleep(1000); handleInstructions(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } } }
/** * Version of {@link JqmClient#getDeliverableContent(Deliverable)} which does not require the web service APIs to be enabled to work. * Also, returned files do not self-destruct on stream close.<br> * See the javadoc of the original method for details. * * @throws FileNotFoundException */ public InputStream getDeliverableContent(Deliverable file) throws FileNotFoundException { List<com.enioka.jqm.model.Deliverable> dd = com.enioka.jqm.model.Deliverable.select(cnx, "deliverable_select_by_id", file.getId()); if (dd.isEmpty()) { throw new JqmInvalidRequestException("no deliverable with this ID"); } com.enioka.jqm.model.Deliverable d = dd.get(0); JobInstance ji = Query.create().setJobInstanceId(d.getJobId()).run().get(0); String nodeName = ji.getNodeName(); Node n = nodes.get(nodeName); return new FileInputStream(FilenameUtils.concat(n.getDlRepo(), file.getFilePath())); } }
/** * Version of {@link JqmClient#getDeliverableContent(Deliverable)} which does not require the web service APIs to be enabled to work. * Also, returned files do not self-destruct on stream close.<br> * See the javadoc of the original method for details. * * @throws FileNotFoundException */ public InputStream getDeliverableContent(Deliverable file) throws FileNotFoundException { List<com.enioka.jqm.model.Deliverable> dd = com.enioka.jqm.model.Deliverable.select(cnx, "deliverable_select_by_id", file.getId()); if (dd.isEmpty()) { throw new JqmInvalidRequestException("no deliverable with this ID"); } com.enioka.jqm.model.Deliverable d = dd.get(0); JobInstance ji = Query.create().setJobInstanceId(d.getJobId()).run().get(0); String nodeName = ji.getNodeName(); Node n = nodes.get(nodeName); return new FileInputStream(FilenameUtils.concat(n.getDlRepo(), file.getFilePath())); } }
return Query.create().setJobInstanceId(idJob).setQueryHistoryInstances(true).setQueryLiveInstances(true).run().get(0);
@Test public void testSendMsg() throws Exception { boolean success = false; boolean success2 = false; boolean success3 = false; int i = JqmSimpleTest.create(cnx, "pyl.EngineApiSend3Msg").run(this); List<String> messages = Query.create().setJobInstanceId(i).run().get(0).getMessages(); for (String msg : messages) { if (msg.equals("Les marsus sont nos amis, il faut les aimer aussi!")) { success = true; } if (msg.equals("Les marsus sont nos amis, il faut les aimer aussi!2")) { success2 = true; } if (msg.equals("Les marsus sont nos amis, il faut les aimer aussi!3")) { success3 = true; } } Assert.assertEquals(true, success); Assert.assertEquals(true, success2); Assert.assertEquals(true, success3); }
@Test public void testFifo() throws Exception { // Single thread available. int qId = Queue.create(cnx, "testqueue", " ", false); DeploymentParameter.create(cnx, TestHelpers.node.getId(), 1, 1, qId); CreationTools.createJobDef(null, true, "pyl.Wait", null, "jqm-tests/jqm-test-pyl-nodep/target/test.jar", qId, 42, "jqm-test-wait", null, "Franquin", "ModuleMachin", "other", "other", false, cnx); cnx.commit(); // No priority = FIFO queue. int i1 = JobRequest.create("jqm-test-wait", "test").addParameter("ms", "100").setPriority(null).submit(); int i2 = JobRequest.create("jqm-test-wait", "test").addParameter("ms", "100").setPriority(null).submit(); addAndStartEngine(); TestHelpers.waitFor(2, 60000, cnx); Assert.assertEquals(2, TestHelpers.getOkCount(cnx)); Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx)); Assert.assertEquals(0, TestHelpers.getQueueRunningCount(cnx)); JobInstance ji1 = Query.create().setJobInstanceId(i1).run().get(0); JobInstance ji2 = Query.create().setJobInstanceId(i2).run().get(0); Assert.assertTrue(ji1.getBeganRunningDate().compareTo(ji2.getEndDate()) <= 0); }
@Test public void testPriority() throws Exception { // Single thread available. int qId = Queue.create(cnx, "testqueue", " ", false); DeploymentParameter.create(cnx, TestHelpers.node.getId(), 1, 1, qId); CreationTools.createJobDef(null, true, "pyl.Wait", null, "jqm-tests/jqm-test-pyl-nodep/target/test.jar", qId, 42, "jqm-test-wait", null, "Franquin", "ModuleMachin", "other", "other", false, cnx); cnx.commit(); // Enqueue a low priority first, then a higher priority one. The higher priority should run first. int i1 = JobRequest.create("jqm-test-wait", "test").addParameter("ms", "100").setPriority(1).submit(); int i2 = JobRequest.create("jqm-test-wait", "test").addParameter("ms", "100").setPriority(6).submit(); addAndStartEngine(); TestHelpers.waitFor(2, 60000, cnx); Assert.assertEquals(2, TestHelpers.getOkCount(cnx)); Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx)); Assert.assertEquals(0, TestHelpers.getQueueRunningCount(cnx)); JobInstance ji1 = Query.create().setJobInstanceId(i1).run().get(0); JobInstance ji2 = Query.create().setJobInstanceId(i2).run().get(0); Assert.assertEquals(1, (int) ji1.getPriority()); Assert.assertEquals(6, (int) ji2.getPriority()); Assert.assertTrue(ji1.getBeganRunningDate().compareTo(ji2.getEndDate()) >= 0); }