/** * Return the default client. Note this client is shared in the static context. (said otherwise: the same client is always returned * inside a same class loading context). The initialization cost is only paid at first call. * * @return the default client */ public static JqmClient getClient() { return getClient(null, null, true); }
private void close() { s.stop(); s.shutdown(); cnx.close(); JqmClientFactory.resetClient(); JqmClientFactory.setProperties(new Properties()); }
/** * Return a new client that may be cached or not. Given properties are always use when not cached, and only used at creation time for * cached clients. * * @param name * if null, default client. Otherwise, helpful to retrieve cached clients later. * @param p * a set of properties. Implementation specific. Unknown properties are silently ignored. * @param cached * if false, the client will not be cached and subsequent calls with the same name will return different objects. */ public static JqmClient getClient(String name, Properties p, boolean cached) { Properties p2 = null; if (binder == null) { bind(); } if (p == null) { p2 = props; } else { p2 = new Properties(props); p2.putAll(p); } return binder.getClientFactory().getClient(name, p2, cached); }
/** * Retrieve a remote file with authentication, with SSL. */ @Test public void testGetOneDeliverableWithAuthWithSsl() throws Exception { Helpers.setSingleParam("disableWsApi", "false", cnx); Helpers.setSingleParam("enableWsApiAuth", "true", cnx); Helpers.setSingleParam("enableWsApiSsl", "true", cnx); JqmClientFactory.resetClient(null); JqmClientFactory.setProperty("com.enioka.jqm.ws.truststoreFile", "./conf/trusted.jks"); JqmClientFactory.setProperty("com.enioka.jqm.ws.truststorePass", "SuperPassword"); int jobId = JqmSimpleTest.create(cnx, "pyl.EngineApiSendDeliverable").addDefParameter("filepath", TestHelpers.node.getDlRepo()) .addDefParameter("fileName", "jqm-test-deliverable4.txt").run(this); File f = new File(TestHelpers.node.getDlRepo() + "jqm-test-deliverable4.txt"); Assert.assertEquals(false, f.exists()); // file should have been moved List<com.enioka.jqm.api.Deliverable> files = JqmClientFactory.getClient().getJobDeliverables(jobId); Assert.assertEquals(1, files.size()); InputStream tmp = JqmClientFactory.getClient().getDeliverableContent(files.get(0)); Assert.assertTrue(tmp.available() > 0); String res = IOUtils.toString(tmp, Charset.defaultCharset()); Assert.assertTrue(res.startsWith("Hello World!")); tmp.close(); }
/** * This is {@link #resetClient(String)} with name = null. */ public static void resetClient() { resetClient(null); }
private static Db createFactory() { try { Properties p = Db.loadProperties(); Db n = new Db(p); p.put("com.enioka.jqm.jdbc.contextobject", n); // Share the DataSource in engine and client. JqmClientFactory.setProperties(p); return n; } catch (Exception e) { jqmlogger.error("Unable to connect with the database. Maybe your configuration file is wrong. " + "Please check the password or the url in the $JQM_DIR/conf/resources.xml", e); throw new JqmInitError("Database connection issue", e); } }
private static final void bind() { Set<URL> staticClientBinderPathSet = findClientBinders(); if (staticClientBinderPathSet.isEmpty()) { throw new JqmClientException("there was no client implementation on the classpath"); } if (staticClientBinderPathSet.size() > 1) { throw new JqmClientException("there were multiple client implementations on the classpath. Only keep the one you want to use"); } try { @SuppressWarnings("unchecked") Class<IClientFactoryBinder> binderClass = (Class<IClientFactoryBinder>) JqmClientFactory.class.getClassLoader() .loadClass(STATIC_CLIENT_BINDER_NAME); binder = (IClientFactoryBinder) binderClass.getMethod("getSingleton").invoke(null); } catch (ClassNotFoundException e) { // Should never happen... } catch (Exception e) { throw new JqmClientException("could not load the client provider", e); } }
/** * Stops all engines. Only returns when engines are fully stopped. */ public void stop() { if (!hasStarted) { throw new IllegalStateException("cannot stop a tester which has not started"); } for (JqmEngineOperations op : this.engines.values()) { op.stop(); } JqmClientFactory.resetClient(); cnx.close(); s.stop(); waitDbStop(); s = null; hasStarted = false; this.engines.clear(); }
private static Db createFactory() { try { Properties p = Db.loadProperties(); Db n = new Db(p); p.put("com.enioka.jqm.jdbc.contextobject", n); // Share the DataSource in engine and client. JqmClientFactory.setProperties(p); return n; } catch (Exception e) { jqmlogger.error("Unable to connect with the database. Maybe your configuration file is wrong. " + "Please check the password or the url in the $JQM_DIR/conf/resources.xml", e); throw new JqmInitError("Database connection issue", e); } }
private JqmClient getJqmClient() { return JqmClientFactory.getClient(); }
private void close() { s.stop(); s.shutdown(); cnx.close(); JqmClientFactory.resetClient(); JqmClientFactory.setProperties(new Properties()); }
/** * Stops all engines. Only returns when engines are fully stopped. */ public void stop() { if (!hasStarted) { throw new IllegalStateException("cannot stop a tester which has not started"); } for (JqmEngineOperations op : this.engines.values()) { op.stop(); } JqmClientFactory.resetClient(); cnx.close(); s.stop(); waitDbStop(); s = null; hasStarted = false; this.engines.clear(); }
JqmClientFactory.setProperties(p2);
/** * Remove the client of the given name from the static cache. Next time {@link #getClient(String, Properties, boolean)} is called, * initialization cost will have to be paid once again.<br> * Use <code>null</code> to reset the default client.<br> * This method is mostly useful for tests when databases are reset and therefore clients become invalid as they hold connections to * them.<br> * If the name does not exist, no exception is thrown. * * @param name * the client to reset, or <code>null</code> for the default client */ public static void resetClient(String name) { if (binder == null) { bind(); } binder.getClientFactory().resetClient(name); }
private JqmClient getJqmClient() { return JqmClientFactory.getClient(); }
@Before public void beforeTest() { jqmlogger.debug("**********************************************************"); jqmlogger.debug("Starting test " + testName.getMethodName()); try { ((JndiContext) NamingManager.getInitialContext(null)).resetSingletons(); } catch (NamingException e) { jqmlogger.warn("Could not purge test JNDI context", e); } JqmClientFactory.resetClient(null); cnx = getNewDbSession(); TestHelpers.cleanup(cnx); TestHelpers.createTestData(cnx); cnx.commit(); }
JqmClientFactory.setProperties(p2);
@Override int doWork() { jqmlogger.info("Will enqueue application named " + applicationName + " without parameter overloads"); jqmlogger.info("Request ID is: " + JqmClientFactory.getClient().enqueue(applicationName, "CommandLineUser")); return 0; } }
public JqmAsyncTester() { // Ext dir File extDir = new File("./ext"); if (!extDir.exists() && !extDir.mkdir()) { throw new RuntimeException(new IOException("./ext directory does not exist and cannot create it")); } s = Common.createHsqlServer(); s.start(); JDBCDataSource ds = new JDBCDataSource(); ds.setDatabase("jdbc:hsqldb:mem:" + s.getDatabaseName(0, true)); db = new Db(ds, true); cnx = db.getConn(); Properties p2 = Common.dbProperties(s); p2.put("com.enioka.jqm.jdbc.contextobject", db); JqmClientFactory.setProperties(p2); JqmEngineFactory.setDatasource(db); JqmEngineFactory.initializeMetadata(); cnx.runUpdate("dp_delete_all"); cnx.runUpdate("q_delete_all"); cnx.commit(); // Needed parameters addGlobalParameter("defaultConnection", ""); addGlobalParameter("disableWsApi", "true"); addGlobalParameter("logFilePerLaunch", "false"); // Prepare DB }
/** * The end of the fluent Query API. It simply executes the query and returns the results. */ public List<JobInstance> run() { return JqmClientFactory.getClient().getJobs(this); }