@Override public List<com.enioka.jqm.api.JobInstance> getActiveJobs() { return Query.create().setQueryHistoryInstances(false).setQueryLiveInstances(true).addSortAsc(Sort.ID).run(); }
@Override public List<com.enioka.jqm.api.JobInstance> getUserActiveJobs(String user) { if (user == null || user.isEmpty()) { throw new JqmInvalidRequestException("user cannot be null or empty"); } return Query.create().setUser(user).setQueryHistoryInstances(false).setQueryLiveInstances(true).addSortAsc(Sort.ID).run(); }
/** * 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 testRunnableInject() throws Exception { JqmSimpleTest.create(cnx, "pyl.EngineApiInjectThread").expectOk(3).run(this); Assert.assertEquals(3, (int) cnx.runSelectSingle("message_select_count_all", Integer.class)); Assert.assertEquals(100, (int) Query.create().addSortAsc(Sort.ID).run().get(0).getProgress()); }
@Test public void testPauseInQueue() throws Exception { CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-datetimemaven/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other", false, cnx); int i = JobRequest.create("MarsuApplication", "TestUser").submit(); JqmClientFactory.getClient().pauseQueuedJob(i); JobRequest.create("MarsuApplication", "TestUser").submit(); addAndStartEngine(); TestHelpers.waitFor(1, 5000, cnx); List<JobInstance> res1 = Query.create().addSortAsc(Sort.DATEENQUEUE).run(); List<JobInstance> res2 = Query.create().addSortAsc(Sort.DATEENQUEUE).setQueryHistoryInstances(false).setQueryLiveInstances(true) .run(); Assert.assertEquals(1, res1.size()); Assert.assertEquals(1, res2.size()); Assert.assertEquals(State.HOLDED, res2.get(0).getState()); Assert.assertEquals(State.ENDED, res1.get(0).getState()); }
@Test public void testChangeQueue() throws Exception { CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-datetimemaven/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other", false, cnx); int i = JobRequest.create("MarsuApplication", "TestUser").submit(); JqmClientFactory.getClient().setJobQueue(i, TestHelpers.qSlow); addAndStartEngine(); TestHelpers.waitFor(1, 10000, cnx); List<JobInstance> res = Query.create().addSortAsc(Sort.DATEENQUEUE).run(); Assert.assertEquals(1, res.size()); Assert.assertEquals(State.ENDED, res.get(0).getState()); Assert.assertEquals("SlowQueue", res.get(0).getQueue().getName()); }
@Test public void testHighlanderEngineRunning() throws Exception { // This test launches an infinite loop as Highlander, checks if no other job can launch. Job is killed at the end - which allows a // second one to run, which also has to be killed. CreationTools.createJobDef(null, true, "pyl.KillMe", null, "jqm-tests/jqm-test-pyl/target/test.jar", TestHelpers.qVip, 42, "kill", null, "Franquin", "ModuleMachin", "other", "other", true, cnx); addAndStartEngine(); int firstJob = JobRequest.create("kill", "TestUser").submit(); for (int i = 0; i < 100; i++) { JobRequest.create("kill", "TestUser").submit(); } Thread.sleep(3000); Calendar killTime1 = Calendar.getInstance(); JqmClientFactory.getClient().killJob(firstJob); Thread.sleep(3000); JqmClientFactory.getClient().killJob(JqmClientFactory.getClient().getUserActiveJobs("TestUser").get(0).getId()); TestHelpers.waitFor(2, 10000, cnx); List<com.enioka.jqm.api.JobInstance> res = Query.create().addSortAsc(Sort.ID).run(); Assert.assertEquals(2, res.size()); Assert.assertEquals(State.CRASHED, res.get(0).getState()); Assert.assertEquals(State.CRASHED, res.get(1).getState()); Assert.assertTrue(killTime1.compareTo(res.get(1).getBeganRunningDate()) <= 0); }
@Test public void testCancelJob() throws Exception { CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-datetimemaven/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other", false, cnx); int i = JobRequest.create("MarsuApplication", "TestUser").submit(); JqmClientFactory.getClient().cancelJob(i); JobRequest.create("MarsuApplication", "TestUser").submit(); addAndStartEngine(); TestHelpers.waitFor(2, 5000, cnx); List<JobInstance> res = Query.create().addSortAsc(Sort.DATEENQUEUE).run(); Assert.assertEquals(2, res.size()); Assert.assertEquals(State.CANCELLED, res.get(0).getState()); Assert.assertEquals(State.ENDED, res.get(1).getState()); }
@Test public void testRestartJob() throws Exception { CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-datetimemaven/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other", true, cnx); int i = JobRequest.create("MarsuApplication", "TestUser").submit(); addAndStartEngine(); TestHelpers.waitFor(1, 10000, cnx); JqmClientFactory.getClient().enqueueFromHistory(i); TestHelpers.waitFor(2, 10000, cnx); Assert.assertEquals(2, TestHelpers.getOkCount(cnx)); Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx)); List<JobInstance> res = Query.create().addSortAsc(Sort.DATEENQUEUE).run(); Assert.assertEquals(2, res.size()); Assert.assertEquals("MarsuApplication", res.get(0).getApplicationName()); Assert.assertEquals("MarsuApplication", res.get(1).getApplicationName()); }
List<com.enioka.jqm.api.JobInstance> res = Query.create().addSortAsc(Sort.ID).run();
.addSortAsc(Sort.ID).run();
@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); } }