/** * Public constructor for fluid API. * * @param applicationName * name (key) of the job to launch * @param user * name of the human user that is at the origin of the request. If no user (e.g. inside an automated system), * the application module name should be used. */ public static JobRequest create(String applicationName, String user) { return new JobRequest(applicationName, user); }
@Override public int enqueue(String applicationName, String userName) { return enqueue(new JobRequest(applicationName, userName)); }
@Override public int enqueue(String applicationName, String userName) { return enqueue(new JobRequest(applicationName, userName)); }
@Override public void start() { log.info("Starting payload"); EntityManagerFactory emf = Persistence.createEntityManagerFactory("marsu-pu"); EntityManager em = emf.createEntityManager(); log.info("Running query"); em.createQuery("SELECT e from Entity e"); if (this.getParameters().size() == 0) { log.info("Queuing again - with parameter and through the full API"); JobRequest jd = new JobRequest("jqm-test-em", "marsu"); jd.addParameter("stop", "1"); JqmClientFactory.getClient().enqueue(jd); } log.info("End of payload"); } }
JobRequest j = new JobRequest("MarsuApplication", "TestUser"); int i = JqmClientFactory.getClient().enqueue(j); TestHelpers.waitFor(1, 10000, cnx);
@Test public void testProvidedApi() throws Exception { CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-providedapi/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other", true, cnx); // Create an empty lib directory just to be sure no dependencies will be resolved. FileUtils.forceMkdir(new File("../jqm-tests/jqm-test-providedapi/target/lib")); JobRequest j = new JobRequest("MarsuApplication", "TestUser"); JqmClientFactory.getClient().enqueue(j); addAndStartEngine(); TestHelpers.waitFor(1, 10000, cnx); Assert.assertEquals(1, TestHelpers.getOkCount(cnx)); Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx)); }
@Override public int enqueueFromHistory(int jobIdToCopy) { JobInstance h = getJob(jobIdToCopy); JobRequest jd = new JobRequest(); jd.setApplication(h.getApplication()); jd.setApplicationName(h.getApplicationName()); jd.setEmail(h.getEmail()); jd.setKeyword1(h.getKeyword1()); jd.setKeyword2(h.getKeyword2()); jd.setKeyword3(h.getKeyword3()); jd.setModule(h.getModule()); jd.setParentID(h.getParent()); jd.setSessionID(h.getSessionID()); jd.setUser(h.getUser()); for (Map.Entry<String, String> p : h.getParameters().entrySet()) { jd.addParameter(p.getKey(), p.getValue()); } return enqueue(jd); }
"MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other", true, cnx); JobRequest j = new JobRequest("MarsuApplication", "TestUser"); for (int i = 0; i < 9; i++)
@Test public void testLongName() throws Exception { CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-datetimemaven/target/test.jar", TestHelpers.qVip, 42, "Marsu-Application-nnnnnnnn-nnnnnn-nnnnnnnnnn-nnNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNnn-nnnnnnnnn", null, "Franquin", "ModuleMachin", "other", "other", true, cnx); JobRequest j = new JobRequest("Marsu-Application-nnnnnnnn-nnnnnn-nnnnnnnnnn-nnNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNnn-nnnnnnnnn", "TestUser"); JqmClientFactory.getClient().enqueue(j); addAndStartEngine(); TestHelpers.waitFor(1, 10000, cnx); Assert.assertEquals(1, TestHelpers.getOkCount(cnx)); Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx)); }
public void testDbFailureUnderLoadWithExternalDb() throws Exception { // Many starting jobs simultaneously cnx.runUpdate("dp_update_threads_by_id", 50, TestHelpers.dpVip.getId()); cnx.commit(); TestHelpers.setNodesLogLevel("INFO", cnx); CreationTools.createJobDef(null, true, "pyl.Nothing", null, "jqm-tests/jqm-test-pyl-nodep/target/test.jar", TestHelpers.qVip, -1, "TestJqmApplication", "appFreeName", "TestModule", "kw1", "kw2", "kw3", false, cnx); JobRequest j = new JobRequest("TestJqmApplication", "TestUser"); for (int i = 0; i < 1000; i++) { JqmClientFactory.getClient().enqueue(j); } addAndStartEngine(); // TestHelpers.waitFor(ji, 120000, this.getNewDbSession()); this.sleep(1000); }
CreationTools.createJobDef(null, true, "pyl.EngineApiSendMsg", null, "jqm-tests/jqm-test-pyl/target/test.jar", TestHelpers.qVip2, 42, "AppliNode2-1", null, "Franquin", "ModuleMachin", "other", "other", false, cnx); JobRequest j11 = new JobRequest("AppliNode1-1", "TestUser"); JobRequest j21 = new JobRequest("AppliNode2-1", "TestUser");
@Override public Integer enqueue(String applicationName, String user, String mail, String sessionId, String application, String module, String keyword1, String keyword2, String keyword3, Map<String, String> parameters) { JobRequest jr = new JobRequest(applicationName, user, mail); jr.setApplicationName(applicationName); jr.setUser(user == null ? ji.getUserName() : user); jr.setEmail(mail); jr.setSessionID(sessionId == null ? this.ji.getSessionID() : sessionId); jr.setApplication(application == null ? this.ji.getJD().getApplication() : application); jr.setModule(module == null ? this.ji.getJD().getModule() : module); jr.setKeyword1(keyword1); jr.setKeyword2(keyword2); jr.setKeyword3(keyword3); jr.setParentID(this.ji.getId()); if (parameters != null) { jr.setParameters(parameters); } return getJqmClient().enqueue(jr); }
@Test public void testOneQueueTwoNodes() throws Exception { CreationTools.createJobDef(null, true, "pyl.EngineApiSendMsg", null, "jqm-tests/jqm-test-pyl/target/test.jar", TestHelpers.qVip, 42, "AppliNode1-1", null, "Franquin", "ModuleMachin", "other", "other", false, cnx); JobRequest j11 = new JobRequest("AppliNode1-1", "TestUser"); for (int i = 0; i < 10; i++) { JqmClientFactory.getClient().enqueue(j11); } addAndStartEngine("localhost"); addAndStartEngine("localhost4"); for (int j = 0; j < 3; j++) { for (int i = 0; i < 10; i++) { JqmClientFactory.getClient().enqueue(j11); } Thread.sleep(200); } TestHelpers.waitFor(40, 60000, cnx); Thread.sleep(2000); // to ensure there are no additional runs Assert.assertEquals(40, (int) cnx.runSelectSingle("message_select_count_all", Integer.class)); Assert.assertEquals(40, TestHelpers.getOkCount(cnx)); Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx)); // Ran on both nodes? Assert.assertTrue(Query.create().setNodeName("localhost48").run().size() == 0L); Assert.assertTrue(Query.create().setNodeName("localhost").run().size() > 0L); Assert.assertTrue(Query.create().setNodeName("localhost4").run().size() > 0L); }
@Override public Integer enqueue(String applicationName, String user, String mail, String sessionId, String application, String module, String keyword1, String keyword2, String keyword3, Map<String, String> parameters) { JobRequest jr = new JobRequest(applicationName, user, mail); jr.setApplicationName(applicationName); jr.setUser(user == null ? ji.getUserName() : user); jr.setEmail(mail); jr.setSessionID(sessionId == null ? this.ji.getSessionID() : sessionId); jr.setApplication(application == null ? this.ji.getJD().getApplication() : application); jr.setModule(module == null ? this.ji.getJD().getModule() : module); jr.setKeyword1(keyword1); jr.setKeyword2(keyword2); jr.setKeyword3(keyword3); jr.setParentID(this.ji.getId()); if (parameters != null) { jr.setParameters(parameters); } return getJqmClient().enqueue(jr); }
@Test public void testHighlanderenqueueEngineDead() 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); JobRequest j = new JobRequest("MarsuApplication", "TestUser"); JqmClientFactory.getClient().enqueue(j); JqmClientFactory.getClient().enqueue(j); addAndStartEngine(); TestHelpers.waitFor(1, 10000, cnx); Assert.assertEquals(1, TestHelpers.getOkCount(cnx)); Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx)); }
"Franquin", "WithoutH", "other", "other", false, cnx); int i1 = JqmClientFactory.getClient().enqueue(new JobRequest("WithH", "TestUser")); int i2 = JqmClientFactory.getClient().enqueue(new JobRequest("WithH", "TestUser")); sleep(2); int i3 = JqmClientFactory.getClient().enqueue(new JobRequest("WithoutH", "TestUser"));
JobRequest j11 = new JobRequest("AppliNode1-1", "TestUser"); for (int i = 0; i < 10; i++)
@Test public void testJobWithPersistenceUnitAndEngineApiAndXmlParams() throws Exception { CreationTools.createDatabaseProp("jdbc/test", "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:testdbmarsu", "SA", "", cnx, "SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS", null); CreationTools.createDatabaseProp("jdbc/jqm2", "org.hsqldb.jdbcDriver", "jdbc:hsqldb:hsql://localhost/testdbengine", "SA", "", cnx, "SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS", null); cnx.commit(); XmlJobDefParser.parse("target/payloads/jqm-test-xml/xmlstop.xml", cnx); cnx.commit(); JobRequest j = new JobRequest("CompatHibApi", "TestUser"); JqmClientFactory.getClient().enqueue(j); addAndStartEngine(); TestHelpers.waitFor(1, 10000, cnx); Assert.assertEquals(1, TestHelpers.getOkCount(cnx)); }
@Test public void testDbFailureUnderLoad() throws Exception { // Many starting jobs simultaneously cnx.runUpdate("dp_update_threads_by_id", 50, TestHelpers.dpVip.getId()); cnx.commit(); TestHelpers.setNodesLogLevel("INFO", cnx); CreationTools.createJobDef(null, true, "pyl.Nothing", null, "jqm-tests/jqm-test-pyl-nodep/target/test.jar", TestHelpers.qVip, -1, "TestJqmApplication", "appFreeName", "TestModule", "kw1", "kw2", "kw3", false, cnx); JobRequest j = new JobRequest("TestJqmApplication", "TestUser"); for (int i = 0; i < 1000; i++) { JqmClientFactory.getClient().enqueue(j); } addAndStartEngine(); this.sleep(1); jqmlogger.info("Stopping db"); simulateDbFailure(); TestHelpers.waitFor(1000, 120000, this.getNewDbSession()); Assert.assertEquals(1000, TestHelpers.getOkCount(this.getNewDbSession())); // Assert.assertTrue(this.engines.get("localhost").isAllPollersPolling()); } }
public void testNoDuplicateLaunchesUnderLoad() throws Exception { // Many starting jobs simultaneously cnx.runUpdate("dp_update_threads_by_id", 50, TestHelpers.dpVip.getId()); cnx.commit(); TestHelpers.setNodesLogLevel("INFO", cnx); CreationTools.createJobDef(null, true, "pyl.Nothing", null, "jqm-tests/jqm-test-pyl-nodep/target/test.jar", TestHelpers.qVip, -1, "TestJqmApplication", "appFreeName", "TestModule", "kw1", "kw2", "kw3", false, cnx); JobRequest j = new JobRequest("TestJqmApplication", "TestUser"); int ji = 0; for (int i = 0; i < 1000; i++) { ++ji; JqmClientFactory.getClient().enqueue(j); } addAndStartEngine(); TestHelpers.waitFor(ji, 120000, this.getNewDbSession()); this.sleep(3); Assert.assertEquals(1000, TestHelpers.getHistoryAllCount(cnx)); } }