protected void displayAllHistoryTable() { java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("HH:mm:ss.SSS"); jqmlogger.debug("=========================================================================================="); for (JobInstance h : Query.create().run()) { jqmlogger.debug("JobInstance Id: " + h.getId() + " | " + h.getState() + " | JD: " + h.getApplicationName() + " | " + h.getQueueName() + " | enqueue: " + format.format(h.getEnqueueDate().getTime()) + " | exec: " + (h.getBeganRunningDate() != null ? format.format(h.getBeganRunningDate().getTime()) : null) + " | end: " + (h.getEndDate() != null ? format.format(h.getEndDate().getTime()) : null)); } jqmlogger.debug("=========================================================================================="); } }
/** * A parent job can wait for all its children - then its end date should be after the end date of the children. */ @Test public void testWaitChildren() throws Exception { JqmSimpleTest.create(cnx, "pyl.EngineApiWaitAll").expectOk(6).run(this); List<JobInstance> jj = Query.create().addSortAsc(Sort.ID).addStatusFilter(State.ENDED).run(); Calendar parentEnd = jj.get(0).getEndDate(); for (int i = 1; i < 6; i++) { Assert.assertTrue(parentEnd.after(jj.get(i).getEndDate())); } }
@Test public void testEnqueueSynchronously() throws Exception { JqmSimpleTest.create(cnx, "pyl.StressFiboSync").addRuntimeParameter("p1", "34").addRuntimeParameter("p2", "55").expectOk(4) .run(this); List<JobInstance> res = Query.create().addSortAsc(Sort.ID).run(); JobInstance h1, h2 = null; for (JobInstance h : res) { h1 = h2; h2 = h; if (h1 == null) { continue; } Assert.assertEquals(h2.getParent(), h1.getId()); Assert.assertTrue(h2.getEndDate().compareTo(h1.getEndDate()) <= 0); Assert.assertTrue(h2.getEndDate().compareTo(h1.getBeganRunningDate()) > 0); } }
@Test public void testHistoryFields() throws Exception { CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-datetimemaven/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other2", true, cnx); int i = JobRequest.create("MarsuApplication", "TestUser").setSessionID("session42").setKeyword1("k1").setKeyword2("k2").submit(); addAndStartEngine(); TestHelpers.waitFor(1, 10000, cnx); Assert.assertEquals(1, TestHelpers.getOkCount(cnx)); JobInstance h = JqmClientFactory.getClient().getJob(i); SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm"); jqmlogger.debug("enqueueDate: " + df.format(h.getEnqueueDate().getTime())); jqmlogger.debug("ExecutionDate: " + df.format(h.getBeganRunningDate().getTime())); jqmlogger.debug("EndDate: " + df.format(h.getEndDate().getTime())); Assert.assertTrue(h.getEnqueueDate() != null); Assert.assertTrue(h.getUser() != null); Assert.assertTrue(h.getEndDate() != null); Assert.assertTrue(h.getBeganRunningDate() != null); Assert.assertTrue(h.getSessionID() != null); Assert.assertEquals("session42", h.getSessionID()); JobInstance ji = Query.create().setApplicationName("MarsuApplication").run().get(0); Assert.assertEquals("ModuleMachin", ji.getDefinitionKeyword1()); Assert.assertEquals("other", ji.getDefinitionKeyword2()); Assert.assertEquals("other2", ji.getDefinitionKeyword3()); Assert.assertEquals("k1", ji.getKeyword1()); Assert.assertEquals("k2", ji.getKeyword2()); Assert.assertEquals(null, ji.getKeyword3()); }
prevEnd = h.getEndDate();
@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); }