use of io.vertx.ext.unit.junit.Repeat in project vertx-sql-client by eclipse-vertx.
the class MSSQLQueriesTest method testQueryCurrentTimestamp.
@Test
@Repeat(50)
public void testQueryCurrentTimestamp(TestContext ctx) {
LocalDateTime start = LocalDateTime.now();
connection.query("SELECT current_timestamp").execute(ctx.asyncAssertSuccess(rs -> {
Object value = rs.iterator().next().getValue(0);
ctx.assertTrue(value instanceof LocalDateTime);
LocalDateTime localDateTime = (LocalDateTime) value;
ctx.assertTrue(Math.abs(localDateTime.until(start, ChronoUnit.SECONDS)) < 1);
}));
}
use of io.vertx.ext.unit.junit.Repeat in project vertx-sql-client by eclipse-vertx.
the class PgPoolTest method testNoConnectionLeaks.
@Test
@Repeat(50)
public void testNoConnectionLeaks(TestContext ctx) {
Async killConnections = ctx.async();
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
Collector<Row, ?, List<Integer>> collector = mapping(row -> row.getInteger(0), toList());
String sql = "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = $1";
PreparedQuery<SqlResult<List<Integer>>> preparedQuery = conn.preparedQuery(sql).collecting(collector);
Tuple params = Tuple.of(options.getDatabase());
preparedQuery.execute(params).compose(cf -> conn.close()).onComplete(ctx.asyncAssertSuccess(v -> killConnections.complete()));
}));
killConnections.awaitSuccess();
String sql = "SELECT pg_backend_pid() AS pid, (SELECT count(*) FROM pg_stat_activity WHERE application_name LIKE '%vertx%') AS cnt";
int idleTimeout = 50;
poolOptions.setMaxSize(1).setIdleTimeout(idleTimeout).setIdleTimeoutUnit(TimeUnit.MILLISECONDS).setPoolCleanerPeriod(5);
PgPool pool = createPool(options, poolOptions);
Async async = ctx.async();
AtomicInteger pid = new AtomicInteger();
vertx.getOrCreateContext().runOnContext(v -> {
pool.query(sql).execute(ctx.asyncAssertSuccess(rs1 -> {
Row row1 = rs1.iterator().next();
pid.set(row1.getInteger("pid"));
ctx.assertEquals(1, row1.getInteger("cnt"));
vertx.setTimer(2 * idleTimeout, l -> {
pool.query(sql).execute(ctx.asyncAssertSuccess(rs2 -> {
Row row2 = rs2.iterator().next();
ctx.assertEquals(1, row2.getInteger("cnt"));
ctx.assertNotEquals(pid.get(), row2.getInteger("pid"));
async.complete();
}));
});
}));
});
async.awaitSuccess();
}
use of io.vertx.ext.unit.junit.Repeat in project vertx-sql-client by eclipse-vertx.
the class MySQLPoolTest method testNoConnectionLeaks.
@Test
@Repeat(50)
public void testNoConnectionLeaks(TestContext ctx) {
Tuple params = Tuple.of(options.getUser(), options.getDatabase());
Async killConnections = ctx.async();
MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
String sql = "SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE ID <> CONNECTION_ID() AND User = ? AND db = ?";
Collector<Row, ?, List<Integer>> collector = mapping(row -> row.getInteger(0), toList());
conn.preparedQuery(sql).collecting(collector).execute(params, ctx.asyncAssertSuccess(ids -> {
CompositeFuture killAll = ids.value().stream().<Future>map(connId -> conn.query("KILL " + connId).execute()).collect(Collectors.collectingAndThen(toList(), CompositeFuture::all));
killAll.compose(cf -> conn.close()).onComplete(ctx.asyncAssertSuccess(v -> killConnections.complete()));
}));
}));
killConnections.awaitSuccess();
String sql = "SELECT CONNECTION_ID() AS cid, (SELECT count(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE User = ? AND db = ?) AS cnt";
int idleTimeout = 50;
PoolOptions poolOptions = new PoolOptions().setMaxSize(1).setIdleTimeout(idleTimeout).setIdleTimeoutUnit(TimeUnit.MILLISECONDS).setPoolCleanerPeriod(5);
pool = MySQLPool.pool(options, poolOptions);
Async async = ctx.async();
AtomicInteger cid = new AtomicInteger();
vertx.getOrCreateContext().runOnContext(v -> {
pool.preparedQuery(sql).execute(params, ctx.asyncAssertSuccess(rs1 -> {
Row row1 = rs1.iterator().next();
cid.set(row1.getInteger("cid"));
ctx.assertEquals(1, row1.getInteger("cnt"));
vertx.setTimer(2 * idleTimeout, l -> {
pool.preparedQuery(sql).execute(params, ctx.asyncAssertSuccess(rs2 -> {
Row row2 = rs2.iterator().next();
ctx.assertEquals(1, row2.getInteger("cnt"));
ctx.assertNotEquals(cid.get(), row2.getInteger("cid"));
async.complete();
}));
});
}));
});
async.awaitSuccess();
}
Aggregations