/** * Create a MySQL client which maintains its own pool. * @param vertx the Vert.x instance * @param config the configuration * @return the client */ public static io.vertx.rxjava.ext.asyncsql.AsyncSQLClient createNonShared(io.vertx.rxjava.core.Vertx vertx, JsonObject config) { io.vertx.rxjava.ext.asyncsql.AsyncSQLClient ret = io.vertx.rxjava.ext.asyncsql.AsyncSQLClient.newInstance(io.vertx.ext.asyncsql.MySQLClient.createNonShared(vertx.getDelegate(), config)); return ret; }
public static io.vertx.ext.asyncsql.AsyncSQLClient createNonShared(io.vertx.ext.asyncsql.MySQLClient j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> config) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.asyncsql.MySQLClient.createNonShared(vertx, config != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(config) : null)); } public static io.vertx.ext.asyncsql.AsyncSQLClient createShared(io.vertx.ext.asyncsql.MySQLClient j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> config, java.lang.String poolName) {
@Override protected void internalInit(Handler<AsyncResult<IDataStore>> handler) { try { mySQLClient = shared ? MySQLClient.createShared(vertx, getConfig()) : MySQLClient.createNonShared(vertx, getConfig()); datastore = new MySqlDataStore(vertx, mySQLClient, getConfig()); handler.handle(Future.succeededFuture(datastore)); } catch (Exception e) { handler.handle(Future.failedFuture(e)); } }
@Override protected SQLClient createClient(Vertx vertx, JsonObject config) { return MySQLClient.createNonShared(vertx, config.mergeIn(new JsonObject() .put("host", mysql.getContainerIpAddress()) .put("port", mysql.getMappedPort(3306)) .put("database", MYSQL_DATABASE) .put("username", MYSQL_USERNAME) .put("password", MYSQL_PASSWORD))); }
@Override protected SQLClient createClient(Vertx vertx, JsonObject config) { return MySQLClient.createNonShared(vertx, config.mergeIn(new JsonObject() .put("host", mysql.getContainerIpAddress()) .put("port", mysql.getMappedPort(3306)) .put("database", MYSQL_DATABASE) .put("username", MYSQL_USERNAME) .put("password", MYSQL_PASSWORD))); }
@Override protected SQLClient createClient(Vertx vertx, JsonObject config) { return MySQLClient.createNonShared(vertx, config.mergeIn(new JsonObject() .put("host", mysql.getContainerIpAddress()) .put("port", mysql.getMappedPort(3306)) .put("database", MYSQL_DATABASE) .put("username", MYSQL_USERNAME) .put("password", MYSQL_PASSWORD))); }
@Before public void init() { mysql.start(); client = MySQLClient.createNonShared(vertx, new JsonObject() .put("host", mysql.getContainerIpAddress()) .put("port", mysql.getMappedPort(3306)) .put("database", MYSQL_DATABASE) .put("username", MYSQL_USERNAME) .put("password", MYSQL_PASSWORD)); clientNoDatabase = MySQLClient.createNonShared(vertx, new JsonObject() .put("host", "localhost") .put("port", 65000) .put("maxPoolSize", 2) ); }
@Before public void init() { mysql.start(); client = MySQLClient.createNonShared(vertx, new JsonObject() .put("host", mysql.getContainerIpAddress()) .put("port", mysql.getMappedPort(3306)) .put("database", MYSQL_DATABASE) .put("username", MYSQL_USERNAME) .put("password", MYSQL_PASSWORD)); clientNoDatabase = MySQLClient.createNonShared(vertx, new JsonObject() .put("host", "localhost") .put("port", 65000) .put("maxPoolSize", 2) ); }
@Before public void init() { mysql.start(); client = MySQLClient.createNonShared(vertx, new JsonObject() .put("host", mysql.getContainerIpAddress()) .put("port", mysql.getMappedPort(3306)) .put("database", MYSQL_DATABASE) .put("username", MYSQL_USERNAME) .put("password", MYSQL_PASSWORD)); clientNoDatabase = MySQLClient.createNonShared(vertx, new JsonObject() .put("host", "localhost") .put("port", 65000) .put("maxPoolSize", 2) ); }
@Test public void testConnection(TestContext context) { Vertx vertx = Vertx.vertx(); String host = System.getProperty("MySqlDataStoreContainer.host", null); if (host == null) { throw new ParameterRequiredException("you must set the property 'MySqlDataStoreContainer.host'"); } String username = System.getProperty("MySqlDataStoreContainer.username", null); if (username == null) { throw new ParameterRequiredException("you must set the property 'MySqlDataStoreContainer.username'"); } String password = System.getProperty("MySqlDataStoreContainer.password", null); if (password == null) { throw new ParameterRequiredException("you must set the property 'MySqlDataStoreContainer.password'"); } JsonObject mySQLClientConfig = new JsonObject().put("host", host).put("username", username) .put("password", password).put("database", "test").put("port", 3306); AsyncSQLClient client = MySQLClient.createNonShared(vertx, mySQLClientConfig); client.getConnection(res -> { if (res.succeeded()) { SQLConnection connection = res.result(); // Got a connection LOGGER.info("succeeded connection"); } else { LOGGER.error("", res.cause()); context.fail(res.cause()); } }); }
@Test public void testNonShared() { LocalMap<String, Object> map = getLocalMap(); JsonObject config = new JsonObject(); SQLClient client1 = MySQLClient.createNonShared(vertx, config); assertEquals(1, map.size()); SQLClient client2 = MySQLClient.createNonShared(vertx, config); assertEquals(2, map.size()); SQLClient client3 = MySQLClient.createNonShared(vertx, config); assertEquals(3, map.size()); client1.close(); assertEquals(2, map.size()); client2.close(); assertEquals(1, map.size()); client3.close(); assertEquals(0, map.size()); assertWaitUntil(() -> getLocalMap().size() == 0); assertWaitUntil(() -> map != getLocalMap()); // Map has been closed }
@Test public void testNonShared() { LocalMap<String, Object> map = getLocalMap(); JsonObject config = new JsonObject(); SQLClient client1 = MySQLClient.createNonShared(vertx, config); assertEquals(1, map.size()); SQLClient client2 = MySQLClient.createNonShared(vertx, config); assertEquals(2, map.size()); SQLClient client3 = MySQLClient.createNonShared(vertx, config); assertEquals(3, map.size()); client1.close(); assertEquals(2, map.size()); client2.close(); assertEquals(1, map.size()); client3.close(); assertEquals(0, map.size()); assertWaitUntil(() -> getLocalMap().size() == 0); assertWaitUntil(() -> map != getLocalMap()); // Map has been closed }
@Test public void testNonShared() { LocalMap<String, Object> map = getLocalMap(); JsonObject config = new JsonObject(); SQLClient client1 = MySQLClient.createNonShared(vertx, config); assertEquals(1, map.size()); SQLClient client2 = MySQLClient.createNonShared(vertx, config); assertEquals(2, map.size()); SQLClient client3 = MySQLClient.createNonShared(vertx, config); assertEquals(3, map.size()); client1.close(); assertEquals(2, map.size()); client2.close(); assertEquals(1, map.size()); client3.close(); assertEquals(0, map.size()); assertWaitUntil(() -> getLocalMap().size() == 0); assertWaitUntil(() -> map != getLocalMap()); // Map has been closed }