/** * Create a new connection using the information specified in the * {@code prefs}. * * @param prefs a {@link ConcourseClientPreferences prefs} handler * @return the connection */ public static Concourse connectWithPrefs(ConcourseClientPreferences prefs) { return connect(prefs.getHost(), prefs.getPort(), prefs.getUsername(), String.valueOf(prefs.getPassword()), prefs.getEnvironment()); }
/** * Return a {@link ConnectionPool} that has no limit on the number of * connections it can manage to the Concourse instance at {@code host}: * {@code port} on behalf of the user identified by {@code username} and * {@code password}, but will try to use previously created connections * before establishing new ones for any request. * * @param prefs * @return the ConnectionPool */ public static ConnectionPool newCachedConnectionPool(String prefs) { ConcourseClientPreferences cp = ConcourseClientPreferences .from(Paths.get(prefs)); return new CachedConnectionPool(cp.getHost(), cp.getPort(), cp.getUsername(), new String(cp.getPassword()), cp.getEnvironment(), DEFAULT_POOL_SIZE); }
/** * Return a new {@link ConnectionPool} with a fixed number of * connections to the Concourse instance defined in the client {@code prefs} * on behalf of the user defined in the client {@code prefs}. * <p> * If all the connections from the pool are active, subsequent request * attempts will block until a connection is returned. * </p> * * @param prefs * @param poolSize * @return the ConnectionPool */ public static ConnectionPool newFixedConnectionPool(String prefs, int poolSize) { ConcourseClientPreferences cp = ConcourseClientPreferences .from(Paths.get(prefs)); return new FixedConnectionPool(cp.getHost(), cp.getPort(), cp.getUsername(), new String(cp.getPassword()), cp.getEnvironment(), poolSize); }
options.password = new String(prefs.getPasswordExplicit()); options.host = prefs.getHost(); options.port = prefs.getPort(); options.environment = prefs.getEnvironment();
@Test public void testGetPortWhenNotProvided() { ConcourseClientPreferences prefs = ConcourseClientPreferences .from(prefsPath); Assert.assertEquals(1717, prefs.getPort()); }
@Test public void testGetPortWhenWrittenAsString() { appendLine("port = \"1717\""); ConcourseClientPreferences prefs = ConcourseClientPreferences .from(prefsPath); Assert.assertEquals(1717, prefs.getPort()); }
opts.password = new String(prefs.getPasswordExplicit()); opts.host = prefs.getHost(); opts.port = prefs.getPort(); opts.environment = prefs.getEnvironment();
@Test public void testSet() { ConcourseClientPreferences prefs = ConcourseClientPreferences .from(prefsPath); prefs.setPort(9000); prefs = ConcourseClientPreferences.from(prefsPath); Assert.assertEquals(9000, prefs.getPort()); }