use of io.vertx.sqlclient.Row in project raml-module-builder by folio-org.
the class PostgresClientIT method maxPoolSize.
/**
* Each connection runs pg_sleep(1) that takes 1 second.
* Setting maxPoolSize=90 runs them in parallel so that it
* completes within 5 seconds.
*
* <p>If you want to test with a higher maxPoolSize you
* need to increase max_connections so that maxPoolSize is within
* (max_connections - superuser_reserved_connections):
* <a href="https://www.postgresql.org/docs/current/runtime-config-connection.html">
* https://www.postgresql.org/docs/current/runtime-config-connection.html</a>
*/
// milliseconds
@Test(timeout = 5000)
public void maxPoolSize(TestContext context) {
int maxPoolSize = 90;
postgresClient = createA(context, TENANT);
JsonObject configuration = postgresClient.getConnectionConfig().copy().put("maxPoolSize", maxPoolSize);
postgresClient.setClient(PostgresClient.createPgPool(vertx, configuration));
List<Future> futures = new ArrayList<>();
for (int i = 0; i < maxPoolSize; i++) {
futures.add(Future.<RowSet<Row>>future(promise -> postgresClient.execute("SELECT pg_sleep(1)", promise)));
}
CompositeFuture.all(futures).onComplete(context.asyncAssertSuccess());
}
use of io.vertx.sqlclient.Row in project raml-module-builder by folio-org.
the class PostgresClientIT method saveBatchJson.
@Test
public void saveBatchJson(TestContext context) {
String id = randomUuid();
JsonArray array = new JsonArray().add("{ \"x\" : \"a\" }").add("{ \"y\" : \"z\", \"id\": \"" + id + "\" }").add("{ \"z\" : \"'\" }");
createFoo(context).saveBatch(FOO, array, context.asyncAssertSuccess(res -> {
// iterate over all RowSets in batch result to get total count
RowSet<Row> resCurrent = res;
int total = 0;
while (resCurrent != null) {
total += resCurrent.size();
resCurrent = resCurrent.next();
}
context.assertEquals(3, total);
context.assertEquals("id", res.columnsNames().get(0));
// second set
Row row = res.next().iterator().next();
context.assertEquals(id, row.getValue("id").toString());
postgresClient.getById(FOO, id, context.asyncAssertSuccess(get -> {
context.assertEquals("z", get.getString("y"));
}));
}));
}
use of io.vertx.sqlclient.Row in project raml-module-builder by folio-org.
the class PostgresClientIT method selectReturnEmptySet.
@Test
public void selectReturnEmptySet(TestContext context) {
RowSet rowSet = new LocalRowSet(0);
Promise<RowSet<Row>> promise = Promise.promise();
promise.complete(rowSet);
PostgresClient.selectReturn(promise.future(), context.asyncAssertSuccess(res -> context.assertEquals(null, res)));
}
use of io.vertx.sqlclient.Row in project raml-module-builder by folio-org.
the class PostgresClientIT method postgresClientQueryFails.
/**
* @return a PostgresClient where invoking SQLConnection::update, SQLConnection::updateWithParams or
* SQLConnection::queryWithParams will report a failure via the resultHandler.
*/
private PostgresClient postgresClientQueryFails() {
PgConnection pgConnection = new PgConnection() {
@Override
public PgConnection notificationHandler(Handler<PgNotification> handler) {
return this;
}
@Override
public PgConnection cancelRequest(Handler<AsyncResult<Void>> handler) {
handler.handle(Future.failedFuture("cancelRequestFails"));
return this;
}
@Override
public int processId() {
return 0;
}
@Override
public int secretKey() {
return 0;
}
@Override
public PgConnection prepare(String s, Handler<AsyncResult<PreparedStatement>> handler) {
prepare(s).onComplete(handler);
return null;
}
@Override
public Future<PreparedStatement> prepare(String s) {
return Future.failedFuture("preparedFails");
}
@Override
public SqlConnection prepare(String sql, PrepareOptions options, Handler<AsyncResult<PreparedStatement>> handler) {
prepare(sql, options).onComplete(handler);
return null;
}
@Override
public Future<PreparedStatement> prepare(String sql, PrepareOptions options) {
return prepare(sql);
}
@Override
public PgConnection exceptionHandler(Handler<Throwable> handler) {
return null;
}
@Override
public PgConnection closeHandler(Handler<Void> handler) {
return null;
}
@Override
public void begin(Handler<AsyncResult<Transaction>> handler) {
}
@Override
public Future<Transaction> begin() {
return null;
}
@Override
public boolean isSSL() {
return false;
}
@Override
public void close(Handler<AsyncResult<Void>> handler) {
}
@Override
public Query<RowSet<Row>> query(String s) {
return new Query<RowSet<Row>>() {
@Override
public void execute(Handler<AsyncResult<RowSet<Row>>> handler) {
handler.handle(execute());
}
@Override
public Future<RowSet<Row>> execute() {
return Future.failedFuture("queryFails");
}
@Override
public <R> Query<SqlResult<R>> collecting(Collector<Row, ?, R> collector) {
return null;
}
@Override
public <U> Query<RowSet<U>> mapping(Function<Row, U> function) {
return null;
}
};
}
@Override
public PreparedQuery<RowSet<Row>> preparedQuery(String sql, PrepareOptions options) {
return preparedQuery(sql);
}
@Override
public PreparedQuery<RowSet<Row>> preparedQuery(String s) {
throw new RuntimeException("queryFails");
}
@Override
public Future<Void> close() {
return null;
}
@Override
public DatabaseMetadata databaseMetadata() {
return null;
}
};
PgPool client = new PgPoolBase() {
@Override
public Future<SqlConnection> getConnection() {
return Future.succeededFuture(pgConnection);
}
};
try {
PostgresClient postgresClient = new PostgresClient(vertx, TENANT);
postgresClient.setClient(client);
return postgresClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.vertx.sqlclient.Row in project raml-module-builder by folio-org.
the class PostgresClientTest method getMockTestJsonbPojoResultSet.
private RowSet<Row> getMockTestJsonbPojoResultSet(int total) {
List<String> columnNames = new ArrayList<String>(Arrays.asList(new String[] { "jsonb" }));
RowDesc rowDesc = new RowDesc(columnNames);
List<String> baz = new ArrayList<String>(Arrays.asList(new String[] { "This", "is", "a", "test" }));
List<Row> rows = new LinkedList<>();
for (int i = 0; i < total; i++) {
Row row = new RowImpl(rowDesc);
row.addValue(new JsonObject().put("id", UUID.randomUUID().toString()).put("foo", "foo " + i).put("bar", "bar " + i).put("biz", (double) i).put("baz", baz));
rows.add(row);
}
return new LocalRowSet(total).withColumns(columnNames).withRows(rows);
}
Aggregations