Skip to content

close the connection after the execution #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ private <T> void executeDirect(Function<SQLConnection, Future<T>> action, Handle
} catch (Throwable e) {
future = Future.failedFuture(e);
}
future.setHandler(handler);
future.setHandler(asyncResult -> conn.close(close -> {
if (close.failed()) {
handler.handle(Future.failedFuture(close.cause()));
} else {
handler.handle(asyncResult);
}
}));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.github.jasync.sql.db.exceptions.InsufficientParametersException;
import io.vertx.ext.asyncsql.category.NeedsDocker;
import io.vertx.ext.sql.SQLClient;
import org.junit.*;

import io.vertx.core.AsyncResult;
Expand Down Expand Up @@ -129,6 +130,22 @@ public void test(TestContext context){
});
}

public void testCloseAfterClientExecute(TestContext context){
Async async = context.async();
SQLClient mysqlClient = 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)
.put("maxPoolSize", 1));// one connection for two execution
mysqlClient.query("select 1;", r -> {
mysqlClient.query("select 1;", r2 -> {
async.complete();
});
});
}

@Override
protected void compareInstantStrings(TestContext context, String result, String expected) {
// mysql will perform some rounding since it does not have the precision to store the full TS
Expand Down